weak-table.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. #ifndef SCM_WEAK_TABLE_H
  2. #define SCM_WEAK_TABLE_H
  3. /* Copyright 2011-2012,2018
  4. Free Software Foundation, Inc.
  5. This file is part of Guile.
  6. Guile is free software: you can redistribute it and/or modify it
  7. under the terms of the GNU Lesser General Public License as published
  8. by the Free Software Foundation, either version 3 of the License, or
  9. (at your option) any later version.
  10. Guile is distributed in the hope that it will be useful, but WITHOUT
  11. ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
  13. License for more details.
  14. You should have received a copy of the GNU Lesser General Public
  15. License along with Guile. If not, see
  16. <https://www.gnu.org/licenses/>. */
  17. #include "libguile/scm.h"
  18. /* The weak table API is currently only used internally. We could make it
  19. public later, after some API review. */
  20. typedef enum {
  21. SCM_WEAK_TABLE_KIND_KEY,
  22. SCM_WEAK_TABLE_KIND_VALUE,
  23. SCM_WEAK_TABLE_KIND_BOTH,
  24. } scm_t_weak_table_kind;
  25. /* Function that returns nonzero if the given mapping is the one we are
  26. looking for. */
  27. typedef int (*scm_t_table_predicate_fn) (SCM k, SCM v, void *closure);
  28. /* Function to fold over the elements of a set. */
  29. typedef SCM (*scm_t_table_fold_fn) (void *closure, SCM k, SCM v, SCM result);
  30. SCM_INTERNAL SCM scm_c_make_weak_table (unsigned long k,
  31. scm_t_weak_table_kind kind);
  32. SCM_INTERNAL SCM scm_weak_table_p (SCM h);
  33. SCM_INTERNAL SCM scm_c_weak_table_ref (SCM table, unsigned long raw_hash,
  34. scm_t_table_predicate_fn pred,
  35. void *closure, SCM dflt);
  36. SCM_INTERNAL void scm_c_weak_table_put_x (SCM table, unsigned long raw_hash,
  37. scm_t_table_predicate_fn pred,
  38. void *closure, SCM key, SCM value);
  39. SCM_INTERNAL void scm_c_weak_table_remove_x (SCM table, unsigned long raw_hash,
  40. scm_t_table_predicate_fn pred,
  41. void *closure);
  42. SCM_INTERNAL SCM scm_weak_table_refq (SCM table, SCM key, SCM dflt);
  43. SCM_INTERNAL void scm_weak_table_putq_x (SCM table, SCM key, SCM value);
  44. SCM_INTERNAL void scm_weak_table_remq_x (SCM table, SCM key);
  45. SCM_INTERNAL void scm_weak_table_clear_x (SCM table);
  46. SCM_INTERNAL SCM scm_c_weak_table_fold (scm_t_table_fold_fn proc, void *closure,
  47. SCM init, SCM table);
  48. SCM_INTERNAL SCM scm_weak_table_fold (SCM proc, SCM init, SCM table);
  49. SCM_INTERNAL void scm_weak_table_for_each (SCM proc, SCM table);
  50. SCM_INTERNAL SCM scm_weak_table_map_to_list (SCM proc, SCM table);
  51. /* Legacy interface. */
  52. SCM_API SCM scm_make_weak_key_hash_table (SCM k);
  53. SCM_API SCM scm_make_weak_value_hash_table (SCM k);
  54. SCM_API SCM scm_make_doubly_weak_hash_table (SCM k);
  55. SCM_API SCM scm_weak_key_hash_table_p (SCM h);
  56. SCM_API SCM scm_weak_value_hash_table_p (SCM h);
  57. SCM_API SCM scm_doubly_weak_hash_table_p (SCM h);
  58. SCM_INTERNAL void scm_i_weak_table_print (SCM exp, SCM port, scm_print_state *pstate);
  59. SCM_INTERNAL void scm_weak_table_prehistory (void);
  60. SCM_INTERNAL void scm_init_weak_table (void);
  61. #endif /* SCM_WEAK_TABLE_H */