1
Fork 0
mirror of https://git.savannah.gnu.org/git/guile.git synced 2025-04-29 19:30:36 +02:00

add weak table implementation

* libguile/weak-table.c:
* libguile/weak-table.h: New files, implementing open-addressed weak
  hash tables, similar to the implementation of weak sets.  This will
  let us remove weak pairs.

* libguile.h:
* libguile/Makefile.am:
* libguile/evalext.c:
* libguile/gc.c:
* libguile/init.c:
* libguile/print.c:
* libguile/tags.h: Update all the pieces for the new files and tc7.
This commit is contained in:
Andy Wingo 2011-10-23 23:23:47 +02:00
parent 2721f9182d
commit 7005c60fcb
9 changed files with 1146 additions and 1 deletions

View file

@ -116,6 +116,7 @@ extern "C" {
#include "libguile/version.h"
#include "libguile/vports.h"
#include "libguile/weak-set.h"
#include "libguile/weak-table.h"
#include "libguile/weaks.h"
#include "libguile/backtrace.h"
#include "libguile/debug.h"

View file

@ -219,6 +219,7 @@ libguile_@GUILE_EFFECTIVE_VERSION@_la_SOURCES = \
vm.c \
vports.c \
weak-set.c \
weak-table.c \
weaks.c
DOT_X_FILES = \
@ -316,6 +317,7 @@ DOT_X_FILES = \
version.x \
vports.x \
weak-set.x \
weak-table.x \
weaks.x
# vm-related snarfs
@ -418,6 +420,7 @@ DOT_DOC_FILES = \
version.doc \
vports.doc \
weak-set.doc \
weak-table.doc \
weaks.doc
EXTRA_DOT_DOC_FILES = @EXTRA_DOT_DOC_FILES@
@ -621,6 +624,7 @@ modinclude_HEADERS = \
vm.h \
vports.h \
weak-set.h \
weak-table.h \
weaks.h
nodist_modinclude_HEADERS = version.h scmconfig.h

View file

@ -77,6 +77,7 @@ SCM_DEFINE (scm_self_evaluating_p, "self-evaluating?", 1, 0, 0,
case scm_tc7_pointer:
case scm_tc7_hashtable:
case scm_tc7_weak_set:
case scm_tc7_weak_table:
case scm_tc7_fluid:
case scm_tc7_dynamic_state:
case scm_tc7_frame:

View file

@ -753,6 +753,8 @@ scm_i_tag_name (scm_t_bits tag)
return "hashtable";
case scm_tc7_weak_set:
return "weak-set";
case scm_tc7_weak_table:
return "weak-table";
case scm_tc7_fluid:
return "fluid";
case scm_tc7_dynamic_state:

View file

@ -384,6 +384,7 @@ scm_i_init_guile (void *base)
scm_storage_prehistory ();
scm_threads_prehistory (base); /* requires storage_prehistory */
scm_weaks_prehistory (); /* requires storage_prehistory */
scm_weak_table_prehistory (); /* requires storage_prehistory */
#ifdef GUILE_DEBUG_MALLOC
scm_debug_malloc_prehistory ();
#endif
@ -490,6 +491,7 @@ scm_i_init_guile (void *base)
scm_init_version ();
scm_init_weaks ();
scm_init_weak_set ();
scm_init_weak_table ();
scm_init_guardians (); /* requires smob_prehistory */
scm_init_vports ();
scm_init_standard_ports (); /* Requires fports */

View file

@ -624,6 +624,9 @@ iprin1 (SCM exp, SCM port, scm_print_state *pstate)
case scm_tc7_weak_set:
scm_i_weak_set_print (exp, port, pstate);
break;
case scm_tc7_weak_table:
scm_i_weak_table_print (exp, port, pstate);
break;
case scm_tc7_fluid:
scm_i_fluid_print (exp, port, pstate);
break;

View file

@ -418,7 +418,7 @@ typedef union SCM { struct { scm_t_bits n; } n; } SCM;
#define scm_tc7_unused_19 69
#define scm_tc7_program 79
#define scm_tc7_weak_set 85
#define scm_tc7_unused_10 87
#define scm_tc7_weak_table 87
#define scm_tc7_unused_20 93
#define scm_tc7_unused_11 95
#define scm_tc7_unused_12 101

1050
libguile/weak-table.c Normal file

File diff suppressed because it is too large Load diff

82
libguile/weak-table.h Normal file
View file

@ -0,0 +1,82 @@
/* classes: h_files */
#ifndef SCM_WEAK_TABLE_H
#define SCM_WEAK_TABLE_H
/* Copyright (C) 2011 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
* as published by the Free Software Foundation; either version 3 of
* the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this library; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA
*/
#include "libguile/__scm.h"
/* The weak table API is currently only used internally. We could make it
public later, after some API review. */
typedef enum {
SCM_WEAK_TABLE_KIND_KEY,
SCM_WEAK_TABLE_KIND_VALUE,
SCM_WEAK_TABLE_KIND_BOTH,
} scm_t_weak_table_kind;
/* Function that returns nonzero if the given mapping is the one we are
looking for. */
typedef int (*scm_t_table_predicate_fn) (SCM k, SCM v, void *closure);
/* Function to fold over the elements of a set. */
typedef SCM (*scm_t_table_fold_fn) (void *closure, SCM k, SCM v, SCM result);
SCM_INTERNAL SCM scm_c_make_weak_table (unsigned long k,
scm_t_weak_table_kind kind);
SCM_INTERNAL SCM scm_weak_table_p (SCM h);
SCM_INTERNAL SCM scm_c_weak_table_ref (SCM table, unsigned long raw_hash,
scm_t_table_predicate_fn pred,
void *closure, SCM dflt);
SCM_INTERNAL void scm_c_weak_table_put_x (SCM table, unsigned long raw_hash,
scm_t_table_predicate_fn pred,
void *closure, SCM key, SCM value);
SCM_INTERNAL void scm_c_weak_table_remove_x (SCM table, unsigned long raw_hash,
scm_t_table_predicate_fn pred,
void *closure);
SCM_INTERNAL SCM scm_weak_table_refq (SCM table, SCM key, SCM dflt);
SCM_INTERNAL SCM scm_weak_table_putq_x (SCM table, SCM key, SCM value);
SCM_INTERNAL SCM scm_weak_table_remq_x (SCM table, SCM key);
SCM_INTERNAL SCM scm_weak_table_clear_x (SCM table);
SCM_INTERNAL SCM scm_c_weak_table_fold (scm_t_table_fold_fn proc, void *closure,
SCM init, SCM table);
SCM_INTERNAL SCM scm_weak_table_fold (SCM proc, SCM init, SCM table);
SCM_INTERNAL SCM scm_weak_table_for_each (SCM proc, SCM table);
SCM_INTERNAL SCM scm_weak_table_map_to_list (SCM proc, SCM table);
SCM_INTERNAL void scm_i_weak_table_print (SCM exp, SCM port, scm_print_state *pstate);
SCM_INTERNAL void scm_weak_table_prehistory (void);
SCM_INTERNAL void scm_init_weak_table (void);
#endif /* SCM_WEAK_TABLE_H */
/*
Local Variables:
c-file-style: "gnu"
End:
*/