23 template <
typename Key>
25 inline Uint32
sdbm_hash(
const void *data_in, Uint32 size, Uint32 h = 5381)
27 const Uint8 *data =
static_cast<const Uint8 *
>(data_in);
30 h = (h << 16) + (h << 6) - h +
static_cast<Uint32
>(data[i++]);
78 return (n & (n - 1)) == 0;
86 template <
class T,
class H = hash<T>,
class E = Equal<T>>
89 Uint32
operator()(std::vector<T> &p, std::vector<Uint32> &xrefs)
91 const Uint32 N = p.size();
92 Uint32 outputCount = 0;
94 Uint32 *hashTable =
new Uint32[hashSize + N];
95 Uint32 *next = hashTable + hashSize;
98 memset(hashTable,
NIL, (hashSize + N) *
sizeof(Uint32));
102 for (Uint32 i = 0; i < N; i++) {
104 const Uint32 hashValue =
hash(e) & (hashSize - 1);
106 Uint32 offset = hashTable[hashValue];
109 while (offset !=
NIL && !equal(p[offset], e)) {
110 offset = next[offset];
118 xrefs[i] = outputCount;
124 next[outputCount] = hashTable[hashValue];
127 hashTable[hashValue] = outputCount++;
134 p.resize(outputCount);
#define NIL
Null index. @ Move this somewhere else... This could have collisions with other definitions!
Definition Weld.h:21
Uint32 nextPowerOfTwo(Uint32 x)
Definition Weld.h:55
bool isPowerOfTwo(Uint32 n)
Return true if n is a power of two.
Definition Weld.h:76
bool operator()(const T &a, const T &b) const
Definition Weld.h:14
Uint32 operator()(std::vector< T > &p, std::vector< Uint32 > &xrefs)
Definition Weld.h:89
Uint32 operator()(Uint32 x) const
Definition Weld.h:46
Uint32 operator()(int x) const
Definition Weld.h:42
Uint32 sdbm_hash(const void *data_in, Uint32 size, Uint32 h=5381)
Definition Weld.h:25
Uint32 operator()(const Key &k)
Definition Weld.h:35