CGAL::Unique_hash_map<Key,Data,UniqueHashFunction>

Definition

An instance map of the parameterized data type Unique_hash_map<Key,Data,UniqueHashFunction> is an injective mapping from the set of keys of type Key to the set of variables of type Data. New keys can be inserted at any time, however keys cannot be individually deleted.

An object hash of the type UniqueHashFunction returns a unique integer index hash(key) of type std::size_t for all objects key stored in map. The template parameter has as default the Handle_hash_function that hashes all types of pointers, handles, iterators, and circulators.

All variables are initialized to default_data, a value of type Data specified in the definition of map.

#include <CGAL/Unique_hash_map.h>

Types

Unique_hash_map<Key,Data,UniqueHashFunction>::Key
the Key type.

Unique_hash_map<Key,Data,UniqueHashFunction>::Data
the Data type.

Unique_hash_map<Key,Data,UniqueHashFunction>::Hash_function
the unique hash function type.

In compliance with STL, the types key_type, data_type, and hasher are defined as well.

Creation

Unique_hash_map<Key,Data,UniqueHashFunction> map ( Data default = Data(),
std::size_t table_size = 1,
Hash_function fct = Hash_function());
creates an injective function map from Key to the set of unused variables of type Data, sets default_data to default, passes the table_size as argument to the internal implementation, and initializes the hash function with fct.


Unique_hash_map<Key,Data,UniqueHashFunction> map ( Key first1,
Key beyond1,
Data first2,
Data default = Data(),
std::size_t table_size = 1,
Hash_function fct = Hash_function());
creates an injective function map from Key to the set of unused variables of type Data, sets default_data to default, passes the table_size as argument to the internal implementation, initializes the hash function with fct, and inserts all keys from the range [first1,beyond1). The data variable for each inserted key is initialized with the corresponding value from the range [first2, first2 + (beyond1-first1)).
Precondition:  The increment operator must be defined for values of type Key and for values of type Data. beyond1 must be reachable from first1 using increments.

Operations

Data map.default_value () the current default_value.
Hash_function map.hash_function () the current hash function.

bool map.is_defined ( Key key) returns true if key is defined in map. Note that there can be keys defined that have not been inserted explicitly. Their variables are initialized to default_value.

void map.clear () resets map to the injective function map from Key to the set of unused variables of type Data. The default_data remains unchanged.

void map.clear ( Data default) resets map to the injective function map from Key to the set of unused variables of type Data and sets default_data to default.

Data& map.operator[] ( const Key& key)
returns a reference to the variable map(key). If key has not been inserted into map before, key is inserted and initialized with default_value.

const Data& map.operator[] ( const Key& key) const
returns a const reference to the variable map(key). If key has not been inserted into map before, a const reference to the default_value is returned. However, key is not inserted into map.

Data map.insert ( Key first1, Key beyond1, Data first2)
inserts all keys from the range [first1,beyond1). The data variable for each inserted key is initilized with the corresponding value from the range [first2, first2 + (beyond1-first1)). Returns first2 + (beyond1-first1).
Precondition:  The increment operator must be defined for values of type Key and for values of type Data. beyond1 must be reachable from first1 using increments.

See Also

UniqueHashFunction
CGAL::Handle_hash_function

Implementation

Unique_hash_map is implemented via a chained hashing scheme. Access operations map[i] take expected time O(1). The table_size parameter passed to chained hashing can be used to avoid unnecessary rehashing when set to the number of expected elements in the map. The design is derived from the STL hash_map and the Leda type map. Its specialization on insertion only and unique hash values allow for a more time- and space-efficient implementation, see also [MN00, Chapter 5]. This implementation makes also use of sentinels that lead to defined keys that have not been inserted.