A STL-like hashset with dense_hashtable as the backend. More...
#include <ash/dense_hashset.h>
Public Types | |
typedef ht::key_type | key_type |
The type used to identify elements. | |
typedef ht::value_type | value_type |
The type of the object the container holds. | |
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::const_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::const_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::const_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::const_local_iterator | local_iterator |
| |
typedef ht::const_local_iterator | const_local_iterator |
| |
Public Member Functions | |
key_type | empty_key () const |
Get the key used for empty buckets. | |
void | set_empty_key (const key_type &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 (const key_type &key) |
Set the key to use for deleted buckets. | |
void | clear_deleted_key () |
Clear the key used for deleted buckets. | |
bool | operator== (const dense_hashset &dhs) const |
Equality operator. | |
Iterator Methods | |
iterator | begin () const |
Get an iterator to the beginning. | |
iterator | end () const |
Get an iterator to the end. | |
local_iterator | begin (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_hashset (size_type n=0, hasher const &h=hasher(), key_equal const &k=key_equal()) | |
Default constructor. | |
template<class InputIterator > | |
dense_hashset (InputIterator f, InputIterator l, size_type n, key_type const &empty_key_val, hasher const &h=hasher(), key_equal const &k=key_equal()) | |
Iterative constructor. | |
void | swap (dense_hashset &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 |
| |
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 minimum load factor. | |
void | min_load_factor (float new_shrink) |
Set the minimum 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) const |
Find an element. | |
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) 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 Val , class HashFx , class EqualKey , class Alloc > | |
void | swap (dense_hashset< Val, HashFx, EqualKey, Alloc > &x, dense_hashset< Val, HashFx, EqualKey, Alloc > &y) |
Global swap function. |
A STL-like hashset with dense_hashtable as the backend.
Value | The type of object stored by the dense_hashset. Also defined as dense_hashset::value_type. |
HashFx | The hash functor used by the dense_hashset. Also defined as dense_hashset::hasher. |
EqualKey | The dense_hashset key equality functor: a binary predicate that determines whether two keys are equal. Also defined as dense_hashset::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_set 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).
This is more different from dense_hashmap than you might think, because all iterators for sets are const (you obviously can't change the key, and for sets there is no value).
NOTE: this is exactly like sparse_hashset, 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.
In other respects, we adhere mostly to the STL semantics for hash-set. 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_hashset: fastest, uses the most memory unless entries are small (2) sparse_hashset: slowest, uses the least memory (3) hash_set / unordered_set (STL): in the middle
typedef Alloc ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::allocator_type |
Concept: tr1::container
typedef ht::const_iterator ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::const_iterator |
The const type used to iterate through the contents of the container.
Concept: stl::simple_associative_container
typedef ht::const_local_iterator ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::const_local_iterator |
Concept: tr1::unordered_set
typedef ht::const_pointer ash::dense_hashset< Value, 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_hashset< Value, HashFx, EqualKey, Alloc >::const_reference |
The type that serves as a pointer to value_type.
Concept: stl::container
typedef ht::difference_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::difference_type |
The signed integral type used to represent the distance between iterators.
Concept: stl::container
typedef ht::hasher ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::hasher |
The functor type used to hash keys.
Concept: stl::hashed_associative_container
typedef ht::const_iterator ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::iterator |
The type used to iterate through the contents of the container.
Concept: stl::simple_associative_container
typedef ht::key_equal ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::key_equal |
The functor used to compare keys for equality.
Concept: stl::hashed_associative_container
typedef ht::key_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::key_type |
The type used to identify elements.
Concept: stl::simple_associative_container
typedef ht::const_local_iterator ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::local_iterator |
Concept: tr1::unordered_set
typedef ht::const_pointer ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::pointer |
The type that serves as a pointer to value_type.
Concept: stl::container
typedef ht::const_reference ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::reference |
The type that serves as a reference to value_type.
Concept: stl::container
typedef ht::size_type ash::dense_hashset< Value, 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_hashset< Value, HashFx, EqualKey, Alloc >::value_type |
The type of the object the container holds.
Must be Assignable .
Concept: stl::simple_associative_container
ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::dense_hashset | ( | 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_hashset< Value, HashFx, EqualKey, Alloc >::dense_hashset | ( | InputIterator | f, |
InputIterator | l, | ||
size_type | n, | ||
key_type const & | empty_key_val, | ||
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_hashset< Value, HashFx, EqualKey, Alloc >::begin | ( | ) | const [inline] |
Get an iterator to the beginning.
local_iterator ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::begin | ( | size_type | i | ) | const [inline] |
Concept: tr1::unordered_set
size_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::bucket | ( | key_type const & | key | ) | const [inline] |
Concept: tr1::unordered_associative_container
size_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::bucket_count | ( | ) | const [inline] |
Concept: tr1::unordered_associative_container
size_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::bucket_size | ( | size_type | i | ) | const [inline] |
Concept: tr1::unordered_associative_container
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::clear | ( | ) | [inline] |
Erase all elements.
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::clear_deleted_key | ( | ) | [inline] |
Clear the key used for deleted buckets.
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::clear_no_resize | ( | ) | [inline] |
Clear the container without resizing.
This clears the container without resizing it down to the minimum bucket count, but rather keeps the number of buckets constant.
size_type ash::dense_hashset< Value, 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_hashset< Value, HashFx, EqualKey, Alloc >::deleted_key | ( | ) | const [inline] |
Get the key used for deleted buckets.
bool ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::empty | ( | ) | const [inline] |
key_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::empty_key | ( | ) | const [inline] |
Get the key used for empty buckets.
iterator ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::end | ( | ) | const [inline] |
Get an iterator to the end.
local_iterator ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::end | ( | size_type | i | ) | const [inline] |
Concept: tr1::unordered_set
pair<iterator, iterator> ash::dense_hashset< Value, 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_hashset< Value, HashFx, EqualKey, Alloc >::erase | ( | key_type const & | key | ) | [inline] |
Erase an element.
key | The key of the element to erase. |
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::erase | ( | iterator | itr | ) | [inline] |
Erase an element.
itr | An iterator pointing to the element to erase. |
void ash::dense_hashset< Value, 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_hashset< Value, 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_hashset< Value, HashFx, EqualKey, Alloc >::hash_funct | ( | ) | const [inline] |
Get the hash functor used by the container.
hasher
object. hasher ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::hash_function | ( | ) | const [inline] |
Get the hash functor used by the container.
hasher
object. pair<iterator, bool> ash::dense_hashset< Value, 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_hashset< Value, 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_hashset< Value, 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_hashset< Value, HashFx, EqualKey, Alloc >::insert | ( | iterator | , |
const_reference | obj | ||
) | [inline] |
Insert sematics for std::insert_iterator.
obj | The element to insert. |
key_equal ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::key_eq | ( | ) | const [inline] |
Get the key comparison functor used by the container.
key_equal
object. float ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::load_factor | ( | ) | const [inline] |
Concept: tr1::unordered_associative_container
size_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::max_bucket_count | ( | ) | const [inline] |
Concept: tr1::unordered_associative_container
float ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::max_load_factor | ( | ) | const [inline] |
Concept: tr1::unordered_associative_container
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::max_load_factor | ( | float | new_grow | ) | [inline] |
Concept: tr1::unordered_associative_container
size_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::max_size | ( | ) | const [inline] |
Get the maximum size of the container.
float ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::min_load_factor | ( | ) | const [inline] |
Get the minimum load factor.
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::min_load_factor | ( | float | new_shrink | ) | [inline] |
Set the minimum load factor.
new_shrink | The min load factor before the container shrinks. |
bool ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::operator== | ( | const dense_hashset< Value, HashFx, EqualKey, Alloc > & | dhs | ) | const [inline] |
Equality operator.
bool ash::dense_hashset< Value, 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_hashset< Value, 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_hashset< Value, HashFx, EqualKey, Alloc >::rehash | ( | size_type | n | ) | [inline] |
Concept: tr1::unordered_associative_container
void ash::dense_hashset< Value, 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_hashset< Value, HashFx, EqualKey, Alloc >::set_deleted_key | ( | const key_type & | key | ) | [inline] |
Set the key to use for deleted buckets.
key | The key reserved for deleted buckets. |
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::set_empty_key | ( | const key_type & | key | ) | [inline] |
Set the key to use for empty buckets.
key | The key reserved for empty buckets. |
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::set_resizing_parameters | ( | float | shrink, |
float | grow | ||
) | [inline] |
size_type ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::size | ( | ) | const [inline] |
Get the size of the container.
void ash::dense_hashset< Value, HashFx, EqualKey, Alloc >::swap | ( | dense_hashset< Value, HashFx, EqualKey, Alloc > & | c | ) | [inline] |
Swap method.
Concept: stl::container
bool ash::dense_hashset< Value, 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_hashset< Value, 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 |