]> git.donarmstrong.com Git - lilypond.git/commitdiff
* lily/spanner.cc (find_broken_piece):
authorJoe Neeman <joeneeman@gmail.com>
Thu, 7 Sep 2006 11:16:10 +0000 (11:16 +0000)
committerJoe Neeman <joeneeman@gmail.com>
Thu, 7 Sep 2006 11:16:10 +0000 (11:16 +0000)
* lily/spacing-spanner.cc (get_columns):
* lily/source-file.cc (get_line):
* lily/simple-spacer.cc (get_column_description):
* lily/keyword.cc (lookup):
use the new binary search.

* flower/include/std-vector.hh: replace binary_search with
a more STL-like version

ChangeLog
flower/include/std-vector.hh
lily/include/paper-column.hh
lily/include/source-file.hh
lily/include/spanner.hh
lily/keyword.cc
lily/paper-column.cc
lily/simple-spacer.cc
lily/source-file.cc
lily/spacing-spanner.cc
lily/spanner.cc

index 4501574500139ecd34553bbc8fc50b3fcce83475..4733dca8d3fb460870f450ec50c2dc52cd1bec2a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,25 @@
+2006-09-07  Joe Neeman  <joeneeman@gmail.com>
+
+       * lily/spanner.cc (find_broken_piece): 
+       * lily/spacing-spanner.cc (get_columns): 
+       * lily/source-file.cc (get_line): 
+       * lily/simple-spacer.cc (get_column_description): 
+       * lily/keyword.cc (lookup): 
+       use the new binary search.
+
+       * flower/include/std-vector.hh: replace binary_search with
+       a more STL-like version
+
+2006-09-05  Joe Neeman  <joeneeman@gmail.com>
+
+       * lily/page-turn-engraver.cc (penalty): minPageTurnLength ->
+       minimumPageTurnLength
+
+       * scm/define-context-properties.scm (all-user-translation-properties):
+       add minimumPageTurnLength and minimumRepeatLengthForPageTurn
+
+       * Documentation/user/page.itely: update page breaking documentation
+
 2006-09-04  Michael Welsh Duggan  <md5i@cs.cmu.edu>
 
        * lily/tie-performer.cc: remove unused last_event_ property.
index 83e58d299ccbc180babe5a7f2aa34f2b1a5dbca7..55b28d7da641cb9701dc09125a48942ba509b12c 100644 (file)
@@ -132,106 +132,55 @@ concat (vector<T> &v, vector<T> const& w)
   v.insert (v.end (), w.begin (), w.end ());
 }
 
-template<class T>
-void
-binary_search_bounds (vector<T> const &table,
-                     T const &key, int (*compare) (T const &, T const &),
-                     vsize *lo,
-                     vsize *hi)
+template<typename T, typename Compare>
+vsize
+lower_bound (vector<T> const &v,
+            T const &key,
+            Compare less,
+            vsize b=0, vsize e=VPOS)
 {
-  if (*lo >= *hi)
-    return;
-
-  int cmp;
-  int result;
-
-  /* binary search */
-  do
-    {
-      cmp = (*lo + *hi) / 2;
-
-      result = (*compare) (key, table[cmp]);
+  if (e == VPOS)
+    e = v.size ();
+  typename vector<T>::const_iterator i = lower_bound (v.begin () + b,
+                                                     v.begin () + e,
+                                                     key,
+                                                     less);
 
-      if (result < 0)
-       *hi = cmp;
-      else
-       *lo = cmp;
-    }
-  while (*hi - *lo > 1);
+  return i - v.begin ();
 }
 
-template<typename T>
-void
-binary_search_bounds (vector<T*> const &table,
-                     T const *key, int (*compare) (T *const &, T *const &),
-                     vsize *lo,
-                     vsize *hi)
+template<typename T, typename Compare>
+vsize
+upper_bound (vector<T> const &v,
+            T const &key,
+            Compare less,
+            vsize b=0, vsize e=VPOS)
 {
-  vsize cmp;
-  int result;
-
-  /* binary search */
-  do
-    {
-      cmp = (*lo + *hi) / 2;
+  if (e == VPOS)
+    e = v.size ();
 
-      result = (*compare) ((T *) key, table[cmp]);
+  typename vector<T>::const_iterator i = upper_bound (v.begin () + b,
+                                                     v.begin () + e,
+                                                     key,
+                                                     less);
 
-      if (result < 0)
-       *hi = cmp;
-      else
-       *lo = cmp;
-    }
-  while (*hi - *lo > 1);
+  return i - v.begin ();
 }
 
-#if 0
-/* FIXME: what if COMPARE is named: int operator == (T const&, T const&),
-   wouldn't that work for most uses of BINARY_SEARCH?
-*/
-template<typename T>
+template<typename T, typename Compare>
 vsize
 binary_search (vector<T> const &v,
-              T const &key, int (*compare) (T const &, T const &),
-              vsize b=0, vsize e=VPOS)
-{
-  if (e == VPOS)
-    e = v.size ();
-  typename vector<T>::const_iterator i = find (v.begin () + b,
-                                              v.begin () + e,
-                                              key);
-  if (i != v.end ())
-    return i - v.begin ();
-  return VPOS;
-}
-#else // c&p from array.icc; cannot easily use stl_algo:find b.o. compare func.
-template<class T>
-vsize
-binary_search (vector<T> const &table,
               T const &key,
-              int (*compare) (T const &, T const &),
-              vsize lo=0,
-              vsize hi=VPOS)
+              Compare less=less<T> (),
+              vsize b=0, vsize e=VPOS)
 {
-  if (hi == VPOS)
-    hi = table.size ();
+  vsize lb = lower_bound (v, key, less, b, e);
 
-  if (lo >= hi)
+  if (lb == v.size () || less (key, v[lb]))
     return VPOS;
-
-  binary_search_bounds (table, key, compare, &lo, &hi);
-
-  if (! (*compare) (key, table[lo]))
-    return lo;
-
-  /* not found */
-  return VPOS;
+  return lb;
 }
 
-
-#endif
-
-
 #if 0
 /* FIXME: the COMPARE functionality is broken?  */
 template<typename T>
index f9686a4968811331cdcf62b9e732a7c1cce528f6..6adbdbe1795f8e80ad5b5c5353b26287f22d76a5 100644 (file)
@@ -33,6 +33,9 @@ public:
 
   static int compare (Grob * const &a,
                      Grob * const &b);
+  static bool less_than (Grob *const &a,
+                        Grob *const &b);
+
   int get_rank () const { return rank_; }
   void set_rank (int);
 
