Skip to content

Commit

Permalink
Started HopScothcTable
Browse files Browse the repository at this point in the history
Signed-off-by: unknown <saq10002@iteb-219.ad.engr.uconn.edu>
  • Loading branch information
unknown committed Sep 16, 2014
1 parent e3480cf commit 8d04e32
Show file tree
Hide file tree
Showing 4 changed files with 110 additions and 2 deletions.
1 change: 1 addition & 0 deletions YASI_12/YASI_12.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
<ClInclude Include="ds.dictionary.h" />
<ClInclude Include="ds.doublylinkedlist.h" />
<ClInclude Include="ds.hashtablebase.h" />
<ClInclude Include="ds.HopScotchHashTable.h" />
<ClInclude Include="ds.IntLinearProbingHashTable.h" />
<ClInclude Include="ds.iterator.h">
<ExcludedFromBuild Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">false</ExcludedFromBuild>
Expand Down
3 changes: 3 additions & 0 deletions YASI_12/YASI_12.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,9 @@
<Filter>Header Files\Dictionary</Filter>
</ClInclude>
<ClInclude Include="ds.IntLinearProbingHashTable.h">
<Filter>Header Files\Dictionary</Filter>
</ClInclude>
<ClInclude Include="ds.HopScotchHashTable.h">
<Filter>Header Files</Filter>
</ClInclude>
</ItemGroup>
Expand Down
103 changes: 103 additions & 0 deletions YASI_12/ds.HopScotchHashTable.h
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);

}
}
5 changes: 3 additions & 2 deletions YASI_12/ds.IntLinearProbingHashTable.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,11 @@ namespace yasi{
// a hash table with integer key
template<
class Value = size_t,
class HashFunction = IntHashFunction<int> >
class HashFunction = IntHashFunction<int> ,
class EntryType = KVPair<size_t, Value> >
class IntLinearProbingHashTable
: public LinearProbingHashTable <
size_t, Value, HashFunction, KVPair<size_t, Value> > {
size_t, Value, HashFunction, EntryType > {

///////////////// enable testing ///////////////
friend class IntLinearProbingHashTableTest;
Expand Down

0 comments on commit 8d04e32

Please sign in to comment.