diff --git a/libsrc/general/array.hpp b/libsrc/general/array.hpp index 467e84ee..acd889fb 100644 --- a/libsrc/general/array.hpp +++ b/libsrc/general/array.hpp @@ -12,6 +12,7 @@ namespace netgen { // template class IndirectArray; + template class IndirectArray; @@ -23,7 +24,7 @@ namespace netgen Optional range check by macro RANGE_CHECK */ - template + template class FlatArray { protected: @@ -32,6 +33,7 @@ namespace netgen /// the data T * data; public: + typedef T TELEM; /// provide size and memory FlatArray (int asize, T * adata) @@ -40,11 +42,11 @@ namespace netgen /// the size int Size() const { return size; } - int Begin() const { return BASE; } - int End() const { return size+BASE; } + TIND Begin() const { return TIND(BASE); } + TIND End() const { return TIND(size+BASE); } /// Access array. BASE-based - T & operator[] (int i) const + T & operator[] (TIND i) const { #ifdef DEBUG if (i-BASE < 0 || i-BASE >= size) @@ -54,6 +56,14 @@ namespace netgen return data[i-BASE]; } + template + IndirectArray > operator[] (const FlatArray & ia) const + { + return IndirectArray > (*this, ia); + } + + + /// Access array, one-based (old fashioned) T & Elem (int i) { @@ -113,16 +123,16 @@ namespace netgen } /// takes range starting from position start of end-start elements - const FlatArray Range (int start, int end) + const FlatArray Range (TIND start, TIND end) { return FlatArray (end-start, data+start); } /// first position of element elem, returns -1 if element not contained in array - int Pos(const T & elem) const + TIND Pos(const T & elem) const { - int pos = -1; - for(int i=0; pos==-1 && i < this->size; i++) + TIND pos = -1; + for(TIND i=0; pos==-1 && i < this->size; i++) if(elem == data[i]) pos = i; return pos; } @@ -137,10 +147,10 @@ namespace netgen // print array - template - inline ostream & operator<< (ostream & s, const FlatArray & a) + template + inline ostream & operator<< (ostream & s, const FlatArray & a) { - for (int i = a.Begin(); i < a.End(); i++) + for (TIND i = a.Begin(); i < a.End(); i++) s << i << ": " << a[i] << endl; return s; } @@ -155,12 +165,12 @@ namespace netgen Either the container takes care of memory allocation and deallocation, or the user provides one block of data. */ - template - class Array : public FlatArray + template + class Array : public FlatArray { protected: - using FlatArray::size; - using FlatArray::data; + using FlatArray::size; + using FlatArray::data; /// physical size of array int allocsize; @@ -171,34 +181,34 @@ namespace netgen /// Generate array of logical and physical size asize explicit Array() - : FlatArray (0, NULL) + : FlatArray (0, NULL) { allocsize = 0; ownmem = 1; } explicit Array(int asize) - : FlatArray (asize, new T[asize]) + : FlatArray (asize, new T[asize]) { allocsize = asize; ownmem = 1; } /// Generate array in user data - Array(int asize, T* adata) - : FlatArray (asize, adata) + Array(TIND asize, T* adata) + : FlatArray (asize, adata) { allocsize = asize; ownmem = 0; } /// array copy - explicit Array (const Array & a2) - : FlatArray (a2.Size(), a2.Size() ? new T[a2.Size()] : 0) + explicit Array (const Array & a2) + : FlatArray (a2.Size(), a2.Size() ? new T[a2.Size()] : 0) { allocsize = size; ownmem = 1; - for (int i = BASE; i < size+BASE; i++) + for (TIND i = BASE; i < size+BASE; i++) (*this)[i] = a2[i]; } @@ -249,7 +259,7 @@ namespace netgen /// Delete element i (0-based). Move last element to position i. - void Delete (int i) + void Delete (TIND i) { #ifdef CHECK_Array_RANGE RangeCheck (i+1); @@ -262,7 +272,7 @@ namespace netgen /// Delete element i (1-based). Move last element to position i. - void DeleteElement (int i) + void DeleteElement (TIND i) { #ifdef CHECK_Array_RANGE RangeCheck (i); @@ -290,7 +300,7 @@ namespace netgen /// Fill array with val Array & operator= (const T & val) { - FlatArray::operator= (val); + FlatArray::operator= (val); return *this; } @@ -298,7 +308,7 @@ namespace netgen Array & operator= (const Array & a2) { SetSize (a2.Size()); - for (int i = BASE; i < size+BASE; i++) + for (TIND i (BASE); i < size+BASE; i++) (*this)[i] = a2[i]; return *this; } @@ -307,7 +317,7 @@ namespace netgen Array & operator= (const FlatArray & a2) { SetSize (a2.Size()); - for (int i = BASE; i < size+BASE; i++) + for (TIND i = BASE; i < size+BASE; i++) (*this)[i] = a2[i]; return *this; } @@ -389,29 +399,49 @@ namespace netgen - /* - template - class IndirectArray - { + template + class IndirectArray + { const FlatArray & array; const FlatArray & ia; - - public: + + public: IndirectArray (const FlatArray & aa, const FlatArray & aia) : array(aa), ia(aia) { ; } int Size() const { return ia.Size(); } const T & operator[] (int i) const { return array[ia[i]]; } - }; + }; */ + template + class IndirectArray + { + const TA1 & array; + const TA2 & ia; + + public: + IndirectArray (const TA1 & aa, const TA2 & aia) + : array(aa), ia(aia) { ; } + int Size() const { return ia.Size(); } + int Begin() const { return ia.Begin(); } + int End() const { return ia.End(); } + + const typename TA1::TELEM & operator[] (int i) const { return array[ia[i]]; } + }; + template + inline ostream & operator<< (ostream & s, const IndirectArray & ia) + { + for (int i = ia.Begin(); i < ia.End(); i++) + s << i << ": " << ia[i] << endl; + return s; + } + - - - + /* /// template @@ -566,7 +596,7 @@ namespace netgen ost << i << ": " << a[i] << endl; return ost; } - + */ /// bubble sort array diff --git a/libsrc/general/hashtabl.cpp b/libsrc/general/hashtabl.cpp index 53d7eafb..36caf12f 100644 --- a/libsrc/general/hashtabl.cpp +++ b/libsrc/general/hashtabl.cpp @@ -139,7 +139,7 @@ namespace netgen BASE_INDEX_CLOSED_HASHTABLE (int size) : hash(size) { - hash.SetName ("index-hashtable, hash"); + // hash.SetName ("index-hashtable, hash"); invalid = -1; for (int i = 1; i <= size; i++) @@ -216,7 +216,7 @@ namespace netgen BASE_INDEX_2_CLOSED_HASHTABLE (int size) : hash(size) { - hash.SetName ("i2-hashtable, hash"); + // hash.SetName ("i2-hashtable, hash"); invalid = -1; for (int i = 1; i <= size; i++) diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index fb37eb38..d05cdc83 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -468,7 +468,8 @@ class BASE_INDEX_CLOSED_HASHTABLE { protected: /// - MoveableArray hash; + // MoveableArray hash; + Array hash; /// int invalid; public: @@ -543,14 +544,15 @@ template class INDEX_CLOSED_HASHTABLE : public BASE_INDEX_CLOSED_HASHTABLE { /// - MoveableArray cont; +// MoveableArray cont; + Array cont; public: /// INDEX_CLOSED_HASHTABLE (int size) : BASE_INDEX_CLOSED_HASHTABLE(size), cont(size) { - cont.SetName ("ind-hashtable, contents"); + ; // cont.SetName ("ind-hashtable, contents"); } @@ -617,8 +619,8 @@ public: void SetName (const char * aname) { - cont.SetName(aname); - hash.SetName(aname); + // cont.SetName(aname); + // hash.SetName(aname); } }; @@ -634,7 +636,8 @@ class BASE_INDEX_2_CLOSED_HASHTABLE { protected: /// - MoveableArray hash; + // MoveableArray hash; + Array hash; /// int invalid; public: @@ -695,7 +698,8 @@ template class INDEX_2_CLOSED_HASHTABLE : public BASE_INDEX_2_CLOSED_HASHTABLE { /// - MoveableArray cont; +// MoveableArray cont; + Array cont; public: /// @@ -726,8 +730,9 @@ public: void SetName (const char * aname) { - cont.SetName(aname); - hash.SetName(aname); + ; + // cont.SetName(aname); + // hash.SetName(aname); } }; @@ -755,14 +760,15 @@ inline ostream & operator<< (ostream & ost, const INDEX_2_CLOSED_HASHTABLE & class BASE_INDEX_3_CLOSED_HASHTABLE { protected: - MoveableArray hash; + // MoveableArray hash; + Array hash; int invalid; protected: BASE_INDEX_3_CLOSED_HASHTABLE (int size) : hash(size) { - hash.SetName ("i3-hashtable, hash"); + // hash.SetName ("i3-hashtable, hash"); invalid = -1; for (int i = 0; i < size; i++) hash[i].I1() = invalid; @@ -848,13 +854,14 @@ protected: template class INDEX_3_CLOSED_HASHTABLE : public BASE_INDEX_3_CLOSED_HASHTABLE { - MoveableArray cont; + // MoveableArray cont; + Array cont; public: INDEX_3_CLOSED_HASHTABLE (int size) : BASE_INDEX_3_CLOSED_HASHTABLE(size), cont(size) { - cont.SetName ("i3-hashtable, contents"); + ; //cont.SetName ("i3-hashtable, contents"); } void Set (const INDEX_3 & ahash, const T & acont) @@ -923,8 +930,9 @@ public: void SetName (const char * aname) { - cont.SetName(aname); - hash.SetName(aname); + ; + // cont.SetName(aname); + // hash.SetName(aname); } }; @@ -1167,7 +1175,7 @@ inline INDEX_2_CLOSED_HASHTABLE :: INDEX_2_CLOSED_HASHTABLE (int size) : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(size) { - cont.SetName ("i2-hashtable, contents"); + // cont.SetName ("i2-hashtable, contents"); } template