-
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.
Added IntLinearProbingHashTable, which is a specialization of LinearP…
…robingHashTable with keys of type size_t. It extended LinearProbingHashTable, and its test code, IntLinearProbingHashTableTest, extended from LinearProbingHashTableTestBase. Signed-off-by: saad0105050 <saad0105050@gmail.com>
- Loading branch information
saad0105050
committed
Sep 16, 2014
1 parent
8d58f38
commit e3480cf
Showing
5 changed files
with
401 additions
and
289 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,89 @@ | ||
#pragma once | ||
#include "common.h" | ||
#include "ds.LinearProbingHashTable.h" | ||
using namespace std; | ||
|
||
namespace yasi{ | ||
namespace ds{ | ||
|
||
// a hash table with integer key | ||
template< | ||
class Value = size_t, | ||
class HashFunction = IntHashFunction<int> > | ||
class IntLinearProbingHashTable | ||
: public LinearProbingHashTable < | ||
size_t, Value, HashFunction, KVPair<size_t, Value> > { | ||
|
||
///////////////// enable testing /////////////// | ||
friend class IntLinearProbingHashTableTest; | ||
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 LinearProbingHashTable < size_t, Value, KVPairSimple<int, Value>, HashFunction > | ||
base; | ||
|
||
|
||
/////////// simplify some table accessor/modifier interface /////////// | ||
virtual inline bool isNull(const int bucket) const{ | ||
return table[bucket].key == 0; | ||
} | ||
virtual inline void makeNull(const int bucket) const{ | ||
table[bucket].key = 0; | ||
} | ||
virtual inline bool isKeyZero(const Key* pKey) const{ | ||
return *pKey == 0; | ||
} | ||
virtual inline bool isKeyZero(const Key& key) const{ | ||
return key == 0; | ||
} | ||
virtual inline void setKeyZero(Key* pKey) const{ | ||
*pKey = 0; | ||
} | ||
|
||
public: | ||
|
||
virtual ~IntLinearProbingHashTable(){} | ||
IntLinearProbingHashTable(unsigned int logSize = INIT_LOGSIZE) :LinearProbingHashTable(logSize){} | ||
|
||
}; | ||
|
||
////////// test IntLinearProbingHashTable | ||
// inherit tests from base class, just redefine the types | ||
|
||
class IntLinearProbingHashTableTest : public LinearProbingHashTableTestBase< | ||
IntLinearProbingHashTable<int, Mod8Function<int> >, | ||
IntLinearProbingHashTable<int, Mod16Function<int> >, | ||
IntLinearProbingHashTable<int, Mod32Function<int> > | ||
>{ | ||
// | ||
protected: | ||
typedef IntLinearProbingHashTable<int, Mod8Function<int> > IntHashTable8; | ||
typedef IntLinearProbingHashTable<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 | ||
|
||
}; | ||
ADD_TEST_F(IntLinearProbingHashTableTest, insert); | ||
ADD_TEST_F(IntLinearProbingHashTableTest, copyTable); | ||
ADD_TEST_F(IntLinearProbingHashTableTest, growCondition); | ||
ADD_TEST_F(IntLinearProbingHashTableTest, shrinkCondition); | ||
ADD_TEST_F(IntLinearProbingHashTableTest, isKeyZero); | ||
ADD_TEST_F(IntLinearProbingHashTableTest, remove); | ||
|
||
} | ||
} |
Oops, something went wrong.