diff options
author | Andy Wingo <wingo@pobox.com> | 2011-10-24 07:57:17 +0200 |
---|---|---|
committer | Andy Wingo <wingo@pobox.com> | 2011-10-24 12:48:15 +0200 |
commit | 54a9b981a4e64dd58e1d3dec474b8c397c30c1c9 (patch) | |
tree | 1a9ef59642abaea035d71b2da9de2f7e9222b08b /libguile/weak-table.c | |
parent | 7005c60fcbb8053d58dde579d8eef40bfe4d670f (diff) | |
download | guile-54a9b981a4e64dd58e1d3dec474b8c397c30c1c9.tar.gz |
reimplement hashtab.c's weak hash tables in terms of weak-table.c
* libguile/hashtab.c:
* libguile/hashtab.h: Reimplement the weak hash table implementation in
terms of weak tables. All is well except for the horrific hack for
hashx tables.
* libguile/weak-table.h:
* libguile/weak-table.c (scm_make_weak_key_hash_table)
(scm_make_weak_value_hash_table, scm_make_doubly_weak_hash_table)
(scm_weak_key_hash_table_p, scm_weak_value_hash_table_p)
(scm_doubly_weak_hash_table_p): Move these definitions here.
Diffstat (limited to 'libguile/weak-table.c')
-rw-r--r-- | libguile/weak-table.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/libguile/weak-table.c b/libguile/weak-table.c index fb4776322..160eca2cf 100644 --- a/libguile/weak-table.c +++ b/libguile/weak-table.c @@ -1024,6 +1024,90 @@ scm_weak_table_map_to_list (SCM proc, SCM table) #undef FUNC_NAME + + +/* Legacy interface. */ + +SCM_DEFINE (scm_make_weak_key_hash_table, "make-weak-key-hash-table", 0, 1, 0, + (SCM n), + "@deffnx {Scheme Procedure} make-weak-value-hash-table size\n" + "@deffnx {Scheme Procedure} make-doubly-weak-hash-table size\n" + "Return a weak hash table with @var{size} buckets.\n" + "\n" + "You can modify weak hash tables in exactly the same way you\n" + "would modify regular hash tables. (@pxref{Hash Tables})") +#define FUNC_NAME s_scm_make_weak_key_hash_table +{ + return scm_c_make_weak_table (SCM_UNBNDP (n) ? 0 : scm_to_ulong (n), + SCM_WEAK_TABLE_KIND_KEY); +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_make_weak_value_hash_table, "make-weak-value-hash-table", 0, 1, 0, + (SCM n), + "Return a hash table with weak values with @var{size} buckets.\n" + "(@pxref{Hash Tables})") +#define FUNC_NAME s_scm_make_weak_value_hash_table +{ + return scm_c_make_weak_table (SCM_UNBNDP (n) ? 0 : scm_to_ulong (n), + SCM_WEAK_TABLE_KIND_VALUE); +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_make_doubly_weak_hash_table, "make-doubly-weak-hash-table", 1, 0, 0, + (SCM n), + "Return a hash table with weak keys and values with @var{size}\n" + "buckets. (@pxref{Hash Tables})") +#define FUNC_NAME s_scm_make_doubly_weak_hash_table +{ + return scm_c_make_weak_table (SCM_UNBNDP (n) ? 0 : scm_to_ulong (n), + SCM_WEAK_TABLE_KIND_BOTH); +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_weak_key_hash_table_p, "weak-key-hash-table?", 1, 0, 0, + (SCM obj), + "@deffnx {Scheme Procedure} weak-value-hash-table? obj\n" + "@deffnx {Scheme Procedure} doubly-weak-hash-table? obj\n" + "Return @code{#t} if @var{obj} is the specified weak hash\n" + "table. Note that a doubly weak hash table is neither a weak key\n" + "nor a weak value hash table.") +#define FUNC_NAME s_scm_weak_key_hash_table_p +{ + return scm_from_bool (SCM_WEAK_TABLE_P (obj) && + SCM_WEAK_TABLE (obj)->kind == SCM_WEAK_TABLE_KIND_KEY); +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_weak_value_hash_table_p, "weak-value-hash-table?", 1, 0, 0, + (SCM obj), + "Return @code{#t} if @var{obj} is a weak value hash table.") +#define FUNC_NAME s_scm_weak_value_hash_table_p +{ + return scm_from_bool (SCM_WEAK_TABLE_P (obj) && + SCM_WEAK_TABLE (obj)->kind == SCM_WEAK_TABLE_KIND_VALUE); +} +#undef FUNC_NAME + + +SCM_DEFINE (scm_doubly_weak_hash_table_p, "doubly-weak-hash-table?", 1, 0, 0, + (SCM obj), + "Return @code{#t} if @var{obj} is a doubly weak hash table.") +#define FUNC_NAME s_scm_doubly_weak_hash_table_p +{ + return scm_from_bool (SCM_WEAK_TABLE_P (obj) && + SCM_WEAK_TABLE (obj)->kind == SCM_WEAK_TABLE_KIND_BOTH); +} +#undef FUNC_NAME + + + + + void scm_weak_table_prehistory (void) { |