21 template <
typename KEY,
typename VALUE>
59 typename KEY,
typename VALUE,
unsigned int NUM_BYTES_HASH_TABLE = 1,
60 unsigned int NUM_HAS_TABLE_COLLISIONS_ALLOWED = 5,
61 typename VECTOR_T = std::array<
62 std::array<ts_map_entry<KEY, VALUE>, NUM_HAS_TABLE_COLLISIONS_ALLOWED>,
63 1u << (8 * NUM_BYTES_HASH_TABLE)>>
69 typedef ts_hash_map<KEY, VALUE, NUM_BYTES_HASH_TABLE,
70 NUM_HAS_TABLE_COLLISIONS_ALLOWED, VECTOR_T>
73 typedef ts_map_entry<KEY, VALUE> value_type;
74 typedef VECTOR_T vec_t;
81 :
m_vec(nullptr), m_parent(nullptr), m_idx_outer(0), m_idx_inner(0)
85 const VECTOR_T& vec,
const self_t& parent,
int idx_outer,
87 :
m_vec(const_cast<VECTOR_T*>(&vec)),
88 m_parent(const_cast<self_t*>(&parent)),
89 m_idx_outer(idx_outer),
90 m_idx_inner(idx_inner)
96 m_idx_outer = o.m_idx_outer;
97 m_idx_inner = o.m_idx_inner;
102 return m_vec == o.m_vec && m_idx_outer == o.m_idx_outer &&
103 m_idx_inner == o.m_idx_inner;
108 return (*
m_vec)[m_idx_outer][m_idx_inner];
110 const value_type* operator->()
const 112 return &(*m_vec)[m_idx_outer][m_idx_inner];
129 int m_idx_outer, m_idx_inner;
136 if (++m_idx_inner >= (
int)NUM_HAS_TABLE_COLLISIONS_ALLOWED)
141 }
while (m_idx_outer < (
int)m_parent->m_vec.size() &&
142 !(*m_vec)[m_idx_outer][m_idx_inner].used);
150 iterator(VECTOR_T& vec, self_t& parent,
int idx_outer,
int idx_inner)
157 [const_iterator::m_idx_inner];
159 value_type* operator->()
161 return &(*const_iterator::m_vec)[const_iterator::m_idx_outer]
162 [const_iterator::m_idx_inner];
172 const_iterator::incr();
192 for (
size_t oi = 0; oi <
m_vec.size(); oi++)
193 for (
size_t ii = 0; ii < NUM_HAS_TABLE_COLLISIONS_ALLOWED; ii++)
194 m_vec[oi][ii] = value_type();
203 NUM_BYTES_HASH_TABLE>
::type hash;
205 std::array<ts_map_entry<KEY, VALUE>, NUM_HAS_TABLE_COLLISIONS_ALLOWED>&
206 match_arr =
m_vec[hash];
207 for (
unsigned int i = 0; i < NUM_HAS_TABLE_COLLISIONS_ALLOWED; i++)
209 if (!match_arr[i].used)
212 match_arr[i].used =
true;
213 match_arr[i].first = key;
214 return match_arr[i].second;
216 if (match_arr[i].
first == key)
return match_arr[i].second;
223 NUM_BYTES_HASH_TABLE>
::type hash;
225 const std::array<ts_map_entry<KEY, VALUE>,
226 NUM_HAS_TABLE_COLLISIONS_ALLOWED>& match_arr =
228 for (
unsigned int i = 0; i < NUM_HAS_TABLE_COLLISIONS_ALLOWED; i++)
230 if (match_arr[i].used && match_arr[i].
first == key)
const_iterator end() const
unsigned __int16 uint16_t
ts_hash_map()
< Default constructor */
iterator operator++(int)
A thread-safe (ts) container which minimally emulates a std::map<>'s [] and find() methods but which ...
#define THROW_EXCEPTION(msg)
const_iterator begin() const
Usage: uint_select_by_bytecount<N>type var; allows defining var as a unsigned integer with...
const Scalar * const_iterator
const_iterator find(const KEY &key) const
bool operator==(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
void clear()
Clear the contents of this container.
bool operator!=(const mrpt::utils::TCamera &a, const mrpt::utils::TCamera &b)
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn't exist already.
GLsizei const GLchar ** string
void reduced_hash(const std::string &value, uint8_t &hash)
hash function used by ts_hash_map.
size_t m_size
Number of elements accessed with write access so far.
vec_t m_vec
The actual container.
unsigned __int64 uint64_t
This is the global namespace for all Mobile Robot Programming Toolkit (MRPT) libraries.
GLsizei const GLfloat * value
unsigned __int32 uint32_t
GLuint GLuint GLsizei GLenum type
std::vector< T1 > operator*(const std::vector< T1 > &a, const std::vector< T2 > &b)
a*b (element-wise multiplication)