summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c31
1 files changed, 31 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index f26e83c2..dcd28011 100644
--- a/hash.c
+++ b/hash.c
@@ -51,6 +51,7 @@ struct hash {
val table;
cnum modulus;
cnum count;
+ val userdata;
};
/*
@@ -141,6 +142,8 @@ static void hash_mark(val hash)
struct hash *h = (struct hash *) hash->co.handle;
cnum i;
+ gc_mark(h->userdata);
+
switch (h->flags) {
case hash_weak_none:
/* If the hash is not weak, we can simply mark the table
@@ -235,6 +238,7 @@ val make_hash(val weak_keys, val weak_vals)
h->modulus = c_num(mod);
h->count = 0;
h->table = table;
+ h->userdata = nil;
return hash;
}
@@ -258,6 +262,14 @@ val gethash(val hash, val key)
return cdr(found);
}
+val gethash_f(val hash, val key, val *found)
+{
+ struct hash *h = (struct hash *) hash->co.handle;
+ val chain = *vecref_l(h->table, num(ll_hash(key) % h->modulus));
+ *found = assoc(chain, key);
+ return cdr(*found);
+}
+
val sethash(val hash, val key, val value)
{
val new_p;
@@ -275,6 +287,25 @@ val remhash(val hash, val key)
return nil;
}
+val get_hash_userdata(val hash)
+{
+ struct hash *h = (struct hash *) hash->co.handle;
+ return h->userdata;
+}
+
+val set_hash_userdata(val hash, val data)
+{
+ struct hash *h = (struct hash *) hash->co.handle;
+ val olddata = h->userdata;
+ h->userdata = data;
+ return olddata;
+}
+
+val hashp(val obj)
+{
+ return typeof(obj) == hash_s ? t : nil;
+}
+
/*
* Called from garbage collector. Hash module must process all weak tables
* that were visited during the marking phase, maintained in the list