2 scm-hash.cc -- implement Scheme_hash_table
4 source file of the GNU LilyPond music typesetter
6 (c) 1999 Han-Wen Nienhuys <hanwen@cs.uu.nl>
11 #include "scm-hash.hh"
12 #include "hash-table-iter.hh"
14 Scheme_hash_table::Scheme_hash_table ()
16 hash_func_ = ly_scm_hash;
22 Scheme_hash_table::operator =(Scheme_hash_table const & src)
24 Hash_table<SCM,SCM>::operator = (src);
26 // we do not copy the self_scm_ field!
30 Scheme_hash_table::do_smobify_self ()
34 #include "ly-smobs.icc"
35 IMPLEMENT_SMOBS(Scheme_hash_table);
38 Scheme_hash_table::mark_smob (SCM s)
41 can't typecheck naively, since GC bit lives in CAR of S
43 //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
45 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
46 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
48 scm_gc_mark (i.key());
49 scm_gc_mark (i.val ());
55 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
56 : Hash_table<SCM,SCM> (src)
58 hash_func_ = src.hash_func_;
64 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
66 assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
68 sprintf (str, "#<Scheme_hash_table 0x%0ulx ", s);
70 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
71 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
73 scm_display (i.key(), p);
75 scm_display (i.val (), p);
84 Scheme_hash_table::set (SCM k, SCM v)
87 scm_unprotect_object (v);
91 Scheme_hash_table::get (SCM k)
97 Scheme_hash_table::~Scheme_hash_table( )
103 Scheme_hash_table::to_alist () const
106 for (Hash_table_iter<SCM,SCM> i (*this); i.ok(); i++)
107 l = gh_cons (gh_cons (i.key (), i.val()), l);