|
|
6.56 Dictionary
- Defined in namespace Smalltalk
- Category: Collections-Keyed
- I implement a dictionary, which is an object that is indexed by
unique objects (typcially instances of Symbol), and associates another
object with that index. I use the equality operator = to determine
equality of indices.
6.56.1 Dictionary class: instance creation
- new
- Create a new dictionary with a default size
6.56.2 Dictionary: accessing
- add: newObject
- Add the newObject association to the receiver
- associationAt: key
- Answer the key/value Association for the given key. Fail if the key is not found
- associationAt: key ifAbsent: aBlock
- Answer the key/value Association for the given key. Evaluate aBlock (answering the result) if the key is not found
- at: key
- Answer the value associated to the given key. Fail if the key is not found
- at: key ifAbsent: aBlock
- Answer the value associated to the given key, or the result of evaluating aBlock if the key is not found
- at: aKey ifAbsentPut: aBlock
- Answer the value associated to the given key. If the key is not found, evaluate aBlock and associate the result to aKey before returning.
- at: aKey ifPresent: aBlock
- If aKey is absent, answer nil. Else, evaluate aBlock passing the associated value and answer the result of the invocation
- at: key put: value
- Store value as associated to the given key
- keyAtValue: value
- Answer the key associated to the given value. Evaluate exceptionBlock (answering the result) if the value is not found
- keyAtValue: value ifAbsent: exceptionBlock
- Answer the key associated to the given value. Evaluate exceptionBlock (answering the result) if the value is not found. IMPORTANT: == is used to compare values
- keys
- Answer a kind of Set containing the keys of the receiver
- values
- Answer a Bag containing the values of the receiver
6.56.3 Dictionary: awful ST-80 compatibility hacks
- findKeyIndex: key
- Tries to see if key exists as a the key of an indexed variable. As soon as nil or an association with the correct key is found, the index of that slot is answered
6.56.4 Dictionary: dictionary enumerating
- associationsDo: aBlock
- Pass each association in the dictionary to aBlock
- collect: aBlock
- Answer a new dictionary where the keys are the same and the values are obtained by passing each value to aBlock and collecting the return values
- do: aBlock
- Pass each value in the dictionary to aBlock
- keysAndValuesDo: aBlock
- Pass each key/value pair in the dictionary as two distinct parameters to aBlock
- keysDo: aBlock
- Pass each key in the dictionary to aBlock
- reject: aBlock
- Answer a new dictionary containing the key/value pairs for which aBlock returns false. aBlock only receives the value part of the pairs.
- select: aBlock
- Answer a new dictionary containing the key/value pairs for which aBlock returns true. aBlock only receives the value part of the pairs.
6.56.5 Dictionary: dictionary removing
- remove: anObject
- This method should not be called for instances of this class.
- remove: anObject ifAbsent: aBlock
- This method should not be called for instances of this class.
- removeAllKeys: keys
- Remove all the keys in keys, without raising any errors
- removeAllKeys: keys ifAbsent: aBlock
- Remove all the keys in keys, passing the missing keys as parameters to aBlock as they're encountered
- removeAssociation: anAssociation
- Remove anAssociation's key from the dictionary
- removeKey: key
- Remove the passed key from the dictionary, fail if it is not found
- removeKey: key ifAbsent: aBlock
- Remove the passed key from the dictionary, answer the result of evaluating aBlock if it is not found
6.56.6 Dictionary: dictionary testing
- includes: anObject
- Answer whether the receiver contains anObject as one of its values
- includesAssociation: anAssociation
- Answer whether the receiver contains the key which is anAssociation's key and its value is anAssociation's value
- includesKey: key
- Answer whether the receiver contains the given key
- occurrencesOf: aValue
- Answer whether the number of occurrences of aValue as one of the receiver's values
6.56.7 Dictionary: polymorphism hacks
- withAllSuperspaces
- This method is needed by the compiler
6.56.8 Dictionary: printing
- printOn: aStream
- Print a representation of the receiver on aStream
6.56.9 Dictionary: rehashing
- rehash
- Rehash the receiver
6.56.10 Dictionary: storing
- storeOn: aStream
- Print Smalltalk code compiling to the receiver on aStream
6.56.11 Dictionary: testing
- = aDictionary
- Answer whether the receiver and aDictionary are equal
- hash
- Answer the hash value for the receiver
|