summaryrefslogtreecommitdiffstats
path: root/hash.c
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2019-11-02 18:49:54 -0700
committerKaz Kylheku <kaz@kylheku.com>2019-11-02 18:49:54 -0700
commit5135b7a124340e50bd376d22dce41fd0d20852fe (patch)
treec789dc54f200604bbd088cf1e7a1798f4b85e501 /hash.c
parent1a71176dca92298cbb4e93530be2a79c80956471 (diff)
downloadtxr-5135b7a124340e50bd376d22dce41fd0d20852fe.tar.gz
txr-5135b7a124340e50bd376d22dce41fd0d20852fe.tar.bz2
txr-5135b7a124340e50bd376d22dce41fd0d20852fe.zip
hash: new hash-reset function.
* hash.c (hash_reset): New function. (hash_init): hash-reset intrinsic registered. * hash.h (hash_reset): Declared. * txr.1: Documented.
Diffstat (limited to 'hash.c')
-rw-r--r--hash.c20
1 files changed, 20 insertions, 0 deletions
diff --git a/hash.c b/hash.c
index 177e639b..c2b0ef4d 100644
--- a/hash.c
+++ b/hash.c
@@ -29,6 +29,7 @@
#include <stdio.h>
#include <stdarg.h>
#include <stdlib.h>
+#include <string.h>
#include <limits.h>
#include <signal.h>
#include "config.h"
@@ -1145,6 +1146,24 @@ val hash_peek(val iter)
return hash_iter_peek(hi);
}
+val hash_reset(val iter, val hash)
+{
+ val self = lit("hash-reset");
+ struct hash_iter *hi = coerce(struct hash_iter *,
+ cobj_handle(self, iter, hash_iter_s));
+
+ if (hi->hash) {
+ struct hash *h = coerce(struct hash *, hash->co.handle);
+ h->usecount--;
+ }
+
+ if (hash)
+ hash_iter_init(hi, hash, self);
+ else
+ memset(hi, 0, sizeof hi);
+ return iter;
+}
+
val maphash(val fun, val hash)
{
val self = lit("maphash");
@@ -1891,6 +1910,7 @@ void hash_init(void)
reg_fun(intern(lit("hash-begin"), user_package), func_n1(hash_begin));
reg_fun(intern(lit("hash-next"), user_package), func_n1(hash_next));
reg_fun(intern(lit("hash-peek"), user_package), func_n1(hash_peek));
+ reg_fun(intern(lit("hash-reset"), user_package), func_n2(hash_reset));
reg_fun(intern(lit("set-hash-traversal-limit"), system_package),
func_n1(set_hash_traversal_limit));
reg_fun(intern(lit("gen-hash-seed"), user_package), func_n0(gen_hash_seed));