-/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1998,1999,2000,2001, 2003, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
}
#undef FUNC_NAME
+\f
+/* Accessing hash table entries. */
SCM
-scm_hash_fn_get_handle (SCM table, SCM obj, unsigned long (*hash_fn)(), SCM (*assoc_fn)(), void * closure)
+scm_hash_fn_get_handle (SCM table, SCM obj,
+ scm_t_hash_fn hash_fn, scm_t_assoc_fn assoc_fn,
+ void * closure)
#define FUNC_NAME "scm_hash_fn_get_handle"
{
int weak = 0;
"Uses @code{eq?} for equality testing.")
#define FUNC_NAME s_scm_hashq_get_handle
{
- return scm_hash_fn_get_handle (table, key, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_get_handle (table, key,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
"associates @var{key} with @var{init}.")
#define FUNC_NAME s_scm_hashq_create_handle_x
{
- return scm_hash_fn_create_handle_x (table, key, init, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_create_handle_x (table, key, init,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
{
if (SCM_UNBNDP (dflt))
dflt = SCM_BOOL_F;
- return scm_hash_fn_ref (table, key, dflt, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_ref (table, key, dflt,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
"store @var{value} there. Uses @code{eq?} for equality testing.")
#define FUNC_NAME s_scm_hashq_set_x
{
- return scm_hash_fn_set_x (table, key, val, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_set_x (table, key, val,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
"@var{table}. Uses @code{eq?} for equality tests.")
#define FUNC_NAME s_scm_hashq_remove_x
{
- return scm_hash_fn_remove_x (table, key, scm_ihashq, scm_sloppy_assq, 0);
+ return scm_hash_fn_remove_x (table, key,
+ (scm_t_hash_fn) scm_ihashq,
+ (scm_t_assoc_fn) scm_sloppy_assq,
+ 0);
}
#undef FUNC_NAME
"Uses @code{eqv?} for equality testing.")
#define FUNC_NAME s_scm_hashv_get_handle
{
- return scm_hash_fn_get_handle (table, key, scm_ihashv, scm_sloppy_assv, 0);
+ return scm_hash_fn_get_handle (table, key,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
"associates @var{key} with @var{init}.")
#define FUNC_NAME s_scm_hashv_create_handle_x
{
- return scm_hash_fn_create_handle_x (table, key, init, scm_ihashv,
- scm_sloppy_assv, 0);
+ return scm_hash_fn_create_handle_x (table, key, init,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
{
if (SCM_UNBNDP (dflt))
dflt = SCM_BOOL_F;
- return scm_hash_fn_ref (table, key, dflt, scm_ihashv, scm_sloppy_assv, 0);
+ return scm_hash_fn_ref (table, key, dflt,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
"store @var{value} there. Uses @code{eqv?} for equality testing.")
#define FUNC_NAME s_scm_hashv_set_x
{
- return scm_hash_fn_set_x (table, key, val, scm_ihashv, scm_sloppy_assv, 0);
+ return scm_hash_fn_set_x (table, key, val,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
"@var{table}. Uses @code{eqv?} for equality tests.")
#define FUNC_NAME s_scm_hashv_remove_x
{
- return scm_hash_fn_remove_x (table, key, scm_ihashv, scm_sloppy_assv, 0);
+ return scm_hash_fn_remove_x (table, key,
+ (scm_t_hash_fn) scm_ihashv,
+ (scm_t_assoc_fn) scm_sloppy_assv,
+ 0);
}
#undef FUNC_NAME
"Uses @code{equal?} for equality testing.")
#define FUNC_NAME s_scm_hash_get_handle
{
- return scm_hash_fn_get_handle (table, key, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_get_handle (table, key,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
"associates @var{key} with @var{init}.")
#define FUNC_NAME s_scm_hash_create_handle_x
{
- return scm_hash_fn_create_handle_x (table, key, init, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_create_handle_x (table, key, init,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
{
if (SCM_UNBNDP (dflt))
dflt = SCM_BOOL_F;
- return scm_hash_fn_ref (table, key, dflt, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_ref (table, key, dflt,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
"testing.")
#define FUNC_NAME s_scm_hash_set_x
{
- return scm_hash_fn_set_x (table, key, val, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_set_x (table, key, val,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
"@var{table}. Uses @code{equal?} for equality tests.")
#define FUNC_NAME s_scm_hash_remove_x
{
- return scm_hash_fn_remove_x (table, key, scm_ihash, scm_sloppy_assoc, 0);
+ return scm_hash_fn_remove_x (table, key,
+ (scm_t_hash_fn) scm_ihash,
+ (scm_t_assoc_fn) scm_sloppy_assoc,
+ 0);
}
#undef FUNC_NAME
static unsigned long
-scm_ihashx (SCM obj, unsigned long n, scm_t_ihashx_closure *closure)
+scm_ihashx (SCM obj, unsigned long n, void *arg)
{
- SCM answer = scm_call_2 (closure->hash, obj, scm_from_ulong (n));
+ SCM answer;
+ scm_t_ihashx_closure *closure = (scm_t_ihashx_closure *) arg;
+ answer = scm_call_2 (closure->hash, obj, scm_from_ulong (n));
return scm_to_ulong (answer);
}
static SCM
-scm_sloppy_assx (SCM obj, SCM alist, scm_t_ihashx_closure *closure)
+scm_sloppy_assx (SCM obj, SCM alist, void *arg)
{
+ scm_t_ihashx_closure *closure = (scm_t_ihashx_closure *) arg;
return scm_call_2 (closure->assoc, obj, alist);
}
#ifndef SCM_HASHTAB_H
#define SCM_HASHTAB_H
-/* Copyright (C) 1995,1996,1999,2000,2001, 2003, 2004, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,1999,2000,2001, 2003, 2004, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
#define SCM_SET_HASHTABLE_BUCKET(h, i, x) \
SCM_SIMPLE_VECTOR_SET (SCM_HASHTABLE_VECTOR (h), i, x)
+/* Function that computes a hash of OBJ modulo MAX. */
+typedef unsigned long (*scm_t_hash_fn) (SCM obj, unsigned long max,
+ void *closure);
+
+/* Function that returns the value associated with OBJ in ALIST according to
+ some equality predicate. */
+typedef SCM (*scm_t_assoc_fn) (SCM obj, SCM alist, void *closure);
+
typedef struct scm_t_hashtable {
int flags; /* properties of table */
unsigned long n_items; /* number of items in table */
unsigned long upper; /* when to grow */
int size_index; /* index into hashtable_size */
int min_size_index; /* minimum size_index */
- unsigned long (*hash_fn) (); /* for rehashing after a GC. */
+ scm_t_hash_fn hash_fn; /* for rehashing after a GC. */
} scm_t_hashtable;
\f
SCM_API SCM scm_weak_value_hash_table_p (SCM h);
SCM_API SCM scm_doubly_weak_hash_table_p (SCM h);
-SCM_INTERNAL void scm_i_rehash (SCM table, unsigned long (*hash_fn)(),
+SCM_INTERNAL void scm_i_rehash (SCM table, scm_t_hash_fn hash_fn,
void *closure, const char *func_name);
-SCM_API SCM scm_hash_fn_get_handle (SCM table, SCM obj, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
-SCM_API SCM scm_hash_fn_create_handle_x (SCM table, SCM obj, SCM init, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
-SCM_API SCM scm_hash_fn_ref (SCM table, SCM obj, SCM dflt, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
-SCM_API SCM scm_hash_fn_set_x (SCM table, SCM obj, SCM val, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
-SCM_API SCM scm_hash_fn_remove_x (SCM table, SCM obj, unsigned long (*hash_fn) (), SCM (*assoc_fn) (), void * closure);
+
+SCM_API SCM scm_hash_fn_get_handle (SCM table, SCM obj,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
+SCM_API SCM scm_hash_fn_create_handle_x (SCM table, SCM obj, SCM init,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
+SCM_API SCM scm_hash_fn_ref (SCM table, SCM obj, SCM dflt,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
+SCM_API SCM scm_hash_fn_set_x (SCM table, SCM obj, SCM val,
+ scm_t_hash_fn hash_fn,
+ scm_t_assoc_fn assoc_fn,
+ void *closure);
+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_hash_clear_x (SCM table);
#ifndef SCM_SRCPROP_H
#define SCM_SRCPROP_H
-/* Copyright (C) 1995,1996,2000,2001, 2006, 2008 Free Software Foundation, Inc.
+/* Copyright (C) 1995,1996,2000,2001, 2006, 2008, 2009 Free Software Foundation, Inc.
*
* This library is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public License
#define scm_whash_handle SCM
-#define scm_whash_get_handle(whash, key) scm_hash_fn_get_handle (whash, key, scm_ihashq, scm_sloppy_assq, 0)
+#define scm_whash_get_handle(whash, key) \
+ scm_hashq_get_handle ((whash), (key))
#define SCM_WHASHFOUNDP(h) (scm_is_true (h))
#define SCM_WHASHREF(whash, handle) SCM_CDR (handle)
#define SCM_WHASHSET(whash, handle, obj) SCM_SETCDR (handle, obj)
-#define scm_whash_create_handle(whash, key) scm_hash_fn_create_handle_x (whash, key, SCM_UNSPECIFIED, scm_ihashq, scm_sloppy_assq, 0)
-#define scm_whash_lookup(whash, obj) scm_hash_fn_ref (whash, obj, SCM_BOOL_F, scm_ihashq, scm_sloppy_assq, 0)
+#define scm_whash_create_handle(whash, key) \
+ scm_hashq_create_handle_x ((whash), (key), SCM_UNSPECIFIED)
+#define scm_whash_lookup(whash, obj) \
+ scm_hashq_ref ((whash), (obj), SCM_BOOL_F)
#define scm_whash_insert(whash, key, obj) \
do { \
register SCM w = (whash); \