diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-06-23 22:22:13 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-06-23 22:22:13 -0700 |
commit | e65fc7cc213436bba321a9b616bb77874b2a789a (patch) | |
tree | a1f6c1ca19b1aa1d865e2a985b14d0ec093f1a1c /hash.c | |
parent | 742b9e4d64a178578476894636bf94911738d957 (diff) | |
download | txr-e65fc7cc213436bba321a9b616bb77874b2a789a.tar.gz txr-e65fc7cc213436bba321a9b616bb77874b2a789a.tar.bz2 txr-e65fc7cc213436bba321a9b616bb77874b2a789a.zip |
Hash subset testing.
* eval.c (eval_init): Register hash-subset and hash-proper-subset
intrinsics.
* hash.c (hash_subset, hash_proper_subset): New functions.
* hash.h (hash_subset, hash_proper_subset): Declared.
* txr.1: New functions documented.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 21 |
1 files changed, 21 insertions, 0 deletions
@@ -1065,6 +1065,27 @@ val hash_isec(val hash1, val hash2, val join_func) } } +val hash_subset(val hash1, val hash2) +{ + val hiter, entry; + + for (hiter = hash_begin(hash1), entry = hash_next(hiter); + entry; + entry = hash_next(hiter)) + { + if (!inhash(hash2, car(entry), colon_k)) + return nil; + } + + return t; +} + +val hash_proper_subset(val hash1, val hash2) +{ + return and2(hash_subset(hash1, hash2), + null(numeq(hash_count(hash1), hash_count(hash2)))); +} + val hash_update(val hash, val fun) { val iter = hash_begin(hash); |