Panda3D
 All Classes Functions Variables Enumerations
Classes | Public Member Functions | 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 Member Functions

 SimpleHashMap (const Compare &comp=Compare())
 
void clear ()
 Completely empties the table. More...
 
int find (const Key &key) const
 Searches for the indicated key in the table. More...
 
const Value & get_data (int n) const
 Returns the data in the nth slot of the table. More...
 
const Key & get_key (int n) const
 Returns the key in the nth slot of the table. More...
 
int get_num_entries () const
 Returns the number of active entries in the table. More...
 
int get_size () const
 Returns the total number of slots in the table. More...
 
bool has_element (int n) const
 Returns true if there is an element stored in the nth slot, false otherwise. More...
 
bool is_empty () const
 Returns true if the table is empty; i.e. More...
 
Value & modify_data (int n)
 Returns a modifiable reference to the data in the nth slot 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...
 
void output (ostream &out) const
 
bool remove (const Key &key)
 Removes the indicated key and its associated data from the table. More...
 
void remove_element (int n)
 Removes the nth slot from the table. More...
 
void set_data (int n, const Value &data)
 Changes the data for the nth slot of 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 (ostream &out) const
 

Detailed Description

template<class Key, class Value, class Compare = method_hash<Key, 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), and (c) it doesn't depend on the system STL providing hash_map.

Definition at line 33 of file simpleHashMap.h.

Member Function Documentation

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

Completely empties the table.

Definition at line 212 of file simpleHashMap.I.

References TypeHandle::none().

Referenced by RenderState::clear_cache().

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

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

Returns the data in the nth slot of the table.

It is an error to call this if there is nothing stored in the nth slot (use has_element() to check this first). n should be in the range 0 <= n < get_size().

Definition at line 300 of file simpleHashMap.I.

Referenced by RenderState::clear_cache(), RenderState::get_composition_cache_result(), RenderState::get_invert_composition_cache_result(), and RenderState::get_num_unused_states().

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

Returns the number of active entries in the table.

This is not necessarily related to the number of slots in the table as reported by get_size(). Use get_size() to iterate through all of the slots, not get_num_entries().

Definition at line 401 of file simpleHashMap.I.

Referenced by RenderState::clear_cache(), RenderAttrib::garbage_collect(), RenderState::garbage_collect(), RenderState::get_composition_cache_num_entries(), RenderState::get_invert_composition_cache_num_entries(), RenderAttrib::get_num_attribs(), RenderState::get_num_states(), RenderAttrib::list_attribs(), and RenderState::list_states().

template<class Key , class Value , class Compare >
int SimpleHashMap< Key, Value, Compare >::get_size ( ) const
inline
template<class Key , class Value , class Compare >
bool SimpleHashMap< Key, Value, Compare >::has_element ( int  n) const
inline
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 413 of file simpleHashMap.I.

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

template<class Key , class Value , class Compare >
Value & SimpleHashMap< Key, Value, Compare >::modify_data ( int  n)
inline

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

It is an error to call this if there is nothing stored in the nth slot (use has_element() to check this first). n should be in the range 0 <= n < get_size().

Definition at line 318 of file simpleHashMap.I.

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

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.

Definition at line 196 of file simpleHashMap.I.

template<class Key , class Value , class Compare >
void SimpleHashMap< Key, Value, Compare >::remove_element ( int  n)

Removes the nth slot from the table.

It is an error to call this if there is nothing stored in the nth slot (use has_element() to check this first). n should be in the range 0 <= n < get_size().

Definition at line 352 of file simpleHashMap.I.

template<class Key , class Value, class Compare >
void SimpleHashMap< Key, Value, Compare >::set_data ( int  n,
const Value &  data 
)
inline

Changes the data for the nth slot of the table.

It is an error to call this if there is nothing stored in the nth slot (use has_element() to check this first). n should be in the range 0 <= n < get_size().

Definition at line 335 of file simpleHashMap.I.

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

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

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

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


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