3 #ifndef SCM_WEAK_TABLE_H
4 #define SCM_WEAK_TABLE_H
6 /* Copyright (C) 2011, 2012 Free Software Foundation, Inc.
8 * This library is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU Lesser General Public License
10 * as published by the Free Software Foundation; either version 3 of
11 * the License, or (at your option) any later version.
13 * This library is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * Lesser General Public License for more details.
18 * You should have received a copy of the GNU Lesser General Public
19 * License along with this library; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
26 #include "libguile/__scm.h"
30 /* The weak table API is currently only used internally. We could make it
31 public later, after some API review. */
34 SCM_WEAK_TABLE_KIND_KEY
,
35 SCM_WEAK_TABLE_KIND_VALUE
,
36 SCM_WEAK_TABLE_KIND_BOTH
,
37 } scm_t_weak_table_kind
;
39 /* Function that returns nonzero if the given mapping is the one we are
41 typedef int (*scm_t_table_predicate_fn
) (SCM k
, SCM v
, void *closure
);
43 /* Function to fold over the elements of a set. */
44 typedef SCM (*scm_t_table_fold_fn
) (void *closure
, SCM k
, SCM v
, SCM result
);
46 SCM_INTERNAL SCM
scm_c_make_weak_table (unsigned long k
,
47 scm_t_weak_table_kind kind
);
48 SCM_INTERNAL SCM
scm_weak_table_p (SCM h
);
50 SCM_INTERNAL SCM
scm_c_weak_table_ref (SCM table
, unsigned long raw_hash
,
51 scm_t_table_predicate_fn pred
,
52 void *closure
, SCM dflt
);
53 SCM_INTERNAL
void scm_c_weak_table_put_x (SCM table
, unsigned long raw_hash
,
54 scm_t_table_predicate_fn pred
,
55 void *closure
, SCM key
, SCM value
);
56 SCM_INTERNAL
void scm_c_weak_table_remove_x (SCM table
, unsigned long raw_hash
,
57 scm_t_table_predicate_fn pred
,
60 SCM_INTERNAL SCM
scm_weak_table_refq (SCM table
, SCM key
, SCM dflt
);
61 SCM_INTERNAL
void scm_weak_table_putq_x (SCM table
, SCM key
, SCM value
);
62 SCM_INTERNAL
void scm_weak_table_remq_x (SCM table
, SCM key
);
64 SCM_INTERNAL
void scm_weak_table_clear_x (SCM table
);
66 SCM_INTERNAL SCM
scm_c_weak_table_fold (scm_t_table_fold_fn proc
, void *closure
,
68 SCM_INTERNAL SCM
scm_weak_table_fold (SCM proc
, SCM init
, SCM table
);
69 SCM_INTERNAL
void scm_weak_table_for_each (SCM proc
, SCM table
);
70 SCM_INTERNAL SCM
scm_weak_table_map_to_list (SCM proc
, SCM table
);
74 /* Legacy interface. */
75 SCM_API SCM
scm_make_weak_key_hash_table (SCM k
);
76 SCM_API SCM
scm_make_weak_value_hash_table (SCM k
);
77 SCM_API SCM
scm_make_doubly_weak_hash_table (SCM k
);
78 SCM_API SCM
scm_weak_key_hash_table_p (SCM h
);
79 SCM_API SCM
scm_weak_value_hash_table_p (SCM h
);
80 SCM_API SCM
scm_doubly_weak_hash_table_p (SCM h
);
84 SCM_INTERNAL
void scm_i_weak_table_print (SCM exp
, SCM port
, scm_print_state
*pstate
);
85 SCM_INTERNAL
void scm_weak_table_prehistory (void);
86 SCM_INTERNAL
void scm_init_weak_table (void);
88 #endif /* SCM_WEAK_TABLE_H */