![]() |
The Simons
|
#include <Map.h>
Inheritance diagram for Map:
A Map is a kind of dictionary, in which Objects may be looked up against other Objects, which serve as search keys. The search keys are called the domain of the Map, and the corresponding values are called the range. A Map may also be considered a Set, whose elements are all of the type Entry with unique domain keys. An Entry is a single mapping from a domain Object to a range Object and is stored uniquely in the Map, according to the value of its domain Object, which serves as the search key. Adding an Entry with the same search key as an existing Entry will replace the old Entry.
A Map is implemented as an open hash-table. It locates its entries by hashing on the entries, with an average seek time of 1.3 lookups. In the rare event of a collision, entries are relocated. When entries are removed, the table is compacted in an average time of 2.3 lookups. The hash table is never more than 2/3 full for optimum performance.
Public Member Functions | |
Map () | |
Construct an empty Map. | |
virtual | ~Map () |
Release an unused Map. | |
Map (CollectionID) | |
Copy a Map from another Collection. | |
virtual ObjectID | clone () const |
Clone a shallow copy of this Map. | |
virtual Void | add (ObjectID) |
Add an Object to this Map. | |
virtual Void | remove (ObjectID) |
Remove an Object from this Map. | |
virtual Void | retainAll (CollectionID) |
Retain only the elements present in another Collection. | |
Void | addAt (ObjectID, ObjectID) |
Add a new Entry to this Map. | |
Void | removeAt (ObjectID) |
Remove an Entry from this Map. | |
ObjectID | getAt (ObjectID) const |
Seek a range value at a domain key. | |
SetID | domain () const |
Return the domain of this Map as a Set. | |
SetID | range () const |
Return the range of this Map as a Set. | |
ObjectID | domain (Integer) const |
Select a domain Object in this Map. | |
ObjectID | range (Integer) const |
Select a range Object in this Map. | |
MapID | compose (MapID) const |
Compose this Map with another Map. | |
Protected Member Functions | |
Map (const Map &) | |
Copy another Map. |
|
Copy another Map. Required by C++ to ensure that copying a Map faithfully copies the underlying Set. Takes a shallow copy of the other Map by allocating a hash table with the same capacity, then transferring all the other Map's entries to the same hashed locations. Transferred entries will be shared until they are replaced. This method is more efficient than the constructor to build a Map from a Collection.
|
|
Construct an empty Map. The size() of the Map is zero, but a hash table of the default capacity is constructed and every entry is initialised to null.
|
|
Release an unused Map. Deletes the hash table used to store the Map's entries. |
|
Copy a Map from another Collection. Allocates a hash table with enough capacity to hold all the elements of the other Collection. Inserts the elements of the other Collection using addAll(), which iterates using item() and inserts each element using add(). If an element is an Entry, it is added. If an element is some other Object, a new Entry is created mapping from the Object to itself. Transferred entries will be shared until they are replaced.
|
|
Add an Object to this Map. If the Object is an Entry, adds the Entry to this Map, replacing any old Entry having the same domain key. Otherwise, creates a new Entry mapping from the Object to itself and adds it to this Map, replacing any old Entry with the same domain key.
Reimplemented from Set. |
|
Add a new Entry to this Map. Creates a new Entry mapping from the domain Object to the range Object and adds it to this Map, replacing any old Entry with the same domain key, judged EQUAL under compare(). |
|
Clone a shallow copy of this Map.
Reimplemented from Set. |
|
Compose this Map with another Map. Returns a new Map, which is the forward composition of this Map with another Map. The resulting Map contains entries whose domain keys come from this Map and whose range values come from the other Map. An Entry exists in the result for each value associated with a key in this Map that is also a key in the other Map. The result contains as many, or fewer keys than this Map. Likewise, the result contains as many, or fewer Entries than this Map.
|
|
Select a domain Object in this Map. Provided for convenience, this is equivalent to selecting the domain of the Entry accessible at the given index. Each distinct index is guaranteed to access a different location in this Map. Iterating over the domain will visit each domain Object exactly once.
|
|
Return the domain of this Map as a Set. Builds a Set of the domain keys of each Entry in this Set. Each domain key occurs uniquely in this Map, so the result contains exactly as many elements as this Map.
|
|
Seek a range value at a domain key. Searches this Map for the domain Object and returns the corresponding range Object. If no such domain key exists in this Map, returns null.
|
|
Select a range Object in this Map. Provided for convenience, this is equivalent to selecting the range of the Entry accessible at the given index. Each distinct index is guaranteed to access a different location in this Map. Iterating over the range will visit each range Object once for each time it appears in the Map and may visit the identical Object many times.
|
|
Return the range of this Map as a Set. Builds a Set of the range values of each Entry in this Map. Multiple occurrences of each range value in this Map will therefore be eliminated. The result will contain the same, or fewer elements than this Map. To visit the unique range elements of a Map, iterate using item() on the result.
|
|
Remove an Object from this Map. If the Object is an Entry, removes an Entry from this Map only if its domain and range are both EQUAL to the domain and range of the Entry. Otherwise, removes an Entry whose domain is EQUAL to the given Object, treating it as a domain key. This affects the semantics of removeAll() and retainAll(), which behave like set difference and set intersection; or like domain anti-restriction and domain restriction, respectively.
Reimplemented from Set. |
|
Remove an Entry from this Map. Removes the Entry mapping from the domain Object to whatever range Object exists in the Map. Has no effect if the domain Object is not in the domain of this Map.
|
|
Retain only the elements present in another Collection. If the other Collection consists of Entries, this is equivalent to Set intersection, retaining all those Entries from this Map that are deep EQUAL, under deepCompare(), to some Entry in the Collection. Otherwise, this is equivalent to domain restriction, retaining all those Entries from this Map that are judged EQUAL, under compare(), to a domain key in the Collection.
Reimplemented from Unordered. |