]> git.donarmstrong.com Git - lilypond.git/commitdiff
flower-1.0.19
authorfred <fred>
Thu, 9 Jan 1997 22:42:29 +0000 (22:42 +0000)
committerfred <fred>
Thu, 9 Jan 1997 22:42:29 +0000 (22:42 +0000)
17 files changed:
flower/Makefile
flower/Sources.make
flower/Variables.make
flower/assoc.hh
flower/associter.hh
flower/dstream.cc
flower/fproto.hh
flower/smat.hh
flower/sstack.hh
flower/textdb.cc
flower/textdb.hh
flower/tsmat.hh
flower/tvsmat.hh
flower/unionfind.hh
flower/varray.hh [new file with mode: 0644]
flower/vector.hh
flower/vsmat.hh

index 89e3bd6f5cdbad5a47e854bea278497b484ae2b4..ed618974ebd208cbc380dad5ea194b731b630640 100644 (file)
@@ -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)
 
index 2a618814c3fd9db08bcfa5a23af1b78b511f4ce8..eae2acaf4d80773fae6738a15eb9759d07746c90 100644 (file)
@@ -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\
index 7d6f0479a5a57aac95f4bcf32fc63959deff7e76..c1801c14c4d851e3b5a0719f8a4f13827e7ab736 100644 (file)
@@ -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)
index 3a49c8a05876d9e795744bca91b29b8e5eabdf0e..d17b10a70b9e7bfae787838006cd77333105b731 100644 (file)
@@ -1,7 +1,7 @@
 #ifndef ASSOC_HH
 #define ASSOC_HH
 
-#include "vray.hh"
+#include "varray.hh"
 #include <assert.h>
 
 template<class K, class V>
