mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-20 19:50:24 +02:00
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.
This commit is contained in:
parent
f044da55c5
commit
a07010bf18
2 changed files with 19 additions and 12 deletions
|
@ -1039,7 +1039,8 @@ SCM_DEFINE (scm_hashx_remove_x, "hashx-remove!", 4, 0, 0,
|
||||||
static const char s_scm_hash_fold[];
|
static const char s_scm_hash_fold[];
|
||||||
|
|
||||||
SCM
|
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;
|
long i, n;
|
||||||
SCM buckets, result = init;
|
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[];
|
static const char s_scm_hash_for_each[];
|
||||||
|
|
||||||
void
|
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;
|
long i, n;
|
||||||
SCM buckets;
|
SCM buckets;
|
||||||
|
@ -1145,7 +1147,8 @@ SCM_DEFINE (scm_hash_fold, "hash-fold", 3, 0, 0,
|
||||||
SCM_VALIDATE_PROC (1, proc);
|
SCM_VALIDATE_PROC (1, proc);
|
||||||
if (!SCM_HASHTABLE_P (table))
|
if (!SCM_HASHTABLE_P (table))
|
||||||
SCM_VALIDATE_VECTOR (3, 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
|
#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))
|
if (!SCM_HASHTABLE_P (table))
|
||||||
SCM_VALIDATE_VECTOR (2, 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),
|
(void *) SCM_UNPACK (proc),
|
||||||
table);
|
table);
|
||||||
return SCM_UNSPECIFIED;
|
return SCM_UNSPECIFIED;
|
||||||
|
|
|
@ -72,6 +72,14 @@ typedef unsigned long (*scm_t_hash_fn) (SCM obj, unsigned long max,
|
||||||
some equality predicate. */
|
some equality predicate. */
|
||||||
typedef SCM (*scm_t_assoc_fn) (SCM obj, SCM alist, void *closure);
|
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 {
|
typedef struct scm_t_hashtable {
|
||||||
int flags; /* properties of table */
|
int flags; /* properties of table */
|
||||||
unsigned long n_items; /* number of items in 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_vector_to_hash_table (SCM vector);
|
||||||
SCM_API SCM scm_c_make_hash_table (unsigned long k);
|
SCM_API SCM scm_c_make_hash_table (unsigned long k);
|
||||||
SCM_API SCM scm_make_hash_table (SCM n);
|
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_hash_fn hash_fn,
|
||||||
scm_t_assoc_fn assoc_fn,
|
scm_t_assoc_fn assoc_fn,
|
||||||
void *closure);
|
void *closure);
|
||||||
SCM_API SCM scm_internal_hash_fold (SCM (*fn) (), void *closure, SCM init, SCM table);
|
SCM_API SCM scm_internal_hash_fold (scm_t_hash_fold_fn fn, void *closure,
|
||||||
SCM_API void scm_internal_hash_for_each_handle (SCM (*fn) (), void *closure, SCM table);
|
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_hash_clear_x (SCM table);
|
||||||
|
|
||||||
SCM_API SCM scm_hashq_get_handle (SCM table, SCM obj);
|
SCM_API SCM scm_hashq_get_handle (SCM table, SCM obj);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue