42 static const unsigned int InitialFNV = 2166136261u;
43 static const unsigned int FNVMultiple = 16777619u;
46 unsigned int hash = InitialFNV;
48 for (
int i = 0; m_string1.c_str()[i]; i++)
50 hash = hash ^ (m_string1.c_str()[i]);
51 hash = hash * FNVMultiple;
89 return getUid1() == other.
getUid1();
94 unsigned int key = m_uid;
111 unsigned int m_hashValues[2];
133 const bool VOID_IS_8 = ((
sizeof(
void*) == 8));
135 unsigned int key = VOID_IS_8 ? m_hashValues[0] + m_hashValues[1] : m_hashValues[0];
147 template <
class Value>
164 return getUid1() == other.
getUid1();
170 unsigned int key = m_uid;
182 template <
class Value>
199 return getUid1() == other.
getUid1();
204 unsigned int key = m_uid;
218 template <
class Key,
class Value>
230 int newCapacity = m_valueArray.
capacity();
232 if (m_hashTable.
size() < newCapacity)
235 int curHashtableSize = m_hashTable.
size();
237 m_hashTable.
resize(newCapacity);
238 m_next.
resize(newCapacity);
242 for (i = 0; i < newCapacity; ++i)
246 for (i = 0; i < newCapacity; ++i)
251 for (i = 0; i < curHashtableSize; i++)
256 int hashValue = m_keyArray[i].getHash() & (m_valueArray.
capacity() - 1);
257 m_next[i] = m_hashTable[hashValue];
258 m_hashTable[hashValue] = i;
264 void insert(
const Key& key,
const Value& value)
266 int hash = key.getHash() & (m_valueArray.
capacity() - 1);
269 int index = findIndex(key);
272 m_valueArray[index] = value;
276 int count = m_valueArray.
size();
277 int oldCapacity = m_valueArray.
capacity();
281 int newCapacity = m_valueArray.
capacity();
282 if (oldCapacity < newCapacity)
286 hash = key.getHash() & (m_valueArray.
capacity() - 1);
288 m_next[count] = m_hashTable[hash];
289 m_hashTable[hash] = count;
292 void remove(
const Key& key)
294 int hash = key.getHash() & (m_valueArray.
capacity() - 1);
296 int pairIndex = findIndex(key);
304 int index = m_hashTable[hash];
308 while (index != pairIndex)
311 index = m_next[index];
316 btAssert(m_next[previous] == pairIndex);
317 m_next[previous] = m_next[pairIndex];
321 m_hashTable[hash] = m_next[pairIndex];
328 int lastPairIndex = m_valueArray.
size() - 1;
331 if (lastPairIndex == pairIndex)
339 int lastHash = m_keyArray[lastPairIndex].getHash() & (m_valueArray.
capacity() - 1);
341 index = m_hashTable[lastHash];
345 while (index != lastPairIndex)
348 index = m_next[index];
353 btAssert(m_next[previous] == lastPairIndex);
354 m_next[previous] = m_next[lastPairIndex];
358 m_hashTable[lastHash] = m_next[lastPairIndex];
362 m_valueArray[pairIndex] = m_valueArray[lastPairIndex];
363 m_keyArray[pairIndex] = m_keyArray[lastPairIndex];
366 m_next[pairIndex] = m_hashTable[lastHash];
367 m_hashTable[lastHash] = pairIndex;
375 return m_valueArray.
size();
382 if (index >= 0 && index < m_valueArray.
size())
384 return &m_valueArray[index];
393 if (index >= 0 && index < m_valueArray.
size())
395 return &m_valueArray[index];
404 return m_keyArray[index];
411 return m_keyArray[index];
424 const Value*
find(
const Key& key)
const 426 int index = findIndex(key);
431 return &m_valueArray[index];
436 int index = findIndex(key);
441 return &m_valueArray[index];
446 unsigned int hash = key.getHash() & (m_valueArray.
capacity() - 1);
448 if (hash >= (
unsigned int)m_hashTable.
size())
453 int index = m_hashTable[hash];
454 while ((index !=
BT_HASH_NULL) && key.equals(m_keyArray[index]) ==
false)
456 index = m_next[index];
465 m_valueArray.
clear();
470 #endif //BT_HASH_MAP_H
const void * getPointer() const
btAlignedObjectArray< int > m_hashTable
void push_back(const T &_Val)
bool equals(const btHashInt &other) const
btHashPtr(const void *ptr)
bool equals(const btHashKey< Value > &other) const
Value * find(const Key &key)
int findIndex(const Key &key) const
const Value * find(const Key &key) const
bool equals(const btHashPtr &other) const
unsigned int getHash() const
btAlignedObjectArray< int > m_next
#define SIMD_FORCE_INLINE
Value * operator[](const Key &key)
const Value * operator[](const Key &key) const
btAlignedObjectArray< Key > m_keyArray
The btHashMap template class implements a generic and lightweight hashmap.
const Value * getAtIndex(int index) const
unsigned int getHash() const
void clear()
clear the array, deallocated memory. Generally it is better to use array.resize(0), to reduce performance overhead of run-time memory (de)allocations.
void growTables(const Key &)
Value * getAtIndex(int index)
Key getKeyAtIndex(int index)
btHashString(const char *name)
int capacity() const
return the pre-allocated (reserved) elements, this is at least as large as the total number of elemen...
void insert(const Key &key, const Value &value)
btAlignedObjectArray< Value > m_valueArray
int size() const
return the number of elements in the array
very basic hashable string implementation, compatible with btHashMap
void resize(int newsize, const T &fillData=T())
unsigned int getHash() const
unsigned int getHash() const
bool equals(const btHashString &other) const
unsigned int getHash() const
bool equals(const btHashKeyPtr< Value > &other) const
const Key getKeyAtIndex(int index) const