|
|
6.92 MappedCollection
- Defined in namespace Smalltalk
- Category: Collections-Keyed
- I represent collections of objects that are indirectly indexed by names.
There are really two collections involved: domain and a map. The map maps
between external names and indices into domain, which contains the
real association. In order to work properly, the domain must be an instance
of a subclass of SequenceableCollection, and the map must be an instance of
Dictionary, or of a subclass of SequenceableCollection.
As an example of using me, consider implenting a Dictionary whose elements
are indexed. The domain would be a SequenceableCollection with n elements,
the map a Dictionary associating each key to an index in the domain. To
access by key, to perform enumeration, etc. you would ask an instance of me;
to access by index, you would access the domain directly.
Another idea could be to implement row access or column access to a matrix
implemented as a single n*m Array: the Array would be the domain, while the
map would be an Interval.
6.92.1 MappedCollection class: instance creation
- collection: aCollection map: aMap
- Answer a new MappedCollection using the given domain (aCollection) and map
- new
- This method should not be used; instead, use #collection:map: to create MappedCollection.
6.92.2 MappedCollection: basic
- add: anObject
- This method should not be called for instances of this class.
- at: key
- Answer the object at the given key
- at: key put: value
- Store value at the given key
- collect: aBlock
- Answer a MappedCollection with a copy of the receiver's map and a domain obtained by passing each object through aBlock
- contents
- Answer a bag with the receiver's values
- do: aBlock
- Evaluate aBlock for each object
- domain
- Answer the domain
- map
- Answer the map
- reject: aBlock
- Answer the objects in the domain for which aBlock returns false
- select: aBlock
- Answer the objects in the domain for which aBlock returns true
- size
- Answer the receiver's size
|