This template class implements an unordered map of keys to data, implemented as a hashtable. More...
#include "simpleHashMap.h"
Public Types | |
typedef SimpleKeyValuePair< Key, Value > | TableEntry |
Public Member Functions | |
constexpr | SimpleHashMap (const Compare &comp=Compare()) |
SimpleHashMap (const SimpleHashMap ©) | |
SimpleHashMap (SimpleHashMap &&from) noexcept | |
void | clear () |
Completely empties the table. More... | |
bool | consider_shrink_table () |
Shrinks the table if the allocated storage is significantly larger than the number of elements in it. More... | |
int | find (const Key &key) const |
Searches for the indicated key in the table. More... | |
const Value & | get_data (size_t n) const |
Returns the data in the nth entry of the table. More... | |
const Key & | get_key (size_t n) const |
Returns the key in the nth entry of the table. More... | |
size_t | get_num_entries () const |
Returns the number of active entries in the table. More... | |
bool | is_empty () const |
Returns true if the table is empty; i.e. More... | |
Value & | modify_data (size_t n) |
Returns a modifiable reference to the data in the nth entry of the table. More... | |
Value & | operator [] (const Key &key) |
Returns a modifiable reference to the data associated with the indicated key, or creates a new data entry and returns its reference. More... | |
SimpleHashMap & | operator= (const SimpleHashMap ©) |
SimpleHashMap & | operator= (SimpleHashMap &&from) noexcept |
void | output (std::ostream &out) const |
bool | remove (const Key &key) |
Removes the indicated key and its associated data from the table. More... | |
void | remove_element (size_t n) |
Removes the nth entry from the table. More... | |
void | set_data (size_t n, const Value &data) |
Changes the data for the nth entry of the table. More... | |
void | set_data (size_t n, Value &&data) |
Changes the data for the nth entry of the table. More... | |
constexpr size_t | size () const |
Returns the total number of entries in the table. More... | |
int | store (const Key &key, const Value &data) |
Records the indicated key/data pair in the map. More... | |
void | swap (SimpleHashMap &other) |
Quickly exchanges the contents of this map and the other map. More... | |
bool | validate () const |
Returns true if the internal table appears to be consistent, false if there are some internal errors. More... | |
void | write (std::ostream &out) const |
Public Attributes | |
Compare | _comp |
DeletedBufferChain * | _deleted_chain |
size_t | _num_entries |
TableEntry * | _table |
size_t | _table_size |
This template class implements an unordered map of keys to data, implemented as a hashtable.
It is similar to STL's hash_map, but (a) it has a simpler interface (we don't mess around with iterators), (b) it wants an additional method on the Compare object, Compare::is_equal(a, b), (c) it doesn't depend on the system STL providing hash_map, (d) it allows for efficient iteration over the entries, (e) permits removal and resizing during forward iteration, and (f) it has a constexpr constructor.
It can also be used as a set, by using nullptr_t as Value typename.
Definition at line 81 of file simpleHashMap.h.
void SimpleHashMap< Key, Value, Compare >::clear | ( | ) |
Completely empties the table.
Definition at line 331 of file simpleHashMap.I.
Referenced by RenderState::clear_munger_cache().
|
inline |
Shrinks the table if the allocated storage is significantly larger than the number of elements in it.
Returns true if shrunk, false otherwise.
Definition at line 693 of file simpleHashMap.I.
int SimpleHashMap< Key, Value, Compare >::find | ( | const Key & | key | ) | const |
Searches for the indicated key in the table.
Returns its index number if it is found, or -1 if it is not present in the table.
Definition at line 156 of file simpleHashMap.I.
|
inline |
Returns the data in the nth entry of the table.
n | should be in the range 0 <= n < size(). |
Definition at line 387 of file simpleHashMap.I.
|
inline |
Returns the key in the nth entry of the table.
n | should be in the range 0 <= n < size(). |
Definition at line 375 of file simpleHashMap.I.
Referenced by RenderState::clear_cache(), RenderState::clear_munger_cache(), PandaNode::compare_tags(), RenderState::get_num_unused_states(), RenderAttrib::list_attribs(), RenderState::list_cycles(), RenderState::list_states(), PT(), and RenderAttrib::validate_attribs().
|
inline |
Returns the number of active entries in the table.
Same as size().
Definition at line 445 of file simpleHashMap.I.
Referenced by RenderState::clear_cache(), RenderState::clear_munger_cache(), RenderAttrib::get_num_attribs(), RenderState::get_num_states(), RenderState::get_num_unused_states(), RenderAttrib::list_attribs(), RenderState::list_cycles(), RenderState::list_states(), PT(), RenderAttrib::validate_attribs(), and RenderState::validate_states().
|
inline |
Returns true if the table is empty; i.e.
get_num_entries() == 0.
Definition at line 454 of file simpleHashMap.I.
Referenced by PT(), RenderAttrib::validate_attribs(), and RenderState::validate_states().
|
inline |
Returns a modifiable reference to the data in the nth entry of the table.
n | should be in the range 0 <= n < size(). |
Definition at line 399 of file simpleHashMap.I.
|
inline |
Returns a modifiable reference to the data associated with the indicated key, or creates a new data entry and returns its reference.
Definition at line 351 of file simpleHashMap.I.
|
inline |
Removes the indicated key and its associated data from the table.
Returns true if the key was removed, false if it was not present.
Iterator safety: To perform removal during iteration, revisit the element at the current index if removal succeeds, keeping in mind that the number of elements has now shrunk by one.
Definition at line 254 of file simpleHashMap.I.
void SimpleHashMap< Key, Value, Compare >::remove_element | ( | size_t | n | ) |
Removes the nth entry from the table.
n | should be in the range 0 <= n < size(). |
Definition at line 435 of file simpleHashMap.I.
|
inline |
Changes the data for the nth entry of the table.
n | should be in the range 0 <= n < size(). |
Definition at line 411 of file simpleHashMap.I.
|
inline |
Changes the data for the nth entry of the table.
n | should be in the range 0 <= n < size(). |
Definition at line 423 of file simpleHashMap.I.
constexpr size_t SimpleHashMap< Key, Value, Compare >::size | ( | ) | const |
Returns the total number of entries in the table.
Same as get_num_entries.
Definition at line 364 of file simpleHashMap.I.
Referenced by PandaNode::compare_tags().
int SimpleHashMap< Key, Value, Compare >::store | ( | const Key & | key, |
const Value & | data | ||
) |
Records the indicated key/data pair in the map.
If the key was already present, silently replaces it. Returns the index at which it was stored.
Definition at line 177 of file simpleHashMap.I.
Referenced by CPT().
|
inline |
Quickly exchanges the contents of this map and the other map.
Definition at line 132 of file simpleHashMap.I.
bool SimpleHashMap< Key, Value, Compare >::validate | ( | ) | const |
Returns true if the internal table appears to be consistent, false if there are some internal errors.
Definition at line 504 of file simpleHashMap.I.
Referenced by RenderAttrib::validate_attribs(), and RenderState::validate_states().