|
Class: PluggableDictionary
Object
|
+--Collection
|
+--Set
|
+--Dictionary
|
+--PluggableDictionary
|
+--Dolphin::PluggableLookupTable
- Package:
- stx:libbasic2
- Category:
- Collections-Unordered
- Version:
- rev:
1.5
date: 2019/02/10 13:44:10
- user: cg
- file: PluggableDictionary.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
- Author:
- Claus Gittinger
a dictionary where the hash- and compare functions can be provided externally.
instance creation
-
hashWith: hashFunctionArg compareWith: compareFunctionArg
-
accessing
-
hashWith: hashFunctionArg compareWith: compareFunctionArg
-
private
-
compareSame: element1 with: element2
-
compare two elements for being the same.
Here, return the value from compareFunction
-
find: key ifAbsent: aBlock
-
Look for the key in the receiver. If it is found, return
the index of the association containing the key, otherwise
return the value of evaluating aBlock.
Redefined - since we inherit this code from Set-Dictionary
(one of the seldom cases, where I could make use of multiple inheritance
and inherit from IdentitySet ... sigh)
-
findKeyOrNil: key
-
Look for the key in the receiver.
If it is found, return return the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present
-
findKeyOrNilOrDeletedEntry: key
-
Look for the key in the receiver.
If it is found, return return the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present
-
hashFor: aKey
-
return an initial index given a key.
queries
-
occurrencesOf: anObject
-
count & return how often anObject is stored in the dictionary.
This counts values - not keys.
Redefined to use #== (identity compare), NOT equality compare.
|s|
s := PluggableDictionary
hashWith:[:k | k asLowercase hash]
compareWith:[:a :b | a notNil and:[b notNil and:[a asLowercase = b asLowercase]]].
s at:'hello' put:123.
s at:'world' put:222.
s at:'abc' put:333.
s at:'Hello'.
s at:'heLLo'.
s at:'ABC'.
s at:'WORLD'.
s size.
s includesKey:'heLlo'.
s includesKey:'wOrLd'.
s includesKey:'wOrLds'.
|