mirror of
https://github.com/thunderbrewhq/squall.git
synced 2025-12-12 10:32:29 +00:00
feat(hash): add memory recycling hash table
This commit is contained in:
parent
06dbb7d1c8
commit
8a232d34f2
5 changed files with 158 additions and 5 deletions
|
|
@ -14,20 +14,22 @@ class TSHashTable {
|
|||
TSGrowableArray<STORM_EXPLICIT_LIST(T, m_linktoslot)> m_slotlistarray;
|
||||
uint32_t m_slotmask = -1;
|
||||
|
||||
// Virtual member functions
|
||||
virtual void InternalDelete(T* ptr);
|
||||
virtual T* InternalNew(STORM_EXPLICIT_LIST(T, m_linktoslot)* listptr, size_t extrabytes, uint32_t flags);
|
||||
virtual ~TSHashTable();
|
||||
virtual void Destroy();
|
||||
|
||||
// Member functions
|
||||
~TSHashTable();
|
||||
void Clear();
|
||||
uint32_t ComputeSlot(uint32_t hashval);
|
||||
void Destroy();
|
||||
int32_t GetLinkOffset();
|
||||
T* Head();
|
||||
void Initialize();
|
||||
bool Initialized();
|
||||
void Insert(T* ptr, uint32_t hashval, const TKey& key);
|
||||
void InternalClear(int32_t warn);
|
||||
void InternalDelete(T* ptr);
|
||||
void InternalLinkNode(T* ptr, uint32_t hashval);
|
||||
T* InternalNew(STORM_EXPLICIT_LIST(T, m_linktoslot)* listptr, size_t extrabytes, uint32_t flags);
|
||||
T* InternalNewNode(uint32_t, size_t extrabytes, uint32_t flags);
|
||||
int32_t MonitorFullness(uint32_t slot);
|
||||
T* New(const char* str, size_t extrabytes, uint32_t flags);
|
||||
|
|
@ -49,6 +51,14 @@ void TSHashTable<T, TKey>::Clear() {
|
|||
this->InternalClear(0);
|
||||
}
|
||||
|
||||
template <class T, class TKey>
|
||||
void TSHashTable<T, TKey>::Destroy() {
|
||||
this->InternalClear(1);
|
||||
this->m_fullnessIndicator = 0;
|
||||
this->m_slotmask = -1;
|
||||
this->m_slotlistarray.Clear();
|
||||
}
|
||||
|
||||
template <class T, class TKey>
|
||||
uint32_t TSHashTable<T, TKey>::ComputeSlot(uint32_t hashval) {
|
||||
return hashval & this->m_slotmask;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue