Hasty Badger
Small UI library (a branch of Turbo Badger)
|
TBHashTable is a minimal hash table, for hashing anything using a uint32_t key. More...
#include <tb_hashtable.h>
Public Member Functions | |
void | RemoveAll () |
Remove all items without deleting the content. More... | |
void | DeleteAll () |
Remove all items and delete the content. More... | |
void * | Get (uint32_t key) const |
Get the content for the given key, or nullptr if not found. More... | |
bool | Add (uint32_t key, void *content) |
Add content with the given key. More... | |
void * | Remove (uint32_t key) |
Remove the content with the given key. More... | |
void | Delete (uint32_t key) |
Delete the content with the given key. More... | |
bool | Rehash (uint32_t num_buckets) |
Rehash the table so use the given number of buckets. More... | |
bool | NeedRehash () const |
Return true if the hashtable itself think it's time to rehash. More... | |
uint32_t | GetSuitableBucketsCount () const |
Get the number of buckets the hashtable itself thinks is suitable for the current number of items. More... | |
Protected Member Functions | |
virtual void | DeleteContent (void *) |
Delete the content of a item. More... | |
Friends | |
class | TBHashTableIterator |
TBHashTable is a minimal hash table, for hashing anything using a uint32_t key.
bool tb::TBHashTable::Add | ( | uint32_t | key, |
void * | content | ||
) |
Add content with the given key.
Returns false if out of memory.
void tb::TBHashTable::Delete | ( | uint32_t | key | ) |
Delete the content with the given key.
|
inline |
Remove all items and delete the content.
This requires TBHashTable to be subclassed and implementing DeleteContent. You would typically do this by using TBHashTableOf or TBHashTableAutoDeleteOf.
|
inlineprotectedvirtual |
Delete the content of a item.
This is called if calling DeleteAll, and must be implemented in a subclass that knows about the content type.
Reimplemented in tb::TBHashTableAutoDeleteOf< T >, tb::TBHashTableAutoDeleteOf< tb::TBFontGlyph >, tb::TBHashTableAutoDeleteOf< tb::TBFontInfo >, tb::TBHashTableAutoDeleteOf< tb::TBWidgetValue >, tb::TBHashTableAutoDeleteOf< tb::TBFontFace >, tb::TBHashTableAutoDeleteOf< tb::TBSkinElement >, tb::TBHashTableOf< T >, tb::TBHashTableOf< tb::TBStr >, and tb::TBHashTableOf< tb::TBBitmapFragment >.
void * tb::TBHashTable::Get | ( | uint32_t | key | ) | const |
Get the content for the given key, or nullptr if not found.
uint32_t tb::TBHashTable::GetSuitableBucketsCount | ( | ) | const |
Get the number of buckets the hashtable itself thinks is suitable for the current number of items.
bool tb::TBHashTable::NeedRehash | ( | ) | const |
Return true if the hashtable itself think it's time to rehash.
bool tb::TBHashTable::Rehash | ( | uint32_t | num_buckets | ) |
Rehash the table so use the given number of buckets.
Returns false if out of memory.
void * tb::TBHashTable::Remove | ( | uint32_t | key | ) |
Remove the content with the given key.
|
inline |
Remove all items without deleting the content.