diff --git a/YASI_12/YASI_12.vcxproj b/YASI_12/YASI_12.vcxproj index c1e149a..89e2516 100644 --- a/YASI_12/YASI_12.vcxproj +++ b/YASI_12/YASI_12.vcxproj @@ -85,6 +85,7 @@ + false diff --git a/YASI_12/YASI_12.vcxproj.filters b/YASI_12/YASI_12.vcxproj.filters index 812c1d4..cf648d9 100644 --- a/YASI_12/YASI_12.vcxproj.filters +++ b/YASI_12/YASI_12.vcxproj.filters @@ -123,6 +123,9 @@ Header Files\Dictionary + Header Files\Dictionary + + Header Files diff --git a/YASI_12/ds.HopScotchHashTable.h b/YASI_12/ds.HopScotchHashTable.h new file mode 100644 index 0000000..7cecc7e --- /dev/null +++ b/YASI_12/ds.HopScotchHashTable.h @@ -0,0 +1,103 @@ +#pragma once +#include "common.h" +#include "ds.IntLinearProbingHashTable.h" + +namespace yasi{ +namespace ds{ +using namespace std; + +template +struct HopScotchEntry{ + size_t key; + Value value; + int bitField; // map of bucket elements + HopScotchEntry(const size_t& k) : key(k){} + HopScotchEntry(const size_t& k, const value& v) : key(k), value(v){} + HopScotchEntry(const size_t& k, const value& v, const int& bf) : + key(k), value(v),bitField(bf){} + +}; + +// a hash table with integer key +template< + class Value = size_t, + class HashFunction = IntHashFunction > +class HopScotchHashTable + : public IntLinearProbingHashTable < + Value, HashFunction, HopScotchEntry > { + + ///////////////// enable testing /////////////// + friend class HopScotchHashTableTest; + template + friend class LinearProbingHashTableTestBase; + +public: + typedef size_t Key; + typedef KVPair EntryType; // must have a public member `key' + typedef EntryType BucketType; // each bucket holds an EntryType object + typedef EntryType Pair; // which is actually a key-value pair + typedef EntryType* BucketEntryPtr; // ptr to an entry object + typedef Key KeyType; + typedef Value ValueType; + +protected: + typedef IntLinearProbingHashTable < Value, HashFunction > + base; + + virtual void copyTable(BucketType* oldTable, const unsigned int oldSize) override{ + h::copyTable(oldTable, oldSize); + } + + + //---------- HopScotch Properties/Methods ---------- + static unsigned int INIT_H = 32; + unsigned size_t H; // the neighborhood size + // push this entry to the right + bool pushToRight(const int bucket){} + // fill this bucket with an entry from the left + void pullFromLeft(const int bucket){} + +public: + + virtual ~HopScotchHashTable(){} + HopScotchHashTable(unsigned int logSize = INIT_LOGSIZE, unsigned int H = INIT_H) :H(H),IntLinearProbingHashTable(logSize){} + +}; + +////////// test IntLinearProbingHashTable +// inherit tests from base class, just redefine the types + +class HopScotchHashTableTest +// : public LinearProbingHashTableTestBase< +// HopScotchHashTable >, +// HopScotchHashTable >, +// HopScotchHashTable > +//> +{ + // +protected: + typedef HopScotchHashTable > IntHashTable8; + typedef HopScotchHashTable > IntHashTable16; + typedef IntHashTable16 IntHashTable; // default + typedef IntLinearProbingHashTable > IntHashTable32; + typedef IntHashTable::BucketType BucketType; + typedef IntHashTable::BucketEntryPtr BucketEntryPtr; + typedef IntHashTable::Pair Pair; + +public: + // inherit all public tests + void pushToRight(){ + IntHashTable h(4, 4); // size 16, H=4 + h.table[2] = HopScotchEntry( 2, 2, 0 ); + } + +}; +//ADD_TEST_F(HopScotchHashTableTest, insert); +//ADD_TEST_F(HopScotchHashTableTest, copyTable); +//ADD_TEST_F(HopScotchHashTableTest, growCondition); +//ADD_TEST_F(HopScotchHashTableTest, shrinkCondition); +//ADD_TEST_F(HopScotchHashTableTest, isKeyZero); +//ADD_TEST_F(HopScotchHashTableTest, remove); + +} +} \ No newline at end of file diff --git a/YASI_12/ds.IntLinearProbingHashTable.h b/YASI_12/ds.IntLinearProbingHashTable.h index ca713cf..84fb1bd 100644 --- a/YASI_12/ds.IntLinearProbingHashTable.h +++ b/YASI_12/ds.IntLinearProbingHashTable.h @@ -9,10 +9,11 @@ namespace yasi{ // a hash table with integer key template< class Value = size_t, - class HashFunction = IntHashFunction > + class HashFunction = IntHashFunction , + class EntryType = KVPair > class IntLinearProbingHashTable : public LinearProbingHashTable < - size_t, Value, HashFunction, KVPair > { + size_t, Value, HashFunction, EntryType > { ///////////////// enable testing /////////////// friend class IntLinearProbingHashTableTest;