Panda3D

Loading...
Searching...
No Matches
Public Types | Public Member Functions | Public Attributes | List of all members
SimpleHashMap< Key, Value, Compare > Class Template Reference

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 &copy)
| SimpleHashMap (SimpleHashMap &&from) noexcept
void | clear ()
| Completely empties the table.
bool | consider_shrink_table ()
| Shrinks the table if the allocated storage is significantly larger than the number of elements in it.
int | find (const Key &key) const
| Searches for the indicated key in the table.
const Value & | get_data (size_t n) const
| Returns the data in the nth entry of the table.
const Key & | get_key (size_t n) const
| Returns the key in the nth entry of the table.
size_t | get_num_entries () const
| Returns the number of active entries in the table.
bool | is_empty () const
| Returns true if the table is empty; i.e.
Value & | modify_data (size_t n)
| Returns a modifiable reference to the data in the nth entry of the table.
SimpleHashMap & | operator= (const SimpleHashMap &copy)
SimpleHashMap & | operator= (SimpleHashMap &&from) noexcept
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.
void | output (std::ostream &out) const
bool | remove (const Key &key)
| Removes the indicated key and its associated data from the table.
void | remove_element (size_t n)
| Removes the nth entry from the table.
void | set_data (size_t n, const Value &data)
| Changes the data for the nth entry of the table.
void | set_data (size_t n, Value &&data)
| Changes the data for the nth entry of the table.
constexpr size_t | size () const
| Returns the total number of entries in the table.
int | store (const Key &key, const Value &data)
| Records the indicated key/data pair in the map.
void | swap (SimpleHashMap &other)
| Quickly exchanges the contents of this map and the other map.
bool | validate () const
| Returns true if the internal table appears to be consistent, false if there are some internal errors.
void | write (std::ostream &out) const

## Public Attributes
Compare | _comp
DeletedBufferChain * | _deleted_chain
size_t | _num_entries
TableEntry * | _table
size_t | _table_size

## Detailed Description

template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> >>
class SimpleHashMap< Key, Value, Compare >

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.

## Member Typedef Documentation

## ◆ TableEntry

template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> >>

typedef SimpleKeyValuePair<Key, Value> SimpleHashMap< Key, Value, Compare >::TableEntry

Definition at line 137 of file simpleHashMap.h.

## Constructor & Destructor Documentation

## ◆ SimpleHashMap() [1/3]

template<class Key, class Value, class Compare>

SimpleHashMap< Key, Value, Compare >::SimpleHashMap | ( | const Compare & | comp = Compare() | ) |
| constexpr

Definition at line 18 of file simpleHashMap.I.

## ◆ SimpleHashMap() [2/3]

template<class Key, class Value, class Compare>

SimpleHashMap< Key, Value, Compare >::SimpleHashMap | ( | const SimpleHashMap< Key, Value, Compare > & | copy | ) |
| inline

Definition at line 32 of file simpleHashMap.I.

## ◆ SimpleHashMap() [3/3]

template<class Key, class Value, class Compare>

SimpleHashMap< Key, Value, Compare >::SimpleHashMap | ( | SimpleHashMap< Key, Value, Compare > && | from | ) |
| inline noexcept

Definition at line 61 of file simpleHashMap.I.

## ◆ ~SimpleHashMap()

template<class Key, class Value, class Compare>

SimpleHashMap< Key, Value, Compare >::~SimpleHashMap | ( |  | ) |
| inline

Definition at line 79 of file simpleHashMap.I.

## Member Function Documentation

## ◆ clear()

template<class Key, class Value, class Compare>

void SimpleHashMap< Key, Value, Compare >::clear | ( |  | ) |

Completely empties the table.

Definition at line 352 of file simpleHashMap.I.

Referenced by RenderState::clear_cache(), TransformState::clear_cache(), and RenderState::clear_munger_cache().

## ◆ consider_shrink_table()

template<class Key, class Value, class Compare>

bool SimpleHashMap< Key, Value, Compare >::consider_shrink_table | ( |  | ) |
| 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 711 of file simpleHashMap.I.

