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.
 
SimpleHashMapoperator= (const SimpleHashMap &copy)
 
SimpleHashMapoperator= (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 >
constexpr 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)
inlinenoexcept

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

Referenced by RenderState::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 710 of file simpleHashMap.I.

Referenced by RenderAttrib::garbage_collect(), and RenderState::garbage_collect().

◆ 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 CPT(), and PT().

◆ 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
nshould be in the range 0 <= n < size().

Definition at line 407 of file simpleHashMap.I.

Referenced by RenderState::clear_cache(), PandaNode::compare_tags(), CPT(), RenderState::get_num_unused_states(), and PT().

◆ get_key()

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

◆ get_num_entries()

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

◆ is_empty()

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

◆ 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
nshould be in the range 0 <= n < size().

Definition at line 419 of file simpleHashMap.I.

◆ 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)
inlinenoexcept

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

◆ output()

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

Definition at line 483 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.

◆ 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
nshould be in the range 0 <= n < size().

Definition at line 455 of file simpleHashMap.I.

Referenced by CPT(), and PT().

◆ 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
nshould be in the range 0 <= n < size().

Definition at line 431 of file simpleHashMap.I.

◆ 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
nshould be in the range 0 <= n < size().

Definition at line 443 of file simpleHashMap.I.

◆ size()

template<class Key , class Value , class Compare >
constexpr 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 384 of file simpleHashMap.I.

Referenced by PandaNode::compare_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.

Referenced by CPT(), RenderState::init_states(), PT(), and RenderAttribRegistry::register_slot().

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

Referenced by RenderAttrib::garbage_collect(), RenderState::garbage_collect(), RenderAttrib::validate_attribs(), and RenderState::validate_states().

◆ write()

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

Definition at line 510 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: