Panda3D
Classes | Public Member Functions

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"

List of all members.

Classes

class  TableEntry

Public Member Functions

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

References TypeHandle::none().

Referenced by TransformState::clear_cache(), and 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 282 of file simpleHashMap.I.

Referenced by TransformState::clear_cache(), RenderState::clear_cache(), TransformState::get_composition_cache_result(), RenderState::get_composition_cache_result(), TransformState::get_invert_composition_cache_result(), RenderState::get_invert_composition_cache_result(), TransformState::get_num_unused_states(), 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]

Returns the key 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 265 of file simpleHashMap.I.

Referenced by TransformState::get_composition_cache_source(), RenderState::get_composition_cache_source(), TransformState::get_invert_composition_cache_source(), and RenderState::get_invert_composition_cache_source().

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

Referenced by TransformState::clear_cache(), RenderState::clear_cache(), TransformState::get_composition_cache_num_entries(), RenderState::get_composition_cache_num_entries(), TransformState::get_invert_composition_cache_num_entries(), and RenderState::get_invert_composition_cache_num_entries().

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

Referenced by RenderState::~RenderState(), and TransformState::~TransformState().

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 300 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 219 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 178 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 334 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 317 of file simpleHashMap.I.

template<class Key, class Value, class Compare >
Value & 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 a reference to the value in the map.

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


The documentation for this class was generated from the following files:
 All Classes Functions Variables Enumerations