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"
18 Scheme_hash_table::Scheme_hash_table ()
25 Scheme_hash_table::operator =(Scheme_hash_table const & src)
27 Scm_stl_map::operator = (src);
29 // we do not copy the self_scm_ field!
33 Scheme_hash_table::do_smobify_self ()
39 Scheme_hash_table::mark_smob (SCM s)
42 can't typecheck naively, since GC bit lives in CAR of S
45 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
47 for (Scm_stl_map::const_iterator i= me->begin (); i != me->end(); i++)
49 scm_gc_mark ((*i).first);
50 scm_gc_mark ((*i).second);
56 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
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%0x ", s);
70 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
71 for (Scm_stl_map ::const_iterator i = me->begin (); i != me->end(); i++)
73 scm_display ((*i).first, p);
75 scm_display ((*i).second, p);
83 Scheme_hash_table::try_retrieve (SCM k, SCM *v)
85 Scm_stl_map ::const_iterator i (find (k));
86 bool found = i != end ();
93 Scheme_hash_table::elem_b (SCM k) const
95 Scm_stl_map::const_iterator i (find (k));
100 Scheme_hash_table::set (SCM k, SCM v)
103 scm_unprotect_object (v);
108 Scheme_hash_table::get (SCM k)const
110 return (*(Scheme_hash_table*)this)[k];
114 Scheme_hash_table::~Scheme_hash_table( )
120 Scheme_hash_table::to_alist () const
123 for (Scm_stl_map ::const_iterator i = begin (); i != end(); i++)
124 l = gh_cons (gh_cons ((*i).first, (*i).second), l);
129 #include "ly-smobs.icc"
130 IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
131 IMPLEMENT_SMOBS(Scheme_hash_table);
134 Scheme_hash_table::Scheme_hash_table ()
136 hash_func_ = ly_scm_hash;
142 Scheme_hash_table::operator =(Scheme_hash_table const & src)
144 Hash_table<SCM,SCM>::operator = (src);
146 // we do not copy the self_scm_ field!
150 Scheme_hash_table::do_smobify_self ()
156 Scheme_hash_table::mark_smob (SCM s)
159 can't typecheck naively, since GC bit lives in CAR of S
161 //assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
163 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
164 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
166 scm_gc_mark (i.key());
167 scm_gc_mark (i.val ());
173 Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
174 : Hash_table<SCM,SCM> (src)
176 hash_func_ = src.hash_func_;
182 Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
184 assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
186 sprintf (str, "#<Scheme_hash_table 0x%0x ", s);
188 Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
189 for (Hash_table_iter<SCM,SCM> i (*me); i.ok(); i++)
191 scm_display (i.key(), p);
193 scm_display (i.val (), p);
202 Scheme_hash_table::set (SCM k, SCM v)
205 scm_unprotect_object (v);
209 Scheme_hash_table::get (SCM k)const
211 return const_elem (k);
215 Scheme_hash_table::~Scheme_hash_table( )
221 Scheme_hash_table::to_alist () const
224 for (Hash_table_iter<SCM,SCM> i (*this); i.ok(); i++)
225 l = gh_cons (gh_cons (i.key (), i.val()), l);
230 #include "ly-smobs.icc"
231 IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
232 IMPLEMENT_SMOBS(Scheme_hash_table);