index 76942ba6b168f54d2e1b46b31d4693a02147cba4..21060e370497c220184dc19b7b85082ed4d06065 100644 (file)
@@ -27,7 +27,7 @@ using namespace std;
 
 class Source_file
 {
-  vector<char*> newline_locations_;
+  vector<char const*> newline_locations_;
   istream *istream_;
   vector<char> characters_;
   SCM str_port_;
index 074c303036877afe40c8536479719eebb6b18f51..2e8906ab96217168333f157b598913a00fd831e1 100644 (file)
@@ -56,6 +56,7 @@ public:
   Real spanner_length () const;
 
   static int compare (Spanner *const &, Spanner *const &);
+  static bool less_than (Spanner *const &, Spanner *const &);
   virtual Grob *find_broken_piece (System *) const;
   virtual void derived_mark () const;
   static bool has_interface (Grob *);
index 84065ab4f6fd0093f621e0d87d3a351b9f027ab3..8f969e6ce858822471c2a0d49adbee8fe663d999 100644 (file)
@@ -9,6 +9,11 @@
 using namespace std;
 
 /* for qsort */
+bool tab_less (Keyword_ent const &p1, Keyword_ent const &p2)
+{
+  return strcmp (p1.name_, p2.name_) < 0;
+}
+
 int tabcmp (Keyword_ent const &p1, Keyword_ent const &p2)
 {
   return strcmp (p1.name_, p2.name_);
@@ -27,7 +32,7 @@ Keyword_table::lookup (char const *s) const
 {
   Keyword_ent e;
   e.name_ = s;
-  vsize idx = binary_search (table_, e, tabcmp);
+  vsize idx = binary_search (table_, e, tab_less);
   if (idx != VPOS)
     return table_[idx].tokcode_;
   return VPOS;
index 299958f643098cd1820c65cdf91a691f0b524ee6..003fa15c9b28d0b45853498165a24d8554c721e3 100644 (file)
@@ -79,6 +79,13 @@ Paper_column::compare (Grob * const &a,
               - dynamic_cast<Paper_column*> (b)->rank_);
 }
 
+bool
+Paper_column::less_than (Grob *const &a,
+                        Grob *const &b)
+{
+  return dynamic_cast<Paper_column*> (a)->rank_ < dynamic_cast<Paper_column*> (b)->rank_;
+}
+
 Moment
 Paper_column::when_mom (Grob *me)
 {
index 560dfecacdb080ecd277cd55a99f3d02a6254b91..bb4104678a0aae8d0da4c868f30da383157bce94 100644 (file)
@@ -332,8 +332,6 @@ struct Column_description
   }
 };
 
-static int compare_paper_column_rank (Grob *const &a, Grob *const &b);
-
 static bool
 is_loose (Grob *g)
 {
@@ -400,7 +398,7 @@ get_column_description (vector<Grob*> const &cols, vsize col_index, bool line_st
        scm_is_pair (s); s = scm_cdr (s))
     {
       Grob *other = unsmob_grob (scm_caar (s));
-      vsize j = binary_search (cols, other, &compare_paper_column_rank, col_index);
+      vsize j = binary_search (cols, other, Paper_column::less_than, col_index);
       if (j != VPOS)
        {
          if (cols[j] == other)
@@ -561,9 +559,3 @@ get_line_configuration (vector<Grob*> const &columns,
   return ret;
 }
 
-static int
-compare_paper_column_rank (Grob *const &a,
-                          Grob *const &b)
-{
-  return Paper_column::get_rank (a) - Paper_column::get_rank (b);
-}
index f1dd4a36942ed73d973f5f139795f4ae23ef0512..c846c9a3761dfc14bd5c080b038b110bfe1cea99 100644 (file)
@@ -335,10 +335,11 @@ Source_file::get_line (char const *pos_str0) const
   if (newline_locations_[hi - 1] < pos_str0)
     return hi;
 
-  binary_search_bounds (newline_locations_,
-                       (char const*&)pos_str0,
-                       default_compare,
-                       &lo, &hi);
+  lo = binary_search (newline_locations_,
+                     pos_str0,
+                     less<char const*> (),
+                     lo, hi);
+
 
   if (*pos_str0 == '\n')
     lo--;
index b21ce3d3ab7feac013832be6d105b7758ee98550..3e7aa266bd7c5cd214f8e3ba5f10adfeaa9c8e2e 100644 (file)
@@ -31,9 +31,9 @@ Spacing_spanner::get_columns (Spanner *me)
 {
   vector<Grob*> all (get_root_system (me)->columns ());
   vsize start = binary_search (all, (Grob*)me->get_bound (LEFT),
-                              &Paper_column::compare);
+                              &Paper_column::less_than);
   vsize end = binary_search (all, (Grob*) me->get_bound (RIGHT),
-                            &Paper_column::compare);
+                            &Paper_column::less_than);
 
   all = vector<Grob*>::vector<Grob*> (all.begin () + start,
                                      all.begin () + end + 1);
index bb6f743a24d5034eab9a0e6cb76805b11308a071..5d11fb1bc25598220004ae7fd3408f47d456e7fb 100644 (file)
@@ -238,7 +238,7 @@ Spanner::get_system () const
 Grob *
 Spanner::find_broken_piece (System *l) const
 {
-  vsize idx = binary_search (broken_intos_, (Spanner *)l, Spanner::compare);
+  vsize idx = binary_search (broken_intos_, (Spanner *)l, Spanner::less_than);
   if (idx != VPOS)
     return broken_intos_ [idx];
   return 0;
@@ -250,6 +250,12 @@ Spanner::compare (Spanner *const &p1, Spanner *const &p2)
   return p1->get_system ()->get_rank () - p2->get_system ()->get_rank ();
 }
 
+bool
+Spanner::less_than (Spanner *const &a, Spanner *const &b)
+{
+  return a->get_system ()->get_rank () < b->get_system ()->get_rank ();
+}
+
 bool
 Spanner::is_broken () const
 {