From ad1cadf3512f3dd789151983e5c93af411f929db Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Sat, 17 Sep 2016 19:27:15 +0000 Subject: restructure --- omegalib/basic/include/basic/Bag.c | 329 -------------- omegalib/basic/include/basic/Bag.h | 78 ---- omegalib/basic/include/basic/BoolSet.h | 283 ------------ omegalib/basic/include/basic/Collection.h | 47 -- omegalib/basic/include/basic/Collections.h | 12 - omegalib/basic/include/basic/ConstString.h | 58 --- omegalib/basic/include/basic/Dynamic_Array.c | 219 --------- omegalib/basic/include/basic/Dynamic_Array.h | 103 ----- omegalib/basic/include/basic/Iterator.h | 131 ------ omegalib/basic/include/basic/Link.h | 98 ----- omegalib/basic/include/basic/List.c | 149 ------- omegalib/basic/include/basic/List.h | 95 ---- omegalib/basic/include/basic/Map.c | 63 --- omegalib/basic/include/basic/Map.h | 68 --- omegalib/basic/include/basic/Section.c | 79 ---- omegalib/basic/include/basic/Section.h | 63 --- omegalib/basic/include/basic/SimpleList.c | 105 ----- omegalib/basic/include/basic/SimpleList.h | 93 ---- omegalib/basic/include/basic/Tuple.c | 254 ----------- omegalib/basic/include/basic/Tuple.h | 90 ---- omegalib/basic/include/basic/boolset-test.cc | 72 --- omegalib/basic/include/basic/boolset.h | 637 --------------------------- omegalib/basic/include/basic/omega_error.h | 14 - omegalib/basic/include/basic/util.h | 263 ----------- 24 files changed, 3403 deletions(-) delete mode 100644 omegalib/basic/include/basic/Bag.c delete mode 100644 omegalib/basic/include/basic/Bag.h delete mode 100644 omegalib/basic/include/basic/BoolSet.h delete mode 100644 omegalib/basic/include/basic/Collection.h delete mode 100644 omegalib/basic/include/basic/Collections.h delete mode 100644 omegalib/basic/include/basic/ConstString.h delete mode 100644 omegalib/basic/include/basic/Dynamic_Array.c delete mode 100644 omegalib/basic/include/basic/Dynamic_Array.h delete mode 100644 omegalib/basic/include/basic/Iterator.h delete mode 100644 omegalib/basic/include/basic/Link.h delete mode 100644 omegalib/basic/include/basic/List.c delete mode 100644 omegalib/basic/include/basic/List.h delete mode 100644 omegalib/basic/include/basic/Map.c delete mode 100644 omegalib/basic/include/basic/Map.h delete mode 100644 omegalib/basic/include/basic/Section.c delete mode 100644 omegalib/basic/include/basic/Section.h delete mode 100644 omegalib/basic/include/basic/SimpleList.c delete mode 100644 omegalib/basic/include/basic/SimpleList.h delete mode 100644 omegalib/basic/include/basic/Tuple.c delete mode 100644 omegalib/basic/include/basic/Tuple.h delete mode 100755 omegalib/basic/include/basic/boolset-test.cc delete mode 100755 omegalib/basic/include/basic/boolset.h delete mode 100644 omegalib/basic/include/basic/omega_error.h delete mode 100644 omegalib/basic/include/basic/util.h (limited to 'omegalib/basic/include') diff --git a/omegalib/basic/include/basic/Bag.c b/omegalib/basic/include/basic/Bag.c deleted file mode 100644 index c3084c1..0000000 --- a/omegalib/basic/include/basic/Bag.c +++ /dev/null @@ -1,329 +0,0 @@ -/**************************************************************** - * * - * Collection constructors, desctructors, assignments * - * * - ****************************************************************/ - -#include - -namespace omega { - -template Bag::Bag() { - contents = new List_Element ; - contents->tail = 0; - } -template Bag::~Bag() { - delete contents; - } - -template Ordered_Bag::Ordered_Bag() {} - -template Set::Set() {} - -template Bag::Bag(const Bag &L) { - contents = new List_Element(*L.contents); - } - -template Bag & Bag::operator=(const Bag &L) { - if (this != &L) { - delete contents; - contents = new List_Element(*L.contents); - } - return *this; - } - - - -template Set::Set(T e) { - assert(this->contents); - this->contents->tail = new List_Element(e, 0); - } - - -/**************************************************************** - * * - * Misc. simple Collection operations * - * * - ****************************************************************/ - -template bool Bag::empty() const { - return contents->tail == 0; - } - -template Iterator *Bag::new_iterator() - { - return new List_Element_Iterator(contents->tail); - } - - -template void Bag::clear() { - if (contents->tail) delete contents->tail; - contents->tail = 0; - } - -template int Bag::size() const { - int i = 0; - List_Element * p = contents->tail; - while (p) { - p = p->tail; - i++; - }; - return i; - } - - -/**************************************************************** - * * - * Collection/Element operations (e.g. insert, contains) * - * * - ****************************************************************/ - -template void Bag::remove(T e) { - List_Element * p = contents; - while (p->tail && p->tail->head != e) p = p->tail; - if (p->tail && p->tail->head == e) { - List_Element * q = p->tail; - p->tail = q->tail; - q->tail = 0; - delete q; - } - } - -template T Bag::extract() { - List_Element * p = contents->tail; - T e = p->head; - contents->tail = p->tail; - p->tail = 0; - delete p; - return e; - } - - -template void Bag::insert(T e) { - List_Element * q = new List_Element(e,contents->tail); - contents->tail = q; - } - -template void Ordered_Bag::insert(T e) { - List_Element * p = this->contents; - while (p->tail && p->tail->head < e) p = p->tail; - if (!p->tail || p->tail->head != e) { - List_Element * q = new List_Element(e,p->tail); - p->tail = q; - } - } - - -template bool Bag::contains(T e) const { - List_Element * p = contents; - while (p->tail && p->tail->head != e) p = p->tail; - return (p->tail && p->tail->head == e); - } - -template bool Ordered_Bag::contains(T e) const { - List_Element * p = this->contents; - while (p->tail && p->tail->head < e) p = p->tail; - return (p->tail && p->tail->head == e); - } - - -template bool Set::contains (const Set& b) const { - List_Element * p = this->contents; - List_Element * q = b.contents; - do { - /* consume matched elements in p and q */ - p = p->tail; - q = q->tail; - if (!q) return 1; /* no more elements to match */ - if (!p) return 0; /* nothing left in p to match with */ - if (q->head < p->head) { - /* nothing smaller than - p->head left in p, so q->head - can't be matched */ - return 0; - }; - while (p && p->head < q->head) { - /* toss away some elements from p */ - p = p->tail; - } - if (!p || q->head < p->head) return 0; - } while (q); - - return 1; - } - - - -/**************************************************************** - * * - * Collection/Collection operations (e.g. |=) * - * * - ****************************************************************/ - -template void Bag::operator |= (const Bag & b) { - assert(this != &b); - List_Element * q = b.contents->tail; - - while (q) { - List_Element * r = new List_Element(q->head,contents->tail); - contents->tail = r; - q = q->tail; - } - } - -template void Ordered_Bag::operator |= (const Ordered_Bag & b) { - if (this == &b) return; - List_Element * p = this->contents; - List_Element * q = b.contents->tail; - - while (q) { - while (p->tail && p->tail->head < q->head) p = p->tail; - List_Element * r = new List_Element(q->head,p->tail); - p->tail = r; - q = q->tail; - } - } - -template void Ordered_Bag::operator |= (const Bag & b) { - Ordered_Bag tmp; - for (List_Element *p = b.contents; p; p=p->tail) { - tmp.insert(p->head); - } - *this |= tmp; -} - -template void Set::operator |= (const Set & b) { - if (this == &b) return; - List_Element * p = this->contents; - List_Element * q = b.contents->tail; - - while (q) { - while (p->tail && p->tail->head < q->head) p = p->tail; - if (!p->tail || p->tail->head != q->head) { - List_Element * r = new List_Element(q->head,p->tail); - p->tail = r; - } - q = q->tail; - } - } - -template void Set::operator |= (const Ordered_Bag & b) { - Set tmp; - for (List_Element *p = b.contents; p; p=p->tail) { - tmp.insert(p->head); - } - *this |= tmp; -} - -template void Set::operator |= (const Bag & b) { - Set tmp; - for (List_Element *p = b.contents; p; p=p->tail) { - tmp.insert(p->head); - } - *this |= tmp; -} - - - -// delete items also in b -template void Set::operator -= (const Set & b) { - if (this == &b) { - this->clear(); - return; - } - List_Element * p = this->contents; - List_Element * q = b.contents->tail; - - while (q) { - while (p->tail && p->tail->head < q->head) p = p->tail; - if (p->tail && p->tail->head == q->head) { - List_Element * r = p->tail; - p->tail = r->tail; - r->tail = 0; - delete r; - } - q = q->tail; - } - } - - -// delete items not in b -template void Set::operator &= (const Set & b) - { - if (this == &b) return; - List_Element * p = this->contents; - List_Element * q = b.contents->tail; - - while (q) { - while (p->tail && p->tail->head < q->head) { - List_Element * r = p->tail; - p->tail = r->tail; - r->tail = 0; - delete r; - }; - if (p->tail && p->tail->head == q->head) { - /* allow p->tail->head into the result */ - p = p->tail; - } - /* q->head has matched anything it is going to match */ - q = q->tail; - } - if (p->tail) { - delete p->tail; - p->tail = 0; - }; - - } - - -template bool Set::operator & (const Set& b) const { - List_Element * p = this->contents; - List_Element * q = b.contents; - do { - p = p->tail; - q = q->tail; - while (p && q && p->head != q->head) { - while (p && p->head < q->head) p = p->tail; - while (p && q && q->head < p->head) q = q->tail; - }; - if (p && q && p->head == q->head) return 1; - } while (p && q); - - return 0; - } - - -template bool Ordered_Bag::operator == (const Ordered_Bag& b) const { - List_Element * p = this->contents; - List_Element * q = b.contents; - while (1) { - p = p->tail; - q = q->tail; - if (!p && !q) return 1; - if (!p || !q) return 0; - if (p->head != q->head) return 0; - }; - - } - -template bool Ordered_Bag::operator != (const Ordered_Bag& b) const { - return !(*this == b); - } - -template bool Ordered_Bag::operator < (const Ordered_Bag& b) const { - List_Element * p = this->contents; - List_Element * q = b.contents; - while (1) { - p = p->tail; - q = q->tail; - if (!p && !q) return 0; - if (!p) return 1; - if (!q) return 0; - if (p->head < q->head) return 1; - if (q->head < p->head) return 0; - }; - - return 1; - } - -} // namespace diff --git a/omegalib/basic/include/basic/Bag.h b/omegalib/basic/include/basic/Bag.h deleted file mode 100644 index 42285d0..0000000 --- a/omegalib/basic/include/basic/Bag.h +++ /dev/null @@ -1,78 +0,0 @@ -#if ! defined _Bag_h -#define _Bag_h 1 - -#include -#include -#include -#include - -namespace omega { - -template class Bag : public Collection { -public: -virtual ~Bag(); - Bag(); - Bag(const Bag&); - Bag & operator=(const Bag&); -virtual void operator |= (const Bag & b); // add elements in b - Iterator *new_iterator(); - bool empty() const; - void remove(T); -virtual void insert(T); - void clear(); -virtual bool contains(T) const; - int size() const; - T extract(); -// protected: breaks g++ 261 - List_Element* contents; -}; - - -template class Ordered_Bag : public Bag { -public: - Ordered_Bag(); -// virtual ~Ordered_Bag(); - Ordered_Bag(const Ordered_Bag& B) : Bag(B) {} - void insert(T); -virtual void operator |= (const Ordered_Bag & b); // add elements in b - void operator |= (const Bag & b); - bool contains(T) const; - bool operator == (const Ordered_Bag&) const; - bool operator != (const Ordered_Bag&) const; - bool operator < (const Ordered_Bag&) const; -}; - -template class Set : public Ordered_Bag { -public: - Set(); -// virtual ~Set(); - Set(T); - Set(const Set& S) : Ordered_Bag(S) {} - - bool contains (const Set& b) const; - bool contains (T t) const { return Ordered_Bag::contains(t); } - // the above makes "standard" C++ happy - -virtual void operator |= (const Set & b); // add elements in b - void operator |= (const Ordered_Bag & b); - void operator |= (const Bag & b); - - void operator -= (const Set & b); // delete items also in b - void operator &= (const Set & b); // delete items not in b - bool operator & (const Set &) const; // check for elements in common -}; - -} // namespace - -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include -#endif - -#define instantiate_Bag(T) template class Bag; \ - instantiate_List_Element(T); -#define instantiate_Ordered_Bag(T) template class Ordered_Bag; \ - instantiate_Bag(T) -#define instantiate_Set(T) template class Set; \ - instantiate_Ordered_Bag(T) - -#endif diff --git a/omegalib/basic/include/basic/BoolSet.h b/omegalib/basic/include/basic/BoolSet.h deleted file mode 100644 index 9fcfd41..0000000 --- a/omegalib/basic/include/basic/BoolSet.h +++ /dev/null @@ -1,283 +0,0 @@ -/***************************************************************************** - Copyright (C) 2009 University of Utah - All Rights Reserved. - - Purpose: - Class of set of bools where each element is indexed by a small integer. - - Notes: - Set operands of binary operations can be of different sizes, missing - elements are treated as false. - - History: - 03/30/2009 Created by Chun Chen. -*****************************************************************************/ - -#ifndef BOOLSET_H -#define BOOLSET_H - -#include -#include -#include - -namespace omega { - -template -class BoolSet { -protected: - unsigned int size_; - std::vector set_; -public: - BoolSet(unsigned int size = 0); - ~BoolSet() {} - - void set(unsigned int); - void unset(unsigned int); - bool get(unsigned int) const; - unsigned int size() const {return size_;} - unsigned int num_elem() const; - bool imply(const BoolSet &) const; - bool empty() const; - - BoolSet &operator|=(const BoolSet &); - BoolSet &operator&=(const BoolSet &); - BoolSet &operator-=(const BoolSet &); - - template friend BoolSet operator|(const BoolSet &, const BoolSet &); // union - template friend BoolSet operator&(const BoolSet &, const BoolSet &); // intersection - template friend BoolSet operator-(const BoolSet &, const BoolSet &); // difference - template friend BoolSet operator~(const BoolSet &); // complement - template friend bool operator==(const BoolSet &, const BoolSet &); - template friend bool operator!=(const BoolSet &, const BoolSet &); - template friend std::ostream& operator<<(std::ostream &, const BoolSet &); -}; - - -template -BoolSet::BoolSet(unsigned int size) { - assert(size >= 0); - size_ = size; - unsigned int n = size / (sizeof(T)*8); - unsigned int r = size % (sizeof(T)*8); - if (r != 0) - n++; - set_ = std::vector(n, static_cast(0)); -} - - -template -void BoolSet::set(unsigned int i) { - assert(i < size_ && i >= 0); - unsigned int n = i / (sizeof(T)*8); - unsigned int r = i % (sizeof(T)*8); - - T t = static_cast(1) << r; - set_[n] |= t; -} - - -template -void BoolSet::unset(unsigned int i) { - assert(i < size_ && i >= 0); - unsigned int n = i / (sizeof(T)*8); - unsigned int r = i % (sizeof(T)*8); - - T t = static_cast(1) << r; - t = ~t; - set_[n] &= t; -} - - -template -bool BoolSet::get(unsigned int i) const { - assert(i < size_ && i >= 0); - unsigned int n = i / (sizeof(T)*8); - unsigned int r = i % (sizeof(T)*8); - - T t = static_cast(1) << r; - t = set_[n] & t; - if (t) - return true; - else - return false; -} - - -template -unsigned int BoolSet::num_elem() const { - unsigned int n = size_; - unsigned int c = 0; - unsigned int p = 0; - while (n != 0) { - unsigned int m; - if (n >= sizeof(T)*8) { - m = sizeof(T)*8; - n -= sizeof(T)*8; - } - else { - m = n; - n = 0; - } - - T v = set_[p++]; - if (v != static_cast(0)) { - for (unsigned int i = 0; i < m; i++) { - if (v & static_cast(1)) - c++; - v >>= 1; - } - } - } - - return c; -} - - -template -bool BoolSet::imply(const BoolSet &b) const { - if (size_ >= b.size_) { - for (unsigned int i = 0; i < b.set_.size(); i++) - if ((set_[i] & b.set_[i]) != b.set_[i]) - return false; - } - else { - for (unsigned int i = 0; i < set_.size(); i++) - if ((set_[i] & b.set_[i]) != b.set_[i]) - return false; - for (unsigned int i = set_.size(); i < b.set_.size(); i++) - if (b.set_[i] != static_cast(0)) - return false; - } - - return true; -} - - -template -bool BoolSet::empty() const { - for (int i = 0; i < set_.size(); i++) - if (set_[i] != static_cast(0)) - return false; - - return true; -} - - -template -BoolSet operator|(const BoolSet &a, const BoolSet &b) { - if (a.size_ >= b.size_) { - BoolSet c = a; - for (unsigned int i = 0; i < b.set_.size(); i++) - c.set_[i] |= b.set_[i]; - return c; - } - else { - BoolSet c = b; - for (unsigned int i = 0; i < a.set_.size(); i++) - c.set_[i] |= a.set_[i]; - return c; - } -} - - -template -BoolSet operator&(const BoolSet &a, const BoolSet &b) { - if (a.size_ >= b.size_) { - BoolSet c = a; - for (unsigned int i = 0; i < b.set_.size(); i++) - c.set_[i] &= b.set_[i]; - for (unsigned int i = b.set_.size(); i < a.set_.size(); i++) - c.set_[i] = static_cast(0); - return c; - } - else { - BoolSet c = b; - for (unsigned int i = 0; i < a.set_.size(); i++) - c.set_[i] &= a.set_[i]; - for (unsigned int i = a.set_.size(); i < b.set_.size(); i++) - c.set_[i] = static_cast(0); - return c; - } -} - - -template -BoolSet operator-(const BoolSet &a, const BoolSet &b) { - BoolSet c(a.size_); - - int sz = a.set_.size(); - if (sz > b.set_.size()) - sz = b.set_.size(); - for (int i = 0; i < sz; i++) - c.set_[i] = a.set_[i] ^ (a.set_[i] & b.set_[i]); - for (int i = sz; i < a.set_.size(); i++) - c.set_[i] = a.set_[i]; - - return c; -} - - -template -BoolSet operator~(const BoolSet &b) { - unsigned int r = b.size_ % (sizeof(T)*8); - BoolSet a(b.size_); - for (unsigned int i = 0; i < b.set_.size(); i++) - a.set_[i] = ~b.set_[i]; - - if (r != 0) { - T t = static_cast(1); - for (unsigned int i = 1; i < r; i++) - t = (t << 1) | static_cast(1); - a.set_[a.set_.size()-1] &= t; - } - return a; -} - - -template -bool operator==(const BoolSet &a, const BoolSet &b) { - return (a.size_ == b.size_) && (a.set_ == b.set_); -} - - -template -bool operator!=(const BoolSet &a, const BoolSet &b) { - return !(a == b); -} - - - -template -BoolSet & BoolSet::operator|=(const BoolSet &b) { - *this = *this | b; - return *this; -} - - -template -BoolSet & BoolSet::operator&=(const BoolSet &b) { - *this = *this & b; - return *this; -} - - -template -BoolSet & BoolSet::operator-=(const BoolSet &b) { - *this = *this - b; - return *this; -} - - -template -std::ostream& operator<<(std::ostream &os, const BoolSet &b) { - for (int i = b.size()-1; i >= 0; i--) - if (b.get(i)) - os << '1'; - else - os << '0'; - return os; -} - -} // namespace - -#endif diff --git a/omegalib/basic/include/basic/Collection.h b/omegalib/basic/include/basic/Collection.h deleted file mode 100644 index c7e4eef..0000000 --- a/omegalib/basic/include/basic/Collection.h +++ /dev/null @@ -1,47 +0,0 @@ -#if !defined Already_Included_Collection -#define Already_Included_Collection - -namespace omega { - -template class Iterator; -template class Any_Iterator; - - -/* - * protocol for any kind of collection - */ - -template class Collection { -public: - virtual Iterator *new_iterator() = 0; - virtual Any_Iterator any_iterator() { return Any_Iterator(new_iterator()); } - - virtual int size() const = 0; -}; - - -/* - * protocol for collections whose elements are ordered - * by the way they are entered into the collection, and - * whose elements can be accessed by "index" - * - * note that the implementation need not be a linked list - */ - -template class Sequence : public Collection { -public: - virtual const T &operator[](int) const = 0; - virtual T &operator[](int) = 0; - - virtual int index(const T &) const = 0; // Y in X --> X[X.index(Y)] == Y -}; - -} // namespace - -#define instantiate_Collection(T) template class Collection; \ - instantiate_Any_Iterator(T) -#define instantiate_Sequence(T) template class Sequence; \ - instantiate_Collection(T) - -#endif - diff --git a/omegalib/basic/include/basic/Collections.h b/omegalib/basic/include/basic/Collections.h deleted file mode 100644 index 1e68031..0000000 --- a/omegalib/basic/include/basic/Collections.h +++ /dev/null @@ -1,12 +0,0 @@ -#if !defined Already_Included_Collections -#define Already_Included_Collections - -#include -#include -#include -#include -#include -#include - -#endif - diff --git a/omegalib/basic/include/basic/ConstString.h b/omegalib/basic/include/basic/ConstString.h deleted file mode 100644 index 5149e55..0000000 --- a/omegalib/basic/include/basic/ConstString.h +++ /dev/null @@ -1,58 +0,0 @@ -#if ! defined _Const_String_h -#define _Const_String_h 1 - -#include - -namespace omega { - -// should be inside Const_String, but I can't get it to -// compile the hashTable when it is: hashTable can't be -// global, but if it and its size are static to Const_String, -// the compiler still doesn't seem to like the definition, -// or the declaration either for that matter. - -class ConstStringRep { -public: - const char *name; - int count; - ConstStringRep *nextInBucket; - ConstStringRep(const char *t); -}; - -class Const_String { -private: - ConstStringRep *rep; - void buildRep(const char *t); - -public: - Const_String(); - Const_String(const char* t); - Const_String(const std::string &s); - Const_String(const Const_String & t) {rep = t.rep;} - - operator int() const; - int null() const; - - operator const char*() const; - operator std::string() const; - int operator++(int); - int operator++(); - int operator--(int); - int operator--(); - friend int operator==(const Const_String &x, const Const_String &y); - friend int operator!=(const Const_String &x, const Const_String &y); - friend int operator<(const Const_String &x, const Const_String &y); - friend int operator >(const Const_String &x, const Const_String &y); - -}; - -#if defined SCREWED_UP_CASTING_RULES -static int operator==(const Const_String &x, const char *y) -{ return x == (Const_String) y; } -static int operator!=(const Const_String &x, const char *y) -{ return x != (Const_String) y; } -#endif - -} // namespace - -#endif diff --git a/omegalib/basic/include/basic/Dynamic_Array.c b/omegalib/basic/include/basic/Dynamic_Array.c deleted file mode 100644 index 0300fd8..0000000 --- a/omegalib/basic/include/basic/Dynamic_Array.c +++ /dev/null @@ -1,219 +0,0 @@ -#include -#include - -namespace omega { - -template void Dynamic_Array::do_constr() - { -// #if ! defined SHUT_UP_ABOUT_STATEMENT_WITH_NO_EFFECT_IN_DYNAMIC_ARRAY_CREATION -// assert(d > 0); -// #endif - bounds = 0; - elements = 0; - partial = false; - } - - -template void Dynamic_Array1::do_construct(int d0) - { - this->bounds = new int[1]; - this->bounds[0] = d0; - this->elements = new T [d0]; - this->partial = false; - } - -template void Dynamic_Array2::do_construct(int d0, int d1) - { - this->bounds = new int[2]; - this->bounds[0] = d0; - this->bounds[1] = d1; - this->elements = new T [d0 * d1]; - this->partial = false; - } - -template void Dynamic_Array3::do_construct(int d0,int d1,int d2) - { - this->bounds = new int[3]; - this->bounds[0] = d0; - this->bounds[1] = d1; - this->bounds[2] = d2; - this->elements = new T [d0 * d1 * d2]; - this->partial = false; - } - -template void Dynamic_Array4::do_construct(int d0,int d1,int d2,int d3) - { - this->bounds = new int[4]; - this->bounds[0] = d0; - this->bounds[1] = d1; - this->bounds[2] = d2; - this->bounds[3] = d3; - this->elements = new T [d0 * d1 * d2 * d3]; - this->partial = false; - } - -template Dynamic_Array::Dynamic_Array() - { - do_constr(); - } - -template Dynamic_Array1::Dynamic_Array1(const char *) - { - this->do_constr(); - } - -template Dynamic_Array2::Dynamic_Array2(const char *,const char *) - { - this->do_constr(); - } - -template Dynamic_Array3::Dynamic_Array3(const char *,const char *,const char *) - { - this->do_constr(); - } - -template Dynamic_Array4::Dynamic_Array4(const char *,const char *,const char *,const char *) - { - this->do_constr(); - } - -template Dynamic_Array1::Dynamic_Array1(int d0) - { - do_construct(d0); - } - -template Dynamic_Array2::Dynamic_Array2(int d0, int d1) - { - do_construct(d0, d1); - } - -template Dynamic_Array3::Dynamic_Array3(int d0,int d1,int d2) - { - do_construct(d0, d1, d2); - } - -template Dynamic_Array4::Dynamic_Array4(int d0,int d1,int d2,int d3) - { - do_construct(d0, d1, d2, d3); - } - - -template void Dynamic_Array::do_destruct() - { - if (! partial) - { - delete [] bounds; - delete [] elements; - } - } - - -template Dynamic_Array::~Dynamic_Array() - { - do_destruct(); - } - - -template void Dynamic_Array1::resize(int d0) - { - assert(!this->partial); - this->do_destruct(); - if (d0 == 0) - this->do_constr(); - else - do_construct(d0); - } - -template void Dynamic_Array2::resize(int d0, int d1) - { - assert(!this->partial); - this->do_destruct(); - if (d0 == 0 && d1 == 0) - this->do_constr(); - else - do_construct(d0, d1); - } - -template void Dynamic_Array3::resize(int d0, int d1, int d2) - { - assert(!this->partial); - this->do_destruct(); - if (d0 == 0 && d1 == 0 && d2 == 0) - this->do_constr(); - else - do_construct(d0, d1, d2); - } - -template void Dynamic_Array4::resize(int d0, int d1, int d2, int d3) - { - assert(!this->partial); - this->do_destruct(); - if (d0 == 0 && d1 == 0 && d2 == 0 && d3 == 0) - this->do_constr(); - else - do_construct(d0, d1, d2, d3); - } - - -template T& Dynamic_Array1::operator[](int d0) - { -#if !defined (NDEBUG) - assert(this->elements != 0 && "Trying to dereference undefined array"); - assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds"); -#endif - - return this->elements[d0]; - } - -template Dynamic_Array1 Dynamic_Array2::operator[](int d0) - { -#if !defined (NDEBUG) - assert(this->elements != 0 && "Trying to dereference undefined array"); - assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds"); -#endif - - Dynamic_Array1 result; - result.bounds = this->bounds+1; - result.elements = this->elements + this->bounds[1] * d0; - result.partial = true; - return result; - } - -template Dynamic_Array2 Dynamic_Array3::operator[](int d0) - { -#if !defined (NDEBUG) - assert(this->elements != 0 && "Trying to dereference undefined array"); - assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds"); -#endif - Dynamic_Array2 result; - result.bounds = this->bounds+1; - result.elements = this->elements + this->bounds[1] * this->bounds[2] * d0; - result.partial = true; - return result; - } - -template Dynamic_Array3 Dynamic_Array4::operator[](int d0) - { -#if !defined (NDEBUG) - assert(this->elements != 0 && "Trying to dereference undefined array"); - assert(0 <= d0 && d0 < this->bounds[0] && "Array subscript out of bounds"); -#endif - - Dynamic_Array3 result; - result.bounds = this->bounds+1; - result.elements = this->elements + this->bounds[1] * this->bounds[2] * this->bounds[3] * d0; - result.partial = true; - return result; - } - - -template - Dynamic_Array::Dynamic_Array(Dynamic_Array &D) - { - assert(D.elements != 0 && "Trying to copy an undefined array"); - partial = true; - bounds = D.bounds; - elements = D.elements; - } - -} // namespace diff --git a/omegalib/basic/include/basic/Dynamic_Array.h b/omegalib/basic/include/basic/Dynamic_Array.h deleted file mode 100644 index c0bdf12..0000000 --- a/omegalib/basic/include/basic/Dynamic_Array.h +++ /dev/null @@ -1,103 +0,0 @@ -#ifndef Already_Included_Dynamic_Array -#define Already_Included_Dynamic_Array - -namespace omega { - -template class Dynamic_Array2; -template class Dynamic_Array3; -template class Dynamic_Array4; - -template class Dynamic_Array - { - public: - Dynamic_Array(Dynamic_Array &D); - ~Dynamic_Array(); - - protected: - Dynamic_Array(); - bool partial; - int *bounds; - T *elements; - - void do_constr(); - void do_destruct(); - }; - - -template class Dynamic_Array1 : public Dynamic_Array - { - public: - Dynamic_Array1(const char *s0 = 0); - Dynamic_Array1(int d0); - void resize(int d0); - T& operator[](int d); - - friend class Dynamic_Array2; - - private: - void do_construct(int d0); - }; - - -template class Dynamic_Array2 : public Dynamic_Array - { - public: - Dynamic_Array2(const char *s0 = 0, const char *s1 = 0); - Dynamic_Array2(int d0, int d1); - void resize(int d0, int d1); - Dynamic_Array1 operator[](int d); - - friend class Dynamic_Array3; - - private: - void do_construct(int d0, int d1); - }; - - -template class Dynamic_Array3 : public Dynamic_Array - { - public: - Dynamic_Array3(const char *s0 = 0, const char *s1 = 0, const char *s2 = 0); - Dynamic_Array3(int d0, int d1, int d2); - void resize(int d0, int d1, int d2); - Dynamic_Array2 operator[](int d); - - friend class Dynamic_Array4; - - private: - void do_construct(int d0, int d1, int d2); - }; - -template class Dynamic_Array4 : public Dynamic_Array - { - public: - Dynamic_Array4(const char *s0 = 0, const char *s1 = 0, const char *s2 = 0, const char *s3 = 0); - Dynamic_Array4(int d0, int d1, int d2, int d3); - void resize(int d0, int d1, int d2, int d3); - Dynamic_Array3 operator[](int d); - - private: - void do_construct(int d0, int d1, int d2, int d3); - }; - -} // namespace - -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include -#endif - -#define instantiate_Dynamic_Array1(T) template class Dynamic_Array1; \ - template class Dynamic_Array; - -#define instantiate_Dynamic_Array2(T) template class Dynamic_Array2; \ - template class Dynamic_Array; \ - instantiate_Dynamic_Array1(T); - -#define instantiate_Dynamic_Array3(T) template class Dynamic_Array3; \ - template class Dynamic_Array; \ - instantiate_Dynamic_Array2(T); - -#define instantiate_Dynamic_Array4(T) template class Dynamic_Array4; \ - template class Dynamic_Array; \ - instantiate_Dynamic_Array3(T); -#endif diff --git a/omegalib/basic/include/basic/Iterator.h b/omegalib/basic/include/basic/Iterator.h deleted file mode 100644 index 8975d9e..0000000 --- a/omegalib/basic/include/basic/Iterator.h +++ /dev/null @@ -1,131 +0,0 @@ -/* - * Base classes for iterators, generators - * - * These don't really work yet for constant collections. - * I'm not sure how to make that happen. - */ - -#if ! defined _Iterator_h -#define _Iterator_h 1 - -#include - -namespace omega { - -#define foreach(x,T,S,A) do {for (omega::Any_Iterator __P_##x = (S).any_iterator();__P_##x;__P_##x++) {T & x = *__P_##x; A;}} while (0) - -#define foreachSeparated(x,T,S,A,B) do {for (omega::Any_Iterator __P_##x = (S).any_iterator();__P_##x;) {T & x = *__P_##x; A; __P_##x++; if (__P_##x) B;}} while (0) - -/* - * Abstract base class Iterator - * Supports two styles of iteration: - * - * for ( ... initialize i (typically i = collection) ... ; i ; i++ ) - * operate_on(*i) - * - * or - * - * for ( ... initialize i ... ; i.live() ; i.next() ) - * operate_on(i.curr()) - * - * >>> IF THE COLLECTION IS CHANGED, THE ITERATOR IS NO LONGER VALID <<< - * - * For collections that are not "Sequence"s, the order in - * which the elements are returned may not be consistent. - */ - -template class Iterator { -public: - virtual const T & operator*() const = 0; - virtual T & operator*() = 0; - - virtual void operator++(int) = 0; - virtual void operator++() = 0; - - virtual bool live() const = 0; - operator bool() const { return live(); } - - const T & curr() const { return *(*this); } - T & curr() { return *(*this); } - void next() { (*this)++; } - - virtual Iterator *new_copy() const = 0; - virtual ~Iterator() {} -}; - - -// A generator is like an iterator but it gives out values, -// which may or may not exist in some writable collection - -template class Generator { -public: - virtual T operator*() const = 0; - - virtual void operator++(int) = 0; - virtual void operator++() = 0; - - virtual int live() const = 0; - operator int() const { return live(); } - - const T curr() const { return *(*this); } - T curr() { return *(*this); } - void next() { (*this)++; } -}; - - - -// Delegate to any kind of iterator (on the heap) -// If created via a reference, become a copy of the iterator -// If created via a pointer, manipulate that pointer and free *p when this dies -// -// Mostly useful for Collection::iterator -// Iterator::Iterator(Collection) - - -template class Any_Iterator : public Iterator { -public: - Any_Iterator(Collection &c); - Any_Iterator(const Iterator &i); // copy of i - - virtual ~Any_Iterator() { delete me; } - - Any_Iterator &operator=(const Any_Iterator &rhs) - { delete me; me = rhs.me->new_copy(); return *this; } - - const T & operator*() const { return *(*me); } - T & operator*() { return *(*me); } - void operator++(int) { (*me)++; } - void operator++() { ++(*me); } - bool live() const { return (*me).live(); } - - Iterator *new_copy() const { return new Any_Iterator((*me).new_copy()); } - -private: - Any_Iterator(Iterator *p) // take over *p, *p MUST BE ON THE HEAP - { me = p; } - friend class Collection; -#if 0 - // Couldn't make this work with g++258 - friend Any_Iterator Collection::any_iterator(); -#endif - Iterator *me; -}; - -template inline Any_Iterator::Any_Iterator(Collection &c) - { - me = c.new_iterator(); - } - -template inline Any_Iterator::Any_Iterator(const Iterator &i) - { - me = i.new_copy(); - } - -} // namespace - -#define instantiate_Iterator(T) template class Iterator; -#define instantiate_Generator(T) template class Generator; -#define instantiate_Any_Iterator(T) template class Any_Iterator; \ - instantiate_Iterator(T) - -#endif diff --git a/omegalib/basic/include/basic/Link.h b/omegalib/basic/include/basic/Link.h deleted file mode 100644 index ede7a2b..0000000 --- a/omegalib/basic/include/basic/Link.h +++ /dev/null @@ -1,98 +0,0 @@ -#if ! defined _Link_h -#define _Link_h 1 - -#include -#include - -namespace omega { - -// By default, if ndebug is not set, do not do free list - -#if ! defined ListElementFreeList -#if ! defined NDEBUG || defined ASSERTIONS_ANYWAY -#define ListElementFreeList 0 -#else -#define ListElementFreeList 1 -#endif -#endif - -/* - List_Element: one item in a list and the pointer to the next. - Each such object should be pointed to by either exactly one - other List_Element or by some other pointer(s), exactly one - of which will delete the List_Element. - ListElements should ONLY be allocated on the heap. - */ - -#if ListElementFreeList - // g++ 2.5.8 does not allow static data in template classes, so... - extern void *kludgy_List_Element_new(size_t size); - extern void kludgy_List_Element_delete(void *ptr, size_t size); -#endif - -template class List_Element { -public: -#if ListElementFreeList - void *operator new(size_t size) - { - return kludgy_List_Element_new(size); - } - void operator delete(void *ptr, size_t size) - { - kludgy_List_Element_delete(ptr, size); - } -#endif - - T head; - List_Element *tail; - - List_Element() { - tail = 0; - } - List_Element(T h, List_Element * t) { - head = h; - tail = t; - } - List_Element(const List_Element & L) { - head = L.head; - if (L.tail) tail = new List_Element(*L.tail); - else tail = 0; - } - List_Element & operator=(const List_Element &L) { - if (this != &L) { - head = L.head; - if (tail) delete tail; - if (L.tail) tail = new List_Element(*L.tail); - else tail = 0; - } - return *this; - } - virtual ~List_Element() { // virtual ensures 2nd arg of delete is right - delete tail; - } -}; - - - -template class List_Element_Iterator : public Iterator { -public: - List_Element_Iterator(List_Element* j) { i = j; } - virtual const T & operator*() const { return i->head; } - virtual T & operator*() { return i->head; } - virtual void operator++(int) { i = i->tail; } - virtual void operator++() { i = i->tail; } - virtual bool live() const { return i != 0; } - Iterator * new_copy() const { return new List_Element_Iterator(i);} - -protected: - List_Element *i; -}; - -} // namespace - -#define instantiate_Only_List_Element(T) template class List_Element; \ - template class List_Element_Iterator; -#define instantiate_List_Element(T) instantiate_Only_List_Element(T)\ - instantiate_Collection(T) - -#endif diff --git a/omegalib/basic/include/basic/List.c b/omegalib/basic/include/basic/List.c deleted file mode 100644 index f05e0de..0000000 --- a/omegalib/basic/include/basic/List.c +++ /dev/null @@ -1,149 +0,0 @@ -#include - -namespace omega { - -template List_Iterator::List_Iterator(List &l) -: List_Element_Iterator(l.contents) {} - -template List_Iterator::List_Iterator(const List &l) -: List_Element_Iterator(l.contents) {} - -template List_Iterator::List_Iterator() -: List_Element_Iterator(0) {} - -template Iterator *List::new_iterator() -{ - return new List_Iterator(*this); -} - -template const T &List::operator[](int i) const -{ - assert(i > 0 && "Subscript out of bounds"); - List_Iterator p(*this); - - while(--i > 0 && p) - p++; - - if (p) - return *p; - else - return *((T *)0); -} - -template T &List::operator[](int i) -{ - assert(i > 0 && "Subscript out of bounds"); - List_Iterator p(*this); - - while(--i > 0 && p) - p++; - - if (p) - return *p; - else - return *((T *)0); -} - -template int List::index(const T &item) const -{ - List_Iterator p(*this); - int i = 1; - - while(p && *p != item) - { - p++; - i++; - } - - if (p) - return i; - else - return 0; -} - -template int List::size() const - { - int i = 0; - List_Element * p = contents; - while (p) - { - p = p->tail; - i++; - } - return i; - } - -template T &List::front() const - { - return contents->head; - } - -template T List::remove_front() - { - List_Element *frunt = contents; - contents = contents->tail; - T fruntT = frunt->head; - frunt->tail = 0; - delete frunt; - return fruntT; - } - -template void List::prepend(const T &item) - { - contents = new List_Element(item, contents); - } - - -template void List::append(const T &item) - { - *(end()) = new List_Element(item, 0); - } - -template void List::ins_after(List_Iterator i, - const T &item) - { -#if ! defined NDEBUG - for (List_Element *e = contents; e != &(i.element()); e=e->tail) - { - assert(e); - } -#endif - i.element().tail = new List_Element(item, i.element().tail); - } - -template void List::del_front() - { - List_Element *e = contents; - contents = contents->tail; - e->tail = 0; - delete e; - } - -template void List::del_after(List_Iterator i) - { -#if ! defined NDEBUG - for (List_Element *e0 = contents; e0 != &(i.element()); e0=e0->tail) - { - assert(e0); - } -#endif - List_Element *e = i.element().tail; - i.element().tail = e->tail; - e->tail = 0; - delete e; - } - -template void List::clear() - { - delete contents; - contents = 0; - } - -template void List::join(List &consumed) - { - List_Element *e = consumed.contents; - consumed.contents = 0; - *(end()) = e; - } - -} // namespace diff --git a/omegalib/basic/include/basic/List.h b/omegalib/basic/include/basic/List.h deleted file mode 100644 index c6fc062..0000000 --- a/omegalib/basic/include/basic/List.h +++ /dev/null @@ -1,95 +0,0 @@ -#if ! defined _List_h -#define _List_h 1 - -/* - * Linked lists with an interface like a bit of libg++'s SLList class - */ - - -#if 0 -#include /* List requires assert which needs Exit which */ -#endif /* needs List! just include assert in List.c */ -#include // for NULL -#include -#include -#include - -namespace omega { - -template class List_Iterator; - -// -// indexing of Lists starts at 1, index == 0 means not there -// - -template class List : public Sequence { -public: - List(const List &l) - { contents = l.contents ? new List_Element(*l.contents) : 0; } - List() { contents = 0; } - virtual ~List() { delete contents; } - - Iterator *new_iterator(); - const T &operator[](int) const; - T &operator[](int); - - int index(const T &) const; - - int size() const; - int length() const { return size(); } - bool empty() const { return size() == 0; } - - T &front() const; - -// insertion/deletion on a list invalidates any iterators -// that are on/after the element added/removed - - T remove_front(); - - void prepend(const T &item); - void append(const T &item); - void ins_after(List_Iterator i, const T &item); - - void del_front(); - void del_after(List_Iterator i); - void clear(); - - void join(List &consumed); - -private: - friend class List_Iterator; - List_Element **end() - { - List_Element **e = &contents; - while (*e) - e = &((*e)->tail); - return e; - } - - List_Element *contents; -}; - - -template class List_Iterator : public List_Element_Iterator { -public: - List_Iterator(List &l); - List_Iterator(const List &l); - List_Iterator(); -private: - List_Element &element() { return *List_Element_Iterator::i; } ; - friend class List; -}; - -} // namespace - -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include -#endif - -#define instantiate_List(T) template class List; \ - template class List_Iterator; \ - instantiate_Only_List_Element(T) \ - instantiate_Sequence(T) - - -#endif diff --git a/omegalib/basic/include/basic/Map.c b/omegalib/basic/include/basic/Map.c deleted file mode 100644 index 69cc3f7..0000000 --- a/omegalib/basic/include/basic/Map.c +++ /dev/null @@ -1,63 +0,0 @@ -namespace omega { - -template MapElement:: MapElement(const MapElement& M) { - if (M.tail) tail = new MapElement(*M.tail); - else tail = 0; - k = M.k; - v = M.v; - } - -template MapElement & - MapElement:: operator=(const MapElement& M) { - if (this != &M) { - if (tail) delete tail; - if (M.tail) tail = new MapElement(*M.tail); - else tail = 0; - k = M.k; - v = M.v; - } - return *this; - } - - - - -#if ! defined linux -template Map ::Map(const V &default_value) -#else -template Map ::Map(V default_value) -#endif - : _default_value(default_value) - { - contents = 0; - } - -template Map ::~Map() - { - delete contents; - } - -template V Map::operator()(K k) const { - MapElement * P = contents; - while (P) { - if (P->k == k) return P->v; - P = P->tail; - }; - return _default_value; - } - -template V & Map::operator[](K k) { - MapElement * P = contents; - while (P) { - if (P->k == k) return P->v; - P = P->tail; - }; - P = new MapElement ; - P->k = k; - P->v = _default_value; - P->tail = contents; - contents = P; - return P->v; - } - -} // namespace diff --git a/omegalib/basic/include/basic/Map.h b/omegalib/basic/include/basic/Map.h deleted file mode 100644 index f94a10c..0000000 --- a/omegalib/basic/include/basic/Map.h +++ /dev/null @@ -1,68 +0,0 @@ -#if ! defined _Map_h -#define _Map_h 1 - -#include -#include // for NULL - -namespace omega { - -#define foreach_map(k,K,v,V,M,A) {for (omega::MapElementIterator __M_##k = (M).iterator();__M_##k;__M_##k++) {K & k = *__M_##k; V & v = __M_##k.value(); A;}} - -template class MapElement { -public: - K k; - V v; - MapElement *tail; - MapElement(const MapElement&); - MapElement() {} - MapElement & operator=(const MapElement&); - ~MapElement() { delete tail; } -}; - -template class MapElementIterator { -public: - MapElementIterator(MapElement* j) { i = j;} - virtual const K & operator*() const { return i->k; } - virtual K & operator*() { return i->k;} - virtual const V & value() const { return i->v; } - virtual V & value() { return i->v; } - virtual void operator++(int) { i = i->tail; } - virtual void operator++() { i = i->tail; } - virtual bool live() const { return i != NULL; } - operator bool() const { return live(); } -protected: -MapElement *i; -}; - -template class Map { -public: -#if ! defined linux - Map(const V &default_value); -#else - // work around for '386 g++ on Linux - Map(V default_value); -#endif - ~Map(); - MapElementIterator iterator() - {return MapElementIterator(contents);} - int empty() const {return contents == NULL;} - V operator()(K) const; - V& operator[](K); -private: - MapElement * contents; - V _default_value; -}; - -} // namespace - -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include -#endif - -#define instantiate_Map(T1,T2) template class Map; \ - template class MapElement; \ - template class MapElementIterator; -#define instantiate_MapElement(T1,T2) instantiate_Map(T1,T2) -#define instantiate_MapElementIterator(T1,T2) instantiate_Map(T1,T2) - -#endif diff --git a/omegalib/basic/include/basic/Section.c b/omegalib/basic/include/basic/Section.c deleted file mode 100644 index 754e002..0000000 --- a/omegalib/basic/include/basic/Section.c +++ /dev/null @@ -1,79 +0,0 @@ -#include - -namespace omega { - -template Section::Section(Sequence *s, int start, int length) - { - assert(s->size() >= start-1 + length); - it = s; - _start = start; - _length = length; - } - -template Iterator *Section::new_iterator() - { - return new Section_Iterator(*this); - } - -template const T &Section::operator[](int i) const - { - assert(1 <= i && i <= size()); - return (*it)[i+(_start-1)]; - } - -template T &Section::operator[](int i) - { - assert(1 <= i && i <= size()); - return (*it)[i+(_start-1)]; - } - -template int Section::index(const T &var) const - { - int i; - for (i=1; i<=size(); i++) - if ((*this)[i] == var) - return i; - return 0; - } - -template int Section::size() const - { - return _length; - } - - -template Section_Iterator::Section_Iterator(Section &sec) - { - it = sec.it->new_iterator(); - for (int i = 1; i < sec._start; i++) - (*it)++; - remaining = sec.size(); - } - - -template Section_Iterator::Section_Iterator(const Section_Iterator &si) : it(si.it), remaining(si.remaining) {} - - -template void Section_Iterator::operator++() - { this->operator++(0); } - -template void Section_Iterator::operator++(int) - { - if (remaining > 0) - { - (*it)++; - remaining--; - } - } - -template bool Section_Iterator::live() const - { - return (remaining > 0); - } - -template Iterator *Section_Iterator::new_copy() const - { - return new Section_Iterator(*this); - } - -} // namespace diff --git a/omegalib/basic/include/basic/Section.h b/omegalib/basic/include/basic/Section.h deleted file mode 100644 index 60821d1..0000000 --- a/omegalib/basic/include/basic/Section.h +++ /dev/null @@ -1,63 +0,0 @@ -#if ! defined _Section_h -#define _Section_h 1 -/* - Section of an existing collection viewed as a collection - */ - -#include - -namespace omega { - -template class Section_Iterator; - -template class Section : public Sequence { -public: - Section(Sequence *, int start, int length); - - Iterator *new_iterator(); - - const T &operator[](int) const; - T &operator[](int); - - int index(const T &) const; - int size() const; - - friend class Section_Iterator; - -private: - Sequence *it; - int _start, _length; -}; - -template class Section_Iterator : public Iterator { -public: - Section_Iterator(Section &sec); - virtual ~Section_Iterator() { delete it; } - - const T & operator*() const { return *(*it); } - T & operator*() { return *(*it); } - - void operator++(int); - void operator++(); - - bool live() const; - Iterator *new_copy() const; - -private: - Section_Iterator(const Section_Iterator &si); - Iterator *it; - int remaining; -}; - -} // namespace - -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include -#endif - -#define instantiate_Section(T) template class Section; \ - template class Section_Iterator; \ - instantiate_Sequence(T) -#define instantiate_Section_Iterator(T) instantiate_Section(T) - -#endif diff --git a/omegalib/basic/include/basic/SimpleList.c b/omegalib/basic/include/basic/SimpleList.c deleted file mode 100644 index da7de9b..0000000 --- a/omegalib/basic/include/basic/SimpleList.c +++ /dev/null @@ -1,105 +0,0 @@ -namespace omega { - -template Simple_List_Iterator::Simple_List_Iterator(Simple_List &l) -: List_Element_Iterator(l.contents) {} - -template Simple_List_Iterator::Simple_List_Iterator(const Simple_List &l) -: List_Element_Iterator(l.contents) {} - -template Simple_List_Iterator::Simple_List_Iterator() -: List_Element_Iterator(0) {} - -template Iterator *Simple_List::new_iterator() -{ - return new Simple_List_Iterator(*this); -} - -template const T &Simple_List::operator[](int i) const -{ - Simple_List_Iterator p(*this); - - while(--i > 0 && p) - p++; - - if (p) - return *p; - else - return *((T *)0); -} - -template T &Simple_List::operator[](int i) -{ - Simple_List_Iterator p(*this); - - while(--i > 0 && p) - p++; - - if (p) - return *p; - else - return *((T *)0); -} - - -template int Simple_List::size() const - { - int i = 0; - List_Element * p = contents; - while (p) - { - p = p->tail; - i++; - } - return i; - } - -template T &Simple_List::front() const - { - return contents->head; - } - -template T Simple_List::remove_front() - { - List_Element *frunt = contents; - contents = contents->tail; - T fruntT = frunt->head; - frunt->tail = 0; - delete frunt; - return fruntT; - } - -template void Simple_List::prepend(const T &item) - { - contents = new List_Element(item, contents); - } - - -template void Simple_List::append(const T &item) - { - *(end()) = new List_Element(item, 0); - } - - -template void Simple_List::del_front() - { - List_Element *e = contents; - contents = contents->tail; - e->tail = 0; - delete e; - } - - -template void Simple_List::clear() - { - delete contents; - contents = 0; - } - -template void Simple_List::join(Simple_List &consumed) - { - List_Element *e = consumed.contents; - consumed.contents = 0; - *(end()) = e; - } - -} // namespace diff --git a/omegalib/basic/include/basic/SimpleList.h b/omegalib/basic/include/basic/SimpleList.h deleted file mode 100644 index a08b307..0000000 --- a/omegalib/basic/include/basic/SimpleList.h +++ /dev/null @@ -1,93 +0,0 @@ -#if ! defined _Simple_List_h -#define _Simple_List_h 1 - -/* - * Linked lists with an interface like a bit of libg++'s SLSimple_List class - */ - -#include -#include -#include -#include - -namespace omega { - -#define Simple_List Omega_Simple_List -#define Simple_List_Iterator Omega_Simple_List_Iterator - -template class Simple_List_Iterator; - -// A TEMPORARY HACK - ERROR IF YOU TRY TO USE "INDEX" - FERD - -template class Simple_List : public Sequence { -public: - Simple_List(const Simple_List &l) - { contents = l.contents ? new List_Element(*l.contents) : 0; } - Simple_List() { contents = 0; } - virtual ~Simple_List() { delete contents; } - - Iterator *new_iterator(); - const T &operator[](int) const; - T &operator[](int); - - - int size() const; - int length() const { return size(); } - int empty() const { return size() == 0; } - - T &front() const; - -// insertion/deletion on a list invalidates any iterators -// that are on/after the element added/removed - - T remove_front(); - - void prepend(const T &item); - void append(const T &item); - - void del_front(); - void clear(); - - void join(Simple_List &consumed); - - int index(const T &) const { - assert(0&&"ILLEGAL SimpleList operation\n"); - return -1; - } - -private: - friend class Simple_List_Iterator; - List_Element **end() - { - List_Element **e = &contents; - while (*e) - e = &((*e)->tail); - return e; - } - - List_Element *contents; -}; - - -template class Simple_List_Iterator : public List_Element_Iterator { -public: - Simple_List_Iterator(Simple_List &l); - Simple_List_Iterator(const Simple_List &l); - Simple_List_Iterator(); -private: - List_Element &element() { return *this->i; } ; - friend class Simple_List; -}; - -} // namespace - -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include -#endif - -#define instantiate_Simple_List(T) template class Simple_List; \ - template class Simple_List_Iterator; \ - instantiate_Only_List_Element(T) \ - instantiate_Sequence(T) - -#endif diff --git a/omegalib/basic/include/basic/Tuple.c b/omegalib/basic/include/basic/Tuple.c deleted file mode 100644 index ce99e82..0000000 --- a/omegalib/basic/include/basic/Tuple.c +++ /dev/null @@ -1,254 +0,0 @@ -/* class Tuple */ - -// THESE FIRST TWO REALLY SHOULD BE INLINE BUT IT BREAKS CFRONT: - -namespace omega { - -template T &Tuple::operator[](int index) - { - assert(1 <= index && index <= sz); return data[index-1]; - } - -template const T &Tuple::operator[](int index) const - { - assert(1 <= index && index <= sz); return data[index-1]; - } - - -template Tuple::~Tuple() - { - if (data) - delete [] data; - } - -template Tuple::Tuple() : sz(0), alloc_sz(0), - prealloc_min(20),prealloc_pad(5), data(0) -{ - // nothing needs be done - } - -template Tuple::Tuple(int size) : sz(size), - prealloc_min(20),prealloc_pad(5) -{ - if (sz > 0) - { - alloc_sz = prealloc_size(sz); - data = new T[alloc_sz]; - assert(alloc_sz >= sz); - //Need some handling for out of memory. - assert (data!=0); - } - else { - alloc_sz = 0; - data = 0; - } -} - - -template Tuple::Tuple(const Tuple& t) - : sz(t.sz), alloc_sz(t.alloc_sz), prealloc_min(20),prealloc_pad(5) -{ - if (sz > 0) { - data = new T[alloc_sz]; - assert (data!=0); - assert (alloc_sz >= sz); - for (int i=0; i Tuple& Tuple::operator=(const Tuple& t) -{ - if (this != &t) { // Delete this - if (data) - delete [] data; - sz = t.sz; - alloc_sz = t.alloc_sz; - assert(alloc_sz >= sz); - if (sz > 0) { // Copy old - data = new T[alloc_sz]; - assert (data!=0); - for (int i=0; i void Tuple::reallocate(const int req_size) -{ - if (alloc_sz >= req_size) { // if (sz >= req_size), does this. - sz = req_size; - return; - } - alloc_sz = prealloc_size(req_size); - T* tmp_data = new T[alloc_sz]; - for(int i=0;i= req_size); -} - -template void Tuple::delete_last() -{ -assert(sz > 0); -sz --; -} - -template void Tuple::append(const T &v) -{ - // Check if reallocation is necessary. - if (sz == 0) { // Empty Tuple - assert(alloc_sz >= 0); // May be nonzero for cleared tuple - - if(alloc_sz == 0) { // If it's > 1 no allocation is necessary - alloc_sz = prealloc_size(1); - data = new T[alloc_sz]; - } - assert (alloc_sz > 0 && data != 0); - } else { - if(sz == alloc_sz) { // Requires new allocation - alloc_sz = realloc_size(alloc_sz); - T * data_tmp = new T[alloc_sz]; - assert (data_tmp!=0); - assert (alloc_sz > sz); - for (int i=0; i= sz); - data[sz++] = v; -} - -template void Tuple::append(const Tuple& t) { - int old_sz = sz; - reallocate(t.size()+size()); - assert(alloc_sz >= sz); - for(int i=0; i void Tuple::join(Tuple& t) { - int old_sz = sz; - reallocate(t.size()+size()); - assert(alloc_sz >= sz); - for(int i=0; i void Tuple::clear() { if (sz) delete [] data; data = 0; alloc_sz = 0; sz = 0; } - -template int Tuple::empty() const { return (sz == 0); } - -template Iterator *Tuple::new_iterator() -{ - return new Tuple_Iterator(*this); -} - -template int Tuple::index(const T & var) const -/* returns index or 0 if var isn't in the tuple */ -{ - int i; - for (i=0; i bool Tuple::operator == (const Tuple& b) const -{ - int i; - if (sz != b.size()) return false; - for (i=0; i Tuple_Iterator::Tuple_Iterator(const Tuple &tpl) : -current(tpl.data), lastptr(tpl.data+tpl.sz-1), firstptr(tpl.data), sz(tpl.sz) -{ -} - -template Tuple_Iterator::Tuple_Iterator(T * cr, T *frst, T * lst, - int insz) - : current(cr), lastptr(lst), firstptr(frst), sz(insz) -{ -} - -template const T & Tuple_Iterator::operator*() const -{ - assert (current<=lastptr && current>=firstptr); - return *current; -} - -template T & Tuple_Iterator::operator*() -{ - assert (current<=lastptr && current >=firstptr); - return *current; -} - -template void Tuple_Iterator::operator++(int) -{ - current++; -} - -template void Tuple_Iterator::operator++() -{ - current++; -} - -template void Tuple_Iterator::operator--(int) -{ - current--; -} - -template void Tuple_Iterator::operator--() -{ - current--; -} - -template void Tuple_Iterator::set_to_last() -{ - current = lastptr; -} - -template void Tuple_Iterator::set_to_first() -{ - current = firstptr; -} - -template void Tuple_Iterator::set_position(const int req_pos) -{ - assert(req_pos <= sz && 1 <= req_pos); - current = firstptr + (req_pos - 1); -} - - -template bool Tuple_Iterator::live() const -{ - return (current !=0 && current<=lastptr && current >= firstptr); -} - -template Iterator *Tuple_Iterator::new_copy() const { - return new Tuple_Iterator(current, firstptr, lastptr, sz); -} - -} // namespace diff --git a/omegalib/basic/include/basic/Tuple.h b/omegalib/basic/include/basic/Tuple.h deleted file mode 100644 index 28e83bd..0000000 --- a/omegalib/basic/include/basic/Tuple.h +++ /dev/null @@ -1,90 +0,0 @@ -#if !defined _Already_defined_tuple -#define _Already_defined_tuple - -#include - -#include -#include -#include - -namespace omega { - -template class Tuple_Iterator; - -// TUPLES ARE INDEXED STARTING AT 1 -// index\(i\) == 0 MEANS i IS NOT IN THE TUPLE - -template class Tuple : public Sequence { -public: - Tuple(); - Tuple(int size); - Tuple (const Tuple& tpl); - virtual ~Tuple(); - Tuple& operator=(const Tuple& tpl); - int size() const { return sz; } - int length() const { return sz; } - bool operator==(const Tuple &b) const; - void reallocate(const int); - void delete_last(); - void append(const Tuple &v); - void append(const T &v); - void join(Tuple &v); - void clear(); - int empty() const; - - Iterator *new_iterator(); - - virtual T &operator[](int index); - virtual const T &operator[](int index) const; - - int index(const T &) const; - - friend class Tuple_Iterator; - -private: - int prealloc_size(const int req_size) - { return max(req_size+prealloc_pad,prealloc_min); } - int realloc_size(const int oldsize) { return 2*oldsize; } - - - int sz, alloc_sz; // Number of elements, size of allocated array - int prealloc_min,prealloc_pad; // These should be static, but that - // causes portability prob. for initialization - -protected: - T * data; -}; - -template class Tuple_Iterator : public Iterator { -public: - Tuple_Iterator(const Tuple &tpl); - const T & operator*() const; - T & operator*(); - void set_position(const int req_pos); - void operator++(int); - void operator++(); - void operator--(int); - void operator--(); - void set_to_last(); - void set_to_first(); -// void set_position(const int req_pos); Don't do this, compiler bug - bool live() const; - Iterator *new_copy() const; - -private: - Tuple_Iterator(T * cr, T * frst, T *lst, int insz); - T * current, * lastptr, *firstptr; - int sz; -}; - -} // namespace - -#if ! defined DONT_INCLUDE_TEMPLATE_CODE -#include -#endif - -#define instantiate_Tuple(T) template class Tuple; \ - template class Tuple_Iterator; \ - instantiate_Sequence(T) - -#endif diff --git a/omegalib/basic/include/basic/boolset-test.cc b/omegalib/basic/include/basic/boolset-test.cc deleted file mode 100755 index 5b68220..0000000 --- a/omegalib/basic/include/basic/boolset-test.cc +++ /dev/null @@ -1,72 +0,0 @@ -#include "boolset.h" -#include - -using namespace omega; - -void foo(const BoolSet<> &B) { - for (BoolSet<>::const_iterator i = B.begin(); i != B.end(); i++) - std::cout << *i << ' '; - std::cout << std::endl; -} - -int main() { - BoolSet<> A(13); - - A.set(2); - std::cout << A << std::endl; - - A.set_all(); - std::cout << A << std::endl; - - A.unset_all(); - std::cout << A << std::endl; - - A.set(2); - A.set(4); - - BoolSet<> B(13); - B.set(2); - - std::cout << "A: " << A << std::endl; - std::cout << "B: " << B << std::endl; - - std::cout << A.imply(B) << std::endl; - std::cout << B.imply(A) << std::endl; - - B.set(10); - std::cout << (A|B) << std::endl; - std::cout << (A&B) << std::endl; - - BoolSet<> C(3); - C.set(0); - std::cout << (A|C) << std::endl; - std::cout << ~(A|C) << std::endl; - - B = BoolSet<>(23); - std::cout << "test iterator\n"; - B.set(12); - B.set(11); - B.set(0); - std::cout << B << std::endl; - for (BoolSet<>::const_iterator i = B.begin(); i != B.end(); i++) { - std::cout << *i << ' '; - if (*i == 11) - B.unset(*i); - } - std::cout << std::endl; - std::cout << B << std::endl; - std::cout << std::endl; - foo(B); - - std::cout << ~BoolSet<>(5) << std::endl; - - std::cout << "------\n"; - B.dump(); - std::cout << std::endl << *(B.begin()+1) << std::endl; - - for (BoolSet<>::iterator i = B.begin(); i != B.end(); i++) - for (BoolSet<>::iterator j = i; j != B.end(); j++) - if (j == i) - std::cout << "ehh-"; - -} diff --git a/omegalib/basic/include/basic/boolset.h b/omegalib/basic/include/basic/boolset.h deleted file mode 100755 index dc9ef83..0000000 --- a/omegalib/basic/include/basic/boolset.h +++ /dev/null @@ -1,637 +0,0 @@ -/***************************************************************************** - Copyright (C) 2009-2011 Chun Chen - All Rights Reserved. - - Purpose: - BoolSet class, used as a set of integers from 0..n-1 where n is a very - small integer. - - Notes: - Set operands of binary operations can be of different sizes, missing - elements are treated as false. - - History: - 03/30/09 Created by Chun Chen. - 03/26/11 iterator added, -chun -*****************************************************************************/ - -#ifndef _BOOLSET_H -#define _BOOLSET_H - -#include -#include -#include -#include -#include - -namespace omega { - -template -class BoolSet { -protected: - unsigned int size_; - std::vector set_; - -public: - BoolSet(unsigned int size = 0); - ~BoolSet() {} - - void set(unsigned int); - void unset(unsigned int); - void set_all(); - void unset_all(); - bool get(unsigned int) const; - unsigned int size() const {return size_;} - unsigned int num_elem() const; - bool imply(const BoolSet &) const; - bool empty() const; - void dump() const; - - BoolSet &operator|=(const BoolSet &); - BoolSet &operator&=(const BoolSet &); - BoolSet &operator-=(const BoolSet &); - - template friend BoolSet operator|(const BoolSet &, const BoolSet &); // union - template friend BoolSet operator&(const BoolSet &, const BoolSet &); // intersection - template friend BoolSet operator-(const BoolSet &, const BoolSet &); // difference - template friend BoolSet operator~(const BoolSet &); // complement - template friend bool operator==(const BoolSet &, const BoolSet &); - template friend bool operator!=(const BoolSet &, const BoolSet &); - template friend std::ostream& operator<<(std::ostream &, const BoolSet &); - template friend bool operator<(const BoolSet &, const BoolSet &); - -// iterator related -public: - class iterator; - class const_iterator; - iterator begin(); - iterator end(); - const_iterator begin() const; - const_iterator end() const; -}; - - -template -BoolSet::BoolSet(unsigned int size) { - assert(size >= 0); - size_ = size; - unsigned int n = size / (sizeof(T)*8); - unsigned int r = size % (sizeof(T)*8); - if (r != 0) - n++; - set_ = std::vector(n, static_cast(0)); -} - - -template -void BoolSet::set(unsigned int i) { - assert(i < size_ && i >= 0); - unsigned int n = i / (sizeof(T)*8); - unsigned int r = i % (sizeof(T)*8); - - T t = static_cast(1) << r; - set_[n] |= t; -} - - -template -void BoolSet::unset(unsigned int i) { - assert(i < size_ && i >= 0); - unsigned int n = i / (sizeof(T)*8); - unsigned int r = i % (sizeof(T)*8); - - T t = static_cast(1) << r; - t = ~t; - set_[n] &= t; -} - - -template -void BoolSet::set_all() { - unsigned int r = size_ % (sizeof(T)*8); - if (r == 0) { - for (unsigned int i = 0; i < set_.size(); i++) - set_[i] = ~static_cast(0); - } - else { - for (unsigned int i = 0; i < set_.size()-1; i++) - set_[i] = ~static_cast(0); - set_[set_.size()-1] = static_cast(0); - T t = static_cast(1); - for (unsigned int i = 0; i < r; i++) { - set_[set_.size()-1] |= t; - t = t<<1; - } - } -} - - -template -void BoolSet::unset_all() { - for (unsigned int i = 0; i < set_.size(); i++) - set_[i] = static_cast(0); -} - - -template -bool BoolSet::get(unsigned int i) const { - assert(i < size_ && i >= 0); - unsigned int n = i / (sizeof(T)*8); - unsigned int r = i % (sizeof(T)*8); - - T t = static_cast(1) << r; - t = set_[n] & t; - if (t) - return true; - else - return false; -} - - -template -unsigned int BoolSet::num_elem() const { - unsigned int n = size_; - unsigned int c = 0; - unsigned int p = 0; - while (n != 0) { - unsigned int m; - if (n >= sizeof(T)*8) { - m = sizeof(T)*8; - n -= sizeof(T)*8; - } - else { - m = n; - n = 0; - } - - T v = set_[p++]; - if (v != static_cast(0)) { - for (unsigned int i = 0; i < m; i++) { - if (v & static_cast(1)) - c++; - v >>= 1; - } - } - } - - return c; -} - - -template -bool BoolSet::imply(const BoolSet &b) const { - if (size_ >= b.size_) { - for (unsigned int i = 0; i < b.set_.size(); i++) - if ((set_[i] & b.set_[i]) != b.set_[i]) - return false; - } - else { - for (unsigned int i = 0; i < set_.size(); i++) - if ((set_[i] & b.set_[i]) != b.set_[i]) - return false; - for (unsigned int i = set_.size(); i < b.set_.size(); i++) - if (b.set_[i] != static_cast(0)) - return false; - } - - return true; -} - - -template -bool BoolSet::empty() const { - for (int i = 0; i < set_.size(); i++) - if (set_[i] != static_cast(0)) - return false; - - return true; -} - - -template -void BoolSet::dump() const { - int j = 1; - for (unsigned int i = 0; i < size(); i++) { - if (get(i)) - std::cout << '1'; - else - std::cout << '0'; - if (j%10 == 0 && i != size() - 1) { - std::cout << ' '; - j = 1; - } - else - j++; - } - std::cout << std::endl; - std::cout.flush(); -} - - -template -BoolSet operator|(const BoolSet &a, const BoolSet &b) { - if (a.size_ >= b.size_) { - BoolSet c = a; - for (unsigned int i = 0; i < b.set_.size(); i++) - c.set_[i] |= b.set_[i]; - return c; - } - else { - BoolSet c = b; - for (unsigned int i = 0; i < a.set_.size(); i++) - c.set_[i] |= a.set_[i]; - return c; - } -} - - -template -BoolSet operator&(const BoolSet &a, const BoolSet &b) { - if (a.size_ >= b.size_) { - BoolSet c = a; - for (unsigned int i = 0; i < b.set_.size(); i++) - c.set_[i] &= b.set_[i]; - for (unsigned int i = b.set_.size(); i < a.set_.size(); i++) - c.set_[i] = static_cast(0); - return c; - } - else { - BoolSet c = b; - for (unsigned int i = 0; i < a.set_.size(); i++) - c.set_[i] &= a.set_[i]; - for (unsigned int i = a.set_.size(); i < b.set_.size(); i++) - c.set_[i] = static_cast(0); - return c; - } -} - - -template -BoolSet operator-(const BoolSet &a, const BoolSet &b) { - BoolSet c(a.size_); - - int sz = a.set_.size(); - if (sz > b.set_.size()) - sz = b.set_.size(); - for (int i = 0; i < sz; i++) - c.set_[i] = a.set_[i] ^ (a.set_[i] & b.set_[i]); - for (int i = sz; i < a.set_.size(); i++) - c.set_[i] = a.set_[i]; - - return c; -} - - -template -BoolSet operator~(const BoolSet &b) { - unsigned int r = b.size_ % (sizeof(T)*8); - BoolSet a(b.size_); - for (unsigned int i = 0; i < b.set_.size(); i++) - a.set_[i] = ~b.set_[i]; - - if (r != 0) { - T t = static_cast(1); - for (unsigned int i = 1; i < r; i++) - t = (t << 1) | static_cast(1); - a.set_[a.set_.size()-1] &= t; - } - return a; -} - - -template -bool operator==(const BoolSet &a, const BoolSet &b) { - return (a.size_ == b.size_) && (a.set_ == b.set_); -} - - -template -bool operator!=(const BoolSet &a, const BoolSet &b) { - return !(a == b); -} - - - -template -BoolSet & BoolSet::operator|=(const BoolSet &b) { - *this = *this | b; - return *this; -} - - -template -BoolSet & BoolSet::operator&=(const BoolSet &b) { - *this = *this & b; - return *this; -} - - -template -BoolSet & BoolSet::operator-=(const BoolSet &b) { - *this = *this - b; - return *this; -} - - -template -std::ostream& operator<<(std::ostream &os, const BoolSet &b) { - os << '{'; - for (typename BoolSet::const_iterator i = b.begin(); i != b.end(); i++) { - os << *i; - if (i+1 != b.end()) - os << ','; - } - os << '}'; - - return os; -} - - -template -bool operator<(const BoolSet &a, const BoolSet &b) { - unsigned int t1, t2; - t1 = a.num_elem(); - t2 = b.num_elem(); - if (t1 < t2) - return true; - else if (t1 > t2) - return false; - else { - t1 = a.size(); - t2 = b.size(); - if (t1 < t2) - return true; - else if (t1 > t2) - return false; - else - for (unsigned int i = 0; i < a.set_.size(); i++) - if (a.set_[i] < b.set_[i]) - return true; - } - return false; -} - - -// -// iterator for BoolSet -// - -template -typename BoolSet::iterator BoolSet::begin() { - typename BoolSet::iterator it(this, 0); - if (size_ == 0) - return it; - else if (set_[0] & static_cast(1)) - return it; - else - return ++it; -} - - -template -typename BoolSet::iterator BoolSet::end() { - return typename BoolSet::iterator(this, size_); -} - - -template -typename BoolSet::const_iterator BoolSet::begin() const { - typename BoolSet::const_iterator it(this, 0); - if (size_ == 0) - return it; - else if (set_[0] & static_cast(1)) - return it; - else - return ++it; -} - - -template -typename BoolSet::const_iterator BoolSet::end() const { - return typename BoolSet::const_iterator(this, size_); -} - - -template -class BoolSet::iterator: public std::iterator { -protected: - BoolSet *s_; - unsigned int pos_; - -protected: - iterator(BoolSet *s, unsigned int pos) { s_ = s; pos_ = pos; } - -public: - ~iterator() {} - - typename BoolSet::iterator &operator++(); - typename BoolSet::iterator operator++(int); - typename BoolSet::iterator operator+(int) const; - unsigned int operator*() const; - bool operator==(const BoolSet::iterator &) const; - bool operator!=(const BoolSet::iterator &) const; - operator typename BoolSet::const_iterator(); - - friend class BoolSet; -}; - - -template -typename BoolSet::iterator &BoolSet::iterator::operator++() { - assert(pos_ < s_->size_); - - pos_++; - unsigned int n = pos_ / (sizeof(T)*8); - unsigned int r = pos_ % (sizeof(T)*8); - while (pos_ < s_->size_) { - if (s_->set_[n] == static_cast(0)) { - pos_ += sizeof(T)*8-r; - n++; - r = 0; - if (pos_ >= s_->size_) - break; - } - - if (r == 0) { - while (pos_ < s_->size_) { - if (s_->set_[n] == static_cast(0)) { - pos_ += sizeof(T)*8; - n++; - } - else - break; - } - if (pos_ >= s_->size_) - break; - } - - for (unsigned int i = r; i < sizeof(T)*8; i++) - if (s_->set_[n] & static_cast(1) << i) { - pos_ = pos_+i-r; - return *this; - } - - pos_ += sizeof(T)*8-r; - n++; - r = 0; - } - - pos_ = s_->size_; - return *this; -} - - -template -typename BoolSet::iterator BoolSet::iterator::operator++(int) { - typename BoolSet::iterator it(*this); - ++(*this); - return it; -} - - -template -typename BoolSet::iterator BoolSet::iterator::operator+(int n) const { - assert(n >= 0); - typename BoolSet::iterator it(*this); - while (n > 0) { - ++it; - --n; - } - return it; -} - - -template -unsigned int BoolSet::iterator::operator*() const { - assert(pos_ < s_->size_); - return pos_; -} - - -template -bool BoolSet::iterator::operator==(const BoolSet::iterator &other) const { - return s_ == other.s_ && pos_ == other.pos_; -} - - -template -bool BoolSet::iterator::operator!=(const BoolSet::iterator &other) const { - return !((*this) == other); -} - - -template -BoolSet::iterator::operator typename BoolSet::const_iterator() { - return BoolSet::const_iterator(s_, pos_); -} - - -template -class BoolSet::const_iterator: public std::iterator { -protected: - const BoolSet *s_; - unsigned int pos_; - -protected: - const_iterator(const BoolSet *s, unsigned int pos) { s_ = s; pos_ = pos; } - -public: - ~const_iterator() {} - - typename BoolSet::const_iterator &operator++(); - typename BoolSet::const_iterator operator++(int); - typename BoolSet::const_iterator operator+(int) const; - unsigned int operator*() const; - bool operator==(const BoolSet::const_iterator &) const; - bool operator!=(const BoolSet::const_iterator &) const; - - friend class BoolSet; -}; - - -template -typename BoolSet::const_iterator &BoolSet::const_iterator::operator++() { - assert(pos_ < s_->size_); - - pos_++; - unsigned int n = pos_ / (sizeof(T)*8); - unsigned int r = pos_ % (sizeof(T)*8); - while (pos_ < s_->size_) { - if (s_->set_[n] == static_cast(0)) { - pos_ += sizeof(T)*8-r; - n++; - r = 0; - if (pos_ >= s_->size_) - break; - } - - if (r == 0) { - while (pos_ < s_->size_) { - if (s_->set_[n] == static_cast(0)) { - pos_ += sizeof(T)*8; - n++; - } - else - break; - } - if (pos_ >= s_->size_) - break; - } - - for (unsigned int i = r; i < sizeof(T)*8; i++) - if (s_->set_[n] & static_cast(1) << i) { - pos_ = pos_+i-r; - return *this; - } - - pos_ += sizeof(T)*8-r; - n++; - r = 0; - } - - pos_ = s_->size_; - return *this; -} - - -template -typename BoolSet::const_iterator BoolSet::const_iterator::operator++(int) { - typename BoolSet::const_iterator it(*this); - ++(*this); - return it; -} - - -template -typename BoolSet::const_iterator BoolSet::const_iterator::operator+(int n) const { - assert(n >= 0); - typename BoolSet::const_iterator it(*this); - while (n > 0) { - ++it; - --n; - } - return it; -} - - -template -unsigned int BoolSet::const_iterator::operator*() const { - assert(pos_ < s_->size_); - return pos_; -} - - -template -bool BoolSet::const_iterator::operator==(const BoolSet::const_iterator &other) const { - return s_ == other.s_ && pos_ == other.pos_; -} - - -template -bool BoolSet::const_iterator::operator!=(const BoolSet::const_iterator &other) const { - return !((*this) == other); -} - -} - -#endif diff --git a/omegalib/basic/include/basic/omega_error.h b/omegalib/basic/include/basic/omega_error.h deleted file mode 100644 index e342efb..0000000 --- a/omegalib/basic/include/basic/omega_error.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef OMEGA_ERROR_H -#define OMEGA_ERROR_H - -namespace omega { - -struct presburger_error: public std::runtime_error { - presburger_error(const std::string &msg): std::runtime_error("presburger error: " + msg) {} -}; - - - -} -#endif - diff --git a/omegalib/basic/include/basic/util.h b/omegalib/basic/include/basic/util.h deleted file mode 100644 index 4e807cd..0000000 --- a/omegalib/basic/include/basic/util.h +++ /dev/null @@ -1,263 +0,0 @@ -#if ! defined Already_Included_Util -#define Already_Included_Util - -#include -#include -#include -#include -#include -#include - -namespace omega { - -#define LONG_LONG_COEF 1 - -#if LONG_LONG_COEF -#if defined BOGUS_LONG_DOUBLE_COEF -typedef long double coef_t; // type of coefficients -#define coef_fmt "%llf" -#define posInfinity (1e+24) -#define negInfinity (-1e+24) -#else -#ifdef WIN32 -typedef _int64 coef_t; // type of coefficients -#else -typedef long long coef_t; -#endif -#define coef_fmt "%lld" -#define posInfinity (0x7ffffffffffffffLL) -#define negInfinity (-0x7ffffffffffffffLL) -#endif -#else -typedef int coef_t; // type of coefficients -#define coef_fmt "%d" -#define posInfinity (0x7ffffff) -#define negInfinity (-0x7ffffff) -#endif - - -template inline const T& max(const T &x, const T &y) { - if (x >= y) return x; else return y; -} - - -template inline const T& max(const T &x, const T &y, const T &z) { - return max(x, max(y, z)); -} - -template inline const T& min(const T &x, const T &y) { - if (x <= y) return x; else return y; -} - -template inline const T& min(const T &x, const T &y, const T &z) { - return min(x, min(y, z)); -} - -template inline void set_max(T &m, const T &x) { - if (m < x) m = x; -} - -template inline void set_min(T &m, const T &x) { - if (m > x) m = x; -} - -/* template inline void swap(T &i, T &j) { */ -/* T tmp; */ -/* tmp = i; */ -/* i = j; */ -/* j = tmp; */ -/* } */ - -/* template inline T copy(const T &t) { return t; } */ - - -/* inline coef_t check_pos_mul(coef_t x, coef_t y) { */ -/* if (y >= 48051280 && y < posInfinity) */ -/* fprintf(stderr, "%d %d\n", x, y); */ -/* /\* #if !defined NDEBUG *\/ */ -/* /\* if (x != 0) *\/ */ -/* /\* assert(((MAXINT)/4) / x > y); *\/ */ -/* /\* #elif defined STILL_CHECK_MULT *\/ */ -/* /\* if (x != 0 && !(((MAXINT)/4) / x > y)) { *\/ */ -/* /\* assert(0&&"Integer overflow during multiplication (util.h)"); *\/ */ -/* /\* } *\/ */ -/* /\* #endif *\/ */ -/* #if !defined NDEBUG */ -/* if (x != 0 && y != 0) */ -/* assert(x*y > 0); */ -/* #elif defined STILL_CHECK_MULT */ -/* if (x != 0 && y != 0 && x*y < 0) */ -/* assert(0&&"Integer overflow during multiplication (util.h)"); */ -/* #endif */ -/* return x * y; */ -/* } */ - - -/* inline int */ -/* check_pos_mul(int x, int y) { */ -/* #if !defined NDEBUG */ -/* if (x != 0) */ -/* assert(((posInfinity)/4) / x > y); */ -/* #elif defined STILL_CHECK_MULT */ -/* if (x != 0 && !(((posInfinity)/4) / x > y)) { */ -/* assert(0&&"Integer overflow during multiplication (util.h)"); */ -/* } */ -/* #endif */ -/* return x * y; */ -/* } */ - -/* inline LONGLONG */ -/* check_pos_mul(LONGLONG x, LONGLONG y) { */ -/* #if !defined NDEBUG */ -/* if (x != 0) */ -/* assert(((posInfinity)/4) / x > y); */ -/* #elif defined STILL_CHECK_MULT */ -/* if (x != 0 && !(((posInfinity)/4) / x > y)) { */ -/* assert(0&&"Integer overflow during multiplication (util.h)"); */ -/* } */ -/* #endif */ -/* return x * y; */ -/* } */ - -/* inline LONGLONG abs(LONGLONG c) { return (c>=0?c:(-c)); } */ - -template inline T check_mul(const T &x, const T &y) { -#if defined NDEBUG && ! defined STILL_CHECK_MULT - return x*y; -#else - if (x == 0 || y == 0) - return 0; - - T z = x*y; - int sign_x = (x>0)?1:-1; - int sign_y = (y>0)?1:-1; - int sign_z = (z>0)?1:-1; - - if (sign_x * sign_y != sign_z) - throw std::overflow_error("coefficient multiply overflow"); - - return z; - - /* if (x > 0) { */ - /* if (y > 0) { */ - /* assert(x*y > 0); */ - /* } */ - /* else */ - /* assert(x*y < 0); */ - /* } */ - /* else { */ - /* if (y > 0) */ - /* assert(x*y < 0); */ - /* else */ - /* assert(x*y > 0); */ - /* } */ - /* return x*y; */ -#endif -} - -template inline T abs(const T &v) { - return (v >= static_cast(0))?v:-v; -} - -template inline T int_div(const T &a, const T &b) { - T result; - assert(b > 0); - if (a>0) result = a/b; - else result = -((-a+b-1)/b); - return result; -} - -template inline T int_mod(const T &a, const T &b) { - return a-b*int_div(a,b); -} - -template inline T int_mod_hat(const T &a, const T &b) { - T r; - assert(b > 0); - r = a-b*int_div(a,b); - if (r > -(r-b)) r -= b; - return r; -} - -template inline T gcd(T b, T a) {/* First argument is non-negative */ - assert(a >= 0); - assert(b >= 0); - if (b == 1) - return (1); - while (b != 0) { - T t = b; - b = a % b; - a = t; - } - return (a); -} - -template inline T lcm(T b, T a) { /* First argument is non-negative */ - assert(a >= 0); - assert(b >= 0); - return check_mul(a/gcd(a,b), b); -} - -template T square_root(const T &n, T precision = 1) { - T guess = 1; - - while (true) { - T next_guess = 0.5*(guess+n/guess); - if (abs(next_guess-guess) <= precision) - return next_guess; - else - guess = next_guess; - } -} - -template T factor(const T &n) { - assert(n >= 0); - if (n == 1) return 1; - - static int prime[30] = {2, 3, 5, 7, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97, 101, 103, 107, 109, 113}; - - if (n <= 113*113) { - for (int i = 0; i < 30; i++) - if (n % static_cast(prime[i]) == 0) - return static_cast(prime[i]); - - return n; - } - - T i = 1; - T k = 2; - T x = static_cast(rand())%n; - T y = x; - while(i < square_root(n, 1)) { - i++; - x = (x*x-1) % n; - T d = gcd(abs(y-x), n); - if(d != 1 && d != n) - return factor(d); - if(i == k) { - y = x; - k *= 2; - } - } - return n; -} - -/* #define implies(A,B) (A==(A&B)) */ - -template std::string to_string(const T &t) { - std::ostringstream ss; - ss << t; - return ss.str(); -} - -template T from_string(const std::string &s) { - std::istringstream ss(s); - ss.exceptions(std::ios::failbit); - T t; - ss >> t; - return t; -} - -} // namespace - -#endif -- cgit v1.2.3-70-g09d2