home *** CD-ROM | disk | FTP | other *** search
-
-
- !AbtWeakValueLookupTable privateMethods !
-
- abtRenameKey: aKey to: newKey ifPresent: aPresentBlock ifAbsent: anAbsentBlock
- "Public - Examine the receiver to see if newKey is present. If it is,
- then answer (aPresentBlock value). If newKey is not present,
- then examine the receiver to see if aKey is present. If it is not,
- then answer (anAbsentBlock value). If aKey is present, then
- remove aKey and answer the result of adding the index at aKey
- to the receiver at newKey."
- "05.29.92 svd - EZE* initial"
-
- | value oldKeyIndex newKeyIndex hashIndex index element elementsSize |
-
- hashIndex := aKey hash \\ (elementsSize := keys size) + 1.
-
- index := hashIndex.
- [oldKeyIndex isNil and: [index <= elementsSize]] whileTrue:
- [(element := keys at: index) == nil
- ifTrue: [^anAbsentBlock value]
- ifFalse:
- [element = aKey
- ifTrue: [oldKeyIndex := index]
- ifFalse: [index := index + 1]].
- ].
-
- oldKeyIndex isNil
- ifTrue:
- [index := 1.
- [(element := keys at: index) == nil
- ifTrue: [^anAbsentBlock value]
- ifFalse:
- [element = aKey ifTrue: [oldKeyIndex := index].
- index := index + 1].
- oldKeyIndex isNil and: [index < hashIndex]] whileTrue: [].
- oldKeyIndex isNil ifTrue: [^anAbsentBlock value]].
-
- hashIndex := newKey hash \\ elementsSize + 1.
- index := hashIndex.
-
- [newKeyIndex isNil and: [index <= elementsSize]] whileTrue:
- [(element := keys at: index) == nil
- ifTrue: [newKeyIndex := index]
- ifFalse:
- [element = newKey ifTrue: [^aPresentBlock value: (values at: oldKeyIndex)].
- index := index + 1].
- ].
-
- newKeyIndex isNil
- ifTrue:
- [index := 1.
- [(element := keys at: index) == nil
- ifTrue: [newKeyIndex := index]
- ifFalse:
- [element = newKey ifTrue: [^aPresentBlock value: (values at: oldKeyIndex)].
- index := index + 1].
- newKeyIndex isNil and: [index < hashIndex]] whileTrue: []].
-
- newKeyIndex isNil
- ifTrue:
- [self expand at: newKey put: (value := values at: oldKeyIndex).
- self removeKey: aKey]
- ifFalse:
- [keys at: newKeyIndex put: newKey.
- values at: newKeyIndex put: (value := values at: oldKeyIndex).
- super rehashTo: oldKeyIndex].
- ^value
- ! !
-