2 This file is part of LilyPond, the GNU music typesetter.
4 Copyright (C) 1999--2015 Han-Wen Nienhuys <hanwen@xs4all.nl>
6 LilyPond is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, either version 3 of the License, or
9 (at your option) any later version.
11 LilyPond is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with LilyPond. If not, see <http://www.gnu.org/licenses/>.
20 #include "scm-hash.hh"
27 Return: number of objects.
30 copy_handle (void *closure, SCM handle)
32 SCM tab = (SCM) closure;
33 scm_hashq_set_x (tab, scm_car (handle), scm_cdr (handle));
38 copy_scm_hashes (SCM dest, SCM src)
40 scm_internal_hash_for_each_handle ((scm_t_hash_handle_fn) ©_handle,
44 Scheme_hash_table::Scheme_hash_table ()
48 hash_tab_ = scm_c_make_hash_table (119);
51 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
52 : Smob<Scheme_hash_table> ()
60 Scheme_hash_table::copy (Scheme_hash_table const &src)
65 hash_tab_ = scm_c_make_hash_table (SCM_HASHTABLE_N_ITEMS (src.hash_tab_));
66 copy_scm_hashes (hash_tab_, src.hash_tab_);
69 Scheme_hash_table::~Scheme_hash_table ()
74 Scheme_hash_table::mark_smob () const
76 scm_gc_mark (hash_tab_);
81 Scheme_hash_table::print_smob (SCM p, scm_print_state *) const
83 scm_puts ("#<Scheme_hash_table ", p);
84 scm_display (hash_tab_, p);
90 Scheme_hash_table::try_retrieve (SCM k, SCM *v)
93 SCM handle = scm_hashq_get_handle (hash_tab_, k);
94 if (scm_is_pair (handle))
96 *v = scm_cdr (handle);
104 Scheme_hash_table::contains (SCM k) const
106 return scm_is_pair (scm_hashq_get_handle (hash_tab_, k));
110 Scheme_hash_table::set (SCM k, SCM v)
112 assert (scm_is_symbol (k));
113 SCM handle = scm_hashq_create_handle_x (hash_tab_, k, SCM_UNDEFINED);
114 scm_set_cdr_x (handle, v);
118 Scheme_hash_table::get (SCM k) const
120 /* SCM_UNSPECIFIED will stick out like a sore thumb, hopefully.
122 return scm_hashq_ref (hash_tab_, k, SCM_UNSPECIFIED);
126 Scheme_hash_table::remove (SCM k)
128 scm_hashq_remove_x (hash_tab_, k);
132 collect_handles (void * /* closure */,
137 return scm_acons (key, value, result);
141 Scheme_hash_table::to_alist () const
143 return scm_internal_hash_fold ((scm_t_hash_fold_fn) &collect_handles,
144 NULL, SCM_EOL, hash_tab_);