summaryrefslogtreecommitdiff
path: root/libguile/hashtab.c
diff options
context:
space:
mode:
authorAndy Wingo <wingo@pobox.com>2009-12-05 10:07:07 +0100
committerAndy Wingo <wingo@pobox.com>2009-12-05 10:07:07 +0100
commitc99de5aa275b15af207c0dba9717d6b865684fc4 (patch)
treed1c78809bf4971a152fd3cd46bf77cf29a2f5621 /libguile/hashtab.c
parent314b87163eac1358923cb84e7f2c87d06aa03756 (diff)
downloadguile-c99de5aa275b15af207c0dba9717d6b865684fc4.tar.gz
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.
Diffstat (limited to 'libguile/hashtab.c')
-rw-r--r--libguile/hashtab.c36
1 files changed, 14 insertions, 22 deletions
diff --git a/libguile/hashtab.c b/libguile/hashtab.c
index f3b35485a..608d53466 100644
--- a/libguile/hashtab.c
+++ b/libguile/hashtab.c
@@ -50,10 +50,7 @@
*
*/
-/* Hash tables are either vectors of association lists or smobs
- * containing such vectors. Currently, the vector version represents
- * constant size tables while those wrapped in a smob represents
- * resizing tables.
+/* A hash table is a cell containing a vector of association lists.
*
* Growing or shrinking, with following rehashing, is triggered when
* the load factor
@@ -69,8 +66,6 @@
* hashtable_size.
*/
-scm_t_bits scm_tc16_hashtable;
-
static unsigned long hashtable_size[] = {
31, 61, 113, 223, 443, 883, 1759, 3517, 7027, 14051, 28099, 56197, 112363,
224717, 449419, 898823, 1797641, 3595271, 7190537, 14381041
@@ -230,7 +225,7 @@ weak_bucket_assoc (SCM table, SCM buckets, size_t bucket_index,
static SCM
make_hash_table (int flags, unsigned long k, const char *func_name)
{
- SCM table, vector;
+ SCM vector;
scm_t_hashtable *t;
int i = 0, n = k ? k : 31;
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->hash_fn = NULL;
- SCM_NEWSMOB2 (table, scm_tc16_hashtable, vector, t);
-
- return table;
+ /* FIXME: we just need two words of storage, not three */
+ return scm_double_cell (scm_tc7_hashtable, SCM_UNPACK (vector),
+ (scm_t_bits)t, 0);
}
void
@@ -342,8 +337,8 @@ scm_i_rehash (SCM table,
}
-static int
-hashtable_print (SCM exp, SCM port, scm_print_state *pstate SCM_UNUSED)
+void
+scm_i_hashtable_print (SCM exp, SCM port, scm_print_state *pstate)
{
scm_puts ("#<", port);
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)),
10, 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");
buckets = table;
}
- if (SCM_SIMPLE_VECTOR_LENGTH (table) == 0)
+ if (SCM_SIMPLE_VECTOR_LENGTH (buckets) == 0)
return SCM_EOL;
k = hash_fn (obj, SCM_SIMPLE_VECTOR_LENGTH (buckets), closure);
@@ -1259,14 +1259,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
scm_init_hashtab ()
{
#include "libguile/hashtab.x"