@@ -13,12 +13,12 @@ struct Assoc_ent_ {
 
 template<class K, class V>
 struct Assoc {
-    svec< Assoc_ent_<K,V> > arr;
+    Array< Assoc_ent_<K,V> > 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 {
index 0902c3953d504a5c2cdabfd7dcf0e4890ba7bdb7..bb312b8e9e1df5c94980c817e5e7492b5e76e85d 100644 (file)
@@ -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);
index b4267f35021cb7cb2b795b41069d624f5f1d9629..fc50506195400dab8130746a5d8c4ff6374e4f3d 100644 (file)
@@ -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;
         }
index 4452176d19a9032c98462e614d2c0785f310e4a4..dcd17595d0a346f752a9792e4236a783f6de72ee 100644 (file)
@@ -7,7 +7,7 @@
 #ifndef FPROTO_HH
 #define FPROTO_HH
 
-template<class T> struct svec;
+template<class T> struct Array;
 template<class T> struct sstack;
 template<class T,class K> struct Assoc;
 template<class T> struct List;
index c05d032d894c684378592c6c38fa83cb51cb2575..9b0987c8f4293232913a126d07479bb6276ad06d 100644 (file)
@@ -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<Real> row(int i) const;
-    virtual svec<Real> column(int j) const;
+    virtual Array<Real> row(int i) const;
+    virtual Array<Real> column(int j) const;
 
     Full_storage() {
        init();
index fa21392de040ae61ce8a44fa91bd8f676efb1a5e..fb4d68c3a5f295da8beae35bb482f368645f7f3a 100644 (file)
@@ -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<class T>
-struct sstack : svec<T> { 
+struct sstack : Array<T> { 
     T top() { return last(); }
     T pop() {
        assert(!empty());
        T l = last();
-        svec<T>::pop();
+        Array<T>::pop();
        return l;
     }
     void push(T l) { add(l); }
 };
 /**
-  Same as for #svec# goes here.
+  Same as for #Array# goes here.
 */
 
 
index 4c101395836ed62f5173715e4d5e92d66562e77d..d94b64ab7980eaef3423123d831d26c1632efd56 100644 (file)
@@ -27,7 +27,7 @@ Text_db::get_record()
 {
    while (1) {
        String s;
-       svec<String> fields;
+       Array<String> 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());
    }
 }
index bea0c4521e449189a749571a7817722a45b8ae7b..afb04f0725772e1927b23a928416e47e6b44c5c3 100644 (file)
@@ -5,8 +5,8 @@
 
 /**: do "#" comments, read quote enclosed  fields */
 
-/// a "const" svec. Contents can't be changed.
-class Text_record : svec<String>  
+/// a "const" Array. Contents can't be changed.
+class Text_record : Array<String>  
 {
     int line_no;
     String filename;
@@ -19,13 +19,13 @@ public:
        cerr << '\n'<< filename << ": "<< line_no << s << "\n";
     }         
     String operator[](int j) {
-       return svec<String>::operator[](j);
+       return Array<String>::operator[](j);
     }
 
-    Text_record(svec<String> s, String fn, int j) : svec<String>(s) { 
+    Text_record(Array<String> s, String fn, int j) : Array<String>(s) { 
        filename = fn; line_no = j; 
     }
-    svec<String>::sz;           
+    Array<String>::size;           
 };
 
 /// abstraction for a datafile
index 0fe3f7af795d32ee120a93b4da4c47870b32a2aa..e8dac44e6e617db2e14ad7e651bdb37130957fed 100644 (file)
@@ -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<T> row(int i) const;
-    virtual svec<T> column(int j) const;
+    virtual Array<T> row(int i) const;
+    virtual Array<T> column(int j) const;
 
     Full_storage() {
        init();
index 5e79634b5574761ac2fa6c14ae0948e2e7d93bc7..32f981d2e93d89d9e1f3eb54c1237ebf700507c4 100644 (file)
@@ -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<Real> row(int i) const = 0;
-    virtual svec<Real> column(int j) const = 0;
+    virtual Array<Real> row(int i) const = 0;
+    virtual Array<Real> column(int j) const = 0;
 #endif
 
     /// add a row
index 8fcc6b438e50baa99db43ae241d2cd13a7622485..523321ff5f9774046a0aa61682225c3527c749de 100644 (file)
@@ -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<int> classes;
+    Array<int> classes;
 
 };
 /*
diff --git a/flower/varray.hh b/flower/varray.hh
new file mode 100644 (file)
index 0000000..bfc6b98
--- /dev/null
@@ -0,0 +1,172 @@
+/*
+  (c) Han-Wen Nienhuys 1995,96
+
+  Distributed under GNU GPL  
+*/
+
+#ifndef ARRAY_H
+#define ARRAY_H
+#include <assert.h>
+
+/// copy a bare (C-)array from #src# to #dest# sized  #count#
+template<class T>
+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 T>
+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<size_);
+       return ((T*)thearray)[i];       
+    }
+
+    /// add to the end of array
+    void add(T x) {
+       if (size_ == max)
+           remax(2*max + 1);
+
+       // T::operator=(T &) is called here. Safe to use with automatic
+       // vars
+       thearray[size_++] = x;
+    }
+
+    /// junk last entry.
+    void pop() { size_ -- ; }
+
+    /// return last entry
+    T& last(int j=0) {
+       return (*this)[size_-j-1];
+    }
+    T last(int j=0) const {
+       return (*this)[size_-j-1];
+    }
+    void swap (int i,int j) {
+       T t((*this)[i]);
+       (*this)[i]=(*this)[j];
+       (*this)[j]=t;
+    }
+    bool empty() { return !size_; }
+    void insert(T k, int j) {
+       assert(j >=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<T> const &src) {
+       int s = size_;
+       set_size(size_ + src.size_);
+       arrcpy(thearray+s,src.thearray, src.size_);     
+    }
+    Array<T> subvec(int lower, int upper) {
+       assert(lower >= 0 && lower <=upper&& upper <= size_);
+       Array<T> 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
index 1929c674a9d702364bbaf18297a8aee136ec9655..2fdf41482a68e52f4477e2a495c4c08ac57d1424 100644 (file)
@@ -3,7 +3,7 @@
 
 #include <math.h>
 #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<Real> dat;
+    Array<Real> 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<Real> () { return dat; }
+    operator Array<Real> () { 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
index 4e1ea797b635e7ec4181ad3cb17b06c01ea31a23..3112ae9b253f40ed9959f014b4874a468d19f61f 100644 (file)
@@ -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<Real> row(int i) const = 0;
-    virtual svec<Real> column(int j) const = 0;
+    virtual Array<Real> row(int i) const = 0;
+    virtual Array<Real> column(int j) const = 0;
 #endif
 
     /// add a row