From: fred Date: Thu, 9 Jan 1997 22:42:29 +0000 (+0000) Subject: flower-1.0.19 X-Git-Tag: release/1.5.59~6422 X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=d31fd9704b66ab00157c07b3e553652133cc8eee;p=lilypond.git flower-1.0.19 --- diff --git a/flower/Makefile b/flower/Makefile index 89e3bd6f5c..ed618974eb 100644 --- a/flower/Makefile +++ b/flower/Makefile @@ -8,7 +8,6 @@ include depend depend: Sources.make $(CXX) -MM $(cc) > depend - clean: rm -f $(obs) $(staticlib) @@ -25,6 +24,6 @@ dist: tar cfz $(DNAME).tar.gz $(DDIR)/* rm -rf $(DDIR)/ -TAGS: +TAGS: $(ALLSOURCES) etags -CT $(inl) $(cc) $(hh) diff --git a/flower/Sources.make b/flower/Sources.make index 2a618814c3..eae2acaf4d 100644 --- a/flower/Sources.make +++ b/flower/Sources.make @@ -3,11 +3,12 @@ cc=lgetopt.cc string.cc dataf.cc textdb.cc unionfind.cc \ smat.cc matrix.cc choleski.cc vector.cc dstream.cc\ matdebug.cc scalar.cc -templatecc=cursor.tcc list.tcc tsmat.tcc plist.tcc interval.tcc +templatecc=cursor.tcc list.tcc tsmat.tcc plist.tcc interval.tcc\ + pcursor.tcc inl=findcurs.inl link.inl list.inl cursor.inl plist.inl hh=cursor.hh pcursor.hh lgetopt.hh link.hh list.hh dstream.hh \ - string.hh stringutil.hh vray.hh textdb.hh textstr.hh assoc.hh\ + string.hh stringutil.hh varray.hh textdb.hh textstr.hh assoc.hh\ findcurs.hh unionfind.hh compare.hh handle.hh matrix.hh\ smat.hh vsmat.hh vector.hh real.hh choleski.hh\ tsmat.hh tvsmat.hh plist.hh associter.hh fproto.hh\ diff --git a/flower/Variables.make b/flower/Variables.make index 7d6f0479a5..c1801c14c4 100644 --- a/flower/Variables.make +++ b/flower/Variables.make @@ -1,6 +1,6 @@ MAJVER=1 MINVER=0 -PATCHLEVEL=18 +PATCHLEVEL=19 PACKAGENAME=flower #PROFILEFLAG=-pg @@ -31,7 +31,7 @@ include Sources.make obs=$(cc:.cc=.o) staticlib=libflower.a - -DFILES=$(hh) $(cc) $(inl) $(templatecc) Makefile Variables.make make_version\ +ALLSOURCES=$(hh) $(cc) $(inl) $(templatecc) +DFILES=$(ALLSOURCES) Makefile Variables.make make_version\ Sources.make TODO README DDIR=$(DNAME) diff --git a/flower/assoc.hh b/flower/assoc.hh index 3a49c8a058..d17b10a70b 100644 --- a/flower/assoc.hh +++ b/flower/assoc.hh @@ -1,7 +1,7 @@ #ifndef ASSOC_HH #define ASSOC_HH -#include "vray.hh" +#include "varray.hh" #include template @@ -13,12 +13,12 @@ struct Assoc_ent_ { template struct Assoc { - svec< Assoc_ent_ > arr; + Array< Assoc_ent_ > arr; /****************/ int find(K key) const { - for (int i = 0; i < arr.sz(); i++) { + for (int i = 0; i < arr.size(); i++) { if (!arr[i].free && key == arr[i].key) return i; } @@ -26,7 +26,7 @@ struct Assoc { } int find_creat(K key) { int free = -1; - for (int i = 0; i < arr.sz(); i++) { + for (int i = 0; i < arr.size(); i++) { if (key == arr[i].key) { return i; } else if (arr[i].free ) { @@ -43,7 +43,7 @@ struct Assoc { ae.free = false; ae.key = key; arr.add(ae); - return arr.sz() -1; + return arr.size() -1; } public: bool elt_query(K key) const { diff --git a/flower/associter.hh b/flower/associter.hh index 0902c3953d..bb312b8e9e 100644 --- a/flower/associter.hh +++ b/flower/associter.hh @@ -21,12 +21,12 @@ struct Assoc_iter { i= next(0); } int next(int j) { - while (j < assoc_.arr.sz() && assoc_.arr[j].free) + while (j < assoc_.arr.size() && assoc_.arr[j].free) j++; return j; } bool ok() const { - return i < assoc_.arr.sz(); + return i < assoc_.arr.size(); } void OK()const { assert(!ok() || !assoc_.arr[i].free); diff --git a/flower/dstream.cc b/flower/dstream.cc index b4267f3502..fc50506195 100644 --- a/flower/dstream.cc +++ b/flower/dstream.cc @@ -114,7 +114,7 @@ Dstream::Dstream(ostream *r, const char * cfg_nm ) Text_db cfg(fn); while (! cfg.eof()){ Text_record r( cfg++); - if (r.sz() != 2) { + if (r.size() != 2) { r.message("not enough fields in Dstream init."); continue; } diff --git a/flower/fproto.hh b/flower/fproto.hh index 4452176d19..dcd17595d0 100644 --- a/flower/fproto.hh +++ b/flower/fproto.hh @@ -7,7 +7,7 @@ #ifndef FPROTO_HH #define FPROTO_HH -template struct svec; +template struct Array; template struct sstack; template struct Assoc; template struct List; diff --git a/flower/smat.hh b/flower/smat.hh index c05d032d89..9b0987c8f4 100644 --- a/flower/smat.hh +++ b/flower/smat.hh @@ -1,6 +1,6 @@ #ifndef SMAT_HH #define SMAT_HH -#include "vray.hh" +#include "varray.hh" #include "vsmat.hh" #include "real.hh" /// simplest matrix storage. refer to its baseclass for the doco. @@ -59,8 +59,8 @@ public: assert(valid(i,j)); return els[i][j]; } - virtual svec row(int i) const; - virtual svec column(int j) const; + virtual Array row(int i) const; + virtual Array column(int j) const; Full_storage() { init(); diff --git a/flower/sstack.hh b/flower/sstack.hh index fa21392de0..fb4d68c3a5 100644 --- a/flower/sstack.hh +++ b/flower/sstack.hh @@ -7,22 +7,22 @@ #ifndef SSTACK_HH #define SSTACK_HH -#include "vray.hh" +#include "varray.hh" -/// A simple stack based on svec. +/// A simple stack based on Array. template -struct sstack : svec { +struct sstack : Array { T top() { return last(); } T pop() { assert(!empty()); T l = last(); - svec::pop(); + Array::pop(); return l; } void push(T l) { add(l); } }; /** - Same as for #svec# goes here. + Same as for #Array# goes here. */ diff --git a/flower/textdb.cc b/flower/textdb.cc index 4c10139583..d94b64ab79 100644 --- a/flower/textdb.cc +++ b/flower/textdb.cc @@ -27,7 +27,7 @@ Text_db::get_record() { while (1) { String s; - svec fields; + Array fields; assert(!eof()); while ((s = get_word()) != "") @@ -40,7 +40,7 @@ Text_db::get_record() if (get_line() != "") assert(false); - assert (fields.sz()); + assert (fields.size()); return Text_record(fields, get_name(), line()); } } diff --git a/flower/textdb.hh b/flower/textdb.hh index bea0c4521e..afb04f0725 100644 --- a/flower/textdb.hh +++ b/flower/textdb.hh @@ -5,8 +5,8 @@ /**: do "#" comments, read quote enclosed fields */ -/// a "const" svec. Contents can't be changed. -class Text_record : svec +/// a "const" Array. Contents can't be changed. +class Text_record : Array { int line_no; String filename; @@ -19,13 +19,13 @@ public: cerr << '\n'<< filename << ": "<< line_no << s << "\n"; } String operator[](int j) { - return svec::operator[](j); + return Array::operator[](j); } - Text_record(svec s, String fn, int j) : svec(s) { + Text_record(Array s, String fn, int j) : Array(s) { filename = fn; line_no = j; } - svec::sz; + Array::size; }; /// abstraction for a datafile diff --git a/flower/tsmat.hh b/flower/tsmat.hh index 0fe3f7af79..e8dac44e6e 100644 --- a/flower/tsmat.hh +++ b/flower/tsmat.hh @@ -1,6 +1,6 @@ #ifndef SMAT_HH #define SMAT_HH -#include "vray.hh" +#include "varray.hh" #include "vsmat.hh" /// simplest matrix storage. refer to its baseclass for the doco. @@ -60,8 +60,8 @@ public: assert(valid(i,j)); return els[i][j]; } - virtual svec row(int i) const; - virtual svec column(int j) const; + virtual Array row(int i) const; + virtual Array column(int j) const; Full_storage() { init(); diff --git a/flower/tvsmat.hh b/flower/tvsmat.hh index 5e79634b55..32f981d2e9 100644 --- a/flower/tvsmat.hh +++ b/flower/tvsmat.hh @@ -1,6 +1,6 @@ #ifndef VSMAT_HH #define VSMAT_HH -#include "vray.hh" +#include "varray.hh" /// a matrix storage baseclass. class virtual_smat { @@ -62,8 +62,8 @@ public: virtual const Real& elem(int i, int j) const = 0; #if 1 - virtual svec row(int i) const = 0; - virtual svec column(int j) const = 0; + virtual Array row(int i) const = 0; + virtual Array column(int j) const = 0; #endif /// add a row diff --git a/flower/unionfind.hh b/flower/unionfind.hh index 8fcc6b438e..523321ff5f 100644 --- a/flower/unionfind.hh +++ b/flower/unionfind.hh @@ -1,6 +1,6 @@ #ifndef UNIONFIND_HH #define UNIONFIND_HH -#include "vray.hh" +#include "varray.hh" /// which points of a graph are connected? struct Union_find { @@ -10,7 +10,7 @@ struct Union_find { Union_find(int sz); private: - svec classes; + Array classes; }; /* diff --git a/flower/varray.hh b/flower/varray.hh new file mode 100644 index 0000000000..bfc6b984fa --- /dev/null +++ b/flower/varray.hh @@ -0,0 +1,172 @@ +/* + (c) Han-Wen Nienhuys 1995,96 + + Distributed under GNU GPL +*/ + +#ifndef ARRAY_H +#define ARRAY_H +#include + +/// copy a bare (C-)array from #src# to #dest# sized #count# +template +inline void arrcpy(T*dest, T*src, int count) { + for (int i=0; i < count ; i++) + *dest++ = *src++; +} + +///scaleable array template, for T with def ctor. +template +class Array { +protected: + /// maximum length of array. + int max; + + /// the data itself + T *thearray; + + /// stretch or shrink array. + void remax(int newmax) { + T* newarr = new T[newmax]; + size_ = (newmax < size_) ? newmax : size_; + arrcpy(newarr, thearray, size_); + + delete[] thearray; + thearray = newarr; + max = newmax; + } + int size_; + +public: + /// check invariants + void OK() const { + assert(max >= size_ && size_ >=0); + if (max) assert(thearray); + } + /// report the size_. See {setsize_} + + int size() const { return size_; } + + /// POST: size() == 0 + void clear() { size_ = 0; } + + Array() { thearray = 0; max =0; size_ =0; } + + /// set the size_ to #s# + void set_size(int s) { + if (s >= max) remax(s); + size_ = s; + } + /** POST: size() == s. + Warning: contents are unspecified */ + + ~Array() { delete[] thearray; } + + /// return a "new"ed copy of array + T* copy_array() const { + T* Tarray = new T[size_]; + arrcpy(Tarray, thearray, size_); + return Tarray; + } + // depracated + operator T* () const { + return copy_array(); + } + void operator=(Array const & src) { + set_size (src.size_); + arrcpy(thearray,src.thearray, size_); + } + Array(const Array & src) { + thearray = src.copy_array(); + max = size_ = src.size_; + } + + /// tighten array size_. + void precompute () { remax(size_); } + + /// this makes Array behave like an array + T &operator[] (const int i) const { + assert(i >=0&&i=0 && j<= size_); + set_size(size_+1); + for (int i=size_-1; i > j; i--) + thearray[i] = thearray[i-1]; + thearray[j] = k; + } + void del(int i) { + assert(i >=0&& i < size_); + arrcpy(thearray+i, thearray+i+1, size_-i-1); + size_--; + } + // quicksort. + void sort (int (*compare)(T& , T& ), + int lower = -1, int upper = -1 ) { + if (lower < 0) { + lower = 0 ; + upper = size()-1; + } + if (lower >= upper) + return; + swap(lower, (lower+upper)/2); + int last = lower; + for (int i= lower +1; i <= upper; i++) + if (compare(thearray[i], thearray[lower]) < 0 ) + swap( ++last,i); + swap(lower, last); + sort(compare, lower, last-1); + sort(compare, last+1, upper); + } + void concat(Array const &src) { + int s = size_; + set_size(size_ + src.size_); + arrcpy(thearray+s,src.thearray, src.size_); + } + Array subvec(int lower, int upper) { + assert(lower >= 0 && lower <=upper&& upper <= size_); + Array r; + int s =upper-lower; + r.set_size(s); + arrcpy(r.thearray, thearray + lower, s); + return r; + } +}; +/** + + This template implements a scaleable vector. With (or without) range + checking. It may be flaky for objects with complicated con- and + destructors. The type T should have a default constructor. It is + best suited for simple types, such as int, double or String + + */ + +#endif diff --git a/flower/vector.hh b/flower/vector.hh index 1929c674a9..2fdf41482a 100644 --- a/flower/vector.hh +++ b/flower/vector.hh @@ -3,7 +3,7 @@ #include #include "real.hh" -#include "vray.hh" +#include "varray.hh" class Dstream; class String; @@ -11,10 +11,10 @@ void set_matrix_debug(Dstream&ds); /// a row of numbers class Vector { - svec dat; + Array dat; public: void OK() const { dat.OK();} - int dim() const { return dat.sz(); } + int dim() const { return dat.size(); } Vector() { } Vector(const Vector&n); Vector(int n) { @@ -69,13 +69,13 @@ public: Real norm_sq() { return ((*this) * (*this)); } - operator svec () { return dat; } + operator Array () { return dat; } void print() const; /// set to j-th element of unit-base void set_unit(int j) ; }; /** - a vector. Storage is handled in svec, Vector only does the mathematics. + a vector. Storage is handled in Array, Vector only does the mathematics. */ inline Vector diff --git a/flower/vsmat.hh b/flower/vsmat.hh index 4e1ea797b6..3112ae9b25 100644 --- a/flower/vsmat.hh +++ b/flower/vsmat.hh @@ -1,6 +1,6 @@ #ifndef VSMAT_HH #define VSMAT_HH -#include "vray.hh" +#include "varray.hh" #include "real.hh" /// a matrix storage baseclass. class virtual_smat { @@ -62,8 +62,8 @@ public: virtual const Real& elem(int i, int j) const = 0; #if 1 - virtual svec row(int i) const = 0; - virtual svec column(int j) const = 0; + virtual Array row(int i) const = 0; + virtual Array column(int j) const = 0; #endif /// add a row