From: Joe Neeman Date: Thu, 7 Sep 2006 11:16:11 +0000 (+0000) Subject: * lily/spanner.cc (find_broken_piece): X-Git-Tag: cvs/HEAD~99 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=d840dc8416a22e73636526a9415ae041af40570b;p=lilypond.git * 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 --- diff --git a/ChangeLog b/ChangeLog index 4501574500..4733dca8d3 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,25 @@ +2006-09-07 Joe Neeman + + * 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 + + * 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 * lily/tie-performer.cc: remove unused last_event_ property. diff --git a/flower/include/std-vector.hh b/flower/include/std-vector.hh index 83e58d299c..55b28d7da6 100644 --- a/flower/include/std-vector.hh +++ b/flower/include/std-vector.hh @@ -132,106 +132,55 @@ concat (vector &v, vector const& w) v.insert (v.end (), w.begin (), w.end ()); } -template -void -binary_search_bounds (vector const &table, - T const &key, int (*compare) (T const &, T const &), - vsize *lo, - vsize *hi) +template +vsize +lower_bound (vector 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::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 -void -binary_search_bounds (vector const &table, - T const *key, int (*compare) (T *const &, T *const &), - vsize *lo, - vsize *hi) +template +vsize +upper_bound (vector 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::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 +template vsize binary_search (vector 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::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 -vsize -binary_search (vector const &table, T const &key, - int (*compare) (T const &, T const &), - vsize lo=0, - vsize hi=VPOS) + Compare less=less (), + 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 diff --git a/lily/include/paper-column.hh b/lily/include/paper-column.hh index f9686a4968..6adbdbe179 100644 --- a/lily/include/paper-column.hh +++ b/lily/include/paper-column.hh @@ -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); diff --git a/lily/include/source-file.hh b/lily/include/source-file.hh index 76942ba6b1..21060e3704 100644 --- a/lily/include/source-file.hh +++ b/lily/include/source-file.hh @@ -27,7 +27,7 @@ using namespace std; class Source_file { - vector newline_locations_; + vector newline_locations_; istream *istream_; vector characters_; SCM str_port_; diff --git a/lily/include/spanner.hh b/lily/include/spanner.hh index 074c303036..2e8906ab96 100644 --- a/lily/include/spanner.hh +++ b/lily/include/spanner.hh @@ -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 *); diff --git a/lily/keyword.cc b/lily/keyword.cc index 84065ab4f6..8f969e6ce8 100644 --- a/lily/keyword.cc +++ b/lily/keyword.cc @@ -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; diff --git a/lily/paper-column.cc b/lily/paper-column.cc index 299958f643..003fa15c9b 100644 --- a/lily/paper-column.cc +++ b/lily/paper-column.cc @@ -79,6 +79,13 @@ Paper_column::compare (Grob * const &a, - dynamic_cast (b)->rank_); } +bool +Paper_column::less_than (Grob *const &a, + Grob *const &b) +{ + return dynamic_cast (a)->rank_ < dynamic_cast (b)->rank_; +} + Moment Paper_column::when_mom (Grob *me) { diff --git a/lily/simple-spacer.cc b/lily/simple-spacer.cc index 560dfecacd..bb4104678a 100644 --- a/lily/simple-spacer.cc +++ b/lily/simple-spacer.cc @@ -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 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 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); -} diff --git a/lily/source-file.cc b/lily/source-file.cc index f1dd4a3694..c846c9a376 100644 --- a/lily/source-file.cc +++ b/lily/source-file.cc @@ -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 (), + lo, hi); + if (*pos_str0 == '\n') lo--; diff --git a/lily/spacing-spanner.cc b/lily/spacing-spanner.cc index b21ce3d3ab..3e7aa266bd 100644 --- a/lily/spacing-spanner.cc +++ b/lily/spacing-spanner.cc @@ -31,9 +31,9 @@ Spacing_spanner::get_columns (Spanner *me) { vector 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::vector (all.begin () + start, all.begin () + end + 1); diff --git a/lily/spanner.cc b/lily/spanner.cc index bb6f743a24..5d11fb1bc2 100644 --- a/lily/spanner.cc +++ b/lily/spanner.cc @@ -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 {