OrderedDictionary.st
author Claus Gittinger <cg@exept.de>
Sat, 08 Mar 2008 11:53:23 +0100
changeset 1932 7bafb4c076d3
parent 1920 fca37db26ef3
child 2011 3c38085cdaff
permissions -rw-r--r--
also show \"what-would-be-done\" in redo item
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     1
"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     2
 COPYRIGHT.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     3
 This is a Manchester Goodie protected by copyright.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     4
 These conditions are imposed on the whole Goodie, and on any significant
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     5
 part of it which is separately transmitted or stored:
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     6
	* You must ensure that every copy includes this notice, and that
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     7
	  source and author(s) of the material are acknowledged.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     8
	* These conditions must be imposed on anyone who receives a copy.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
     9
	* The material shall not be used for commercial gain without the prior
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    10
	  written consent of the author(s).
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    11
 Further information on the copyright conditions may be obtained by
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    12
 sending electronic mail:
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    13
	To: goodies-lib@cs.man.ac.uk
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    14
	Subject: copyright
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    15
 or by writing to The Smalltalk Goodies Library Manager, Dept of
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    16
 Computer Science, The University, Manchester M13 9PL, UK
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
    17
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    18
 (C) Copyright 1992 University of Manchester
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    19
 For more information about the Manchester Goodies Library (from which 
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    20
 this file was distributed) send e-mail:
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    21
	To: goodies-lib@cs.man.ac.uk
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    22
	Subject: help 
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    23
"
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
    24
"{ Package: 'stx:libbasic2' }"
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
    25
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    26
Dictionary subclass:#OrderedDictionary
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    27
	instanceVariableNames:'order'
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    28
	classVariableNames:''
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    29
	poolDictionaries:''
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    30
	category:'Collections-Sequenceable'
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
    31
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
    32
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
    33
!OrderedDictionary class methodsFor:'documentation'!
498
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    34
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    35
copyright
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    36
"
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    37
 COPYRIGHT.
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    38
 This is a Manchester Goodie protected by copyright.
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    39
 These conditions are imposed on the whole Goodie, and on any significant
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    40
 part of it which is separately transmitted or stored:
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    41
	* You must ensure that every copy includes this notice, and that
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    42
	  source and author(s) of the material are acknowledged.
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    43
	* These conditions must be imposed on anyone who receives a copy.
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    44
	* The material shall not be used for commercial gain without the prior
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    45
	  written consent of the author(s).
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    46
 Further information on the copyright conditions may be obtained by
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    47
 sending electronic mail:
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    48
	To: goodies-lib@cs.man.ac.uk
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    49
	Subject: copyright
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    50
 or by writing to The Smalltalk Goodies Library Manager, Dept of
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    51
 Computer Science, The University, Manchester M13 9PL, UK
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    52
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    53
 (C) Copyright 1992 University of Manchester
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    54
 For more information about the Manchester Goodies Library (from which 
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    55
 this file was distributed) send e-mail:
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    56
	To: goodies-lib@cs.man.ac.uk
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    57
	Subject: help 
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    58
"
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    59
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
    60
498
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    61
documentation
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    62
"
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    63
    I am a subclass of Dictionary whose elements (associations) are ordered in a
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    64
    similar fashion to OrderedCollection.
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    65
    That is, while being filled via #at:put: messages (or similar Dictionary protocol),
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    66
    the order in which associations are added is remembered and accessable via the #atIndex:
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    67
    or #order messages.
498
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    68
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    69
    I have one instance variable:
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    70
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    71
    order <OrderedCollection>       Ordered collection of keys reflecting the order of
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    72
                                    associations in the dictionary.
498
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    73
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    74
    [author:]
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    75
        Ifor Wyn Williams <ifor@uk.ac.man.cs>
498
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    76
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
    77
    [see also:]
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    78
        OrderedCollection Dictionary
1581
201be7d15ef0 *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 1571
diff changeset
    79
        OrderedSet
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    80
"
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    81
!
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    82
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    83
examples
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    84
"
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    85
    |o|
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    86
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    87
    o := OrderedDictionary new.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    88
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    89
    o at:'one'   put:1.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    90
    o at:'two'   put:2.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    91
    o at:'three' put:3.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    92
    o at:'four'  put:4.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    93
    o at:'five'  put:5.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    94
    o at:'six'   put:6.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    95
    o at:'seven' put:7.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    96
    o at:'eight' put:8.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    97
    o at:'nine'  put:9.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    98
    o at:'zero'  put:0.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
    99
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   100
    o at:'eight'.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   101
    o atIndex:1.   
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   102
    o atIndex:5.    
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   103
    o atIndex:10.  
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   104
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   105
    o from:3 to:6 do:[:each | Transcript showCR:each ].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   106
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   107
    o collect:[:eachAssoc | eachAssoc key -> eachAssoc value squared]. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   108
    o associations.  
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   109
    o order.         
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   110
    o reverse.    
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   111
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   112
    o atIndex:1.  
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   113
    o atIndex:5. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   114
    o atIndex:10. 
