15 #ifndef SIMPLEHASHMAP_H
16 #define SIMPLEHASHMAP_H
18 #include "pandabase.h"
20 #include "config_util.h"
32 template<
class Key,
class Value,
class Compare = method_hash<Key, less<Key> > >
37 INLINE ~SimpleHashMap();
39 INLINE
void swap(SimpleHashMap &other);
41 int find(
const Key &key)
const;
42 int store(
const Key &key,
const Value &data);
43 INLINE
bool remove(
const Key &key);
50 INLINE
const Key &
get_key(
int n)
const;
51 INLINE
const Value &
get_data(
int n)
const;
53 INLINE
void set_data(
int n,
const Value &data);
59 void output(ostream &out)
const;
60 void write(ostream &out)
const;
66 INLINE
size_t get_hash(
const Key &key)
const;
68 INLINE
bool is_element(
int n,
const Key &key)
const;
69 INLINE
void store_new_element(
int n,
const Key &key,
const Value &data);
70 INLINE
void clear_element(
int n);
71 INLINE
unsigned char *get_exists_array()
const;
74 INLINE
bool consider_expand_table();
79 INLINE TableEntry(
const Key &key,
const Value &data) :
82 INLINE TableEntry(
const TableEntry ©) :
85 #ifdef USE_MOVE_SEMANTICS
86 INLINE TableEntry(TableEntry &&from) NOEXCEPT :
87 _key(move(from._key)),
88 _data(move(from._data)) {}
103 template<
class Key,
class Value,
class Compare>
104 inline ostream &operator << (ostream &out, const SimpleHashMap<Key, Value, Compare> &shm) {
110 #include "simpleHashMap.I"
int find(const Key &key) const
Searches for the indicated key in the table.
int get_num_entries() const
Returns the number of active entries in the table.
Value & operator[](const Key &key)
Returns a modifiable reference to the data associated with the indicated key, or creates a new data e...
int store(const Key &key, const Value &data)
Records the indicated key/data pair in the map.
This template class implements an unordered map of keys to data, implemented as a hashtable...
void clear()
Completely empties the table.
Value & modify_data(int n)
Returns a modifiable reference to the data in the nth slot of the table.
bool is_empty() const
Returns true if the table is empty; i.e.
int get_size() const
Returns the total number of slots in the table.
void set_data(int n, const Value &data)
Changes the data for the nth slot of the table.
bool validate() const
Returns true if the internal table appears to be consistent, false if there are some internal errors...
const Value & get_data(int n) const
Returns the data in the nth slot of the table.
This template class can be used to provide faster allocation/deallocation for many Panda objects...
void remove_element(int n)
Removes the nth slot from the table.
const Key & get_key(int n) const
Returns the key in the nth slot of the table.
void swap(SimpleHashMap &other)
Quickly exchanges the contents of this map and the other map.
bool has_element(int n) const
Returns true if there is an element stored in the nth slot, false otherwise.