diff options
author | Andy Wingo <wingo@pobox.com> | 2013-02-18 17:59:38 +0100 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2013-02-18 17:59:38 +0100 |
commit | 9b977c836bf147d386944c401113aba32776fa68 (patch) | |
tree | d097e1a2376e26bc6b03447445ae239d5514a7a8 /libguile/hashtab.c | |
parent | 180ac9d7b0bac97bdead2813a1b0b23d19002c3e (diff) | |
parent | 739941679c2c7dc36c29c30aff7d4c1b436ba773 (diff) | |
download | guile-9b977c836bf147d386944c401113aba32776fa68.tar.gz |
Merge remote-tracking branch 'origin/stable-2.0'
Conflicts:
libguile/array-handle.c
libguile/deprecated.h
libguile/inline.c
libguile/inline.h
module/ice-9/deprecated.scm
module/language/tree-il/peval.scm
Diffstat (limited to 'libguile/hashtab.c')
-rw-r--r-- | libguile/hashtab.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/libguile/hashtab.c b/libguile/hashtab.c index fc7fa424e..fff48b857 100644 --- a/libguile/hashtab.c +++ b/libguile/hashtab.c @@ -205,6 +205,7 @@ SCM_DEFINE (scm_hash_table_p, "hash-table?", 1, 0, 0, } #undef FUNC_NAME + /* Accessing hash table entries. */ @@ -966,6 +967,33 @@ SCM_DEFINE (scm_hash_map_to_list, "hash-map->list", 2, 0, 0, } #undef FUNC_NAME +static SCM +count_proc (void *pred, SCM key, SCM data, SCM value) +{ + if (scm_is_false (scm_call_2 (SCM_PACK (pred), key, data))) + return value; + else + return scm_oneplus(value); +} + +SCM_DEFINE (scm_hash_count, "hash-count", 2, 0, 0, + (SCM pred, SCM table), + "Return the number of elements in the given hash TABLE that\n" + "cause `(PRED KEY VALUE)' to return true. To quickly determine\n" + "the total number of elements, use `(const #t)' for PRED.") +#define FUNC_NAME s_scm_hash_count +{ + SCM init; + + SCM_VALIDATE_PROC (1, pred); + SCM_VALIDATE_HASHTABLE (2, table); + + init = scm_from_int (0); + return scm_internal_hash_fold ((scm_t_hash_fold_fn) count_proc, + (void *) SCM_UNPACK (pred), init, table); +} +#undef FUNC_NAME + SCM |