A STL-like hashmap with dense_hashtable as the backend. More...
#include <ash/dense_hashmap.h>
Public Types | |
typedef ht::key_type | key_type |
The type used to identify elements. | |
typedef Data | data_type |
The type of object associated with keys. | |
typedef Data | mapped_type |
| |
typedef ht::value_type | value_type |
The type of object stored in the container. | |
typedef ht::hasher | hasher |
The functor type used to hash keys. | |
typedef ht::key_equal | key_equal |
The functor used to compare keys for equality. | |
typedef Alloc | allocator_type |
| |
typedef ht::size_type | size_type |
The unsigned type used to represent the size of the container. | |
typedef ht::difference_type | difference_type |
The signed integral type used to represent the distance between iterators. | |
typedef ht::pointer | pointer |
The type that serves as a pointer to value_type. | |
typedef ht::const_pointer | const_pointer |
The type that serves as a const pointer to value_type. | |
typedef ht::reference | reference |
The type that serves as a reference to value_type. | |
typedef ht::const_reference | const_reference |
The type that serves as a pointer to value_type. | |
typedef ht::iterator | iterator |
The type used to iterate through the contents of the container. | |
typedef ht::const_iterator | const_iterator |
The const type used to iterate through the contents of the container. | |
typedef ht::local_iterator | local_iterator |
The type used to iterate through a set of elements that share a hash code. | |
typedef ht::const_local_iterator | const_local_iterator |
The const type used to iterate through a set of elements that share a hash code. | |
Public Member Functions | |
key_type | empty_key () const |
Get the key used for empty buckets. | |
void | set_empty_key (key_type const &key) |
Set the key to use for empty buckets. | |
key_type | deleted_key () const |
Get the key used for deleted buckets. | |
void | set_deleted_key (key_type const &key) |
Set the key to use for deleted buckets. | |
void | clear_deleted_key () |
Clear the key used for deleted buckets. | |
bool | operator== (const dense_hashmap &dhm) const |
Equality operator. | |
Iterator Methods | |
iterator | begin () |
Get an iterator to the beginning. | |
const_iterator | begin () const |
Get an iterator to the beginning. | |
iterator | end () |
Get an iterator to the end. | |
const_iterator | end () const |
Get an iterator to the end. | |
local_iterator | begin (size_type i) |
| |
const_local_iterator | begin (size_type i) const |
| |
local_iterator | end (size_type i) |
| |
const_local_iterator | end (size_type i) const |
| |
Accessor Methods | |
hasher | hash_funct () const |
Get the hash functor used by the container. | |
hasher | hash_function () const |
Get the hash functor used by the container. | |
key_equal | key_eq () const |
Get the key comparison functor used by the container. | |
Constructors/Destructors | |
We use the default copy constructor. We use the default destructor. | |
dense_hashmap (size_type n=0, hasher const &h=hasher(), key_equal const &k=key_equal()) | |
Default constructor. | |
template<class InputIterator > | |
dense_hashmap (InputIterator f, InputIterator l, key_type const &empty_key_val, size_type n=0, hasher const &h=hasher(), key_equal const &k=key_equal()) | |
Iterative constructor. | |
void | swap (dense_hashmap &c) |
Swap method. | |
Size Methods | |
size_type | size () const |
Get the size of the container. | |
size_type | max_size () const |
Get the maximum size of the container. | |
bool | empty () const |
Check if the container is empty. | |
size_type | bucket_count () const |
Get the number of buckets the container has. | |
size_type | max_bucket_count () const |
| |
size_type | bucket_size (size_type i) const |
| |
size_type | bucket (key_type const &key) const |
| |
float | load_factor () const |
| |
float | max_load_factor () const |
| |
void | max_load_factor (float new_grow) |
| |
float | min_load_factor () const |
Get the min load factor. | |
void | min_load_factor (float new_shrink) |
Set the min load factor. | |
void | set_resizing_parameters (float shrink, float grow) __attribute__((__deprecated__)) |
void | resize (size_type n) |
Resize the container to hold at least n elements. | |
void | rehash (size_type n) |
| |
Lookup Methods | |
iterator | find (key_type const &key) |
Find an element. | |
const_iterator | find (key_type const &key) const |
Find an element. | |
data_type & | operator[] (key_type const &key) |
Element access. | |
size_type | count (key_type const &key) const |
Count the number of elements with a given key. | |
pair< iterator, iterator > | equal_range (key_type const &key) |
Find all elements matching a given key. | |
pair< const_iterator, const_iterator > | equal_range (key_type const &key) const |
Find all elements matching a given key. | |
Insertion Methods | |
pair< iterator, bool > | insert (const_reference obj) |
Insert an element into the container. | |
template<class InputIterator > | |
void | insert (InputIterator f, InputIterator l) |
Insert a range of elements [f,l) into the container. | |
void | insert (const_iterator f, const_iterator l) |
Insert a range of elements [f,l) into the container. | |
iterator | insert (iterator, const_reference obj) |
Insert sematics for std::insert_iterator. | |
Deletion Methods | |
void | clear () |
Erase all elements. | |
void | clear_no_resize () |
Clear the container without resizing. | |
size_type | erase (key_type const &key) |
Erase an element. | |
void | erase (iterator itr) |
Erase an element. | |
void | erase (iterator f, iterator l) |
Erase a range of elements. | |
I/O Methods | |
bool | write_metadata (FILE *fp) |
Write the container contents to file in a byte-order-independent format. | |
bool | read_metadata (FILE *fp) |
Read the container contents from a file written by write_metadata(). | |
bool | write_nopointer_data (FILE *fp) |
Write the container contents to file in an architecture-dependent format. | |
bool | read_nopointer_data (FILE *fp) |
Read the container contents from a file written by write_nopointer_data(). | |
Related Functions | |
(Note that these are not member functions.) | |
template<class Key , class T , class HashFx , class EqualKey , class Alloc > | |
void | swap (dense_hashmap< Key, T, HashFx, EqualKey, Alloc > &x, dense_hashmap< Key, T, HashFx, EqualKey, Alloc > &y) |
Global swap function. |
A STL-like hashmap with dense_hashtable as the backend.
Key | The dense_hashmap's key type. Also defined as dense_hashmap::key_type. |
Data | The dense_hashmap's data type. Also defined as dense_hashmap::data_type. |
HashFx | The hash functor used by the dense_hashmap. Also defined as dense_hashmap::hasher. |
EqualKey | The dense_hashmap key equality functor: a binary predicate that determines whether two keys are equal. Also defined as dense_hashmap::key_equal. |
Alloc | The allocator to use for internal memory management. |
This is just a very thin wrapper over dense_hashtable, just like sgi stl's stl_hash_map is a very thin wrapper over stl_hashtable. The major thing we define is operator[], because we have a concept of a data_type which stl_hashtable doesn't (it only has a key and a value).
NOTE: this is exactly like sparse_hashmap, with the word "sparse" replaced by "dense", except for the addition of set_empty_key().
YOU MUST CALL set_empty_key() IMMEDIATELY AFTER CONSTRUCTION. Otherwise your program will die in mysterious ways. (Note if you use the constructor that takes an InputIterator range, you pass in the empty key in the constructor, rather than after. As a result, this constructor differs from the standard STL version.)
In other respects, we adhere mostly to the STL semantics for hash_map
. One important exception is that insert() may invalidate iterators entirely -- STL semantics are that insert() may reorder iterators, but they all still refer to something valid in the hashtable. Not so for us. Likewise, insert() may invalidate pointers into the hashtable. (Whether insert invalidates iterators and pointers depends on whether it results in a hashtable resize). On the plus side, delete() doesn't invalidate iterators or pointers at all, or even change the ordering of elements.
Here are a few "power user" tips:
1) set_deleted_key(): If you want to use erase() you must call set_deleted_key(), in addition to set_empty_key(), after construction. The deleted and empty keys must differ.
2) resize(0): When an item is deleted, its memory isn't freed right away. This allows you to iterate over a hashtable, and call erase(), without invalidating the iterator. To force the memory to be freed, call resize(0). For tr1 compatibility, this can also be called as rehash(0).
3) min_load_factor(0.0) Setting the minimum load factor to 0.0 guarantees that the hash table will never shrink.
Roughly speaking: (1) dense_hashmap: fastest, uses the most memory unless entries are small (2) sparse_hashmap: slowest, uses the least memory (3) hash_map / unordered_map (STL): in the middle
typedef Alloc ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::allocator_type |
Concept: tr1::container
typedef ht::const_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::const_iterator |
The const type used to iterate through the contents of the container.
Concept: stl::forward_container
typedef ht::const_local_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::const_local_iterator |
The const type used to iterate through a set of elements that share a hash code.
Concept: tr1::unordered_associative_container
typedef ht::const_pointer ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::const_pointer |
The type that serves as a const pointer to value_type.
Concept: stl::container
typedef ht::const_reference ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::const_reference |
The type that serves as a pointer to value_type.
Concept: stl::container
typedef Data ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::data_type |
The type of object associated with keys.
Concept: stl::pair_associative_container
typedef ht::difference_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::difference_type |
The signed integral type used to represent the distance between iterators.
Concept: stl::container
typedef ht::hasher ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::hasher |
The functor type used to hash keys.
Concept: stl::hashed_associative_container
typedef ht::iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::iterator |
The type used to iterate through the contents of the container.
Concept: stl::forward_container
typedef ht::key_equal ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::key_equal |
The functor used to compare keys for equality.
Concept: stl::hashed_associative_container
typedef ht::key_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::key_type |
The type used to identify elements.
Concept: stl::associative_container
typedef ht::local_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::local_iterator |
The type used to iterate through a set of elements that share a hash code.
Concept: tr1::unordered_associative_container
typedef Data ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::mapped_type |
Concept: tr1::unordered_map
typedef ht::pointer ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::pointer |
The type that serves as a pointer to value_type.
Concept: stl::container
typedef ht::reference ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::reference |
The type that serves as a reference to value_type.
Concept: stl::container
typedef ht::size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::size_type |
The unsigned type used to represent the size of the container.
Concept: stl::container
typedef ht::value_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::value_type |
The type of object stored in the container.
Concept: stl::pair_associative_container
ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::dense_hashmap | ( | size_type | n = 0 , |
hasher const & | h = hasher() , |
||
key_equal const & | k = key_equal() |
||
) | [inline, explicit] |
Default constructor.
n | The number of expected elements. |
h | The hasher object to copy, if any. |
k | The key_equal object to copy, if any. |
ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::dense_hashmap | ( | InputIterator | f, |
InputIterator | l, | ||
key_type const & | empty_key_val, | ||
size_type | n = 0 , |
||
hasher const & | h = hasher() , |
||
key_equal const & | k = key_equal() |
||
) | [inline] |
Iterative constructor.
f | The beginning of the range of elements to insert. |
l | The end of the range of elements to insert. |
empty_key_val | The key to use for empty buckets. |
n | The number of expected elements. |
h | The hasher object to copy, if any. |
k | The key_equal object to copy, if any. |
iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::begin | ( | ) | [inline] |
Get an iterator to the beginning.
const_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::begin | ( | ) | const [inline] |
Get an iterator to the beginning.
local_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::begin | ( | size_type | i | ) | [inline] |
Concept: tr1::unordered_associative_container
const_local_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::begin | ( | size_type | i | ) | const [inline] |
Concept: tr1::unordered_associative_container
size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::bucket | ( | key_type const & | key | ) | const [inline] |
Concept: tr1::unordered_associative_container
size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::bucket_count | ( | ) | const [inline] |
Get the number of buckets the container has.
size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::bucket_size | ( | size_type | i | ) | const [inline] |
Concept: tr1::unordered_associative_container
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::clear | ( | ) | [inline] |
Erase all elements.
Concept: stl::associative_container
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::clear_deleted_key | ( | ) | [inline] |
Clear the key used for deleted buckets.
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::clear_no_resize | ( | ) | [inline] |
Clear the container without resizing.
This clears the hash map without resizing it down to the minimum bucket count, but rather keeps the number of buckets constant.
size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::count | ( | key_type const & | key | ) | const [inline] |
Count the number of elements with a given key.
key | The key to search for. |
key
. Because this is a Unique Associative Container , the return value will be 0 or 1. key_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::deleted_key | ( | ) | const [inline] |
Get the key used for deleted buckets.
bool ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::empty | ( | ) | const [inline] |
key_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::empty_key | ( | ) | const [inline] |
Get the key used for empty buckets.
iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::end | ( | ) | [inline] |
Get an iterator to the end.
const_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::end | ( | ) | const [inline] |
Get an iterator to the end.
local_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::end | ( | size_type | i | ) | [inline] |
Concept: tr1::unordered_associative_container
const_local_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::end | ( | size_type | i | ) | const [inline] |
Concept: tr1::unordered_associative_container
pair<iterator, iterator> ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::equal_range | ( | key_type const & | key | ) | [inline] |
Find all elements matching a given key.
key | The key to search for. |
iterator
points to the element, or to the end() if not found. The second iterator
points to 1 past the first, or to the end(). pair<const_iterator, const_iterator> ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::equal_range | ( | key_type const & | key | ) | const [inline] |
Find all elements matching a given key.
key | The key to search for. |
const_iterator
points to the element, or to the end() if not found. The second const_iterator
points to 1 past the first, or to the end(). size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::erase | ( | key_type const & | key | ) | [inline] |
Erase an element.
key | The key of the element to erase. |
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::erase | ( | iterator | itr | ) | [inline] |
Erase an element.
itr | An iterator pointing to the element to erase. |
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::erase | ( | iterator | f, |
iterator | l | ||
) | [inline] |
Erase a range of elements.
f | The beginning of the range to erase. |
l | The end of the range to erase. |
iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::find | ( | key_type const & | key | ) | [inline] |
Find an element.
key | The key of the element to search for. |
const_iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::find | ( | key_type const & | key | ) | const [inline] |
Find an element.
key | The key of the element to search for. |
hasher ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::hash_funct | ( | ) | const [inline] |
Get the hash functor used by the container.
hasher
object. hasher ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::hash_function | ( | ) | const [inline] |
Get the hash functor used by the container.
hasher
object. pair<iterator, bool> ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::insert | ( | const_reference | obj | ) | [inline] |
Insert an element into the container.
obj | The element to insert. |
iterator
and a bool
. The iterator
points to the inserted element, or to another with the same key if one is already in the container. The bool
is true if the element was inserted, and false in the case of a duplicate key. void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::insert | ( | InputIterator | f, |
InputIterator | l | ||
) | [inline] |
Insert a range of elements [f,l) into the container.
f | The beginning of the range to insert. |
l | The end of the range to insert. |
Elements with duplicate keys will be ignored.
Concept: stl::unique_associative_container
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::insert | ( | const_iterator | f, |
const_iterator | l | ||
) | [inline] |
Insert a range of elements [f,l) into the container.
f | The beginning of the range to insert. |
l | The end of the range to insert. |
Elements with duplicate keys will be ignored.
Concept: stl::unique_associative_container
iterator ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::insert | ( | iterator | , |
const_reference | obj | ||
) | [inline] |
Insert sematics for std::insert_iterator.
obj | The element to insert. |
key_equal ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::key_eq | ( | ) | const [inline] |
Get the key comparison functor used by the container.
key_equal
object. float ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::load_factor | ( | ) | const [inline] |
Concept: tr1::unordered_associative_container
size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::max_bucket_count | ( | ) | const [inline] |
Concept: stl::hashed_associative_container
float ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::max_load_factor | ( | ) | const [inline] |
Concept: tr1::unordered_associative_container
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::max_load_factor | ( | float | new_grow | ) | [inline] |
Concept: tr1::unordered_associative_container
size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::max_size | ( | ) | const [inline] |
Get the maximum size of the container.
float ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::min_load_factor | ( | ) | const [inline] |
Get the min load factor.
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::min_load_factor | ( | float | new_shrink | ) | [inline] |
Set the min load factor.
new_shrink | The min load factor before the container shrinks. |
bool ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::operator== | ( | const dense_hashmap< Key, Data, HashFx, EqualKey, Alloc > & | dhm | ) | const [inline] |
Equality operator.
data_type& ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::operator[] | ( | key_type const & | key | ) | [inline] |
Element access.
key | The key of the element to access. |
bool ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::read_metadata | ( | FILE * | fp | ) | [inline] |
Read the container contents from a file written by write_metadata().
fp | The file to read. |
bool ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::read_nopointer_data | ( | FILE * | fp | ) | [inline] |
Read the container contents from a file written by write_nopointer_data().
fp | The file to read. |
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::rehash | ( | size_type | n | ) | [inline] |
Concept: tr1::unordered_associative_container
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::resize | ( | size_type | n | ) | [inline] |
Resize the container to hold at least n elements.
n | The number of elements the container is expected to hold. |
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::set_deleted_key | ( | key_type const & | key | ) | [inline] |
Set the key to use for deleted buckets.
key | The key reserved for deleted buckets. |
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::set_empty_key | ( | key_type const & | key | ) | [inline] |
Set the key to use for empty buckets.
key | The key reserved for empty buckets. |
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::set_resizing_parameters | ( | float | shrink, |
float | grow | ||
) | [inline] |
size_type ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::size | ( | ) | const [inline] |
Get the size of the container.
void ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::swap | ( | dense_hashmap< Key, Data, HashFx, EqualKey, Alloc > & | c | ) | [inline] |
Swap method.
Concept: stl::container
bool ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::write_metadata | ( | FILE * | fp | ) | [inline] |
Write the container contents to file in a byte-order-independent format.
fp | The file to write. |
bool ash::dense_hashmap< Key, Data, HashFx, EqualKey, Alloc >::write_nopointer_data | ( | FILE * | fp | ) | [inline] |
Write the container contents to file in an architecture-dependent format.
fp | The file to write. |
© 2012 | Licensed under | Hosted by | Generated by 1.7.4 |