14 #ifndef SIMPLEHASHMAP_H 15 #define SIMPLEHASHMAP_H 24 template<
class Key,
class Value>
33 ALWAYS_INLINE
const Value &get_data()
const {
36 ALWAYS_INLINE Value &modify_data() {
39 ALWAYS_INLINE
void set_data(
const Value &data) {
42 ALWAYS_INLINE
void set_data(Value &&data) {
43 _data = std::move(data);
62 ALWAYS_INLINE constexpr
static std::nullptr_t get_data() {
return nullptr; }
63 ALWAYS_INLINE constexpr
static std::nullptr_t modify_data() {
return nullptr; }
64 ALWAYS_INLINE
static void set_data(std::nullptr_t) {}
80 template<
class Key,
class Value,
class Compare = method_hash<Key, std::less<Key> > >
84 static const unsigned int sparsity = 2u;
98 int find(
const Key &key)
const;
99 int store(
const Key &key,
const Value &data);
100 INLINE
bool remove(
const Key &key);
104 constexpr
size_t size()
const;
106 INLINE
const Key &
get_key(
size_t n)
const;
107 INLINE
const Value &
get_data(
size_t n)
const;
109 INLINE
void set_data(
size_t n,
const Value &data);
110 INLINE
void set_data(
size_t n, Value &&data);
116 void output(std::ostream &out)
const;
117 void write(std::ostream &out)
const;
123 INLINE
size_t get_hash(
const Key &key)
const;
124 INLINE
size_t next_hash(
size_t hash)
const;
126 INLINE
int find_slot(
const Key &key)
const;
127 INLINE
bool has_slot(
size_t slot)
const;
128 INLINE
bool is_element(
size_t n,
const Key &key)
const;
129 INLINE
size_t store_new_element(
size_t n,
const Key &key,
const Value &data);
130 INLINE
int *get_index_array()
const;
133 INLINE
bool consider_expand_table();
134 void resize_table(
size_t new_size);
147 template<
class Key,
class Value,
class Compare>
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Value & modify_data(size_t n)
Returns a modifiable reference to the data in the nth entry 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 e...
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
const Value & get_data(size_t n) const
Returns the data in the nth entry of the table.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
size_t get_num_entries() const
Returns the number of active entries in the table.
void set_data(size_t n, const Value &data)
Changes the data for the nth entry of the table.
const Key & get_key(size_t n) const
Returns the key in the nth entry of the table.
bool validate() const
Returns true if the internal table appears to be consistent, false if there are some internal errors.
void remove_element(size_t n)
Removes the nth entry from the table.
bool consider_shrink_table()
Shrinks the table if the allocated storage is significantly larger than the number of elements in it.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Entry in the SimpleHashMap.
bool is_empty() const
Returns true if the table is empty; i.e.
constexpr size_t size() const
Returns the total number of entries in the table.
This template class can be used to provide faster allocation/deallocation for many Panda objects.
bool remove(const Key &key)
Removes the indicated key and its associated data from the table.
void swap(SimpleHashMap &other)
Quickly exchanges the contents of this map and the other map.
int find(const Key &key) const
Searches for the indicated key in the table.