Back: Magnitude-misc methods Up: Base classes Forward: MappedCollection class-instance creation   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document

1.106 MappedCollection

Defined in namespace Smalltalk
Superclass: Collection
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.

1.106.1 MappedCollection class: instance creation  (class)
1.106.2 MappedCollection: basic  (instance)


1.106.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.


1.106.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

atAll: keyCollection
Answer a new MappedCollection that only includes the given keys. The new MappedCollection might use keyCollection or consecutive integers for the keys, depending on the map's type. Fail if any of them is not found in the map.

collect: aBlock
Answer a Collection with the same keys as the map, where accessing a key yields the value obtained by passing through aBlock the value accessible from the key in the receiver. The result need not be another MappedCollection

contents
Answer a bag with the receiver's values

copyFrom: a to: b
Answer a new collection containing all the items in the receiver from the a-th to the b-th.

do: aBlock
Evaluate aBlock for each object

domain
Answer the receiver's domain

keys
Answer the keys that can be used to access this collection.

keysAndValuesDo: aBlock
Evaluate aBlock passing two arguments, one being a key that can be used to access this collection, and the other one being the value.

keysDo: aBlock
Evaluate aBlock on the keys that can be used to access this collection.

map
Answer the receiver's 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



Back: MappedCollection class-instance creation Up: MappedCollection Forward: Memory   Top: GNU Smalltalk Library Reference Contents: Table of Contents Index: Class index About: About this document


This document was generated on August, 19 2010 using texi2html