From ff2d9cf3c5e8900535074759171402353ab13979 Mon Sep 17 00:00:00 2001
From: fred <fred>
Date: Tue, 26 Mar 2002 22:47:01 +0000
Subject: [PATCH] lilypond-1.3.33

---
 lily/include/scm-hash.hh |  24 +++++++-
 lily/scm-hash.cc         | 121 +++++++++++++++++++++++++++++++++++++++
 2 files changed, 144 insertions(+), 1 deletion(-)

diff --git a/lily/include/scm-hash.hh b/lily/include/scm-hash.hh
index 0a15bfce9a..409fc1a3cf 100644
--- a/lily/include/scm-hash.hh
+++ b/lily/include/scm-hash.hh
@@ -10,19 +10,41 @@
 #ifndef SCM_HASH_HH
 #define SCM_HASH_HH
 
+
+#include <map>
+
 #include "lily-guile.hh"
 #include "hash-table.hh"
 #include "smobs.hh"
 
+#define usestl
+
+struct SCM_less
+{
+  bool operator  () (SCM s1, SCM s2) const
+  {
+    return long(s1) < long (s2);
+  }
+};
+
+typedef map<SCM,SCM, SCM_less> Scm_stl_map;
+
 /**
    auto resizing hash table. This should come from GUILE.
  */
-class Scheme_hash_table : private Hash_table<SCM,SCM>
+class Scheme_hash_table :  private Scm_stl_map
 {
 public:
+#ifndef usestl 
   //  bool elem_b (SCM k) const;
   Hash_table<SCM,SCM>::try_retrieve;
   Hash_table<SCM,SCM>::elem_b;  
+#else
+  bool try_retrieve (SCM key, SCM *val);
+  bool elem_b (SCM key) const;
+#endif
+
+
   /**
      WARNING: putting something in assumes responsibility for cleaning
      up.  */
diff --git a/lily/scm-hash.cc b/lily/scm-hash.cc
index 83357769fa..ebef9e278c 100644
--- a/lily/scm-hash.cc
+++ b/lily/scm-hash.cc
@@ -11,6 +11,126 @@
 #include "scm-hash.hh"
 #include "hash-table-iter.hh"
 
+
+#ifdef usestl
+
+
+Scheme_hash_table::Scheme_hash_table ()
+{
+  self_scm_ = SCM_EOL;
+  smobify_self ();
+}
+
+void
+Scheme_hash_table::operator =(Scheme_hash_table const & src)
+{
+  Scm_stl_map::operator = (src);
+	
+  // we do not copy the self_scm_ field!
+}
+
+void
+Scheme_hash_table::do_smobify_self ()
+{
+}
+
+
+SCM
+Scheme_hash_table::mark_smob (SCM s)
+{
+  /*
+    can't typecheck naively, since GC bit lives in CAR of S
+   */
+  
+  Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
+
+  for (Scm_stl_map::const_iterator i= me->begin (); i != me->end(); i++)
+    {
+      scm_gc_mark ((*i).first);
+      scm_gc_mark ((*i).second);
+    }
+  return SCM_EOL;
+}
+
+
+Scheme_hash_table::Scheme_hash_table (Scheme_hash_table const &src)
+  : Scm_stl_map (src)
+{
+  self_scm_ = SCM_EOL;
+  smobify_self ();
+}
+
+int
+Scheme_hash_table::print_smob (SCM s, SCM p, scm_print_state*)
+{
+  assert (SMOB_IS_TYPE_B (Scheme_hash_table, s));
+  char str[1000];
+  sprintf (str, "#<Scheme_hash_table 0x%0x ", s);
+  scm_puts (str, p);      
+  Scheme_hash_table *me = SMOB_TO_TYPE(Scheme_hash_table,s);
+  for (Scm_stl_map ::const_iterator i = me->begin (); i != me->end(); i++)
+    {
+      scm_display ((*i).first, p);
+      scm_puts (" = ",p);      
+      scm_display ((*i).second, p);
+      scm_puts ("\n",p);            
+    }
+  scm_puts ("> ",p);        
+  return 1;
+}
+
+bool
+Scheme_hash_table::try_retrieve (SCM k, SCM *v)
+{
+  Scm_stl_map ::const_iterator i (find (k));
+  bool found = i != end ();
+  if (found)
+    *v = (*i).second;
+  return found;
+}
+
+bool
+Scheme_hash_table::elem_b (SCM k) const
+{
+  Scm_stl_map::const_iterator i (find (k));
+  return i != end ();
+}
+
+void
+Scheme_hash_table::set (SCM k, SCM v)
+{
+  (*this)[k] = v;
+  scm_unprotect_object (v);
+}
+
+// UGH. 
+SCM
+Scheme_hash_table::get (SCM k)const
+{
+  return (*(Scheme_hash_table*)this)[k]; 
+}
+
+
+Scheme_hash_table::~Scheme_hash_table( )
+{
+  unsmobify_self ();
+}
+
+SCM
+Scheme_hash_table::to_alist () const
+{
+  SCM l = SCM_EOL;
+  for (Scm_stl_map ::const_iterator i = begin (); i != end(); i++)
+    l = gh_cons (gh_cons ((*i).first, (*i).second), l);
+  return l;  
+}
+
+
+#include "ly-smobs.icc"
+IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
+IMPLEMENT_SMOBS(Scheme_hash_table);
+
+#else
 Scheme_hash_table::Scheme_hash_table ()
 {
   hash_func_ = ly_scm_hash;
@@ -110,3 +230,4 @@ Scheme_hash_table::to_alist () const
 #include "ly-smobs.icc"
 IMPLEMENT_UNSMOB(Scheme_hash_table,scheme_hash);
 IMPLEMENT_SMOBS(Scheme_hash_table);
+#endif
-- 
2.39.5