mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 02:22:30 +00:00
feat(hash): finish implementation of TSHashTable<T, TKey>::Clear
This commit is contained in:
parent
67841ebf14
commit
1d561d4bdf
2 changed files with 35 additions and 6 deletions
|
|
@ -25,8 +25,8 @@ class TSHashTable {
|
||||||
void Initialize(void);
|
void Initialize(void);
|
||||||
bool Initialized(void);
|
bool Initialized(void);
|
||||||
void Insert(T*, uint32_t, const TKey&);
|
void Insert(T*, uint32_t, const TKey&);
|
||||||
void InternalClear(int32_t);
|
void InternalClear(int32_t warn);
|
||||||
void InternalDelete(T*);
|
void InternalDelete(T* ptr);
|
||||||
void InternalLinkNode(T*, uint32_t);
|
void InternalLinkNode(T*, uint32_t);
|
||||||
T* InternalNew(STORM_EXPLICIT_LIST(T, m_linktoslot)*, size_t, size_t);
|
T* InternalNew(STORM_EXPLICIT_LIST(T, m_linktoslot)*, size_t, size_t);
|
||||||
T* InternalNewNode(uint32_t, size_t, size_t);
|
T* InternalNewNode(uint32_t, size_t, size_t);
|
||||||
|
|
@ -94,16 +94,30 @@ void TSHashTable<T, TKey>::Insert(T* ptr, uint32_t hashval, const TKey& key) {
|
||||||
}
|
}
|
||||||
|
|
||||||
template <class T, class TKey>
|
template <class T, class TKey>
|
||||||
void TSHashTable<T, TKey>::InternalClear(int32_t a2) {
|
void TSHashTable<T, TKey>::InternalClear(int32_t warn) {
|
||||||
|
this->m_fullnessIndicator = 0;
|
||||||
|
|
||||||
this->m_fulllist.UnlinkAll();
|
this->m_fulllist.UnlinkAll();
|
||||||
|
|
||||||
uint32_t slotlistCount = this->m_slotlistarray.Count();
|
for (int32_t i = 0; i < this->m_slotlistarray.Count(); i++) {
|
||||||
|
auto& slotList = this->m_slotlistarray[i];
|
||||||
|
|
||||||
if (slotlistCount) {
|
for (auto node = slotList.Head(); node; node = slotList.Link(node)->Next()) {
|
||||||
// TODO
|
if (warn) {
|
||||||
|
slotList.UnlinkNode(node);
|
||||||
|
} else {
|
||||||
|
this->InternalDelete(node);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
template <class T, class TKey>
|
||||||
|
void TSHashTable<T, TKey>::InternalDelete(T* ptr) {
|
||||||
|
ptr->~T();
|
||||||
|
SMemFree(ptr, __FILE__, __LINE__, 0x0);
|
||||||
|
}
|
||||||
|
|
||||||
template <class T, class TKey>
|
template <class T, class TKey>
|
||||||
void TSHashTable<T, TKey>::InternalLinkNode(T* ptr, uint32_t hashval) {
|
void TSHashTable<T, TKey>::InternalLinkNode(T* ptr, uint32_t hashval) {
|
||||||
if (!this->Initialized()) {
|
if (!this->Initialized()) {
|
||||||
|
|
|
||||||
|
|
@ -11,3 +11,18 @@ TEST_CASE("TSHashTable", "[hash]") {
|
||||||
REQUIRE(hashTable.Head() == nullptr);
|
REQUIRE(hashTable.Head() == nullptr);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
TEST_CASE("TSHashTable::Clear", "[hash]") {
|
||||||
|
SECTION("clears empty hash table correctly") {
|
||||||
|
TSHashTable<TestHashObject, HASHKEY_STRI> hashTable;
|
||||||
|
hashTable.Clear();
|
||||||
|
REQUIRE(hashTable.Head() == nullptr);
|
||||||
|
}
|
||||||
|
|
||||||
|
SECTION("clears hash table with entry correctly") {
|
||||||
|
TSHashTable<TestHashObject, HASHKEY_STRI> hashTable;
|
||||||
|
hashTable.New("testKey", 0, 0x0);
|
||||||
|
hashTable.Clear();
|
||||||
|
REQUIRE(hashTable.Head() == nullptr);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue