|
Class: PluggableDictionary
Object
|
+--Collection
|
+--Set
|
+--Dictionary
|
+--PluggableDictionary
|
+--Dolphin::PluggableLookupTable
- Package:
- stx:libbasic2
- Category:
- Collections-Unordered
- Version:
- rev:
1.10
date: 2023/05/12 09:03:32
- user: cg
- file: PluggableDictionary.st directory: libbasic2
- module: stx stc-classLibrary: libbasic2
a dictionary where the hash- and compare functions can be provided externally.
Can be used eg. to implement dictionaries which ignore case differences,
or which map diareses to replacement sequences (as in german: Umlaut-u to ue).
copyrightCOPYRIGHT (c) 2014 by Claus Gittinger
All Rights Reserved
This software is furnished under a license and may be used
only in accordance with the terms of that license and with the
inclusion of the above copyright notice. This software may not
be provided or otherwise made available to, or used by, any
other person. No title to or ownership of the software is
hereby transferred.
instance creation
-
hashWith: hashFunctionArg compareWith: compareFunctionArg
-
return a dictionary which hashes using the given hash function
and compare function (both are one-arg blocks)
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.
-
hashWith: hashFunctionArg compareWith: compareFunctionArg
-
specify how to hash and how to compare elements
(see example on the class side)
queries
-
occurrencesOf: anObject
-
count & return how often anObject is stored in the dictionary.
This counts values - not keys.
Redefined to use compareFunction, instead of the inherited equality compare.
a dictionary which ignores the case of its string-keys:
|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'.
|
|