Set.st
branchjv
changeset 20244 20922299fd44
parent 20079 8d884971c2ed
parent 20236 b99be28d9875
child 20362 fea6b00ed63a
equal deleted inserted replaced
20229:b5cdb27022c8 20244:20922299fd44
     1 "{ Encoding: utf8 }"
       
     2 
       
     3 "
     1 "
     4  COPYRIGHT (c) 1991 by Claus Gittinger
     2  COPYRIGHT (c) 1991 by Claus Gittinger
     5 	      All Rights Reserved
     3 	      All Rights Reserved
     6 
     4 
     7  This software is furnished under a license and may be used
     5  This software is furnished under a license and may be used
   199      Set rehashAllSubInstances
   197      Set rehashAllSubInstances
   200     "
   198     "
   201 
   199 
   202     "Created: / 24.10.1997 / 23:13:44 / cg"
   200     "Created: / 24.10.1997 / 23:13:44 / cg"
   203 ! !
   201 ! !
   204 
       
   205 
   202 
   206 !Set methodsFor:'Compatibility-ST80'!
   203 !Set methodsFor:'Compatibility-ST80'!
   207 
   204 
   208 initialIndexFor:hashKey boundedBy:length
   205 initialIndexFor:hashKey boundedBy:length
   209     "for ST-80 compatibility only; it is (currently) not used in this
   206     "for ST-80 compatibility only; it is (currently) not used in this
   814 
   811 
   815     "Modified: 1.3.1996 / 21:41:13 / cg"
   812     "Modified: 1.3.1996 / 21:41:13 / cg"
   816 ! !
   813 ! !
   817 
   814 
   818 
   815 
       
   816 
   819 !Set methodsFor:'obsolete set operations'!
   817 !Set methodsFor:'obsolete set operations'!
   820 
   818 
   821 + aCollection
   819 + aCollection
   822     "Kept for backward compatibility. 
   820     "Kept for backward compatibility. 
   823      Use #union: instead, to isolate arithmethic and set operations"
   821      Use #union: instead, to isolate arithmethic and set operations"
   922             index := index + 1
   920             index := index + 1
   923         ].
   921         ].
   924         index == startIndex ifTrue:[
   922         index == startIndex ifTrue:[
   925             delIndex ~~ 0 ifTrue:[
   923             delIndex ~~ 0 ifTrue:[
   926                 keyArray basicAt:delIndex put:nil.
   924                 keyArray basicAt:delIndex put:nil.
       
   925                 ^ delIndex
       
   926             ].
       
   927             self grow.
       
   928             length := keyArray basicSize.
       
   929             startIndex := index := self initialIndexForKey:key.
       
   930         ].
       
   931     ] loop.
       
   932 
       
   933     "Modified: / 27-02-2011 / 15:30:42 / cg"
       
   934 !
       
   935 
       
   936 findKeyOrNilOrDeletedEntry:key
       
   937     "Look for the key in the receiver.  
       
   938      If it is found, return the index of the first unused slot. 
       
   939      Grow the receiver, if key was not found, and no unused slots were present.
       
   940      The answer is the index into the keyArray where the (keyArray at:index)
       
   941      may contain:
       
   942         nil             -   an empty slot
       
   943         DeletedEntry    -   an empty slot, but preceeded and followed by non-empty
       
   944                             slots with keys hashing to the same value (hash collisions)
       
   945         key             -   key is laready present in the slot."
       
   946 
       
   947     |index  "{ Class:SmallInteger }"
       
   948      length "{ Class:SmallInteger }"
       
   949      startIndex probe 
       
   950      delIndex "{ Class:SmallInteger }"|
       
   951 
       
   952     delIndex := 0.
       
   953 
       
   954     length := keyArray basicSize.
       
   955     startIndex := index := self initialIndexForKey:key.
       
   956 
       
   957     [
       
   958         probe := keyArray basicAt:index.
       
   959         probe isNil ifTrue:[
       
   960             delIndex == 0 ifTrue:[^ index].
       
   961             ^ delIndex
       
   962         ].
       
   963         probe == DeletedEntry ifTrue:[
       
   964             delIndex == 0 ifTrue:[
       
   965                 delIndex := index
       
   966             ]
       
   967         ] ifFalse:[
       
   968             key = probe ifTrue:[^ index]
       
   969         ].
       
   970 
       
   971         index == length ifTrue:[
       
   972             index := 1
       
   973         ] ifFalse:[
       
   974             index := index + 1
       
   975         ].
       
   976         index == startIndex ifTrue:[
       
   977             delIndex ~~ 0 ifTrue:[
   927                 ^ delIndex
   978                 ^ delIndex
   928             ].
   979             ].
   929             self grow.
   980             self grow.
   930             length := keyArray basicSize.
   981             length := keyArray basicSize.
   931             startIndex := index := self initialIndexForKey:key.
   982             startIndex := index := self initialIndexForKey:key.