37 static const unsigned int InitialFNV = 2166136261u;
38 static const unsigned int FNVMultiple = 16777619u;
41 unsigned int hash = InitialFNV;
43 for(
int i = 0; m_string[i]; i++)
45 hash = hash ^ (m_string[i]);
46 hash = hash * FNVMultiple;
55 while( ! (ret = *(
const unsigned char *)src - *(
const unsigned char *)dst) && *dst)
68 return (m_string == other.
m_string) ||
103 return getUid1() == other.
getUid1();
108 unsigned int key = m_uid;
110 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
124 unsigned int m_hashValues[2];
147 const bool VOID_IS_8 = ((
sizeof(
void*)==8));
149 unsigned int key = VOID_IS_8? m_hashValues[0]+m_hashValues[1] : m_hashValues[0];
151 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
159 template <
class Value>
176 return getUid1() == other.
getUid1();
182 unsigned int key = m_uid;
184 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
192 template <
class Value>
209 return getUid1() == other.
getUid1();
214 unsigned int key = m_uid;
216 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
224 template <
class Key,
class Value>
237 int newCapacity = m_valueArray.
capacity();
239 if (m_hashTable.
size() < newCapacity)
242 int curHashtableSize = m_hashTable.
size();
244 m_hashTable.
resize(newCapacity);
245 m_next.
resize(newCapacity);
249 for (i= 0; i < newCapacity; ++i)
253 for (i = 0; i < newCapacity; ++i)
258 for(i=0;i<curHashtableSize;i++)
263 int hashValue = m_keyArray[i].getHash() & (m_valueArray.
capacity()-1);
264 m_next[i] = m_hashTable[hashValue];
265 m_hashTable[hashValue] = i;
274 void insert(
const Key& key,
const Value& value) {
275 int hash = key.getHash() & (m_valueArray.
capacity()-1);
278 int index = findIndex(key);
281 m_valueArray[index]=value;
285 int count = m_valueArray.
size();
286 int oldCapacity = m_valueArray.
capacity();
290 int newCapacity = m_valueArray.
capacity();
291 if (oldCapacity < newCapacity)
295 hash = key.getHash() & (m_valueArray.
capacity()-1);
297 m_next[count] = m_hashTable[hash];
298 m_hashTable[hash] = count;
301 void remove(
const Key& key) {
303 int hash = key.getHash() & (m_valueArray.
capacity()-1);
305 int pairIndex = findIndex(key);
313 int index = m_hashTable[hash];
317 while (index != pairIndex)
320 index = m_next[index];
325 btAssert(m_next[previous] == pairIndex);
326 m_next[previous] = m_next[pairIndex];
330 m_hashTable[hash] = m_next[pairIndex];
337 int lastPairIndex = m_valueArray.
size() - 1;
340 if (lastPairIndex == pairIndex)
348 int lastHash = m_keyArray[lastPairIndex].getHash() & (m_valueArray.
capacity()-1);
350 index = m_hashTable[lastHash];
354 while (index != lastPairIndex)
357 index = m_next[index];
362 btAssert(m_next[previous] == lastPairIndex);
363 m_next[previous] = m_next[lastPairIndex];
367 m_hashTable[lastHash] = m_next[lastPairIndex];
371 m_valueArray[pairIndex] = m_valueArray[lastPairIndex];
372 m_keyArray[pairIndex] = m_keyArray[lastPairIndex];
375 m_next[pairIndex] = m_hashTable[lastHash];
376 m_hashTable[lastHash] = pairIndex;
386 return m_valueArray.
size();
393 if (index>=0 && index < m_valueArray.
size())
395 return &m_valueArray[index];
404 if (index>=0 && index < m_valueArray.
size())
406 return &m_valueArray[index];
415 return m_keyArray[index];
422 return m_keyArray[index];
434 const Value*
find(
const Key& key)
const 436 int index = findIndex(key);
441 return &m_valueArray[index];
446 int index = findIndex(key);
451 return &m_valueArray[index];
457 unsigned int hash = key.getHash() & (m_valueArray.
capacity()-1);
459 if (hash >= (
unsigned int)m_hashTable.
size())
464 int index = m_hashTable[hash];
465 while ((index !=
BT_HASH_NULL) && key.equals(m_keyArray[index]) ==
false)
467 index = m_next[index];
476 m_valueArray.
clear();
482 #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
int portableStringCompare(const char *src, const char *dst) const
const Key getKeyAtIndex(int index) const