diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2015-08-04 08:37:51 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2015-08-04 08:37:51 -0700 |
commit | 4ecca7c0b2ac3d61658d749f51dc1e7fbc408ed8 (patch) | |
tree | 7d53e099bd63c1546eb91bb41eac2700b2ada339 /hash.c | |
parent | 7b226277f9ab1d27c657e80e4a44c43c0bedf002 (diff) | |
download | txr-4ecca7c0b2ac3d61658d749f51dc1e7fbc408ed8.tar.gz txr-4ecca7c0b2ac3d61658d749f51dc1e7fbc408ed8.tar.bz2 txr-4ecca7c0b2ac3d61658d749f51dc1e7fbc408ed8.zip |
* hash.c (hash_revget): New function.
* hash.h (hash_revget): Declared.
* eval.c (eval_init): Registered hash-revget intrinsic.
* txr.1: Documented hash-revget.
Diffstat (limited to 'hash.c')
-rw-r--r-- | hash.c | 16 |
1 files changed, 16 insertions, 0 deletions
@@ -1149,6 +1149,22 @@ val hash_update_1(val hash, val key, val fun, val init) } } +val hash_revget(val hash, val value, val test, val keyfun) +{ + val iter = hash_begin(hash); + val cell; + + test = default_arg(test, eql_f); + keyfun = default_arg(keyfun, identity_f); + + while ((cell = hash_next(iter)) != nil) { + if (funcall2(test, value, funcall1(keyfun, cdr(cell)))) + return car(cell); + } + + return nil; +} + void hash_init(void) { weak_keys_k = intern(lit("weak-keys"), keyword_package); |