18 template <
typename KEY,
typename VALUE>
56 typename KEY,
typename VALUE,
unsigned int NUM_BYTES_HASH_TABLE = 1,
57 unsigned int NUM_HAS_TABLE_COLLISIONS_ALLOWED = 5,
58 typename VECTOR_T = std::array<
59 std::array<ts_map_entry<KEY, VALUE>, NUM_HAS_TABLE_COLLISIONS_ALLOWED>,
60 1u << (8 * NUM_BYTES_HASH_TABLE)>>
67 KEY, VALUE, NUM_BYTES_HASH_TABLE, NUM_HAS_TABLE_COLLISIONS_ALLOWED,
70 using value_type = ts_map_entry<KEY, VALUE>;
71 using vec_t = VECTOR_T;
78 :
m_vec(nullptr), m_parent(nullptr), m_idx_outer(0), m_idx_inner(0)
82 const VECTOR_T& vec,
const self_t& parent,
int idx_outer,
84 :
m_vec(const_cast<VECTOR_T*>(&vec)),
85 m_parent(const_cast<self_t*>(&parent)),
86 m_idx_outer(idx_outer),
87 m_idx_inner(idx_inner)
93 m_idx_outer = o.m_idx_outer;
94 m_idx_inner = o.m_idx_inner;
99 return m_vec == o.m_vec && m_idx_outer == o.m_idx_outer &&
100 m_idx_inner == o.m_idx_inner;
105 return (*
m_vec)[m_idx_outer][m_idx_inner];
107 const value_type* operator->()
const 109 return &(*m_vec)[m_idx_outer][m_idx_inner];
126 int m_idx_outer, m_idx_inner;
133 if (++m_idx_inner >= (
int)NUM_HAS_TABLE_COLLISIONS_ALLOWED)
138 }
while (m_idx_outer < (
int)m_parent->m_vec.size() &&
139 !(*m_vec)[m_idx_outer][m_idx_inner].used);
147 iterator(VECTOR_T& vec, self_t& parent,
int idx_outer,
int idx_inner)
154 [const_iterator::m_idx_inner];
156 value_type* operator->()
158 return &(*const_iterator::m_vec)[const_iterator::m_idx_outer]
159 [const_iterator::m_idx_inner];
169 const_iterator::incr();
189 for (
size_t oi = 0; oi <
m_vec.size(); oi++)
190 for (
size_t ii = 0; ii < NUM_HAS_TABLE_COLLISIONS_ALLOWED; ii++)
191 m_vec[oi][ii] = value_type();
202 std::array<ts_map_entry<KEY, VALUE>, NUM_HAS_TABLE_COLLISIONS_ALLOWED>&
203 match_arr =
m_vec[hash];
204 for (
unsigned int i = 0; i < NUM_HAS_TABLE_COLLISIONS_ALLOWED; i++)
206 if (!match_arr[i].used)
209 match_arr[i].used =
true;
210 match_arr[i].first = key;
211 return match_arr[i].second;
213 if (match_arr[i].
first == key)
return match_arr[i].second;
215 throw std::runtime_error(
"ts_hash_map: too many hash collisions!");
224 match_arr =
m_vec[hash];
225 for (
unsigned int i = 0; i < NUM_HAS_TABLE_COLLISIONS_ALLOWED; i++)
227 if (match_arr[i].used && match_arr[i].
first == key)
unsigned __int16 uint16_t
const_iterator find(const KEY &key) const
ts_hash_map()
< Default constructor */
VALUE & operator[](const KEY &key)
Write/read via [i] operator, that creates an element if it didn't exist already.
Usage: uint_select_by_bytecount<N>type var; allows defining var as a unsigned integer with...
void reduced_hash(const std::string &value, uint8_t &hash)
hash function used by ts_hash_map.
GLsizei const GLchar ** string
bool operator==(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
unsigned __int64 uint64_t
const_iterator end() const
const_iterator begin() const
vec_t m_vec
The actual container.
GLsizei const GLfloat * value
iterator operator++(int)
A thread-safe (ts) container which minimally emulates a std::map<>'s [] and find() methods but which ...
unsigned __int32 uint32_t
bool operator!=(const mrpt::img::TCamera &a, const mrpt::img::TCamera &b)
void clear()
Clear the contents of this container.
const Scalar * const_iterator
size_t m_size
Number of elements accessed with write access so far.
std::vector< T1 > operator*(const std::vector< T1 > &a, const std::vector< T2 > &b)
a*b (element-wise multiplication)