summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLudovic Courtès <ludo@gnu.org>2009-10-26 23:56:03 +0100
committerLudovic Courtès <ludo@gnu.org>2009-10-27 00:24:09 +0100
commita07010bf1828704edd9a40cadb0eaf820b8f3638 (patch)
tree78f6c3141b4d357aa537ecb78f0a346819b2f141
parentf044da55c5b0c0cf444a25e5bd9a76fea5a95f2d (diff)
Use proper fold/for-each function types in `hashtab.h'.
* libguile/hashtab.h (scm_t_hash_fold_fn, scm_t_hash_handle_fn): New types. (scm_internal_hash_fold, scm_internal_hash_for_each_handle): Use them. * libguile/hashtab.c (scm_internal_hash_fold): Take an `scm_t_hash_fold_fn'. Update callers. (scm_internal_hash_for_each_handle): Take an `scm_t_hash_handle_fn'. Update callers.
-rw-r--r--libguile/hashtab.c11
-rw-r--r--libguile/hashtab.h20
2 files changed, 19 insertions, 12 deletions
diff --git a/libguile/hashtab.c b/libguile/hashtab.c
index 511197781..4ba2ef9ab 100644
--- a/libguile/hashtab.c
+++ b/libguile/hashtab.c
@@ -1039,7 +1039,8 @@ SCM_DEFINE (scm_hashx_remove_x, "hashx-remove!", 4, 0, 0,
static const char s_scm_hash_fold[];
SCM
-scm_internal_hash_fold (SCM (*fn) (), void *closure, SCM init, SCM table)
+scm_internal_hash_fold (scm_t_hash_fold_fn fn, void *closure,
+ SCM init, SCM table)
{
long i, n;
SCM buckets, result = init;
@@ -1103,7 +1104,8 @@ scm_internal_hash_fold (SCM (*fn) (), void *closure, SCM init, SCM table)
static const char s_scm_hash_for_each[];
void
-scm_internal_hash_for_each_handle (SCM (*fn) (), void *closure, SCM table)
+scm_internal_hash_for_each_handle (scm_t_hash_handle_fn fn, void *closure,
+ SCM table)
{
long i, n;
SCM buckets;
@@ -1145,7 +1147,8 @@ SCM_DEFINE (scm_hash_fold, "hash-fold", 3, 0, 0,
SCM_VALIDATE_PROC (1, proc);
if (!SCM_HASHTABLE_P (table))
SCM_VALIDATE_VECTOR (3, table);
- return scm_internal_hash_fold (scm_call_3, (void *) SCM_UNPACK (proc), init, table);
+ return scm_internal_hash_fold ((scm_t_hash_fold_fn) scm_call_3,
+ (void *) SCM_UNPACK (proc), init, table);
}
#undef FUNC_NAME
@@ -1185,7 +1188,7 @@ SCM_DEFINE (scm_hash_for_each_handle, "hash-for-each-handle", 2, 0, 0,
if (!SCM_HASHTABLE_P (table))
SCM_VALIDATE_VECTOR (2, table);
- scm_internal_hash_for_each_handle (call,
+ scm_internal_hash_for_each_handle ((scm_t_hash_handle_fn) call,
(void *) SCM_UNPACK (proc),
table);
return SCM_UNSPECIFIED;
diff --git a/libguile/hashtab.h b/libguile/hashtab.h
index f72e8ab08..b60cd4349 100644
--- a/libguile/hashtab.h
+++ b/libguile/hashtab.h
@@ -72,6 +72,14 @@ typedef unsigned long (*scm_t_hash_fn) (SCM obj, unsigned long max,
some equality predicate. */
typedef SCM (*scm_t_assoc_fn) (SCM obj, SCM alist, void *closure);
+/* Function to fold over the entries of a hash table. */
+typedef SCM (*scm_t_hash_fold_fn) (void *closure, SCM key, SCM value,
+ SCM result);
+
+/* Function to iterate over the handles (key-value pairs) of a hash
+ table. */
+typedef SCM (*scm_t_hash_handle_fn) (void *closure, SCM handle);
+
typedef struct scm_t_hashtable {
int flags; /* properties of table */
unsigned long n_items; /* number of items in table */
@@ -84,12 +92,6 @@ typedef struct scm_t_hashtable {
-#if 0
-typedef unsigned int scm_t_hash_fn (SCM obj, unsigned int d, void *closure);
-typedef SCM scm_t_assoc_fn (SCM key, SCM alist, void *closure);
-typedef SCM scm_t_delete_fn (SCM elt, SCM list);
-#endif
-
SCM_API SCM scm_vector_to_hash_table (SCM vector);
SCM_API SCM scm_c_make_hash_table (unsigned long k);
SCM_API SCM scm_make_hash_table (SCM n);
@@ -126,8 +128,10 @@ SCM_API SCM scm_hash_fn_remove_x (SCM table, SCM obj,
scm_t_hash_fn hash_fn,
scm_t_assoc_fn assoc_fn,
void *closure);
-SCM_API SCM scm_internal_hash_fold (SCM (*fn) (), void *closure, SCM init, SCM table);
-SCM_API void scm_internal_hash_for_each_handle (SCM (*fn) (), void *closure, SCM table);
+SCM_API SCM scm_internal_hash_fold (scm_t_hash_fold_fn fn, void *closure,
+ SCM init, SCM table);
+SCM_API void scm_internal_hash_for_each_handle (scm_t_hash_handle_fn fn,
+ void *closure, SCM table);
SCM_API SCM scm_hash_clear_x (SCM table);
SCM_API SCM scm_hashq_get_handle (SCM table, SCM obj);