summaryrefslogtreecommitdiff
path: root/flower
diff options
context:
space:
mode:
authorHan-Wen Nienhuys <hanwen@xs4all.nl>1996-12-21 00:03:06 +0100
committerHan-Wen Nienhuys <hanwen@xs4all.nl>1996-12-21 00:03:06 +0100
commitafa9eb0922477ed70c182b3fc023a3baedb5c6f0 (patch)
treeceb7dfb3f73a4670111f1433f97f09914c959def /flower
parentb346828b743d4fe2636a6e58597b3cb6d547357d (diff)
release: 0.0.16
Diffstat (limited to 'flower')
-rw-r--r--flower/TODO6
-rw-r--r--flower/Variables.make2
-rw-r--r--flower/interval.cc9
-rw-r--r--flower/interval.hh28
-rw-r--r--flower/vray.hh79
5 files changed, 82 insertions, 42 deletions
diff --git a/flower/TODO b/flower/TODO
index 9d4ade3bcd..6ce4b741d2 100644
--- a/flower/TODO
+++ b/flower/TODO
@@ -1,3 +1,6 @@
+
+ * PointerVec ?
+
* PCursor -> Pointer_cursor / PointerCursor ?
* efficient copy cons for List
@@ -12,9 +15,6 @@
* 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.
-
* move towards gnu or STL?
parsestream.h
diff --git a/flower/Variables.make b/flower/Variables.make
index 83a740ac4a..ca0275af87 100644
--- a/flower/Variables.make
+++ b/flower/Variables.make
@@ -1,6 +1,6 @@
MAJVER=1
MINVER=0
-PATCHLEVEL=15
+PATCHLEVEL=16
PACKAGENAME=flower
VERSION=$(MAJVER).$(MINVER).$(PATCHLEVEL)
diff --git a/flower/interval.cc b/flower/interval.cc
index 6fac1f55dc..f176c7486f 100644
--- a/flower/interval.cc
+++ b/flower/interval.cc
@@ -17,20 +17,24 @@ Interval::length() const {
assert(max >= min);
return max-min;
}
+
void
Interval::unite(Interval h)
{
+ compare(h, *this );
if (h.min<min)
min = h.min;
if (h.max>max)
max = h.max;
}
+
void
Interval::intersect(Interval h)
{
min = MAX(h.min, min);
max = MIN(h.max, max);
}
+
Interval
intersection(Interval a, Interval const&b)
{
@@ -38,6 +42,7 @@ intersection(Interval a, Interval const&b)
return a;
}
+
int
Interval::compare(const Interval&a,Interval const&b)
{
@@ -62,8 +67,8 @@ intersect(Interval x, Interval const &y)
return x;
}
-
-Interval::operator String() const
+String
+Interval::str() const
{
if (empty())
return "[empty]";
diff --git a/flower/interval.hh b/flower/interval.hh
index a7a269153b..5331c1d125 100644
--- a/flower/interval.hh
+++ b/flower/interval.hh
@@ -16,6 +16,9 @@
struct Interval {
Real min, max;
+ /****************/
+
+ Real center() { return (min + max) /2;}
void translate(Real t) {
min += t;
max += t;
@@ -31,6 +34,10 @@ struct Interval {
}
void unite(Interval h) ;
+ /**
+ PRE
+ *this and h are comparable
+ */
void intersect(Interval h);
Real length() const;
@@ -49,13 +56,17 @@ struct Interval {
return *this;
}
bool elt_q(Real r);
- operator String() const;
+ String str() const;
/// partial ordering
static compare(const Interval&,Interval const&);
+ /**
+ inclusion ordering. Crash if not comparable.
+ */
};
/**
- this represents the closed interval [min,max]
+ this represents the closed interval [min,max].
+ No invariants
*/
Interval intersection(Interval, Interval const&);
@@ -64,6 +75,19 @@ Interval intersection(Interval, Interval const&);
instantiate_compare(Interval&, Interval::compare);
+
+inline
+Interval operator +(double a,Interval i )
+{
+ i += a;
+ return i;
+}
+
+inline
+Interval operator +(Interval i,double a ){
+ return a+i;
+}
+
#endif // INTERVAL_HH
diff --git a/flower/vray.hh b/flower/vray.hh
index 180008c4c6..39913fc423 100644
--- a/flower/vray.hh
+++ b/flower/vray.hh
@@ -28,32 +28,35 @@ protected:
/// stretch or shrink array.
void remax(int newmax) {
T* newarr = new T[newmax];
- size = (newmax < size) ? newmax : size;
- arrcpy(newarr, thearray, size);
+ size_ = (newmax < size_) ? newmax : size_;
+ arrcpy(newarr, thearray, size_);
delete[] thearray;
thearray = newarr;
max = newmax;
}
- int size;
+ int size_;
public:
/// check invariants
void OK() const {
- assert(max >= size && size >=0);
+ assert(max >= size_ && size_ >=0);
if (max) assert(thearray);
}
- /// report the size. See {setsize}
- int sz() const { return size; }
+ /// report the size_. See {setsize_}
- /// POST: sz() == 0
- void clear() { size = 0; }
+ int size() const { return size_; }
+ int sz() const { return size(); }
+
+ /// POST: size() == 0
+ void clear() { size_ = 0; }
+
+ svec() { thearray = 0; max =0; size_ =0; }
- svec() { thearray = 0; max =0; size =0; }
- /// set the size to #s#
+ /// set the size_ to #s#
void set_size(int s) {
if (s >= max) remax(s);
- size = s;
+ size_ = s;
}
/** POST: sz() == s.
Warning: contents are unspecified */
@@ -62,8 +65,8 @@ public:
/// return a "new"ed copy of array
T* copy_array() const {
- T* Tarray = new T[size];
- arrcpy(Tarray, thearray, size);
+ T* Tarray = new T[size_];
+ arrcpy(Tarray, thearray, size_);
return Tarray;
}
// depracated
@@ -71,60 +74,60 @@ public:
return copy_array();
}
void operator=(svec const & src) {
- set_size (src.size);
- arrcpy(thearray,src.thearray, size);
+ set_size (src.size_);
+ arrcpy(thearray,src.thearray, size_);
}
svec(const svec & src) {
thearray = src.copy_array();
- max = size = src.size;
+ max = size_ = src.size_;
}
- /// tighten array size.
- void precompute () { remax(size); }
+ /// tighten array size_.
+ void precompute () { remax(size_); }
/// this makes svec behave like an array
T &operator[] (const int i) const {
- assert(i >=0&&i<size);
+ assert(i >=0&&i<size_);
return ((T*)thearray)[i];
}
/// add to the end of array
void add(T x) {
- if (size == max)
+ if (size_ == max)
remax(2*max + 1);
// T::operator=(T &) is called here. Safe to use with automatic
// vars
- thearray[size++] = x;
+ thearray[size_++] = x;
}
/// junk last entry.
- void pop() { size -- ; }
+ void pop() { size_ -- ; }
/// return last entry
T& last(int j=0) {
- return (*this)[size-j-1];
+ return (*this)[size_-j-1];
}
T last(int j=0) const {
- return (*this)[size-j-1];
+ 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; }
+ 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--)
+ 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--;
+ assert(i >=0&& i < size_);
+ arrcpy(thearray+i, thearray+i+1, size_-i-1);
+ size_--;
}
// quicksort.
void sort (int (*compare)(T& , T& ),
@@ -145,9 +148,17 @@ public:
sort(compare, last+1, lower);
}
void concat(svec<T> const &src) {
- int s = size;
- set_size(size + src.size);
- arrcpy(thearray+s,src.thearray, src.size);
+ int s = size_;
+ set_size(size_ + src.size_);
+ arrcpy(thearray+s,src.thearray, src.size_);
+ }
+ svec<T> subvec(int lower, int upper) {
+ assert(lower >= 0 && lower <=upper&& upper <= size_);
+ svec<T> r;
+ int s =upper-lower;
+ r.set_size(s);
+ arrcpy(r.thearray, thearray + lower, s);
+ return r;
}
};
/**