diff --git a/libsrc/general/hashtabl.cpp b/libsrc/general/hashtabl.cpp index 9856431e..a9ef002c 100644 --- a/libsrc/general/hashtabl.cpp +++ b/libsrc/general/hashtabl.cpp @@ -232,8 +232,8 @@ namespace netgen mask = size-1; hash.SetSize(size); - for (int i = 1; i <= size; i++) - hash.Elem(i).I1() = invalid; + for (size_t i = 0; i < size; i++) + hash[i].I1() = invalid; } diff --git a/libsrc/general/hashtabl.hpp b/libsrc/general/hashtabl.hpp index 72263cba..cdc504b5 100644 --- a/libsrc/general/hashtabl.hpp +++ b/libsrc/general/hashtabl.hpp @@ -707,31 +707,65 @@ protected: template class INDEX_2_CLOSED_HASHTABLE : public BASE_INDEX_2_CLOSED_HASHTABLE { - /// -// MoveableArray cont; Array cont; - public: + INDEX_2_CLOSED_HASHTABLE (size_t size) + : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(RoundUp2(size)) + { ; } + + void Set (const INDEX_2 & ahash, const T & acont) + { + int pos; + PositionCreate0 (ahash, pos); + hash[pos] = ahash; + cont[pos] = acont; + } + + const T & Get (const INDEX_2 & ahash) const + { + int pos = Position0 (ahash); + return cont[pos]; + } + + inline bool Used (const INDEX_2 & ahash) const + { + int pos = Position0 (ahash); + return (pos != -1); + } + + inline void SetData0 (int pos, const INDEX_2 & ahash, const T & acont) + { + hash[pos] = ahash; + cont[pos] = acont; + } + /// - inline INDEX_2_CLOSED_HASHTABLE (int size); - /// - inline void Set (const INDEX_2 & ahash, const T & acont); - /// - inline const T & Get (const INDEX_2 & ahash) const; - /// - inline bool Used (const INDEX_2 & ahash) const; - /// - inline void SetData0 (int pos, const INDEX_2 & ahash, const T & acont); - /// - inline void GetData0 (int pos, INDEX_2 & ahash, T & acont) const; - /// - inline void SetData0 (int pos, const T & acont); - /// - inline void GetData0 (int pos, T & acont) const; + inline void GetData0 (int pos, INDEX_2 & ahash, T & acont) const + { + ahash = hash[pos]; + acont = cont[pos]; + } + + inline void SetData0 (int pos, const T & acont) + { + cont[pos] = acont; + } + + inline void GetData0 (int pos, T & acont) const + { + acont = cont[pos]; + } + /// const T & GetData0 (int pos) { return cont[pos]; } /// - inline void SetSize (int size); + inline void SetSize (size_t size) + { + BaseSetSize(size); + cont.SetSize(RoundUp2(size)); + } + + /// inline void PrintMemInfo (ostream & ost) const; /// @@ -756,7 +790,7 @@ inline ostream & operator<< (ostream & ost, const INDEX_2_CLOSED_HASHTABLE & { INDEX_2 hash; T data; - ht.GetData (i, hash, data); + ht.GetData0 (i, hash, data); ost << "hash = " << hash << ", data = " << data << endl; } return ost; @@ -1189,83 +1223,6 @@ inline void INDEX_HASHTABLE :: PrintMemInfo (ostream & ost) const /* *********** Closed Hashing ************************* */ - - - -template -inline INDEX_2_CLOSED_HASHTABLE :: -INDEX_2_CLOSED_HASHTABLE (int size) - : BASE_INDEX_2_CLOSED_HASHTABLE(size), cont(RoundUp2(size)) -{ - // cont.SetName ("i2-hashtable, contents"); -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -Set (const INDEX_2 & ahash, const T & acont) -{ - int pos; - PositionCreate0 (ahash, pos); - hash[pos] = ahash; - cont[pos] = acont; -} - -template -inline const T & INDEX_2_CLOSED_HASHTABLE :: -Get (const INDEX_2 & ahash) const -{ - int pos = Position0 (ahash); - return cont[pos]; -} - -template -inline bool INDEX_2_CLOSED_HASHTABLE :: -Used (const INDEX_2 & ahash) const -{ - int pos = Position0 (ahash); - return (pos != -1); -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -SetData0 (int pos, const INDEX_2 & ahash, const T & acont) -{ - hash[pos] = ahash; - cont[pos] = acont; -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -GetData0 (int pos, INDEX_2 & ahash, T & acont) const -{ - ahash = hash[pos]; - acont = cont[pos]; -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -SetData0 (int pos, const T & acont) -{ - cont[pos] = acont; -} - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -GetData0 (int pos, T & acont) const -{ - acont = cont[pos]; -} - - -template -inline void INDEX_2_CLOSED_HASHTABLE :: -SetSize (int size) -{ - BaseSetSize(size); - cont.SetSize(size); -} - - template inline void INDEX_2_CLOSED_HASHTABLE ::