Category: Collections-Keyed
Superclass: HashedCollection
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. In almost all places where you would use a plain Dictionary, a LookupTable would be more efficient; see LookupTable's comment before you use it. I do have a couple of special features that are useful in certain special cases.

Method category index

instance creation (class)
accessing (instance)
awful ST-80 compatibility hacks (instance)
compilation (instance)
dictionary enumerating (instance)
dictionary removing (instance)
dictionary testing (instance)
namespace protocol (instance)
printing (instance)
rehashing (instance)
removing (instance)
storing (instance)
testing (instance)

instance creation (class)

from: anArray
Answer a new dictionary created from the keys and values of Associations in anArray, such as {1 -> 2. 3 -> 4}. anArray should be specified using brace-syntax.

new

Create a new dictionary with a default size

top


accessing (instance)

add: newObject
Add the newObject association to the receiver

addAll: aCollection

Adds all the elements of 'aCollection' to the receiver, answer aCollection

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

associations

Returns the content of a Dictionary as a Set of Associations.

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

atAll: keyCollection

Answer a Dictionary that only includes the given keys. Fail if any of them is not found

keyAtValue: value

Answer the key associated to the given value, or nil 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 an Array containing the values of the receiver

top


awful ST-80 compatibility hacks (instance)

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

top


compilation (instance)

scopeDictionary
Answer the dictionary that is used when the receiver is before a period in Smalltalk source code.

top


dictionary enumerating (instance)

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.

top


dictionary removing (instance)

remove: anAssociation
Remove anAssociation's key from the dictionary

remove: anAssociation ifAbsent: aBlock

Remove anAssociation's key from the dictionary

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

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

top


dictionary testing (instance)

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

top


namespace protocol (instance)

allSuperspaces
Answer all the receiver's superspaces in a collection

allSuperspacesDo: aBlock

Evaluate aBlock once for each of the receiver's superspaces (which is none for BindingDictionary).

definedKeys

Answer a kind of Set containing the keys of the receiver

definesKey: key

Answer whether the receiver defines the given key. `Defines' means that the receiver's superspaces, if any, are not considered.

hereAssociationAt: key

Return the association for the variable named as specified by `key' *in this namespace*. If the key is not found search will *not* be carried on in superspaces and the method will fail.

hereAssociationAt: key ifAbsent: aBlock

Return the association for the variable named as specified by `key' *in this namespace*. If the key is not found search will *not* be carried on in superspaces and aBlock will be immediately evaluated.

hereAt: key

Return the value associated to the variable named as specified by `key' *in this namespace*. If the key is not found search will *not* be carried on in superspaces and the method will fail.

hereAt: key ifAbsent: aBlock

Return the value associated to the variable named as specified by `key' *in this namespace*. If the key is not found search will *not* be carried on in superspaces and aBlock will be immediately evaluated.

inheritsFrom: aNamespace

Answer whether aNamespace is one of the receiver's direct and indirect superspaces

superspace

Answer the receiver's superspace, which is nil for BindingDictionary.

withAllSuperspaces

Answer the receiver and all of its superspaces in a collection, which is none for BindingDictionary

withAllSuperspacesDo: aBlock

Invokes aBlock for the receiver and all superspaces, both direct and indirect (though a BindingDictionary does not have any).

top


printing (instance)

examineOn: aStream
Print all the instance variables and objects in the receiver on aStream

printOn: aStream

Print a representation of the receiver on aStream

top


rehashing (instance)

rehash
Rehash the receiver

top


removing (instance)

removeAllKeysSuchThat: aBlock
Remove from the receiver all keys for which aBlock returns true.

top


storing (instance)

storeOn: aStream
Print Smalltalk code compiling to the receiver on aStream

top


testing (instance)

= aDictionary
Answer whether the receiver and aDictionary are equal

hash

Answer the hash value for the receiver

top