25 template <
typename Key>
27 inline Uint32
sdbm_hash(
const void *data_in, Uint32 size, Uint32 h = 5381)
29 const Uint8 *data =
static_cast<const Uint8 *
>(data_in);
32 h = (h << 16) + (h << 6) - h +
static_cast<Uint32
>(data[i++]);
80 return (n & (n - 1)) == 0;
88 template <
class T,
class H = hash<T>,
class E = Equal<T>>
91 Uint32
operator()(std::vector<T> &p, std::vector<Uint32> &xrefs)
93 const Uint32 N = p.size();
94 Uint32 outputCount = 0;
96 Uint32 *hashTable =
new Uint32[hashSize + N];
97 Uint32 *next = hashTable + hashSize;
100 memset(hashTable,
NIL, (hashSize + N) *
sizeof(Uint32));
104 for (Uint32 i = 0; i < N; i++) {
106 const Uint32 hashValue =
hash(e) & (hashSize - 1);
108 Uint32 offset = hashTable[hashValue];
111 while (offset !=
NIL && !equal(p[offset], e)) {
112 offset = next[offset];
120 xrefs[i] = outputCount;
126 next[outputCount] = hashTable[hashValue];
129 hashTable[hashValue] = outputCount++;
136 p.resize(outputCount);
#define NIL
Null index. @ Move this somewhere else... This could have collisions with other definitions!
Definition: Weld.h:23
Uint32 nextPowerOfTwo(Uint32 x)
Definition: Weld.h:57
bool isPowerOfTwo(Uint32 n)
Return true if n is a power of two.
Definition: Weld.h:78
bool operator()(const T &a, const T &b) const
Definition: Weld.h:16
Uint32 operator()(std::vector< T > &p, std::vector< Uint32 > &xrefs)
Definition: Weld.h:91
Uint32 operator()(Uint32 x) const
Definition: Weld.h:48
Uint32 operator()(int x) const
Definition: Weld.h:44
Uint32 sdbm_hash(const void *data_in, Uint32 size, Uint32 h=5381)
Definition: Weld.h:27
Uint32 operator()(const Key &k)
Definition: Weld.h:37