| 1 | /* classes: h_files */ |
| 2 | |
| 3 | #ifndef SCM_WEAK_TABLE_H |
| 4 | #define SCM_WEAK_TABLE_H |
| 5 | |
| 6 | /* Copyright (C) 2011, 2012 Free Software Foundation, Inc. |
| 7 | * |
| 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. |
| 12 | * |
| 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. |
| 17 | * |
| 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 |
| 21 | * 02110-1301 USA |
| 22 | */ |
| 23 | |
| 24 | \f |
| 25 | |
| 26 | #include "libguile/__scm.h" |
| 27 | |
| 28 | \f |
| 29 | |
| 30 | /* The weak table API is currently only used internally. We could make it |
| 31 | public later, after some API review. */ |
| 32 | |
| 33 | typedef enum { |
| 34 | SCM_WEAK_TABLE_KIND_KEY, |
| 35 | SCM_WEAK_TABLE_KIND_VALUE, |
| 36 | SCM_WEAK_TABLE_KIND_BOTH, |
| 37 | } scm_t_weak_table_kind; |
| 38 | |
| 39 | /* Function that returns nonzero if the given mapping is the one we are |
| 40 | looking for. */ |
| 41 | typedef int (*scm_t_table_predicate_fn) (SCM k, SCM v, void *closure); |
| 42 | |
| 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); |
| 45 | |
| 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); |
| 49 | |
| 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, |
| 58 | void *closure); |
| 59 | |
| 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); |
| 63 | |
| 64 | SCM_INTERNAL void scm_weak_table_clear_x (SCM table); |
| 65 | |
| 66 | SCM_INTERNAL SCM scm_c_weak_table_fold (scm_t_table_fold_fn proc, void *closure, |
| 67 | SCM init, SCM table); |
| 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); |
| 71 | |
| 72 | \f |
| 73 | |
| 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); |
| 81 | |
| 82 | \f |
| 83 | |
| 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); |
| 87 | |
| 88 | #endif /* SCM_WEAK_TABLE_H */ |
| 89 | |
| 90 | /* |
| 91 | Local Variables: |
| 92 | c-file-style: "gnu" |
| 93 | End: |
| 94 | */ |