From 62f7acd88465f4f20b9b25c3f7edd4e3b7ce453b Mon Sep 17 00:00:00 2001 From: Tuowen Zhao Date: Mon, 19 Sep 2016 11:36:10 -0600 Subject: rm template.c --- omegalib/omega/include/basic/Bag.c | 329 --------------------------- omegalib/omega/include/basic/DynamicArray.c | 219 ------------------ omegalib/omega/include/basic/List.c | 149 ------------ omegalib/omega/include/basic/Map.c | 63 ----- omegalib/omega/include/basic/Section.c | 79 ------- omegalib/omega/include/basic/SimpleList.c | 105 --------- omegalib/omega/include/basic/Tuple.c | 254 --------------------- omegalib/omega/include/basic/boolset-test.cc | 72 ------ 8 files changed, 1270 deletions(-) delete mode 100644 omegalib/omega/include/basic/Bag.c delete mode 100644 omegalib/omega/include/basic/DynamicArray.c delete mode 100644 omegalib/omega/include/basic/List.c delete mode 100644 omegalib/omega/include/basic/Map.c delete mode 100644 omegalib/omega/include/basic/Section.c delete mode 100644 omegalib/omega/include/basic/SimpleList.c delete mode 100644 omegalib/omega/include/basic/Tuple.c delete mode 100755 omegalib/omega/include/basic/boolset-test.cc diff --git a/omegalib/omega/include/basic/Bag.c b/omegalib/omega/include/basic/Bag.c deleted file mode 100644 index c3084c1..0000000 --- a/omegalib/omega/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/omega/include/basic/DynamicArray.c b/omegalib/omega/include/basic/DynamicArray.c deleted file mode 100644 index 8ede2f7..0000000 --- a/omegalib/omega/include/basic/DynamicArray.c +++ /dev/null @@ -1,219 +0,0 @@ -#include -#include - -namespace omega { - -template void DynamicArray::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 DynamicArray1::do_construct(int d0) - { - this->bounds = new int[1]; - this->bounds[0] = d0; - this->elements = new T [d0]; - this->partial = false; - } - -template void DynamicArray2::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 DynamicArray3::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 DynamicArray4::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 DynamicArray::DynamicArray() - { - do_constr(); - } - -template DynamicArray1::DynamicArray1(const char *) - { - this->do_constr(); - } - -template DynamicArray2::DynamicArray2(const char *,const char *) - { - this->do_constr(); - } - -template DynamicArray3::DynamicArray3(const char *,const char *,const char *) - { - this->do_constr(); - } - -template DynamicArray4::DynamicArray4(const char *,const char *,const char *,const char *) - { - this->do_constr(); - } - -template DynamicArray1::DynamicArray1(int d0) - { - do_construct(d0); - } - -template DynamicArray2::DynamicArray2(int d0, int d1) - { - do_construct(d0, d1); - } - -template DynamicArray3::DynamicArray3(int d0,int d1,int d2) - { - do_construct(d0, d1, d2); - } - -template DynamicArray4::DynamicArray4(int d0,int d1,int d2,int d3) - { - do_construct(d0, d1, d2, d3); - } - - -template void DynamicArray::do_destruct() - { - if (! partial) - { - delete [] bounds; - delete [] elements; - } - } - - -template DynamicArray::~DynamicArray() - { - do_destruct(); - } - - -template void DynamicArray1::resize(int d0) - { - assert(!this->partial); - this->do_destruct(); - if (d0 == 0) - this->do_constr(); - else - do_construct(d0); - } - -template void DynamicArray2::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 DynamicArray3::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 DynamicArray4::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& DynamicArray1::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 DynamicArray1 DynamicArray2::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 - - DynamicArray1 result; - result.bounds = this->bounds+1; - result.elements = this->elements + this->bounds[1] * d0; - result.partial = true; - return result; - } - -template DynamicArray2 DynamicArray3::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 - DynamicArray2 result; - result.bounds = this->bounds+1; - result.elements = this->elements + this->bounds[1] * this->bounds[2] * d0; - result.partial = true; - return result; - } - -template DynamicArray3 DynamicArray4::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 - - DynamicArray3 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 - DynamicArray::DynamicArray(DynamicArray &D) - { - assert(D.elements != 0 && "Trying to copy an undefined array"); - partial = true; - bounds = D.bounds; - elements = D.elements; - } - -} // namespace diff --git a/omegalib/omega/include/basic/List.c b/omegalib/omega/include/basic/List.c deleted file mode 100644 index f05e0de..0000000 --- a/omegalib/omega/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/omega/include/basic/Map.c b/omegalib/omega/include/basic/Map.c deleted file mode 100644 index 69cc3f7..0000000 --- a/omegalib/omega/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/omega/include/basic/Section.c b/omegalib/omega/include/basic/Section.c deleted file mode 100644 index 754e002..0000000 --- a/omegalib/omega/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/omega/include/basic/SimpleList.c b/omegalib/omega/include/basic/SimpleList.c deleted file mode 100644 index da7de9b..0000000 --- a/omegalib/omega/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/omega/include/basic/Tuple.c b/omegalib/omega/include/basic/Tuple.c deleted file mode 100644 index ee6648f..0000000 --- a/omegalib/omega/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/omega/include/basic/boolset-test.cc b/omegalib/omega/include/basic/boolset-test.cc deleted file mode 100755 index 5b68220..0000000 --- a/omegalib/omega/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-"; - -} -- cgit v1.2.3-70-g09d2