From f4c20290509d7ed3a8fd5304577e7a4cc0b9d974 Mon Sep 17 00:00:00 2001 From: Mike Buland Date: Tue, 3 Apr 2007 03:49:53 +0000 Subject: Ok, no code is left in src, it's all in src/old. We'll gradually move code back into src as it's fixed and re-org'd. This includes tests, which, I may write a unit test system into libbu++ just to make my life easier. --- src/old/ordhash.h | 104 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 104 insertions(+) create mode 100644 src/old/ordhash.h (limited to 'src/old/ordhash.h') diff --git a/src/old/ordhash.h b/src/old/ordhash.h new file mode 100644 index 0000000..e946f95 --- /dev/null +++ b/src/old/ordhash.h @@ -0,0 +1,104 @@ +#ifndef ORD_HASH_H +#define ORD_HASH_H + +#include "hash.h" +#include "tqsort.h" + +template, typename valuealloc = std::allocator, typename challoc = std::allocator > +class OrdHash : public Hash +{ +public: + OrdHash() : + bSorted( false ), + aData( NULL ) + { + } + + virtual ~OrdHash() + { + } + +protected: + virtual void invalidate() + { + bSorted = false; + delete[] aData; + aData = NULL; + } + + virtual void onInsert() + { + invalidate(); + } + + virtual void onUpdate() + { + invalidate(); + } + + virtual void onDelete() + { + invalidate(); + } + + virtual void onReHash() + { + invalidate(); + } + + virtual std::pair getAtPos( uint32_t nPos ) + { + return Hash::getAtPos( aData[nPos].nIndex ); + } + + virtual void buildIndex() + { + aData = new struct ind[this->nFilled]; + uint32_t k = 0; + for( uint32_t j = 0; j < this->nCapacity; j++ ) + { + if( this->isFilled( j ) ) + { + if( !this->isDeleted( j ) ) + { + aData[k].pVal = &(this->aValues[j]); + aData[k].nIndex = j; + k++; + } + } + } + + tqsort::ind, cmpfnc, value **>( aData, this->nFilled ); + + bSorted = true; + } + + virtual uint32_t getFirstPos( bool &bFinished ) + { + if( bSorted == false ) + buildIndex(); + + return 0; + } + + virtual uint32_t getNextPos( uint32_t nPos, bool &bFinished ) + { + if( nPos+1 >= this->nFilled ) + { + bFinished = true; + return 0; + } + return ++nPos; + } +public: + typedef struct ind + { + value *pVal; + uint32_t nIndex; + } ind; +private: + bool bSorted; + ind *aData; +}; + +#endif -- cgit v1.2.3