498
90e67ae0c062 tuned #at:put:
Claus Gittinger <cg@exept.de>
parents: 497
diff changeset
   115
"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   116
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   117
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   118
info
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   119
"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   120
	NAME            OrderedDictionary
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   121
	AUTHOR          Ifor Wyn Williams <ifor@uk.ac.man.cs>
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   122
	CONTRIBUTOR     Ifor Wyn Williams <ifor@uk.ac.man.cs>
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   123
	FUNCTION        An ordered dictionary
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   124
	ST-VERSIONS     2.3-5, 4.0
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   125
	PREREQUISITES   
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   126
	CONFLICTS       
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   127
	DISTRIBUTION    global
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   128
	VERSION         1.2
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   129
	DATE            28.3.90
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   130
	SUMMARY         A dictionary that behaves like a SequencableCollection
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   131
			(except that associations cannot be removed). 
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   132
"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   133
! !
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   134
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   135
!OrderedDictionary class methodsFor:'instance creation'!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   136
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   137
new
1571
fa44f16fd6cd proper #initialize
Claus Gittinger <cg@exept.de>
parents: 1444
diff changeset
   138
        ^ super new initializeOrder
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   139
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   140
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   141
new: anInteger
1571
fa44f16fd6cd proper #initialize
Claus Gittinger <cg@exept.de>
parents: 1444
diff changeset
   142
        ^(super new: anInteger) initializeOrder
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   143
! !
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   144
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   145
!OrderedDictionary methodsFor:'accessing'!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   146
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   147
after: anAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   148
    "Return the association after anAssociation in the order. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   149
     If anAssociation is the last association in the order, return nil. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   150
     If anAssociation is not found, invoke an error notifier"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   151
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   152
    1 to: order size - 1 do: [:index | (self associationAt: (order at: index))
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   153
                    = anAssociation ifTrue: [^self associationAt: (order at: index + 1)]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   154
    (self associationAt: (order last))
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   155
            = anAssociation
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   156
            ifTrue: [^nil]
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   157
            ifFalse: [^self error: 'not found']
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   158
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   159
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   160
associations
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   161
    "Return an OrderedCollection containing the receiver's associations."
497
1337168140ae added #addAllAssociations: , #addAllAssociationsFirst: and #addAllAssociationsLast:
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   162
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   163
    ^ order collect: [:key | self associationAt: key ].
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   164
!
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   165
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   166
at:aKey ifAbsentPut:valueBlock
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   167
    |val|
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   168
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   169
    ^ self at:aKey ifAbsent:[ self at:aKey put:valueBlock value ]
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   170
!
497
1337168140ae added #addAllAssociations: , #addAllAssociationsFirst: and #addAllAssociationsLast:
Claus Gittinger <cg@exept.de>
parents: 457
diff changeset
   171
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   172
at: key put: anObject 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   173
    "Set the value at key to be anObject. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   174
     If key is not found, create a new entry for key and set is value to anObject. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   175
     If key is already present, the order remains unchanged.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   176
     Return anObject."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   177
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   178
    "/ claus: super can check this much faster ...
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   179
    "/ (super includesKey:key)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   180
    "/ ... but that leads to trouble in add:* methods. (sigh)
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   181
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   182
    (order includes: key)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   183
            ifFalse: [order add: key].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   184
    ^ super at: key put: anObject
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   185
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   186
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   187
atAll:indexCollection put: anObject 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   188
    "Put anObject into the value field of every association specified by indexCollection,
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   189
     which is typically an interval."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   190
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   191
    indexCollection do:[:index | self at:(order at: index) put:anObject]
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   192
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   193
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   194
atAllPut: anObject 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   195
    "Put anObject into the value field of every association in the dictionary"
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   196
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   197
    order do: [:key | self at: key put: anObject]
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   198
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   199
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   200
atIndex:index
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   201
    "return an element at a given index"
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   202
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   203
    ^ self at:(order at:index)
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   204
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   205
    "Created: 28.9.1995 / 13:49:39 / stefan"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   206
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   207
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   208
atIndex:index put:anAssociation
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   209
    "put an association to a given index. remove the old associatioan at this index"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   210
    |key|
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   211
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   212
    key := anAssociation key.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   213
    (super includesKey:key) ifTrue:[
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   214
        ^ self error:'duplicate key'.
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   215
    ].
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   216
    super removeKey:(order at:index) ifAbsent:[].
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   217
    order at:index put:key.
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   218
    ^ super add:anAssociation.
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   219
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   220
    "Created: 28.9.1995 / 16:30:15 / stefan"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   221
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   222
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   223
before: anAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   224
    "Return the association before anAssociation in the order. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   225
     If anAssociation is the first association in the order, return nil. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   226
     If anAssociation is not found, invoke an error notifier"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   227
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   228
    2 to:order size do:[:index | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   229
        (self associationAt:(order at:index)) = anAssociation 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   230
            ifTrue:[ ^ self associationAt:(order at:index - 1)] 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   231
    ].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   232
    (self associationAt:order first) = anAssociation ifTrue: [^ nil].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   233
    ^ self error: 'not found'
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   234
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   235
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   236
first
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   237
    "Return the first association of the receiver.  
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   238
     Provide an error notification if the receiver contains no elements."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   239
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   240
    order emptyCheck.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   241
    ^ self associationAt: (order first)
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   242
!
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   243
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   244
keyAt:index
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   245
    "get the key at the given index"
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   246
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   247
    ^ order at:index.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   248
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   249
    "Created: 29.9.1995 / 11:32:07 / stefan"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   250
!
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   251
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   252
keys
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   253
    "Return a OrderedCollection containing the receiver's keys."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   254
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   255
    ^ order copy.
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   256
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   257
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   258
last
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   259
    "Return the last association of the receiver. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   260
     Provide an error notification if the receiver contains no elements."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   261
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   262
    order emptyCheck.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   263
    ^ self associationAt: (order last)
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   264
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   265
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   266
order
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   267
    "returns the values in the order of their appearance"
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   268
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   269
    ^ order
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   270
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   271
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   272
values
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   273
    "Return a OrderedCollection containing the receiver's values."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   274
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   275
    ^ order collect: [:key | (self at: key) ].
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   276
! !
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   277
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   278
!OrderedDictionary methodsFor:'adding'!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   279
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   280
add: anAssociation 
1917
61c602336f3d Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents: 1589
diff changeset
   281
      "add anAssociation to the dictionary. 
61c602336f3d Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents: 1589
diff changeset
   282
       If anAssociation is already present in the dictionary,
61c602336f3d Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents: 1589
diff changeset
   283
       the order will not be changed. (See also: #addLast:)"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   284
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   285
      | key |
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   286
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   287
      key := anAssociation key.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   288
      (super includesKey: key)
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   289
              ifFalse: [order add: key].
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   290
      ^ super add: anAssociation
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   291
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   292
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   293
add: anAssociation after: oldAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   294
    "Add the argument, anAssociation, as an element of the dictionary. Put it 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   295
    in the position just succeeding oldAssociation. Return anAssociation."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   296
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   297
    | index |
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   298
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   299
    index := self indexOfAssociation: oldAssociation 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   300
                            ifAbsent: [self error: 'association not found'].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   301
    self removeFromOrder: anAssociation key.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   302
    order add: anAssociation key after: (order at: index).
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   303
    super add: anAssociation.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   304
    ^ anAssociation
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   305
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   306
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   307
add: anAssociation before: oldAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   308
    "Add the argument, anAssociation, as an element of the dictionary. Put it 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   309
    in the position just preceding oldAssociation. Return anAssociation."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   310
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   311
    | index |
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   312
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   313
    index := self indexOfAssociation: oldAssociation 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   314
                            ifAbsent: [self error: 'association not found'].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   315
    self removeFromOrder: anAssociation key.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   316
    order add: anAssociation key before: (order at: index).
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   317
    super add: anAssociation.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   318
    ^ anAssociation
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   319
!
504
df82d5a5de53 undone last change - all add: methods have trouble with that....
Claus Gittinger <cg@exept.de>
parents: 503
diff changeset
   320
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   321
add: anAssociation beforeIndex: spot 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   322
    "Add the argument, anAssociation, as an element of the receiver.  Put it
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   323
    in the position just preceding the indexed position spot.  Return newObject."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   324
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   325
    self removeFromOrder: anAssociation key.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   326
    order add: anAssociation key beforeIndex: spot.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   327
    ^ super add: anAssociation
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   328
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   329
    "Modified: 28.9.1995 / 14:06:53 / stefan"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   330
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   331
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   332
addAll:aCollectionOfAssociations 
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   333
    "Add each element of anOrderedCollectionOfAssociations at my end. 
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   334
     We expect the argument to enumerate associations with #reverseDo:; 
1348
c70abbed0c65 comment
Claus Gittinger <cg@exept.de>
parents: 1242
diff changeset
   335
     if it does not (i.e. it is another OD or a dictionary), use #addAllAssociationsFirst:.
c70abbed0c65 comment
Claus Gittinger <cg@exept.de>
parents: 1242
diff changeset
   336
     Returns the argument, aCollectionOfAssociations (sigh)."
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   337
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   338
    self addAllLast:aCollectionOfAssociations.
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   339
    ^ aCollectionOfAssociations
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   340
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   341
    "Modified: 28.2.1997 / 15:51:23 / cg"
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   342
!
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   343
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   344
addAllAssociations:aDictionaryOrOrderedDictionary
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   345
    "Add each association of aDictionaryOrOrderedDictionary to my end.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   346
     We expect the argument to respond to #associationsDo:."
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   347
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   348
    self addAllAssociationsLast:aDictionaryOrOrderedDictionary.
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   349
    ^ aDictionaryOrOrderedDictionary
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   350
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   351
    "Created: 28.2.1997 / 15:52:02 / cg"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   352
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   353
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   354
addAllAssociationsFirst:aDictionaryOrOrderedDictionary
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   355
    "Add each association of aDictionaryOrOrderedDictionary at the beginning of the 
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   356
     receiver. We expect the argument to respond to #associationsReverseDo:."
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   357
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   358
    aDictionaryOrOrderedDictionary associationsReverseDo:[:each | self addFirst:each].
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   359
    ^ aDictionaryOrOrderedDictionary
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   360
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   361
    "Created: 28.2.1997 / 15:50:14 / cg"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   362
!
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   363
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   364
addAllAssociationsLast:aDictionaryOrOrderedDictionary
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   365
    "Add each association of aDictionaryOrOrderedDictionary at the end of the 
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   366
     receiver. We expect the argument to respond to #associationsDo:."
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   367
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   368
    aDictionaryOrOrderedDictionary associationsDo:[:each | self addLast:each].
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   369
    ^ aDictionaryOrOrderedDictionary
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   370
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   371
    "Created: 28.2.1997 / 15:48:37 / cg"
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   372
!
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   373
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   374
addFirst: anAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   375
    "Add anAssociation to the beginning of the receiver."
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   376
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   377
    self removeFromOrder: anAssociation key.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   378
    order addFirst: anAssociation key.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   379
    ^ super add: anAssociation.
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   380
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   381
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   382
addLast: anAssociation 
1917
61c602336f3d Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents: 1589
diff changeset
   383
    "Add anAssociation to the end of the receiver.
61c602336f3d Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents: 1589
diff changeset
   384
     If anAssociation is already present in the dictionary,
61c602336f3d Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents: 1589
diff changeset
   385
     it will be moved to the end. (See also: #add:)"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   386
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   387
    self removeFromOrder: anAssociation key.
1917
61c602336f3d Clean up code and document differences between #add: and #addLast:
Stefan Vogel <sv@exept.de>
parents: 1589
diff changeset
   388
    order add: anAssociation key.
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   389
    ^ super add: anAssociation.
838
9454fd75930e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   390
! !
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   391
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   392
!OrderedDictionary methodsFor:'copying'!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   393
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   394
copyEmpty
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   395
    "Return a copy of the receiver that contains no elements."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   396
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   397
    ^ (self class) new: 10
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   398
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   399
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   400
copyEmpty: aSize
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   401
    "Return a copy of the receiver that contains no elements."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   402
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   403
    ^ (self class) new: aSize
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   404
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   405
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   406
copyFrom: startIndex to: endIndex 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   407
    "Return a copy of the receiver that contains elements from 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   408
     position startIndex to endIndex."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   409
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   410
    | newDict |
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   411
    endIndex < startIndex ifTrue: [^self copyEmpty].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   412
    (startIndex < 1 or: [endIndex > order size])
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   413
            ifTrue: [^self error: 'No such element'].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   414
    newDict := self copyEmpty: endIndex - startIndex + 1.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   415
    startIndex to: endIndex do: [:index | newDict add: (self associationAt: (order at: index))].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   416
    ^ newDict
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   417
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   418
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   419
copyWith: anAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   420
    "Return a copy of the dictionary that is 1 bigger than the receiver and 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   421
     includes the argument, anAssociation, at the end."
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   422
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   423
    | newDict |
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   424
    newDict := self copy.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   425
    newDict add: anAssociation.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   426
    ^ newDict
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   427
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   428
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   429
copyWithout: anAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   430
    "Return a copy of the dictionary that is 1 smaller than the receiver and 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   431
     does not include the argument, anAssociation"
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   432
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   433
    | newDict |
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   434
    newDict := OrderedDictionary new: order size - 1.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   435
    self associationsDo: [:assoc | anAssociation = assoc ifFalse: [newDict add: assoc]]
1920
fca37db26ef3 fixed copy: must copy the order too (otherwise, its shared)
sr
parents: 1917
diff changeset
   436
!
fca37db26ef3 fixed copy: must copy the order too (otherwise, its shared)
sr
parents: 1917
diff changeset
   437
fca37db26ef3 fixed copy: must copy the order too (otherwise, its shared)
sr
parents: 1917
diff changeset
   438
postCopy
fca37db26ef3 fixed copy: must copy the order too (otherwise, its shared)
sr
parents: 1917
diff changeset
   439
    "have to copy the order too"
fca37db26ef3 fixed copy: must copy the order too (otherwise, its shared)
sr
parents: 1917
diff changeset
   440
fca37db26ef3 fixed copy: must copy the order too (otherwise, its shared)
sr
parents: 1917
diff changeset
   441
    super postCopy.
fca37db26ef3 fixed copy: must copy the order too (otherwise, its shared)
sr
parents: 1917
diff changeset
   442
    order := order copy
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   443
! !
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   444
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   445
!OrderedDictionary methodsFor:'enumerating'!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   446
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   447
associationsCollect: aBlock 
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   448
    "Evaluate aBlock with each of the associations of the dictionary as argument,
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   449
     and return a new (ordered) collection with the results"
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   450
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   451
    ^ order collect:[:key | (aBlock value: (self associationAt:key))].
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   452
!
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   453
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   454
associationsDo: aBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   455
    "Evaluate aBlock for each of the dictionary's associations."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   456
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   457
    order do: [:key | aBlock value: (self associationAt: key)]
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   458
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   459
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   460
associationsDo: aBlock from: firstIndex to: secondIndex 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   461
    "Evaluate aBlock with each of the dictionary's associations from index 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   462
    firstIndex to index secondIndex as the argument."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   463
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   464
    firstIndex to: secondIndex do: [:index | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   465
        aBlock value: (self associationAt: (order at: index))
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   466
    ]
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   467
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   468
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   469
associationsReverseDo: aBlock 
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   470
    "Evaluate aBlock for each of the dictionary's associations in reverse order."
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   471
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   472
    order reverseDo:[:key | aBlock value:(self associationAt:key)]
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   473
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   474
    "Created: 28.2.1997 / 15:52:31 / cg"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   475
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   476
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   477
associationsSelect:aBlock 
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   478
    "Evaluate aBlock with each of the dictionary's associations as the argument.
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   479
     Collect into a new OrderedDictionary only those associations for which 
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   480
     aBlock evaluates to true. Return the new OrderedDictionary."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   481
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   482
    |newDict|
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   483
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   484
    newDict := OrderedDictionary new.
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   485
    order do:[:key | 
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   486
        |assoc|
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   487
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   488
        assoc := self associationAt:key.
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   489
        (aBlock value:assoc) ifTrue: [
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   490
            newDict add:assoc
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   491
        ]
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   492
    ].
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   493
    ^ newDict
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   494
!
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   495
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   496
collect: aBlock 
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   497
    "Evaluate aBlock with each of the values of the dictionary as argument,
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   498
     and return a new (ordered) collection with the results"
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   499
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   500
    ^ order collect:[:key | (aBlock value: (self at:key))].
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   501
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   502
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   503
do: aBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   504
    "Evaluate aBlock for each of the dictionary's values."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   505
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   506
    order do: [:key | aBlock value: (self at: key)]
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   507
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   508
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   509
do: aBlock from: firstIndex to: lastIndex 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   510
    "Evaluate aBlock with each of the dictionary's associations from index 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   511
    firstIndex to index secondIndex as the argument."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   512
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   513
    self from:firstIndex to:lastIndex do:aBlock.
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   514
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   515
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   516
findFirst: aBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   517
    "Return the index of the first association in the dictionary for which aBlock
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   518
    evaluates as true. If the block does not evaluate to true, return 0"
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   519
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   520
    1 to:order size do:[:index | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   521
        (aBlock value:(self associationAt:(order at:index))) ifTrue: [^ index]
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   522
    ].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   523
    ^ 0
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   524
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   525
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   526
findLast:aBlock 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   527
    "Return the index of the last association in the dictionary for which aBlock
1424
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   528
     evaluates as true. If the block does not evaluate to true, return 0"
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   529
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   530
    order size to:1 by:-1 do: [:index | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   531
        (aBlock value:(self associationAt:(order at:index))) ifTrue: [^ index]
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   532
    ].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   533
    ^ 0
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   534
!
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   535
1424
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   536
findLast:aBlock startingAt:startIndex
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   537
    "Return the index of the last association in the dictionary for which aBlock
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   538
     evaluates as true. Start the search at startIndex.
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   539
     If the block does not evaluate to true, return 0"
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   540
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   541
    startIndex to:1 by:-1 do: [:index | 
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   542
        (aBlock value:(self associationAt:(order at:index))) ifTrue: [^ index]
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   543
    ].
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   544
    ^ 0
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   545
!
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   546
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   547
findLast:aBlock startingAt:startIndex endingAt:endIndex
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   548
    "Return the index of the last association in the dictionary for which aBlock
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   549
     evaluates as true. Start the search at startIndex.
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   550
     End the search at endIndex or when an element is found.
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   551
     If the block does not evaluate to true, return 0"
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   552
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   553
    startIndex to:endIndex by:-1 do: [:index | 
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   554
        (aBlock value:(self associationAt:(order at:index))) ifTrue: [^ index]
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   555
    ].
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   556
    ^ 0
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   557
!
459c00460dc0 + findLast:startingAt:endingAt:
ca
parents: 1348
diff changeset
   558
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   559
from:firstIndex to:lastIndex do: aBlock
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   560
    "Evaluate aBlock with each of the dictionary's associations from index 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   561
    firstIndex to index secondIndex as the argument."
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   562
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   563
    order from:firstIndex to:lastIndex do:[:key |
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   564
        aBlock value: (self at:key)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   565
    ].
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   566
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   567
835
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   568
keysAndValuesDo:aBlock
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   569
    "perform the block for all keys in the collection.
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   570
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   571
     See also:
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   572
        #associationsDo:   (which passes key-value associations)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   573
        #keysAndValuesDo:  (which passes keys & values separately)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   574
        #do:               (which passes values only)
835
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   575
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   576
     WARNING: do not add/remove elements while iterating over the receiver.
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   577
              Iterate over a copy to do this."
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   578
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   579
    order do: [:key | aBlock value:key value:(self at: key)].
835
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   580
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   581
    "Modified: / 26.6.1999 / 10:55:30 / ps"
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   582
    "Created: / 15.10.1999 / 16:49:31 / cg"
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   583
    "Modified: / 15.10.1999 / 16:53:50 / cg"
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   584
!
180efa0787ce checkin from browser
Claus Gittinger <cg@exept.de>
parents: 775
diff changeset
   585
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   586
keysDo:aBlock
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   587
    "perform the block for all keys in the collection.
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   588
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   589
     See also:
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   590
        #associationsDo:   (which passes key-value associations)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   591
        #keysAndValuesDo:  (which passes keys & values separately)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   592
        #do:               (which passes values only)
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   593
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   594
     WARNING: do not add/remove elements while iterating over the receiver.
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   595
              Iterate over a copy to do this."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   596
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   597
    order do:[:key | aBlock value:key].
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   598
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   599
    "Created: / 26.6.1999 / 10:53:00 / ps"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   600
    "Modified: / 26.6.1999 / 10:55:30 / ps"
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   601
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   602
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   603
reverse
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   604
    "Destructively reverse my order.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   605
     WARNING: this is a destructive operation, which modifies the receiver."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   606
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   607
    order reverse
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   608
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   609
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   610
reverseDo: aBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   611
    "Evaluate aBlock with each of the dictionary's associations as the argument,
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   612
    starting with the last element and taking each in sequence up to the first."
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   613
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   614
    order size to:1 by:-1 do: [:index | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   615
        aBlock value:(self associationAt:(order at:index))
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   616
    ]
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   617
!
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   618
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   619
reversed
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   620
    "Return with a new OrderedDictionary with its associations in reverse order."
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   621
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   622
    | newDict|
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   623
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   624
    newDict := OrderedDictionary new.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   625
    order size to:1 by:-1 do:[:index | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   626
        |key|
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   627
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   628
        key := order at:index.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   629
        newDict at:key put:(self at:key)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   630
    ].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   631
    ^ newDict
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   632
!
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   633
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   634
select:aBlock 
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   635
    "Evaluate aBlock with each of the dictionary's values as the argument.
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   636
     Collect into a new OrderedDictionary only those associations for which 
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   637
     aBlock evaluated to true. Return the new OrderedDictionary."
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   638
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   639
    |newColl|
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   640
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   641
    newColl := self species new.
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   642
    order do:[:key | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   643
        |assoc|
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   644
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   645
        assoc := self associationAt:key.
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   646
        (aBlock value:(assoc value)) ifTrue: [
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   647
            newColl add:assoc
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   648
        ]
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   649
    ].
1589
f0607bf986e0 fixed collect/associationsCollect:
Claus Gittinger <cg@exept.de>
parents: 1581
diff changeset
   650
    ^ newColl
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   651
! !
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   652
1571
fa44f16fd6cd proper #initialize
Claus Gittinger <cg@exept.de>
parents: 1444
diff changeset
   653
!OrderedDictionary methodsFor:'initialization'!
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   654
1571
fa44f16fd6cd proper #initialize
Claus Gittinger <cg@exept.de>
parents: 1444
diff changeset
   655
initializeOrder
fa44f16fd6cd proper #initialize
Claus Gittinger <cg@exept.de>
parents: 1444
diff changeset
   656
        order := OrderedCollection new
fa44f16fd6cd proper #initialize
Claus Gittinger <cg@exept.de>
parents: 1444
diff changeset
   657
! !
fa44f16fd6cd proper #initialize
Claus Gittinger <cg@exept.de>
parents: 1444
diff changeset
   658
fa44f16fd6cd proper #initialize
Claus Gittinger <cg@exept.de>
parents: 1444
diff changeset
   659
!OrderedDictionary methodsFor:'private'!
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   660
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   661
removeFromOrder: aKey 
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   662
	order remove: aKey ifAbsent: []
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   663
! !
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   664
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   665
!OrderedDictionary methodsFor:'removing'!
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   666
775
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   667
removeFirst
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   668
    |key|
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   669
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   670
    order size == 0 ifTrue:[
838
9454fd75930e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   671
	"error if collection is empty"
775
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   672
838
9454fd75930e *** empty log message ***
Claus Gittinger <cg@exept.de>
parents: 835
diff changeset
   673
	^ self emptyCollectionError.
775
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   674
    ].
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   675
    key := order removeFirst.
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   676
    ^ super removeKey:key.
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   677
!
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   678
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   679
removeFromIndex:fromIndex toIndex:toIndex
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   680
    | keys |
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   681
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   682
    keys := order copyFrom:fromIndex to:toIndex.
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   683
    order removeFromIndex:fromIndex toIndex:toIndex.
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   684
    keys do:[ :key |
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   685
	super removeKey:key.
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   686
    ].
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   687
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   688
    "Created: 28.9.1995 / 12:04:33 / stefan"
775
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   689
!
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   690
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   691
removeKey:aKey
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   692
    order remove:aKey.
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   693
    ^ super removeKey:aKey.
1444
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   694
!
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   695
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   696
removeLast
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   697
    |key|
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   698
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   699
    order size == 0 ifTrue:[
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   700
	"error if collection is empty"
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   701
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   702
	^ self emptyCollectionError.
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   703
    ].
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   704
    key := order removeLast.
d84641232d2a +removeLast
werner
parents: 1424
diff changeset
   705
    ^ super removeKey:key.
120
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   706
! !
fa3590433788 New methods for SequencableCollection access.
Stefan Vogel <sv@exept.de>
parents: 67
diff changeset
   707
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   708
!OrderedDictionary methodsFor:'searching'!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   709
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   710
identityIndexOfAssociation: anAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   711
    "Return the identity index of anAssociation within the receiver. If the receiver
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   712
    does not contain anAssociation, return 0."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   713
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   714
    ^ self identityIndexOfAssociation: anAssociation ifAbsent: [0]
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   715
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   716
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   717
identityIndexOfAssociation: anAssociation ifAbsent: exceptionBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   718
    "Return the identity index of anAssociation within the receiver. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   719
     If the receiver does not contain anAssociation, 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   720
     return the result of evaluating the exceptionBlock."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   721
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   722
    "/ as ST/X's dictionaries do not store the associations 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   723
    "/ (instead, they store the keys and values in separate collections)
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   724
    "/ this will not work. You have to think about it and rewrite your code.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   725
    self error:'this does not work in Smalltalk/X'.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   726
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   727
    order keysAndValuesDo:[:i :key |
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   728
        (self associationAt:key) == anAssociation ifTrue: [^i]
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   729
    ].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   730
    ^exceptionBlock value
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   731
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   732
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   733
identityIndexOfKey: aKey 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   734
    "Return the identity index of aKey within the receiver. If the receiver 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   735
    does not contain aKey, return 0."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   736
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   737
    ^self identityIndexOfKey: aKey ifAbsent: [0]
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   738
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   739
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   740
identityIndexOfKey: aKey ifAbsent: exceptionBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   741
    "Return the identity index of aKey within the receiver.  If the receiver does
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   742
    not contain aKey, return the result of evaluating the exceptionBlock."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   743
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   744
    ^ order identityIndexOf:aKey ifAbsent:exceptionBlock
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   745
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   746
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   747
identityIndexOfValue: aValue 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   748
    "Return the identity index of aValue within the receiver. If the receiver 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   749
    does not contain aValue, return 0."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   750
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   751
    ^self identityIndexOfValue: aValue ifAbsent: [0]
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   752
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   753
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   754
identityIndexOfValue: aValue ifAbsent: exceptionBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   755
    "Return the identity index of aValue within the receiver. If the receiver 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   756
    does not contain aValue, return the result of evaluating the exceptionBlock."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   757
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   758
    order keysAndValuesDo:[:i :key | (self at:key) == aValue ifTrue: [^i]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   759
    ^exceptionBlock value
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   760
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   761
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   762
indexOfAssociation: anAssociation 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   763
    "Return the index of anAssociation within the receiver. If the receiver does
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   764
    not contain anAssociation, return 0."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   765
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   766
    ^self indexOfAssociation: anAssociation ifAbsent: [0]
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   767
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   768
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   769
indexOfAssociation: anAssociation ifAbsent: exceptionBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   770
    "Return the identity index of anAssociation within the receiver. If the receiver
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   771
    does not contain anAssociation, return the result of evaluating the exceptionBlock."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   772
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   773
    order keysAndValuesDo:[:i :key | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   774
        (self associationAt:key) = anAssociation ifTrue: [^i]
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   775
    ].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   776
    ^exceptionBlock value
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   777
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   778
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   779
indexOfKey: aKey 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   780
    "Return the index of aKey within the receiver. If the receiver does 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   781
     not contain aKey, return 0."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   782
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   783
    ^self indexOfKey: aKey ifAbsent: [0]
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   784
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   785
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   786
indexOfKey: aKey ifAbsent: exceptionBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   787
    "Return the identity index of aKey within the receiver.  If the receiver does
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   788
     not contain aKey, return the result of evaluating the exceptionBlock."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   789
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   790
    ^ order indexOf:aKey ifAbsent:exceptionBlock
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   791
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   792
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   793
indexOfValue: aValue 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   794
    "Return the index of aValue within the receiver. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   795
     If the receiver does not contain aValue, return 0."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   796
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   797
    ^self indexOfValue: aValue ifAbsent: [0]
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   798
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   799
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   800
indexOfValue: aValue ifAbsent: exceptionBlock 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   801
    "Return the identity index of aValue within the receiver. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   802
     If the receiver does not contain aValue, return the result of evaluating the exceptionBlock."
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   803
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   804
    order keysAndValuesDo:[:i :key | (self at:key) = aValue ifTrue: [^i]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   805
    ^ exceptionBlock value
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   806
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   807
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   808
nextIndexOfAssociation: aAssociation from: startIndex to: stopIndex 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   809
    "Return the next index of aAssociation within the receiver between startIndex
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   810
     and stopIndex. If the receiver does not contain aAssociation, return nil"
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   811
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   812
    startIndex to: stopIndex do: [:i | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   813
        (self associationAt: (order at: i)) = aAssociation ifTrue: [^i]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   814
    ^nil
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   815
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   816
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   817
nextIndexOfKey: aKey from: startIndex to: stopIndex 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   818
    "Return the next index of aKey within the receiver between startIndex and 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   819
     stopIndex.  If the receiver does not contain aKey, return nil"
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   820
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   821
    startIndex to: stopIndex do: [:i | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   822
        (order at: i) = aKey ifTrue: [^i]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   823
    ^nil
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   824
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   825
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   826
nextIndexOfValue: aValue from: startIndex to: stopIndex 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   827
    "Return the next index of aValue within the receiver between startIndex and
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   828
     stopIndex. If the receiver does not contain aValue, return nil"
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   829
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   830
    startIndex to: stopIndex do: [:i | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   831
        (self at: (order at: i)) = aValue ifTrue: [^i]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   832
    ^nil
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   833
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   834
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   835
prevIndexOfAssociation: aAssociation from: startIndex to: stopIndex 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   836
    "Return the previous index of aAssociation within the receiver between 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   837
     startIndex  and stopIndex working backwards through the receiver. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   838
     If the receiver does not contain aAssociation, return nil"
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   839
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   840
    startIndex to: stopIndex by: -1
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   841
            do: [:i | (self associationAt: (order at: i)) = aAssociation ifTrue: [^i]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   842
    ^nil
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   843
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   844
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   845
prevIndexOfKey: aKey from: startIndex to: stopIndex 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   846
    "Return the previous index of aKey within the receiver between startIndex and
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   847
     stopIndex working backwards through the receiver. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   848
     If the receiver does not contain aKey, return nil"
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   849
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   850
    startIndex to: stopIndex by: -1
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   851
            do: [:i | (order at: i) = aKey ifTrue: [^i]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   852
    ^nil
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   853
!
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   854
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   855
prevIndexOfValue: aValue from: startIndex to: stopIndex 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   856
    "Return the previous index of aValue within the receiver between startIndex
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   857
     and stopIndex working backwards through the receiver. 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   858
     If the receiver does not contain aValue, return nil"
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   859
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   860
    startIndex to: stopIndex by: -1
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   861
            do: [:i | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   862
                (self at: (order at: i)) = aValue ifTrue: [^i]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   863
    ^nil
1130
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   864
! !
94c1def975c2 category change
Claus Gittinger <cg@exept.de>
parents: 959
diff changeset
   865
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   866
!OrderedDictionary methodsFor:'testing'!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   867
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   868
occurrencesOfKey: aKey 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   869
    "Return how many of the dictionary's keys are equal to aKey."
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   870
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   871
    ^ order count:[:eachKey | aKey = eachKey]
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   872
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   873
"/ cg: the original code was not very smalltalkish:
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   874
"/
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   875
"/    | count |
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   876
"/
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   877
"/    count := 0.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   878
"/    1 to: self size do: [:index | aKey = (order at: index) ifTrue: [count := count + 1]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   879
"/    ^count
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   880
!
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   881
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   882
occurrencesOfValue: aValue 
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   883
    "Return how many of the dictionary's values are equal to aValue."
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   884
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   885
    ^ order count:[:eachKey | aValue = (self at:eachKey)]
62
a759b5c72c98 Initial revision
claus
parents:
diff changeset
   886
1242
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   887
"/ cg: the original code was not very smalltalkish:
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   888
"/
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   889
"/    | count |
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   890
"/
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   891
"/    count := 0.
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   892
"/    1 to: self size do: [:index | 
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   893
"/        aValue = (self at: (order at: index)) ifTrue: [count := count + 1]].
14de3b9cbd39 many code rewrites
Claus Gittinger <cg@exept.de>
parents: 1130
diff changeset
   894
"/    ^count
959
a481d378ccf5 add/at:put: messages return the added element
martin
parents: 885
diff changeset
   895
! !
757
84c4c41ed23f checkin from browser
ps
parents: 504
diff changeset
   896
775
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   897
!OrderedDictionary class methodsFor:'documentation'!
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   898
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   899
version
1920
fca37db26ef3 fixed copy: must copy the order too (otherwise, its shared)
sr
parents: 1917
diff changeset
   900
    ^ '$Header: /cvs/stx/stx/libbasic2/Attic/OrderedDictionary.st,v 1.24 2007-11-29 10:35:24 sr Exp $'
775
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   901
aafd903af15e added #removeKey: and #removeFirst.
Claus Gittinger <cg@exept.de>
parents: 757
diff changeset
   902
! !