## ◆ find()

template<class Key, class Value, class Compare>

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 176 of file simpleHashMap.I.

Referenced by GraphicsStateGuardian::get_geom_munger(), StateMunger::munge_state(), operator[](), and TransformState::validate_composition_cache().

## ◆ get_data()

template<class Key, class Value, class Compare>

const Value & SimpleHashMap< Key, Value, Compare >::get_data | ( | size_t | n | ) | const
| inline

Returns the data in the nth entry of the table.

Parameters

  n | should be in the range 0 <= n < size().

Definition at line 408 of file simpleHashMap.I.

References get_data().

Referenced by RenderState::clear_cache(), TransformState::clear_cache(), PandaNode::compare_tags(), PandaNode::copy_all_properties(), PandaNode::copy_tags(), get_data(), GraphicsStateGuardian::get_geom_munger(), RenderState::get_num_unused_states(), TransformState::get_num_unused_states(), and StateMunger::munge_state().

## ◆ get_key()

template<class Key, class Value, class Compare>

const Key & SimpleHashMap< Key, Value, Compare >::get_key | ( | size_t | n | ) | const
| inline

Returns the key in the nth entry of the table.

Parameters

  n | should be in the range 0 <= n < size().

Definition at line 396 of file simpleHashMap.I.

Referenced by PandaNode::compare_tags(), PandaNode::copy_all_properties(), PandaNode::copy_tags(), GraphicsStateGuardian::get_geom_munger(), PandaNode::get_tag_keys(), and PandaNode::list_tags().

## ◆ get_num_entries()

template<class Key, class Value, class Compare>

size_t SimpleHashMap< Key, Value, Compare >::get_num_entries | ( |  | ) | const
| inline

Returns the number of active entries in the table.

Same as size().

Definition at line 466 of file simpleHashMap.I.

Referenced by RenderState::clear_cache(), TransformState::clear_cache(), GraphicsStateGuardian::get_geom_munger(), RenderState::get_num_unused_states(), and TransformState::get_num_unused_states().

## ◆ is_empty()

template<class Key, class Value, class Compare>

bool SimpleHashMap< Key, Value, Compare >::is_empty | ( |  | ) | const
| inline

Returns true if the table is empty; i.e.

get_num_entries() == 0.

Definition at line 475 of file simpleHashMap.I.

Referenced by RenderState::compose(), PandaNode::copy_tags(), GraphicsStateGuardian::get_geom_munger(), and RenderState::invert_compose().

## ◆ modify_data()

template<class Key, class Value, class Compare>

Value & SimpleHashMap< Key, Value, Compare >::modify_data | ( | size_t | n | ) |
| inline

Returns a modifiable reference to the data in the nth entry of the table.

Parameters

  n | should be in the range 0 <= n < size().

Definition at line 420 of file simpleHashMap.I.

References modify_data().

Referenced by modify_data(), and operator[]().

## ◆ operator=() [1/2]

template<class Key, class Value, class Compare>

SimpleHashMap< Key, Value, Compare > & SimpleHashMap< Key, Value, Compare >::operator= | ( | const SimpleHashMap< Key, Value, Compare > & | copy | ) |
| inline

Definition at line 88 of file simpleHashMap.I.

## ◆ operator=() [2/2]

template<class Key, class Value, class Compare>

SimpleHashMap< Key, Value, Compare > & SimpleHashMap< Key, Value, Compare >::operator= | ( | SimpleHashMap< Key, Value, Compare > && | from | ) |
| inline noexcept

Definition at line 132 of file simpleHashMap.I.

## ◆ operator[]()

template<class Key, class Value, class Compare>

Value & SimpleHashMap< Key, Value, Compare >::operator[] | ( | const Key & | key | ) |
| 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 372 of file simpleHashMap.I.

References find(), modify_data(), and store().

## ◆ output()

template<class Key, class Value, class Compare>

void SimpleHashMap< Key, Value, Compare >::output | ( | std::ostream & | out | ) | const

