|
Class: IdentityDictionary
Object
|
+--Collection
|
+--Set
|
+--Dictionary
|
+--IdentityDictionary
|
+--ColorPreferencesCollection
|
+--ExceptionHandlerSet
|
+--JavaScriptObject
|
+--KeyboardMap
|
+--PropertyListDictionary
|
+--UISpecification::UIBindingsIdentityDictionary
|
+--UserPreferences
|
+--WeakIdentityDictionary
|
+--WeakValueIdentityDictionary
- Package:
- stx:libbasic
- Category:
- Collections-Unordered
- Version:
- rev:
1.46
date: 2023/07/20 08:45:05
- user: stefan
- file: IdentityDictionary.st directory: libbasic
- module: stx stc-classLibrary: libbasic
Same as a Dictionary, but key must be identical - not just equal.
Since compare is on identical keys (using ==), hashing is also done via
#identityHash instead of #hash.
IdentityDictionaries are especially useful when symbols are used as keys.
copyrightCOPYRIGHT (c) 1992 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.
comparing
-
= anIdentityDictionary
-
return true, if the argument is an IdentityDictionary containing the same
key-value pairs as I do
copying
-
copyWithout: anAssociation
-
Return a copy of the dictionary that is 1 smaller than the receiver and
does not include the argument, anAssociation
No error is reported, if elementToSkip is not in the collection.
Usage example(s):
|d d2|
d := IdentityDictionary new
at:1 put:'1';
at:2 put:'2';
at:3 put:'3';
at:4 put:'4';
at:4.0 put:'4';
at:5 put:'5';
yourself.
d2 := d copyWithout:(4->'4').
d2
|
private
-
compareSame: element1 with: element2
-
compare two elements for being the same. Here, return true if the
elements are identical (i.e. using #==).
-
emptyCollectionForKeys
-
return an empty collection used for keys.
Here, an IdentitySet is returned.
Made a separate method to allow redefinition for different kind of
containers in subclasses.
-
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)
-
findIdentical: key ifAbsent: aBlock
-
IdentityDictionary does identity compare anyway...
-
findKeyOrNil: key
-
Look for the key in the receiver.
If it is found, return the index of the first unused slot.
Grow the receiver, if key was not found, and no unused slots were present
Warning: an empty slot MUST be filled by the sender - it is only to be sent
by at:put: / add: - like methods.
-
findKeyOrNilOrDeletedEntry: key
-
Look for the key in the receiver.
If it is found, 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
-
includesValue: aValue
-
return true, if the argument, aValue is stored in the dictionary,
Redefined to use identity compare, NOT equality compare
-
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.
|