diff options
author | Han-Wen Nienhuys <hanwen@xs4all.nl> | 1996-11-28 12:02:01 +0100 |
---|---|---|
committer | Han-Wen Nienhuys <hanwen@xs4all.nl> | 1996-11-28 12:02:01 +0100 |
commit | fc22f69328fd2d5030bb1feff8d0f6da37e8217d (patch) | |
tree | 9e9c59c8c0c104cf4388f728b19f0e9be7b6991d /flower | |
parent | c3fe80ddeb9acfcf5d569fcef1caaef6ef7a01fb (diff) |
release: 0.0.8
Diffstat (limited to 'flower')
-rw-r--r-- | flower/Makefile | 4 | ||||
-rw-r--r-- | flower/README | 10 | ||||
-rw-r--r-- | flower/Sources.make | 5 | ||||
-rw-r--r-- | flower/TODO | 7 | ||||
-rw-r--r-- | flower/cursor.cc | 31 | ||||
-rw-r--r-- | flower/cursor.hh | 2 | ||||
-rw-r--r-- | flower/fproto.hh | 38 | ||||
-rw-r--r-- | flower/interval.cc | 18 | ||||
-rw-r--r-- | flower/interval.hh | 58 | ||||
-rw-r--r-- | flower/lgetopt.cc | 2 | ||||
-rw-r--r-- | flower/pcursor.hh | 6 | ||||
-rw-r--r-- | flower/plist.hh | 2 | ||||
-rw-r--r-- | flower/textstr.hh | 4 |
13 files changed, 166 insertions, 21 deletions
diff --git a/flower/Makefile b/flower/Makefile index e17cbdb0d8..dffea2fb37 100644 --- a/flower/Makefile +++ b/flower/Makefile @@ -1,6 +1,6 @@ MAJVER=1 MINVER=0 -PATCHLEVEL=7 +PATCHLEVEL=8 PACKAGENAME=flower VERSION=$(MAJVER).$(MINVER).$(PATCHLEVEL) @@ -26,7 +26,7 @@ clean: rm -f $(obs) $(staticlib) realclean: clean rm -f depend -DFILES=$(hh) $(cc) $(inl) $(templatecc) Makefile Sources.make TODO +DFILES=$(hh) $(cc) $(inl) $(templatecc) Makefile Sources.make TODO README DDIR=$(DNAME) dist: diff --git a/flower/README b/flower/README new file mode 100644 index 0000000000..d33c68f3df --- /dev/null +++ b/flower/README @@ -0,0 +1,10 @@ +This library contains some general purpose routines which aren't +standardised yet. It was written by: + + Han-Wen Nienhuys <hanwen@stack.nl> + +and + + Jan Nieuwenhuizen <jan@digicash.com> + +It is licensed under the GNU GPL.
\ No newline at end of file diff --git a/flower/Sources.make b/flower/Sources.make index 8016e67323..7f2f6441a1 100644 --- a/flower/Sources.make +++ b/flower/Sources.make @@ -1,7 +1,7 @@ cc=lgetopt.cc string.cc dataf.cc textdb.cc unionfind.cc \ smat.cc matrix.cc choleski.cc vector.cc dstream.cc\ - matdebug.cc + matdebug.cc interval.cc templatecc=cursor.cc list.cc tsmat.cc plist.cc inl=findcurs.inl link.inl list.inl cursor.inl plist.inl @@ -9,5 +9,6 @@ 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\ 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\ + tsmat.hh tvsmat.hh plist.hh associter.hh fproto.hh\ + interval.hh diff --git a/flower/TODO b/flower/TODO index 4d0774ff7c..ef0ab6bac6 100644 --- a/flower/TODO +++ b/flower/TODO @@ -4,6 +4,8 @@ * efficient copy cons for List + * extend Interval + * change String::pos s[s.pos('%')] == '%' @@ -12,9 +14,10 @@ * use template handle in handle.hh for strings. - * Restricted cursor/list: make sublist from a list, and use rcursor as if list is as big as the sublist. + * Restricted cursor/list: make sublist from a list, and use rcursor +as if list is as big as the sublist. - * move towards gnu? + * move towards gnu or STL? parsestream.h vector.h diff --git a/flower/cursor.cc b/flower/cursor.cc index 2a9f885689..75f607dcaa 100644 --- a/flower/cursor.cc +++ b/flower/cursor.cc @@ -68,27 +68,38 @@ Cursor<T>::operator -( int i ) const return r; } - +/* + warning: can't use Cursor::operator == (Cursor), + since it uses Cursor::operator-(Cursor) + */ template<class T> int -Cursor<T>::operator-(Cursor<T> c) const +Cursor<T>::operator-(Cursor<T> rhs) const { - assert(c.list == list); + assert(rhs.list == list); int dif = 0; - Cursor<T> upward(c); - while (upward.ok() && upward.pointer_ != pointer_) { - upward++; + + // search from *this on further up (positive difference) + Cursor<T> c(*this); + while (c.ok() && c.pointer_ != rhs.pointer_) { + c--; dif++; } - if (upward.ok()) - return dif; + if (c.ok()) + goto gotcha; // so, sue me. + + // search in direction of bottom. (negative diff) dif =0; - while (c.ok()&& c.pointer_ != pointer_) { + c=*this; + while (c.ok() && c.pointer_ !=rhs.pointer_) { dif --; - c--; + c++; } assert(c.ok()); + +gotcha: + assert((*this - dif).pointer_ == c.pointer_); return dif; } diff --git a/flower/cursor.hh b/flower/cursor.hh index 4babf96545..6bd4e1895d 100644 --- a/flower/cursor.hh +++ b/flower/cursor.hh @@ -107,7 +107,7 @@ private: template<class T> inline int cursor_compare(Cursor<T> a,Cursor<T>b) { - return b-a; + return a-b; } template_instantiate_compare(Cursor<T>, cursor_compare, template<class T>); diff --git a/flower/fproto.hh b/flower/fproto.hh new file mode 100644 index 0000000000..5241a13dd0 --- /dev/null +++ b/flower/fproto.hh @@ -0,0 +1,38 @@ +/* + fproto.hh -- typenames in flowerlib + + (c) 1996 Han-Wen Nienhuys +*/ + +#ifndef FPROTO_HH +#define FPROTO_HH + +template<class T> struct svec; +template<class T> struct sstack; +template<class T,class K> struct Assoc; +template<class T> struct List; +template<class T> struct PointerList; +template<class T> struct IPointerList; +template<class T> struct Cursor; +template<class T> struct PCursor; +template<class T> struct Link; +template<class T> struct Handle ; + + +struct Assoc_ent_ ; +struct Assoc ; +struct Assoc_iter ; +struct Choleski_decomposition ; +struct Interval ; +struct long_option_init ; +struct Getopt_long ; +struct Matrix ; +struct StringData ; +struct String_handle ; +struct virtual_smat ; +struct Vector ; +class Text_stream; +class Data_file ; +struct Text_db; +#endif // FPROTO_HH + diff --git a/flower/interval.cc b/flower/interval.cc new file mode 100644 index 0000000000..b307f4c634 --- /dev/null +++ b/flower/interval.cc @@ -0,0 +1,18 @@ +#include <assert.h> +#include "interval.hh" +#include <math.h> + +const Real INFTY = HUGE; + +void +Interval::set_empty() { + min = INFTY; + max = -INFTY; +} + +Real +Interval::length() const { + assert(max >= min); + return max-min; +} + diff --git a/flower/interval.hh b/flower/interval.hh new file mode 100644 index 0000000000..950945ca87 --- /dev/null +++ b/flower/interval.hh @@ -0,0 +1,58 @@ +/* + interval.hh -- part of flowerlib + + (c) 1996 Han-Wen Nienhuys +*/ + +#ifndef INTERVAL_HH +#define INTERVAL_HH + +#include <assert.h> +#include "real.hh" + + +/// a Real interval +struct Interval { + Real min, max; + + void translate(Real t) { + min += t; + max += t; + } + Real operator[](int j) { + if (j==-1) + return min; + else if (j==1) + return max; + else + assert(false); + return 0.0; + + } + void unite(Interval h) { + if (h.min<min) + min = h.min; + if (h.max>max) + max = h.max; + } + Real length() const; + void set_empty() ; + bool empty() { return min > max; } + Interval() { + set_empty(); + } + Interval(Real m, Real M) { + min =m; + max = M; + } + Interval &operator += (Real r) { + min += r; + max +=r; + return *this; + } +}; + + +#endif // INTERVAL_HH + + diff --git a/flower/lgetopt.cc b/flower/lgetopt.cc index ac9a12d035..523d54ee5f 100644 --- a/flower/lgetopt.cc +++ b/flower/lgetopt.cc @@ -2,7 +2,7 @@ process command line, GNU style. - this is (Copyleft) 1996, Han-Wen Nienhuys, <hanwen@stack.urc.tue.nl> + this is (Copyleft) 1996, Han-Wen Nienhuys, <hanwen@stack.nl> */ #include <stdio.h> #include <iostream.h> diff --git a/flower/pcursor.hh b/flower/pcursor.hh index 6cc3433e25..5e535300d7 100644 --- a/flower/pcursor.hh +++ b/flower/pcursor.hh @@ -17,7 +17,9 @@ struct PCursor : public Cursor<void *> { PCursor<T> operator -( int no) const { return PCursor<T> (Cursor<void*>::operator-(no)); } - + int operator -(PCursor<T> op) const { + return Cursor<void*>::operator-(op); + } /// make cursor with #no# items further PCursor<T> operator +( int no) const { return PCursor<T> (Cursor<void*>::operator+(no)); @@ -45,7 +47,7 @@ don't create PointerList<void*>'s template<class T> inline int pcursor_compare(PCursor<T> a,PCursor<T>b) { - return cursor_compare(Cursor<void*>(b),Cursor<void*> (a)); + return cursor_compare(Cursor<void*>(a),Cursor<void*> (b)); } #include "compare.hh" diff --git a/flower/plist.hh b/flower/plist.hh index 1bfc2d4ab4..78df40cb17 100644 --- a/flower/plist.hh +++ b/flower/plist.hh @@ -51,7 +51,7 @@ template<class T> void PL_copy(IPointerList<T*> &dst,IPointerList<T*> const&src); -#define PL_instantiate(a) L_instantiate(a *); template class PointerList<a*> +#define PL_instantiate(a) template class PointerList<a*> #define IPL_instantiate(a) PL_instantiate(a); template class IPointerList<a*> #include "plist.inl" diff --git a/flower/textstr.hh b/flower/textstr.hh index 41a979f27f..c64a989c3c 100644 --- a/flower/textstr.hh +++ b/flower/textstr.hh @@ -1,3 +1,6 @@ +#ifndef TEXTSTR_HH +#define TEXTSTR_HH + #include <stdio.h> #include <ctype.h> @@ -112,3 +115,4 @@ class Data_file : private Text_stream exit(1); } }; +#endif |