-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: unknown <saq10002@iteb-219.ad.engr.uconn.edu>
- Loading branch information
unknown
committed
Sep 16, 2014
1 parent
e3480cf
commit 8d04e32
Showing
4 changed files
with
110 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
#pragma once | ||
#include "common.h" | ||
#include "ds.IntLinearProbingHashTable.h" | ||
|
||
namespace yasi{ | ||
namespace ds{ | ||
using namespace std; | ||
|
||
template<class Value> | ||
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<int> > | ||
class HopScotchHashTable | ||
: public IntLinearProbingHashTable < | ||
Value, HashFunction, HopScotchEntry<Value> > { | ||
|
||
///////////////// enable testing /////////////// | ||
friend class HopScotchHashTableTest; | ||
template<typename A, typename B, typename C> | ||
friend class LinearProbingHashTableTestBase; | ||
|
||
public: | ||
typedef size_t Key; | ||
typedef KVPair<Key, Value> 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<int, Mod8Function<int> >, | ||
// HopScotchHashTable<int, Mod16Function<int> >, | ||
// HopScotchHashTable<int, Mod32Function<int> > | ||
//> | ||
{ | ||
// | ||
protected: | ||
typedef HopScotchHashTable<int, Mod8Function<int> > IntHashTable8; | ||
typedef HopScotchHashTable<int, Mod16Function<int> > IntHashTable16; | ||
typedef IntHashTable16 IntHashTable; // default | ||
typedef IntLinearProbingHashTable<int, Mod32Function<int> > 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<int>( 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); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters