Hash map implementation backed by a template parameterized hash table.
More...
#include <tpie/hash_map.h>
Inherits tpie::linear_memory_base< hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t > >.
|
typedef std::pair< key_t, data_t > | value_t |
|
typedef iter_base< const tbl_t > | const_iterator |
| Const iterator type. More...
|
|
|
static double | memory_coefficient () |
| Return the memory coefficient of the structure. More...
|
|
static double | memory_overhead () |
| Return the memory overhead of the structure. More...
|
|
static memory_size_type | memory_usage (memory_size_type size) |
| Return the number of bytes required to create a data structure supporting a given number of elements. More...
|
|
static memory_size_type | memory_fits (memory_size_type memory) |
| Return the maximum number of elements that can be contained in in the structure when it is allowed to fill a given number of bytes. More...
|
|
template<typename key_t, typename data_t, typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
class tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >
Hash map implementation backed by a template parameterized hash table.
- Template Parameters
-
key_t | Type of keys to store. |
data_t | Type of data associated with each key. |
hash_t | (Optional) Hash function to use. |
equal_t | (Optional) Equality predicate. |
index_t | (Optional) Index type into bucket array. Always size_t. |
table_t | (Optional) Hash table implementation. |
Definition at line 377 of file hash_map.h.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::hash_map |
( |
size_t |
size = 0 , |
|
|
const hash_t & |
hash = hash_t() , |
|
|
const equal_t & |
equal = equal_t() , |
|
|
value_t |
u = default_unused<value_t>::v() |
|
) |
| |
|
inline |
Construct hash map.
- Parameters
-
size | Number of buckets in initial hash map. |
hash | Hash function to use. |
equal | Equality predicate to use. |
u | Value to use for unused bucket entries. |
Definition at line 484 of file hash_map.h.
487 tbl(
size, u, key_hash_t(hash), key_equal_t(equal)) {}
size_t size() const
Return number of elements in map.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Return iterator to beginning of map.
Definition at line 563 of file hash_map.h.
563 {
return iterator(tbl, tbl.begin());}
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Return const iterator to beginning of map.
Definition at line 568 of file hash_map.h.
iter_base< const tbl_t > const_iterator
Const iterator type.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Return const iterator to beginning of map.
Definition at line 573 of file hash_map.h.
iter_base< const tbl_t > const_iterator
Const iterator type.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Return const iterator to end of map.
Definition at line 588 of file hash_map.h.
iter_base< const tbl_t > const_iterator
Const iterator type.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
void tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::clear |
( |
| ) |
|
|
inline |
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
bool tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::contains |
( |
const key_t & |
key | ) |
const |
|
inline |
Search for element with key.
Returns true if an element with the given key exists in the hash map.
- Parameters
-
key | Key of element to search for. |
Definition at line 556 of file hash_map.h.
557 return tbl.find(value_t(key, tbl.unused.second)) != tbl.end();
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Return iterator to end of map.
Definition at line 578 of file hash_map.h.
578 {
return iterator(tbl, tbl.end());}
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Return const iterator to end of map.
Definition at line 583 of file hash_map.h.
iter_base< const tbl_t > const_iterator
Const iterator type.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
void tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::erase |
( |
const key_t & |
key | ) |
|
|
inline |
Erase entry from hash map by key.
- Parameters
-
key | Key of entry to remove. |
Definition at line 499 of file hash_map.h.
500 tbl.erase(value_t(key, tbl.unused.second));
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Erase entry from hash map by iterator.
- Parameters
-
Definition at line 507 of file hash_map.h.
References tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::erase().
Referenced by tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::erase().
void erase(const key_t &key)
Erase entry from hash map by key.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Get iterator to element.
- Parameters
-
key | Key of element to find. |
Definition at line 539 of file hash_map.h.
540 return iterator(tbl, tbl.find(value_t(key, tbl.unused.second)));
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
Get iterator to element.
- Parameters
-
key | Key of element to find. |
Definition at line 547 of file hash_map.h.
548 return const_iterator(tbl, tbl.find(value_t(key, tbl.unused.second)));
iter_base< const tbl_t > const_iterator
Const iterator type.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
bool tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::insert |
( |
const key_t & |
key, |
|
|
const data_t & |
data |
|
) |
| |
|
inline |
Insert data into the hash map.
- Parameters
-
key | Key of data to insert. |
data | Data to associate with given key. |
Definition at line 514 of file hash_map.h.
515 return tbl.insert(value_t(key, data)).second;
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
static double tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::memory_coefficient |
( |
| ) |
|
|
inlinestatic |
Return the memory coefficient of the structure.
Allocating a structure with n elements will use at most
bytes. This does not include memory overhead incurred if the structure is allocated using new.
- Returns
- The memory coefficient of the structure.
Definition at line 465 of file hash_map.h.
466 return tbl_t::memory_coefficient();
Return the maximum number of elements that can be contained in in the structure when it is allowed to fill a given number of bytes.
- Parameters
-
memory | The number of bytes the structure is allowed to occupy |
- Returns
- The number of elements that will fit in the structure
Definition at line 93 of file util.h.
94 return static_cast<memory_size_type
>(
95 floor((memory - child_t::memory_overhead()) / child_t::memory_coefficient()));
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
static double tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::memory_overhead |
( |
| ) |
|
|
inlinestatic |
Return the memory overhead of the structure.
- See also
- memory_coefficient()
- Returns
- The memory overhead.
Definition at line 473 of file hash_map.h.
474 return tbl_t::memory_overhead() -
sizeof(tbl_t) +
sizeof(
hash_map);
hash_map(size_t size=0, const hash_t &hash=hash_t(), const equal_t &equal=equal_t(), value_t u=default_unused< value_t >::v())
Construct hash map.
Return the number of bytes required to create a data structure supporting a given number of elements.
- Parameters
-
size | The number of elements to support |
- Returns
- The amount of memory required in bytes
Definition at line 81 of file util.h.
82 return static_cast<memory_size_type
>(
83 floor(static_cast<double>(size) * child_t::memory_coefficient() + child_t::memory_overhead()));
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
data_t& tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::operator[] |
( |
const key_t & |
key | ) |
|
|
inline |
Look up data by key, creating an unused entry if it does not exist.
- Parameters
-
Definition at line 523 of file hash_map.h.
524 return tbl.get(tbl.insert(value_t(key, tbl.unused.second)).first).second;
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
const data_t& tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::operator[] |
( |
const key_t & |
key | ) |
const |
|
inline |
Look up data by key.
- Parameters
-
Definition at line 531 of file hash_map.h.
532 return tbl.get(tbl.find(key))->second;
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
void tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::resize |
( |
size_t |
size | ) |
|
|
inline |
Resize hash map to given size and remove all entries.
- Parameters
-
size | New size of hash map. |
Definition at line 493 of file hash_map.h.
size_t size() const
Return number of elements in map.
template<typename key_t , typename data_t , typename hash_t = hash<key_t>, typename equal_t = std::equal_to<key_t>, typename index_t = size_t, template< typename, typename, typename, typename > class table_t = chaining_hash_table>
size_t tpie::hash_map< key_t, data_t, hash_t, equal_t, index_t, table_t >::size |
( |
| ) |
const |
|
inline |
Return number of elements in map.
Definition at line 593 of file hash_map.h.
The documentation for this class was generated from the following file: