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"
25 Scheme_hash_table::make_smob ()
27 return Smob1::make_smob (scm_c_make_hash_table (119));
31 Scheme_hash_table::print_smob (SCM p, scm_print_state *) const
33 scm_puts ("#<Scheme_hash_table ", p);
34 scm_display (hash_tab (), p);
40 Scheme_hash_table::try_retrieve (SCM k, SCM *v)
43 SCM handle = scm_hashq_get_handle (hash_tab (), k);
44 if (scm_is_pair (handle))
46 *v = scm_cdr (handle);
54 Scheme_hash_table::contains (SCM k) const
56 return scm_is_pair (scm_hashq_get_handle (hash_tab (), k));
60 Scheme_hash_table::set (SCM k, SCM v)
62 assert (scm_is_symbol (k));
63 SCM handle = scm_hashq_create_handle_x (hash_tab (), k, SCM_UNDEFINED);
64 scm_set_cdr_x (handle, v);
68 Scheme_hash_table::get (SCM k) const
70 /* SCM_UNSPECIFIED will stick out like a sore thumb, hopefully.
72 return scm_hashq_ref (hash_tab (), k, SCM_UNSPECIFIED);
76 Scheme_hash_table::remove (SCM k)
78 scm_hashq_remove_x (hash_tab (), k);
82 collect_handles (void * /* closure */,
87 return scm_acons (key, value, result);
91 Scheme_hash_table::to_alist () const
93 return scm_internal_hash_fold ((scm_t_hash_fold_fn) &collect_handles,
94 NULL, SCM_EOL, hash_tab ());