Definition at line 484 of file simpleHashMap.I.

## ◆ remove()

template<class Key, class Value, class Compare>

bool SimpleHashMap< Key, Value, Compare >::remove | ( | const Key & | key | ) |
| 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 274 of file simpleHashMap.I.

References validate().

Referenced by remove_element().

## ◆ remove_element()

template<class Key, class Value, class Compare>

void SimpleHashMap< Key, Value, Compare >::remove_element | ( | size_t | n | ) |

Removes the nth entry from the table.

Parameters

  n | should be in the range 0 <= n < size().

Definition at line 456 of file simpleHashMap.I.

References remove().

Referenced by GraphicsStateGuardian::get_geom_munger(), and StateMunger::munge_state().

## ◆ set_data() [1/2]

template<class Key, class Value, class Compare>

void SimpleHashMap< Key, Value, Compare >::set_data | ( | size_t | n,
|  | const Value & | data )
| inline

Changes the data for the nth entry of the table.

Parameters

  n | should be in the range 0 <= n < size().

Definition at line 432 of file simpleHashMap.I.

Referenced by store().

## ◆ set_data() [2/2]

template<class Key, class Value, class Compare>

void SimpleHashMap< Key, Value, Compare >::set_data | ( | size_t | n,
|  | Value && | data )
| inline

Changes the data for the nth entry of the table.

Parameters

  n | should be in the range 0 <= n < size().

Definition at line 444 of file simpleHashMap.I.

## ◆ size()

template<class Key, class Value, class Compare>

size_t SimpleHashMap< Key, Value, Compare >::size | ( |  | ) | const
| constexpr

Returns the total number of entries in the table.

Same as get_num_entries.

Definition at line 385 of file simpleHashMap.I.

Referenced by PandaNode::compare_tags(), PandaNode::copy_all_properties(), PandaNode::copy_tags(), PandaNode::get_tag_keys(), and PandaNode::list_tags().

## ◆ store()

template<class Key, class Value, class Compare>

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 197 of file simpleHashMap.I.

References set_data(), store(), and validate().

Referenced by PandaNode::copy_all_properties(), PandaNode::copy_tags(), GraphicsStateGuardian::get_geom_munger(), StateMunger::munge_state(), operator[](), and store().

## ◆ swap()

template<class Key, class Value, class Compare>

void SimpleHashMap< Key, Value, Compare >::swap | ( | SimpleHashMap< Key, Value, Compare > & | other | ) |
| inline

Quickly exchanges the contents of this map and the other map.

Definition at line 152 of file simpleHashMap.I.

## ◆ validate()

template<class Key, class Value, class Compare>

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 525 of file simpleHashMap.I.

Referenced by remove(), and store().

## ◆ write()

template<class Key, class Value, class Compare>

void SimpleHashMap< Key, Value, Compare >::write | ( | std::ostream & | out | ) | const

Definition at line 511 of file simpleHashMap.I.

## Member Data Documentation

## ◆ _comp

template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> >>

Compare SimpleHashMap< Key, Value, Compare >::_comp

Definition at line 143 of file simpleHashMap.h.

## ◆ _deleted_chain

template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> >>

DeletedBufferChain* SimpleHashMap< Key, Value, Compare >::_deleted_chain

Definition at line 139 of file simpleHashMap.h.

## ◆ _num_entries

template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> >>

size_t SimpleHashMap< Key, Value, Compare >::_num_entries

Definition at line 141 of file simpleHashMap.h.

## ◆ _table

template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> >>

TableEntry* SimpleHashMap< Key, Value, Compare >::_table

Definition at line 138 of file simpleHashMap.h.

## ◆ _table_size

template<class Key, class Value, class Compare = method_hash<Key, std::less<Key> >>

size_t SimpleHashMap< Key, Value, Compare >::_table_size

Definition at line 140 of file simpleHashMap.h.

The documentation for this class was generated from the following files:

- panda/src/putil/simpleHashMap.h
- panda/src/putil/simpleHashMap.I