mirror of
https://git.savannah.gnu.org/git/guile.git
synced 2025-05-01 04:10:18 +02:00
hash tables have a tc7
* libguile/tags.h (scm_tc7_hashtable): Allocate a tc7 for hashtables. * libguile/hashtab.h: Adjust macros accordingly. (scm_i_hashtable_print, scm_i_hashtable_equal_p): New internal functions. (scm_hashtab_prehistory): Remove, no more need for this. * libguile/hashtab.c (scm_hash_fn_remove_x): Fix a longstanding bug. (make_hash_table): Adapt to the new hash table representation. * libguile/eq.c (scm_equal_p) * libguile/evalext.c (scm_self_evaluating_p) * libguile/print.c (iprin1) * libguile/gc.c (scm_i_tag_name): Add some tc7_hashtab cases. * libguile/init.c: Remove unused environments init functions. Remove call to hashtab_prehistory. * libguile/goops.h (scm_class_hashtable) * libguile/goops.c (scm_class_of, create_standard_classes): Have to make a class for hash tables manually, because they aren't smobs any more.
This commit is contained in:
parent
314b87163e
commit
c99de5aa27
10 changed files with 39 additions and 43 deletions
|
@ -30,6 +30,7 @@
|
||||||
#include "libguile/smob.h"
|
#include "libguile/smob.h"
|
||||||
#include "libguile/arrays.h"
|
#include "libguile/arrays.h"
|
||||||
#include "libguile/vectors.h"
|
#include "libguile/vectors.h"
|
||||||
|
#include "libguile/hashtab.h"
|
||||||
#include "libguile/bytevectors.h"
|
#include "libguile/bytevectors.h"
|
||||||
|
|
||||||
#include "libguile/struct.h"
|
#include "libguile/struct.h"
|
||||||
|
@ -342,6 +343,9 @@ scm_equal_p (SCM x, SCM y)
|
||||||
case scm_tc7_vector:
|
case scm_tc7_vector:
|
||||||
case scm_tc7_wvect:
|
case scm_tc7_wvect:
|
||||||
return scm_i_vector_equal_p (x, y);
|
return scm_i_vector_equal_p (x, y);
|
||||||
|
|
||||||
|
case scm_tc7_hashtable:
|
||||||
|
return scm_i_hashtable_equal_p (x, y);
|
||||||
}
|
}
|
||||||
/* Check equality between structs of equal type (see cell-type test above). */
|
/* Check equality between structs of equal type (see cell-type test above). */
|
||||||
if (SCM_STRUCTP (x))
|
if (SCM_STRUCTP (x))
|
||||||
|
|
|
@ -77,6 +77,7 @@ SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
|
||||||
{
|
{
|
||||||
case scm_tc7_vector:
|
case scm_tc7_vector:
|
||||||
case scm_tc7_wvect:
|
case scm_tc7_wvect:
|
||||||
|
case scm_tc7_hashtable:
|
||||||
case scm_tc7_number:
|
case scm_tc7_number:
|
||||||
case scm_tc7_string:
|
case scm_tc7_string:
|
||||||
case scm_tc7_smob:
|
case scm_tc7_smob:
|
||||||
|
|
|
@ -756,6 +756,8 @@ scm_i_tag_name (scm_t_bits tag)
|
||||||
return "cons (non-immediate car)";
|
return "cons (non-immediate car)";
|
||||||
case scm_tc7_pws:
|
case scm_tc7_pws:
|
||||||
return "pws";
|
return "pws";
|
||||||
|
case scm_tc7_hashtable:
|
||||||
|
return "hashtable";
|
||||||
case scm_tc7_wvect:
|
case scm_tc7_wvect:
|
||||||
return "weak vector";
|
return "weak vector";
|
||||||
case scm_tc7_vector:
|
case scm_tc7_vector:
|
||||||
|
|
|
@ -133,7 +133,7 @@ static scm_t_rstate *goops_rstate;
|
||||||
SCM scm_class_boolean, scm_class_char, scm_class_pair;
|
SCM scm_class_boolean, scm_class_char, scm_class_pair;
|
||||||
SCM scm_class_procedure, scm_class_string, scm_class_symbol;
|
SCM scm_class_procedure, scm_class_string, scm_class_symbol;
|
||||||
SCM scm_class_procedure_with_setter, scm_class_primitive_generic;
|
SCM scm_class_procedure_with_setter, scm_class_primitive_generic;
|
||||||
SCM scm_class_vector, scm_class_null;
|
SCM scm_class_vector, scm_class_hashtable, scm_class_null;
|
||||||
SCM scm_class_integer, scm_class_real, scm_class_complex, scm_class_fraction;
|
SCM scm_class_integer, scm_class_real, scm_class_complex, scm_class_fraction;
|
||||||
SCM scm_class_unknown;
|
SCM scm_class_unknown;
|
||||||
SCM scm_class_top, scm_class_object, scm_class_class;
|
SCM scm_class_top, scm_class_object, scm_class_class;
|
||||||
|
@ -210,6 +210,8 @@ SCM_DEFINE (scm_class_of, "class-of", 1, 0, 0,
|
||||||
case scm_tc7_vector:
|
case scm_tc7_vector:
|
||||||
case scm_tc7_wvect:
|
case scm_tc7_wvect:
|
||||||
return scm_class_vector;
|
return scm_class_vector;
|
||||||
|
case scm_tc7_hashtable:
|
||||||
|
return scm_class_hashtable;
|
||||||
case scm_tc7_string:
|
case scm_tc7_string:
|
||||||
return scm_class_string;
|
return scm_class_string;
|
||||||
case scm_tc7_number:
|
case scm_tc7_number:
|
||||||
|
@ -2400,6 +2402,8 @@ create_standard_classes (void)
|
||||||
scm_class_class, scm_class_top, SCM_EOL);
|
scm_class_class, scm_class_top, SCM_EOL);
|
||||||
make_stdcls (&scm_class_vector, "<vector>",
|
make_stdcls (&scm_class_vector, "<vector>",
|
||||||
scm_class_class, scm_class_top, SCM_EOL);
|
scm_class_class, scm_class_top, SCM_EOL);
|
||||||
|
make_stdcls (&scm_class_hashtable, "<hashtable>",
|
||||||
|
scm_class_class, scm_class_top, SCM_EOL);
|
||||||
make_stdcls (&scm_class_number, "<number>",
|
make_stdcls (&scm_class_number, "<number>",
|
||||||
scm_class_class, scm_class_top, SCM_EOL);
|
scm_class_class, scm_class_top, SCM_EOL);
|
||||||
make_stdcls (&scm_class_complex, "<complex>",
|
make_stdcls (&scm_class_complex, "<complex>",
|
||||||
|
|
|
@ -179,7 +179,9 @@ SCM_API SCM scm_class_string;
|
||||||
SCM_API SCM scm_class_symbol;
|
SCM_API SCM scm_class_symbol;
|
||||||
SCM_API SCM scm_class_procedure_with_setter;
|
SCM_API SCM scm_class_procedure_with_setter;
|
||||||
SCM_API SCM scm_class_primitive_generic;
|
SCM_API SCM scm_class_primitive_generic;
|
||||||
SCM_API SCM scm_class_vector, scm_class_null;
|
SCM_API SCM scm_class_vector;
|
||||||
|
SCM_API SCM scm_class_hashtable;
|
||||||
|
SCM_API SCM scm_class_null;
|
||||||
SCM_API SCM scm_class_real;
|
SCM_API SCM scm_class_real;
|
||||||
SCM_API SCM scm_class_complex;
|
SCM_API SCM scm_class_complex;
|
||||||
SCM_API SCM scm_class_integer;
|
SCM_API SCM scm_class_integer;
|
||||||
|
|
|
@ -50,10 +50,7 @@
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* Hash tables are either vectors of association lists or smobs
|
/* A hash table is a cell containing a vector of association lists.
|
||||||
* containing such vectors. Currently, the vector version represents
|
|
||||||
* constant size tables while those wrapped in a smob represents
|
|
||||||
* resizing tables.
|
|
||||||
*
|
*
|
||||||
* Growing or shrinking, with following rehashing, is triggered when
|
* Growing or shrinking, with following rehashing, is triggered when
|
||||||
* the load factor
|
* the load factor
|
||||||
|
@ -69,8 +66,6 @@
|
||||||
* hashtable_size.
|
* hashtable_size.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
scm_t_bits scm_tc16_hashtable;
|
|
||||||
|
|
||||||
static unsigned long hashtable_size[] = {
|
static unsigned long hashtable_size[] = {
|
||||||
31, 61, 113, 223, 443, 883, 1759, 3517, 7027, 14051, 28099, 56197, 112363,
|
31, 61, 113, 223, 443, 883, 1759, 3517, 7027, 14051, 28099, 56197, 112363,
|
||||||
224717, 449419, 898823, 1797641, 3595271, 7190537, 14381041
|
224717, 449419, 898823, 1797641, 3595271, 7190537, 14381041
|
||||||
|
@ -230,7 +225,7 @@ weak_bucket_assoc (SCM table, SCM buckets, size_t bucket_index,
|
||||||
static SCM
|
static SCM
|
||||||
make_hash_table (int flags, unsigned long k, const char *func_name)
|
make_hash_table (int flags, unsigned long k, const char *func_name)
|
||||||
{
|
{
|
||||||
SCM table, vector;
|
SCM vector;
|
||||||
scm_t_hashtable *t;
|
scm_t_hashtable *t;
|
||||||
int i = 0, n = k ? k : 31;
|
int i = 0, n = k ? k : 31;
|
||||||
while (i < HASHTABLE_SIZE_N && n > hashtable_size[i])
|
while (i < HASHTABLE_SIZE_N && n > hashtable_size[i])
|
||||||
|
@ -250,9 +245,9 @@ make_hash_table (int flags, unsigned long k, const char *func_name)
|
||||||
t->flags = flags;
|
t->flags = flags;
|
||||||
t->hash_fn = NULL;
|
t->hash_fn = NULL;
|
||||||
|
|
||||||
SCM_NEWSMOB2 (table, scm_tc16_hashtable, vector, t);
|
/* FIXME: we just need two words of storage, not three */
|
||||||
|
return scm_double_cell (scm_tc7_hashtable, SCM_UNPACK (vector),
|
||||||
return table;
|
(scm_t_bits)t, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
@ -342,8 +337,8 @@ scm_i_rehash (SCM table,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
void
|
||||||
hashtable_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
|
scm_i_hashtable_print (SCM exp, SCM port, scm_print_state *pstate)
|
||||||
{
|
{
|
||||||
scm_puts ("#<", port);
|
scm_puts ("#<", port);
|
||||||
if (SCM_HASHTABLE_WEAK_KEY_P (exp))
|
if (SCM_HASHTABLE_WEAK_KEY_P (exp))
|
||||||
|
@ -358,7 +353,12 @@ hashtable_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
|
||||||
scm_uintprint (SCM_SIMPLE_VECTOR_LENGTH (SCM_HASHTABLE_VECTOR (exp)),
|
scm_uintprint (SCM_SIMPLE_VECTOR_LENGTH (SCM_HASHTABLE_VECTOR (exp)),
|
||||||
10, port);
|
10, port);
|
||||||
scm_puts (">", port);
|
scm_puts (">", port);
|
||||||
return 1;
|
}
|
||||||
|
|
||||||
|
SCM
|
||||||
|
scm_i_hashtable_equal_p (SCM x, SCM y)
|
||||||
|
{
|
||||||
|
return SCM_BOOL_F;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -650,7 +650,7 @@ scm_hash_fn_remove_x (SCM table, SCM obj,
|
||||||
SCM_ARG1, "hash_fn_remove_x");
|
SCM_ARG1, "hash_fn_remove_x");
|
||||||
buckets = table;
|
buckets = table;
|
||||||
}
|
}
|
||||||
if (SCM_SIMPLE_VECTOR_LENGTH (table) == 0)
|
if (SCM_SIMPLE_VECTOR_LENGTH (buckets) == 0)
|
||||||
return SCM_EOL;
|
return SCM_EOL;
|
||||||
|
|
||||||
k = hash_fn (obj, SCM_SIMPLE_VECTOR_LENGTH (buckets), closure);
|
k = hash_fn (obj, SCM_SIMPLE_VECTOR_LENGTH (buckets), closure);
|
||||||
|
@ -1258,14 +1258,6 @@ SCM_DEFINE (scm_hash_map_to_list, "hash-map->list", 2, 0, 0,
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
void
|
|
||||||
scm_hashtab_prehistory ()
|
|
||||||
{
|
|
||||||
/* Initialize the hashtab SMOB type. */
|
|
||||||
scm_tc16_hashtable = scm_make_smob_type (s_hashtable, 0);
|
|
||||||
scm_set_smob_print (scm_tc16_hashtable, hashtable_print);
|
|
||||||
}
|
|
||||||
|
|
||||||
void
|
void
|
||||||
scm_init_hashtab ()
|
scm_init_hashtab ()
|
||||||
{
|
{
|
||||||
|
|
|
@ -32,14 +32,12 @@
|
||||||
#define SCM_HASHTABLEF_WEAK_CAR SCM_WVECTF_WEAK_KEY
|
#define SCM_HASHTABLEF_WEAK_CAR SCM_WVECTF_WEAK_KEY
|
||||||
#define SCM_HASHTABLEF_WEAK_CDR SCM_WVECTF_WEAK_VALUE
|
#define SCM_HASHTABLEF_WEAK_CDR SCM_WVECTF_WEAK_VALUE
|
||||||
|
|
||||||
SCM_API scm_t_bits scm_tc16_hashtable;
|
#define SCM_HASHTABLE_P(x) (!SCM_IMP (x) && SCM_TYP7(x) == scm_tc7_hashtable)
|
||||||
|
|
||||||
#define SCM_HASHTABLE_P(x) SCM_SMOB_PREDICATE (scm_tc16_hashtable, x)
|
|
||||||
#define SCM_VALIDATE_HASHTABLE(pos, arg) \
|
#define SCM_VALIDATE_HASHTABLE(pos, arg) \
|
||||||
SCM_MAKE_VALIDATE_MSG (pos, arg, HASHTABLE_P, "hash-table")
|
SCM_MAKE_VALIDATE_MSG (pos, arg, HASHTABLE_P, "hash-table")
|
||||||
#define SCM_HASHTABLE_VECTOR(h) SCM_SMOB_OBJECT (h)
|
#define SCM_HASHTABLE_VECTOR(h) SCM_CELL_OBJECT_1 (h)
|
||||||
#define SCM_SET_HASHTABLE_VECTOR(x, v) SCM_SET_SMOB_OBJECT ((x), (v))
|
#define SCM_SET_HASHTABLE_VECTOR(x, v) SCM_SET_CELL_OBJECT_1 ((x), (v))
|
||||||
#define SCM_HASHTABLE(x) ((scm_t_hashtable *) SCM_SMOB_DATA_2 (x))
|
#define SCM_HASHTABLE(x) ((scm_t_hashtable *) SCM_CELL_WORD_2 (x))
|
||||||
#define SCM_HASHTABLE_FLAGS(x) (SCM_HASHTABLE (x)->flags)
|
#define SCM_HASHTABLE_FLAGS(x) (SCM_HASHTABLE (x)->flags)
|
||||||
#define SCM_HASHTABLE_WEAK_KEY_P(x) \
|
#define SCM_HASHTABLE_WEAK_KEY_P(x) \
|
||||||
(SCM_HASHTABLE_FLAGS (x) & SCM_HASHTABLEF_WEAK_CAR)
|
(SCM_HASHTABLE_FLAGS (x) & SCM_HASHTABLEF_WEAK_CAR)
|
||||||
|
@ -158,7 +156,8 @@ SCM_API SCM scm_hash_fold (SCM proc, SCM init, SCM hash);
|
||||||
SCM_API SCM scm_hash_for_each (SCM proc, SCM hash);
|
SCM_API SCM scm_hash_for_each (SCM proc, SCM hash);
|
||||||
SCM_API SCM scm_hash_for_each_handle (SCM proc, SCM hash);
|
SCM_API SCM scm_hash_for_each_handle (SCM proc, SCM hash);
|
||||||
SCM_API SCM scm_hash_map_to_list (SCM proc, SCM hash);
|
SCM_API SCM scm_hash_map_to_list (SCM proc, SCM hash);
|
||||||
SCM_INTERNAL void scm_hashtab_prehistory (void);
|
SCM_INTERNAL void scm_i_hashtable_print (SCM exp, SCM port, scm_print_state *pstate);
|
||||||
|
SCM_INTERNAL SCM scm_i_hashtable_equal_p (SCM x, SCM y);
|
||||||
SCM_INTERNAL void scm_init_hashtab (void);
|
SCM_INTERNAL void scm_init_hashtab (void);
|
||||||
|
|
||||||
#endif /* SCM_HASHTAB_H */
|
#endif /* SCM_HASHTAB_H */
|
||||||
|
|
|
@ -49,9 +49,6 @@
|
||||||
#include "libguile/deprecation.h"
|
#include "libguile/deprecation.h"
|
||||||
#include "libguile/dynl.h"
|
#include "libguile/dynl.h"
|
||||||
#include "libguile/dynwind.h"
|
#include "libguile/dynwind.h"
|
||||||
#if 0
|
|
||||||
#include "libguile/environments.h"
|
|
||||||
#endif
|
|
||||||
#include "libguile/eq.h"
|
#include "libguile/eq.h"
|
||||||
#include "libguile/error.h"
|
#include "libguile/error.h"
|
||||||
#include "libguile/eval.h"
|
#include "libguile/eval.h"
|
||||||
|
@ -443,8 +440,6 @@ scm_i_init_guile (SCM_STACKITEM *base)
|
||||||
scm_smob_prehistory ();
|
scm_smob_prehistory ();
|
||||||
scm_fluids_prehistory ();
|
scm_fluids_prehistory ();
|
||||||
scm_weaks_prehistory ();
|
scm_weaks_prehistory ();
|
||||||
scm_hashtab_prehistory (); /* requires storage_prehistory, and
|
|
||||||
weaks_prehistory */
|
|
||||||
#ifdef GUILE_DEBUG_MALLOC
|
#ifdef GUILE_DEBUG_MALLOC
|
||||||
scm_debug_malloc_prehistory ();
|
scm_debug_malloc_prehistory ();
|
||||||
#endif
|
#endif
|
||||||
|
@ -455,9 +450,6 @@ scm_i_init_guile (SCM_STACKITEM *base)
|
||||||
|
|
||||||
scm_struct_prehistory (); /* requires storage */
|
scm_struct_prehistory (); /* requires storage */
|
||||||
scm_symbols_prehistory (); /* requires storage */
|
scm_symbols_prehistory (); /* requires storage */
|
||||||
#if 0
|
|
||||||
scm_environments_prehistory (); /* requires storage */
|
|
||||||
#endif
|
|
||||||
scm_modules_prehistory (); /* requires storage and hash tables */
|
scm_modules_prehistory (); /* requires storage and hash tables */
|
||||||
scm_init_variable (); /* all bindings need variables */
|
scm_init_variable (); /* all bindings need variables */
|
||||||
scm_init_continuations ();
|
scm_init_continuations ();
|
||||||
|
@ -466,9 +458,6 @@ scm_i_init_guile (SCM_STACKITEM *base)
|
||||||
scm_init_gsubr ();
|
scm_init_gsubr ();
|
||||||
scm_init_thread_procs (); /* requires gsubrs */
|
scm_init_thread_procs (); /* requires gsubrs */
|
||||||
scm_init_procprop ();
|
scm_init_procprop ();
|
||||||
#if 0
|
|
||||||
scm_init_environments ();
|
|
||||||
#endif
|
|
||||||
scm_init_alist ();
|
scm_init_alist ();
|
||||||
scm_init_arbiters ();
|
scm_init_arbiters ();
|
||||||
scm_init_async ();
|
scm_init_async ();
|
||||||
|
|
|
@ -709,6 +709,9 @@ iprin1 (SCM exp, SCM port, scm_print_state *pstate)
|
||||||
case scm_tc7_program:
|
case scm_tc7_program:
|
||||||
scm_i_program_print (exp, port, pstate);
|
scm_i_program_print (exp, port, pstate);
|
||||||
break;
|
break;
|
||||||
|
case scm_tc7_hashtable:
|
||||||
|
scm_i_hashtable_print (exp, port, pstate);
|
||||||
|
break;
|
||||||
case scm_tc7_wvect:
|
case scm_tc7_wvect:
|
||||||
ENTER_NESTED_DATA (pstate, exp, circref);
|
ENTER_NESTED_DATA (pstate, exp, circref);
|
||||||
if (SCM_IS_WHVEC (exp))
|
if (SCM_IS_WHVEC (exp))
|
||||||
|
|
|
@ -417,7 +417,7 @@ typedef scm_t_uintptr scm_t_bits;
|
||||||
|
|
||||||
#define scm_tc7_pws 31
|
#define scm_tc7_pws 31
|
||||||
|
|
||||||
#define scm_tc7_unused_1 29
|
#define scm_tc7_hashtable 29
|
||||||
#define scm_tc7_unused_2 37
|
#define scm_tc7_unused_2 37
|
||||||
#define scm_tc7_unused_3 45
|
#define scm_tc7_unused_3 45
|
||||||
#define scm_tc7_unused_4 47
|
#define scm_tc7_unused_4 47
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue