copying.
* lily/source-file.cc (get_line): use binary search to determine
line number. This kills another quadratic time-complexity term.
* lily/include/source-file.hh (class Source_file): add newline_locations
* flower/include/array.icc (binary_search_bounds): new function.
+2002-08-25 Han-Wen Nienhuys <hanwen@cs.uu.nl>
+
+ * flower/polynomial.cc (operator +): optimize += operator. No
+ copying.
+
+ * lily/source-file.cc (get_line): use binary search to determine
+ line number. This kills another quadratic time-complexity term.
+
+ * lily/include/source-file.hh (class Source_file): add newline_locations
+
+ * flower/include/array.icc (binary_search_bounds): new function.
+
2002-08-22 Han-Wen Nienhuys <hanwen@cs.uu.nl>
* input/regression/tuplet-properties.ly (texidoc): bugfix
}
+template<class T>
+void
+binary_search_bounds (Array<T> const &table,
+ T const &key, int (*compare) (T const&, T const &),
+ int *lo,
+ int *hi)
+{
+ int cmp;
+ int result;
+
+ /* binary search */
+ do
+ {
+ cmp = (*lo + *hi) / 2;
+
+ result = (*compare) (key, table[cmp]);
+
+ if (result < 0)
+ *hi = cmp;
+ else
+ *lo = cmp;
+ }
+ while (*hi - *lo > 1);
+}
+
+
/*
lookup with binsearch, return array index.
*/
int hi = -1
)
{
- int cmp;
- int result;
if (hi < 0)
hi = table.size ();
- /* binary search */
- do
- {
- cmp = (lo + hi) / 2;
-
- result = (*compare) (key, table[cmp]);
+ binary_search_bounds (table, key, compare, &lo, &hi);
- if (result < 0)
- hi = cmp;
- else
- lo = cmp;
- }
- while (hi - lo > 1);
if (! (*compare) (key, table[lo]))
{
return lo;
else
return -1; /* not found */
}
-
#include "array.hh"
+
+
/**
an array of pointers.
template<class T>
class Link_array : private Array<void *>
{
- static int default_compare (T *const& p1, T *const&p2) {
- /* can't do p1 -p2, since T might be an incomplete type */
- if (p1 < p2)
- return -1 ;
- if (p2 < p1)
- return 1;
- return 0;
- }
+
Link_array (Array<void*> v)
:Array<void*> (v)
{
Link_array ()
{}
+ static int default_compare (T *const& p1, T *const&p2)
+ {
+ /* can't do p1 -p2, since T might be an incomplete type */
+ if (p1 < p2)
+ return -1 ;
+ if (p2 < p1)
+ return 1;
+ return 0;
+ }
Link_array (T * const *tp, int n)
: Array<void*> ((void **)tp, n)
{
else
return 0;
}
-
};
template<class T, class V>
}
+template<class T>
+void
+binary_search_bounds (Link_array<T> const &table,
+ T const *key, int (*compare) (T * const& , T *const &),
+ int *lo,
+ int *hi)
+{
+ int cmp;
+ int result;
+
+ /* binary search */
+ do
+ {
+ cmp = (*lo + *hi) / 2;
+
+ result = (*compare) ((T*) key, table[cmp]);
+
+ if (result < 0)
+ *hi = cmp;
+ else
+ *lo = cmp;
+ }
+ while (*hi - *lo > 1);
+}
+
#endif // PARRAY_HH
/// eliminate #x# close to zero
void real_clean ();
- static Polynomial add (const Polynomial & p1, const Polynomial & p2);
void scalarmultiply (Real fact);
void operator *= (Real f) { scalarmultiply (f); }
void operator /= (Real f) { scalarmultiply (1/f); }
void operator -= (Polynomial const &p2);
Polynomial (Real a, Real b =0.0);
Polynomial (){}
- static Polynomial subtract (const Polynomial & p1, const Polynomial & p2);
void set_negate (const Polynomial & src);
/// take the derivative
}
-Polynomial
-Polynomial::add (const Polynomial & p1, const Polynomial & p2)
+
+void
+Polynomial::operator += (Polynomial const &p)
{
- Polynomial dest;
- int tempord = p2.degree () >? p1.degree ();
- for (int i = 0; i <= tempord; i++)
- {
- Real temp = 0.0;
- if (i <= p1.degree ())
- temp += p1.coefs_[i];
- if (i <= p2.degree ())
- temp += p2.coefs_[i];
- dest.coefs_.push (temp);
- }
- return dest;
+ while (degree () < p.degree())
+ coefs_.push (0.0);
+
+ for (int i = 0; i <= p.degree(); i++)
+ coefs_[i] += p.coefs_[i];
}
+
+void
+Polynomial::operator -= (Polynomial const &p)
+{
+ while (degree () < p.degree())
+ coefs_.push (0.0);
+
+ for (int i = 0; i <= p.degree(); i++)
+ coefs_[i] -= p.coefs_[i];
+}
+
+
void
Polynomial::scalarmultiply (Real fact)
{
coefs_[i] *= fact;
}
-Polynomial
-Polynomial::subtract (const Polynomial & p1, const Polynomial & p2)
-{
- Polynomial dest;
- int tempord = p2.degree () >? p1.degree ();
-
- for (int i = 0; i <= tempord; i++)
- {
- Real temp = 0.0; // can't store result directly.. a=a-b
- if (i <= p1.degree ())
- temp += p1.coefs_[i];
- if (i <= p2.degree ())
- temp -= p2.coefs_[i];
- dest.coefs_.push (temp);
- }
- return dest;
-
-}
+
void
Polynomial::set_negate (const Polynomial & src)
*this = multiply (*this,p2);
}
-void
-Polynomial::operator += (Polynomial const &p)
-{
- *this = add ( *this, p);
-}
-void
-Polynomial::operator -= (Polynomial const &p)
-{
- *this = subtract (*this, p);
-}
MODULE_LIBS=$(depth)/flower
MODULE_INCLUDES= $(depth)/flower/include
-MODULE_CXXFLAGS=
+MODULE_CXXFLAGS=
+
+
HELP2MAN_EXECS = lilypond
STEPMAKE_TEMPLATES= c++ executable po help2man
include $(depth)/make/stepmake.make
+USER_LDFLAGS += -static -lltdl -ldl
ETAGS_FLAGS += -r '/^LY_DEFINE *(\([^,]+\),/\1/' -r '/^LY_DEFINE *([^,]+, *"\([^"]+\)"/\1/'
default:
Polynomial p (0.0);
for (int j=0; j <= 3; j++)
{
- p += control_[j][a]
+ p += (control_[j][a] * binomial_coefficient (3, j))
* Polynomial::power (j , Polynomial (0,1))*
- Polynomial::power (3 - j, Polynomial (1,-1))*
- binomial_coefficient (3, j);
+ Polynomial::power (3 - j, Polynomial (1,-1));
}
return p;
SCM ly_deep_copy (SCM);
SCM ly_truncate_list (int k, SCM l );
+#define CACHE_SYMBOLS
+
#if (__GNUC__ > 2)
/*
#include "string.hh"
#include "interval.hh"
#include "protected-scm.hh"
+#include "parray.hh"
/**
class for reading and mapping a file.
int get_char (char const* pos_str0) const;
/*
- DOCUMENT-ME
+ JUNKME.
+
+ This thing doubles as a file-storage/file-iterator object.
*/
char const* pos_str0_;
SCM get_port()const { return str_port_; }
private:
String name_string_;
+ Link_array<char> newline_locations_;
std::istream* istream_;
char * contents_str0_;
int length_;
gh_scm2double (ly_cdr (s)));
}
-
-/*
- convert without too many decimals, and leave a space at the end.
- */
-
LY_DEFINE(ly_number2string, "ly-number->string", 1, 0,0,
(SCM s),
Undef this to see if GUILE GC is causing too many swaps.
*/
-// #define TEST_GC
+//#define TEST_GC
#ifdef TEST_GC
#include <libguile/gc.h>
pos_str0_ = to_str0 ();
init_port();
+
+ for (int i = 0; i < length_; i++)
+ if (contents_str0_[i] == '\n')
+ newline_locations_.push (contents_str0_ + i);
}
void
std::istream*
Source_file::get_istream ()
{
- /*
- if (!name_string_.length ())
- return &cin;
- */
-
if (!istream_)
{
if (length ()) // can-t this be done without such a hack?
if (!in_b (pos_str0))
return 0;
- int i = 1;
- char const* scan_str0 = to_str0 ();
- if (!scan_str0)
- return 0;
-
- while (scan_str0 < pos_str0)
- if (*scan_str0++ == '\n')
- i++;
- return i;
+ int lo=0;
+ int hi = newline_locations_.size();
+
+ binary_search_bounds (newline_locations_,
+ pos_str0,
+ Link_array<char>::default_compare,
+ &lo, &hi);
+
+ return lo;
}
int