summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-10-12 00:53:30 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-10-12 00:53:30 -0700
commitede1079e13ac0cbdcc63738f8a3414fefaa0c48d (patch)
treef69926438c89111224da72189aca2f2b169ad08f /hash.c
parentf557c6110536ed4dcf1191386ac1e63ae35b03f0 (diff)
downloadtxr-ede1079e13ac0cbdcc63738f8a3414fefaa0c48d.tar.gz
txr-ede1079e13ac0cbdcc63738f8a3414fefaa0c48d.tar.bz2
txr-ede1079e13ac0cbdcc63738f8a3414fefaa0c48d.zip
hash: use ucnum for hash values everywhere.
One consequence of this is that we no longer pass negative values to vecref; that functon was protecting us from the consequences of this signed/unsigned mixup, at the cost of cyles. * hash.c (struct hash_ops): hash parameter in assoc_fun and acons_new_c_fun pointers changes from cnum to ucnum. (hash_assoc, hash_assql, hash_assq): hash parameter changes to ucnum. (hash_acons_new_c, hash_aconsql_new_c, hash_aconsq_new_c): Likewise. (gethash_c, gethash_e, remhash): Variable which captures the output of the hashing function is now ucnum instead of cnum. * lib.h (struct cons_hash_entry): Member hash changes from cnum to ucnum.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c22
1 files changed, 11 insertions, 11 deletions
diff --git a/hash.c b/hash.c
index 83e73e35..57b029de 100644
--- a/hash.c
+++ b/hash.c
@@ -64,8 +64,8 @@ typedef enum hash_type {
struct hash_ops {
ucnum (*hash_fun)(val, int *, ucnum);
val (*equal_fun)(val, val);
- val (*assoc_fun)(val key, cnum hash, val list);
- val (*acons_new_c_fun)(val key, cnum hash, loc new_p, loc list);
+ val (*assoc_fun)(val key, ucnum hash, val list);
+ val (*acons_new_c_fun)(val key, ucnum hash, loc new_p, loc list);
};
#define hash_ops_init(hash, equal, assoc, acons) \
@@ -665,7 +665,7 @@ static void hash_grow(struct hash *h, val hash)
setcheck(hash, new_table);
}
-static val hash_assoc(val key, cnum hash, val list)
+static val hash_assoc(val key, ucnum hash, val list)
{
while (list) {
val elem = us_car(list);
@@ -677,7 +677,7 @@ static val hash_assoc(val key, cnum hash, val list)
return nil;
}
-static val hash_assql(val key, cnum hash, val list)
+static val hash_assql(val key, ucnum hash, val list)
{
while (list) {
val elem = us_car(list);
@@ -689,7 +689,7 @@ static val hash_assql(val key, cnum hash, val list)
return nil;
}
-static val hash_assq(val key, cnum hash, val list)
+static val hash_assq(val key, ucnum hash, val list)
{
while (list) {
val elem = us_car(list);
@@ -702,7 +702,7 @@ static val hash_assq(val key, cnum hash, val list)
}
-static val hash_acons_new_c(val key, cnum hash, loc new_p, loc list)
+static val hash_acons_new_c(val key, ucnum hash, loc new_p, loc list)
{
val existing = hash_assoc(key, hash, deref(list));
@@ -720,7 +720,7 @@ static val hash_acons_new_c(val key, cnum hash, loc new_p, loc list)
}
}
-static val hash_aconsql_new_c(val key, cnum hash, loc new_p, loc list)
+static val hash_aconsql_new_c(val key, ucnum hash, loc new_p, loc list)
{
val existing = hash_assql(key, hash, deref(list));
@@ -738,7 +738,7 @@ static val hash_aconsql_new_c(val key, cnum hash, loc new_p, loc list)
}
}
-static val hash_aconsq_new_c(val key, cnum hash, loc new_p, loc list)
+static val hash_aconsq_new_c(val key, ucnum hash, loc new_p, loc list)
{
val existing = hash_assq(key, hash, deref(list));
@@ -893,7 +893,7 @@ val gethash_c(val self, val hash, val key, loc new_p)
{
struct hash *h = coerce(struct hash *, cobj_handle(self, hash, hash_s));
int lim = hash_rec_limit;
- cnum hv = h->hops->hash_fun(key, &lim, h->seed);
+ ucnum hv = h->hops->hash_fun(key, &lim, h->seed);
loc pchain = vecref_l(h->table, num_fast(hv % h->modulus));
val old = deref(pchain);
val cell = h->hops->acons_new_c_fun(key, hv, new_p, pchain);
@@ -906,7 +906,7 @@ val gethash_e(val self, val hash, val key)
{
struct hash *h = coerce(struct hash *, cobj_handle(self, hash, hash_s));
int lim = hash_rec_limit;
- cnum hv = h->hops->hash_fun(key, &lim, h->seed);
+ ucnum hv = h->hops->hash_fun(key, &lim, h->seed);
val chain = vecref(h->table, num_fast(hv % h->modulus));
return h->hops->assoc_fun(key, hv, chain);
}
@@ -960,7 +960,7 @@ val remhash(val hash, val key)
val self = lit("remhash");
struct hash *h = coerce(struct hash *, cobj_handle(self, hash, hash_s));
int lim = hash_rec_limit;
- cnum hv = h->hops->hash_fun(key, &lim, h->seed);
+ ucnum hv = h->hops->hash_fun(key, &lim, h->seed);
val *pchain = valptr(vecref_l(h->table, num_fast(hv % h->modulus)));
val existing = h->hops->assoc_fun(key, hv, *pchain);