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 = *(
unsigned char *)src - *(
unsigned char *)dst) && *dst)
68 return (m_string == other.
m_string) ||
98 return getUid1() == other.
getUid1();
105 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
141 const bool VOID_IS_8 = ((
sizeof(
void*)==8));
143 int key = VOID_IS_8? m_hashValues[0]+m_hashValues[1] : m_hashValues[0];
146 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
154 template <
class Value>
171 return getUid1() == other.
getUid1();
179 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
187 template <
class Value>
204 return getUid1() == other.
getUid1();
211 key += ~(key << 15); key ^= (key >> 10); key += (key << 3); key ^= (key >> 6); key += ~(key << 11); key ^= (key >> 16);
219 template <
class Key,
class Value>
232 int newCapacity = m_valueArray.
capacity();
234 if (m_hashTable.
size() < newCapacity)
237 int curHashtableSize = m_hashTable.
size();
239 m_hashTable.
resize(newCapacity);
240 m_next.
resize(newCapacity);
244 for (i= 0; i < newCapacity; ++i)
248 for (i = 0; i < newCapacity; ++i)
253 for(i=0;i<curHashtableSize;i++)
258 int hashValue = m_keyArray[i].getHash() & (m_valueArray.
capacity()-1);
259 m_next[i] = m_hashTable[hashValue];
260 m_hashTable[hashValue] = i;
269 void insert(
const Key& key,
const Value& value) {
270 int hash = key.getHash() & (m_valueArray.
capacity()-1);
273 int index = findIndex(key);
276 m_valueArray[index]=value;
280 int count = m_valueArray.
size();
281 int oldCapacity = m_valueArray.
capacity();
285 int newCapacity = m_valueArray.
capacity();
286 if (oldCapacity < newCapacity)
290 hash = key.getHash() & (m_valueArray.
capacity()-1);
292 m_next[count] = m_hashTable[hash];
293 m_hashTable[hash] = count;
296 void remove(
const Key& key) {
298 int hash = key.getHash() & (m_valueArray.
capacity()-1);
300 int pairIndex = findIndex(key);
308 int index = m_hashTable[hash];
312 while (index != pairIndex)
315 index = m_next[index];
320 btAssert(m_next[previous] == pairIndex);
321 m_next[previous] = m_next[pairIndex];
325 m_hashTable[hash] = m_next[pairIndex];
332 int lastPairIndex = m_valueArray.
size() - 1;
335 if (lastPairIndex == pairIndex)
343 int lastHash = m_keyArray[lastPairIndex].getHash() & (m_valueArray.
capacity()-1);
345 index = m_hashTable[lastHash];
349 while (index != lastPairIndex)
352 index = m_next[index];
357 btAssert(m_next[previous] == lastPairIndex);
358 m_next[previous] = m_next[lastPairIndex];
362 m_hashTable[lastHash] = m_next[lastPairIndex];
366 m_valueArray[pairIndex] = m_valueArray[lastPairIndex];
367 m_keyArray[pairIndex] = m_keyArray[lastPairIndex];
370 m_next[pairIndex] = m_hashTable[lastHash];
371 m_hashTable[lastHash] = pairIndex;
381 return m_valueArray.
size();
388 return &m_valueArray[index];
395 return &m_valueArray[index];
402 const Value*
find(
const Key& key)
const 404 int index = findIndex(key);
409 return &m_valueArray[index];
414 int index = findIndex(key);
419 return &m_valueArray[index];
425 unsigned int hash = key.getHash() & (m_valueArray.
capacity()-1);
427 if (hash >= (
unsigned int)m_hashTable.
size())
432 int index = m_hashTable[hash];
433 while ((index !=
BT_HASH_NULL) && key.equals(m_keyArray[index]) ==
false)
435 index = m_next[index];
444 m_valueArray.
clear();
450 #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)
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)
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