+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.
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>
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);
class Source_file
{
- vector<char*> newline_locations_;
+ vector<char const*> newline_locations_;
istream *istream_;
vector<char> characters_;
SCM str_port_;
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 *);
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_);
{
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;
- 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)
{
}
};
-static int compare_paper_column_rank (Grob *const &a, Grob *const &b);
-
static bool
is_loose (Grob *g)
{
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)
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);
-}
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--;
{
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);
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;
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
{