diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2016-11-23 20:45:54 -0800 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2016-11-23 20:45:54 -0800 |
commit | 026acf026747478ed25f20671b43c084dd0cbff8 (patch) | |
tree | f9cf51f253ce4e572e3a5872d0700ff69bf03a2e /hash.c | |
parent | 7394c87e3cc11fdb0b7df884603b183df1c41eda (diff) | |
download | txr-026acf026747478ed25f20671b43c084dd0cbff8.tar.gz txr-026acf026747478ed25f20671b43c084dd0cbff8.tar.bz2 txr-026acf026747478ed25f20671b43c084dd0cbff8.zip |
Adding clearhash function.
This is needed for an upcoming bugfix, so why not expose it as
an intrinsic.
* hash.c (clearhash): New function.
(hash_init): clearhash intrinsic registered.
* hash.h (clearhash): Declared.
* txr.1: Documented clearhash.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 13 |
1 files changed, 13 insertions, 0 deletions
@@ -754,6 +754,18 @@ val remhash(val hash, val key) return nil; } +val clearhash(val hash) +{ + struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s)); + val mod = num_fast(256); + val table = vector(mod, nil); + cnum oldcount = h->count; + h->modulus = c_num(mod); + h->count = 0; + h->table = table; + return oldcount ? num(oldcount) : nil; +} + val hash_count(val hash) { struct hash *h = coerce(struct hash *, cobj_handle(hash, hash_s)); @@ -1374,6 +1386,7 @@ void hash_init(void) reg_fun(intern(lit("sethash"), user_package), func_n3(sethash)); reg_fun(intern(lit("pushhash"), user_package), func_n3(pushhash)); reg_fun(intern(lit("remhash"), user_package), func_n2(remhash)); + reg_fun(intern(lit("clearhash"), user_package), func_n1(clearhash)); reg_fun(intern(lit("hash-count"), user_package), func_n1(hash_count)); reg_fun(intern(lit("get-hash-userdata"), user_package), ghu); reg_fun(intern(lit("hash-userdata"), user_package), ghu); |