/* compute p(x), where p is a permutation of 0..(1<<nbits)-1 */
/* permute(0)=0. This is intended and useful. */
-static ub4 permute(x, nbits)
-ub4 x; /* input, a value in some range */
-ub4 nbits; /* input, number of bits in range */
+static ub4 permute(
+ ub4 x, /* input, a value in some range */
+ ub4 nbits) /* input, number of bits in range */
{
int i;
int mask = ((ub4)1<<nbits)-1; /* all ones */
}
/* initialize scramble[] with distinct random values in 0..smax-1 */
-static void scrambleinit(scramble, smax)
-ub4 *scramble; /* hash is a^scramble[tab[b]] */
-ub4 smax; /* scramble values should be in 0..smax-1 */
+static void scrambleinit(
+ ub4 *scramble, /* hash is a^scramble[tab[b]] */
+ ub4 smax) /* scramble values should be in 0..smax-1 */
{
ub4 i;
* Check if key1 and key2 are the same.
* We already checked (a,b) are the same.
*/
-static void checkdup(key1, key2, form)
-key *key1;
-key *key2;
-hashform *form;
+static void checkdup(
+ key *key1,
+ key *key2,
+ hashform *form)
{
switch(form->hashtype)
{
* put keys in tabb according to key->b_k
* check if the initial hash might work
*/
-static int inittab(tabb, blen, keys, form, complete)
-bstuff *tabb; /* output, list of keys with b for (a,b) */
-ub4 blen; /* length of tabb */
-key *keys; /* list of keys already hashed */
-hashform *form; /* user directives */
-int complete; /* TRUE means to complete init despite collisions */
+static int inittab(
+ bstuff *tabb, /* output, list of keys with b for (a,b) */
+ ub4 blen, /* length of tabb */
+ key *keys, /* list of keys already hashed */
+ hashform *form, /* user directives */
+ int complete) /* TRUE means to complete init despite collisions */
{
int nocollision = TRUE;
key *mykey;
/* Do the initial hash for normal mode (use lookup and checksum) */
-static void initnorm(keys, alen, blen, smax, salt, final)
-key *keys; /* list of all keys */
-ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */
-ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */
-ub4 smax; /* maximum range of computable hash values */
-ub4 salt; /* used to initialize the hash function */
-gencode *final; /* output, code for the final hash */
+static void initnorm(
+ key *keys, /* list of all keys */
+ ub4 alen, /* (a,b) has a in 0..alen-1, a power of 2 */
+ ub4 blen, /* (a,b) has b in 0..blen-1, a power of 2 */
+ ub4 smax, /* maximum range of computable hash values */
+ ub4 salt, /* used to initialize the hash function */
+ gencode *final) /* output, code for the final hash */
{
key *mykey;
if (phash_log2(alen)+phash_log2(blen) > UB4BITS)
{
- ub4 initlev = salt*0x9e3779b9; /* the golden ratio; an arbitrary value */
+ ub4 initlev = (salt*0x9e3779b9)&0xffffffff; /* the golden ratio; an arbitrary value */
for (mykey=keys; mykey; mykey=mykey->next_k)
{
else
{
ub4 loga = phash_log2(alen); /* log based 2 of blen */
- ub4 initlev = salt*0x9e3779b9; /* the golden ratio; an arbitrary value */
+ ub4 initlev = (salt*0x9e3779b9)&0xffffffff; /* the golden ratio; an arbitrary value */
for (mykey=keys; mykey; mykey=mykey->next_k)
{
/* Do initial hash for inline mode */
-static void initinl(keys, alen, blen, smax, salt, final)
-key *keys; /* list of all keys */
-ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */
-ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */
-ub4 smax; /* range of computable hash values */
-ub4 salt; /* used to initialize the hash function */
-gencode *final; /* generated code for final hash */
+static void initinl(
+ key *keys, /* list of all keys */
+ ub4 alen, /* (a,b) has a in 0..alen-1, a power of 2 */
+ ub4 blen, /* (a,b) has b in 0..blen-1, a power of 2 */
+ ub4 smax, /* range of computable hash values */
+ ub4 salt, /* used to initialize the hash function */
+ gencode *final) /* generated code for final hash */
{
key *mykey;
ub4 amask = alen-1;
* 1: found distinct (a,b) for all keys, put keys in tabb[]
* 2: found a perfect hash, no need to do any more work
*/
-static ub4 initkey(keys, nkeys, tabb, alen, blen, smax, salt, form, final)
-key *keys; /* list of all keys */
-ub4 nkeys; /* total number of keys */
-bstuff *tabb; /* stuff indexed by b */
-ub4 alen; /* (a,b) has a in 0..alen-1, a power of 2 */
-ub4 blen; /* (a,b) has b in 0..blen-1, a power of 2 */
-ub4 smax; /* range of computable hash values */
-ub4 salt; /* used to initialize the hash function */
-hashform *form; /* user directives */
-gencode *final; /* code for final hash */
+static ub4 initkey(
+ key *keys, /* list of all keys */
+ ub4 nkeys, /* total number of keys */
+ bstuff *tabb, /* stuff indexed by b */
+ ub4 alen, /* (a,b) has a in 0..alen-1, a power of 2 */
+ ub4 blen, /* (a,b) has b in 0..blen-1, a power of 2 */
+ ub4 smax, /* range of computable hash values */
+ ub4 salt, /* used to initialize the hash function */
+ hashform *form, /* user directives */
+ gencode *final) /* code for final hash */
{
/* Do the initial hash of the keys */
switch(form->mode)
}
/* Print an error message and exit if there are duplicates */
-static void duplicates(tabb, blen, keys, form)
-bstuff *tabb; /* array of lists of keys with the same b */
-ub4 blen; /* length of tabb, a power of 2 */
-key *keys;
-hashform *form; /* user directives */
+static void duplicates(
+ bstuff *tabb, /* array of lists of keys with the same b */
+ ub4 blen, /* length of tabb, a power of 2 */
+ key *keys,
+ hashform *form) /* user directives */
{
ub4 i;
key *key1;
/* Try to apply an augmenting list */
-static int apply(tabb, tabh, tabq, blen, scramble, tail, rollback)
-bstuff *tabb;
-hstuff *tabh;
-qstuff *tabq;
-ub4 blen;
-ub4 *scramble;
-ub4 tail;
-int rollback; /* FALSE applies augmenting path, TRUE rolls back */
+static int apply(
+ bstuff *tabb,
+ hstuff *tabh,
+ qstuff *tabq,
+ ub4 blen,
+ ub4 *scramble,
+ ub4 tail,
+ int rollback) /* FALSE applies augmenting path, TRUE rolls back */
{
ub4 hash;
key *mykey;
else if (tabh[hash].key_h)
{
/* very rare: roll back any changes */
- (void *)apply(tabb, tabh, tabq, blen, scramble, tail, TRUE);
+ apply(tabb, tabh, tabq, blen, scramble, tail, TRUE);
return FALSE; /* failure, collision */
}
tabh[hash].key_h = mykey;
this approach to take about nlogn time to map all single-key b's.
-------------------------------------------------------------------------------
*/
-static int augment(tabb, tabh, tabq, blen, scramble, smax, item, nkeys,
- highwater, form)
-bstuff *tabb; /* stuff indexed by b */
-hstuff *tabh; /* which key is associated with which hash, indexed by hash */
-qstuff *tabq; /* queue of *b* values, this is the spanning tree */
-ub4 blen; /* length of tabb */
-ub4 *scramble; /* final hash is a^scramble[tab[b]] */
-ub4 smax; /* highest value in scramble */
-bstuff *item; /* &tabb[b] for the b to be mapped */
-ub4 nkeys; /* final hash must be in 0..nkeys-1 */
-ub4 highwater; /* a value higher than any now in tabb[].water_b */
-hashform *form; /* TRUE if we should do a minimal perfect hash */
+static int augment(
+ bstuff *tabb, /* stuff indexed by b */
+ hstuff *tabh, /* which key is associated with which hash, indexed by hash */
+ qstuff *tabq, /* queue of *b* values, this is the spanning tree */
+ ub4 blen, /* length of tabb */
+ ub4 *scramble, /* final hash is a^scramble[tab[b]] */
+ ub4 smax, /* highest value in scramble */
+ bstuff *item, /* &tabb[b] for the b to be mapped */
+ ub4 nkeys, /* final hash must be in 0..nkeys-1 */
+ ub4 highwater, /* a value higher than any now in tabb[].water_b */
+ hashform *form) /* TRUE if we should do a minimal perfect hash */
{
ub4 q; /* current position walking through the queue */
ub4 tail; /* tail of the queue. 0 is the head of the queue. */
/* find a mapping that makes this a perfect hash */
-static int perfect(tabb, tabh, tabq, blen, smax, scramble, nkeys, form)
-bstuff *tabb;
-hstuff *tabh;
-qstuff *tabq;
-ub4 blen;
-ub4 smax;
-ub4 *scramble;
-ub4 nkeys;
-hashform *form;
+static int perfect(
+ bstuff *tabb,
+ hstuff *tabh,
+ qstuff *tabq,
+ ub4 blen,
+ ub4 smax,
+ ub4 *scramble,
+ ub4 nkeys,
+ hashform *form)
{
ub4 maxkeys; /* maximum number of keys for any b */
ub4 i, j;
* Simple case: user gave (a,b). No more mixing, no guessing alen or blen.
* This assumes a,b reside in (key->a_k, key->b_k), and final->form == AB_HK.
*/
-static void hash_ab(tabb, alen, blen, salt, final,
- scramble, smax, keys, nkeys, form)
-bstuff **tabb; /* output, tab[] of the perfect hash, length *blen */
-ub4 *alen; /* output, 0..alen-1 is range for a of (a,b) */
-ub4 *blen; /* output, 0..blen-1 is range for b of (a,b) */
-ub4 *salt; /* output, initializes initial hash */
-gencode *final; /* code for final hash */
-ub4 *scramble; /* input, hash = a^scramble[tab[b]] */
-ub4 *smax; /* input, scramble[i] in 0..smax-1 */
-key *keys; /* input, keys to hash */
-ub4 nkeys; /* input, number of keys being hashed */
-hashform *form; /* user directives */
+static void hash_ab(
+ bstuff **tabb, /* output, tab[] of the perfect hash, length *blen */
+ ub4 *alen, /* output, 0..alen-1 is range for a of (a,b) */
+ ub4 *blen, /* output, 0..blen-1 is range for b of (a,b) */
+ ub4 *salt, /* output, initializes initial hash */
+ gencode *final, /* code for final hash */
+ ub4 *scramble, /* input, hash = a^scramble[tab[b]] */
+ ub4 *smax, /* input, scramble[i] in 0..smax-1 */
+ key *keys, /* input, keys to hash */
+ ub4 nkeys, /* input, number of keys being hashed */
+ hashform *form) /* user directives */
{
hstuff *tabh;
qstuff *tabq;
/* guess initial values for alen and blen */
-static void initalen(alen, blen, smax, nkeys, form)
-ub4 *alen; /* output, initial alen */
-ub4 *blen; /* output, initial blen */
-ub4 *smax; /* input, power of two greater or equal to max hash value */
-ub4 nkeys; /* number of keys being hashed */
-hashform *form; /* user directives */
+static void initalen(
+ ub4 *alen, /* output, initial alen */
+ ub4 *blen, /* output, initial blen */
+ ub4 *smax,/* input, power of two greater or equal to max hash value */
+ ub4 nkeys, /* number of keys being hashed */
+ hashform *form) /* user directives */
{
/*
* Find initial *alen, *blen