University of Sheffield   

    The Simons
    Component Library

Introduction   Class Hierarchy   Class Listing   Index of Classes   Index of Methods   Header Files  

Map Class Reference

#include <Map.h>

Inheritance diagram for Map:

Set Unordered Collection Object List of all members.

Detailed Description

Map: a unique mapping from domain objects to range objects.

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.


Constructor & Destructor Documentation

Map::Map const Map &  map  )  [protected]
 

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.

Parameters:
map - the other Map to copy.
Returns:
a Map, a shallow copy.

Map::Map  ) 
 

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.

Returns:
an empty Map.

Map::~Map  )  [virtual]
 

Release an unused Map.

Deletes the hash table used to store the Map's entries.

Map::Map CollectionID  other  ) 
 

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.

Parameters:
other - the other Collection to copy.
Returns:
a Map containing the elements of the other Collection.


Member Function Documentation

Void Map::add ObjectID  object  )  [virtual]
 

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.

Parameters:
object - the Object to add.

Reimplemented from Set.

Void Map::addAt ObjectID  domain,
ObjectID  range
 

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().

Parameters:
domain - the domain Object.
range - the range Object.

ObjectID Map::clone  )  const [virtual]
 

Clone a shallow copy of this Map.

Returns:
a shallow copy of this Map.

Reimplemented from Set.

MapID Map::compose MapID  other  )  const
 

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.

Parameters:
other - the other Map.
Returns:
the forward composition of this and the other Map.

ObjectID Map::domain Integer  index  )  const
 

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.

Parameters:
index - an Integer index.
Returns:
the ith Object in this Map's domain.
See also:
item, for a description of iteration.

SetID Map::domain  )  const
 

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.

Returns:
the domain of this Map.

ObjectID Map::getAt ObjectID  domain  )  const
 

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.

Parameters:
domain - the domain Object.
Returns:
the range Object, or null.

ObjectID Map::range Integer  index  )  const
 

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.

Parameters:
index - an Integer index.
Returns:
the ith Object in this Map's range.
See also:
item, for a description of iteration.

SetID Map::range  )  const
 

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.

Returns:
the range of this Map.

Void Map::remove ObjectID  object  )  [virtual]
 

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.

Parameters:
object - the Object to remove.

Reimplemented from Set.

Void Map::removeAt ObjectID  domain  ) 
 

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.

Parameters:
domain - the domain Object.

Void Map::retainAll CollectionID  other  )  [virtual]
 

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.

Parameters:
other - another Collection.

Reimplemented from Unordered.


The documentation for this class was generated from the following files:
Generated on Fri May 5 17:17:18 2006 for The Simons Component Library by doxygen1.3