Added Hashtable::Size() method.

* Automatic whitespace cleanup.
This commit is contained in:
Axel Dörfler
2012-12-02 21:03:41 +01:00
parent 2ede175119
commit 772c9704b9
2 changed files with 18 additions and 10 deletions
+16 -9
View File
@@ -40,11 +40,11 @@ Hashtable::Hashtable(int capacity, float loadFactor)
if (!capacity)
capacity = 1;
if (!(fTable = (struct Entry **)malloc(capacity * sizeof(void *))))
return;
memset(fTable,0,capacity * sizeof(void *));
fThreshold = (int)(capacity * loadFactor);
fModCount = 0;
fLoadFactor = loadFactor;
@@ -58,7 +58,7 @@ Hashtable::Hashtable(int capacity, float loadFactor)
Hashtable::~Hashtable()
{
struct Entry **table = fTable;
for(int32 index = fCapacity;--index >= 0;)
{
struct Entry *entry,*next;
@@ -136,7 +136,7 @@ void *Hashtable::Remove(const void *key)
table = fTable;
hash = (func = fHashFunc)(key);
index = hash % fCapacity;
for(entry = table[index],prev = NULL;entry;entry = entry->next)
{
if ((func(entry->key) == hash) && fCompareFunc(entry->key,key))
@@ -148,7 +148,7 @@ void *Hashtable::Remove(const void *key)
prev->next = entry->next;
else
table[index] = entry->next;
fCount--;
value = entry->value;
delete entry;
@@ -180,7 +180,7 @@ status_t Hashtable::GetNextEntry(void **value)
*value = fIteratorEntry->value;
return B_OK;
}
return B_ENTRY_NOT_FOUND;
}
@@ -227,10 +227,17 @@ Hashtable::MakeEmpty(int8 keyMode,int8 valueMode)
}
size_t
Hashtable::Size() const
{
return fCount;
}
/** The hash table will be doubled in size, and rebuild.
* @return true on success
*/
bool Hashtable::Rehash()
{
uint32 (*hashCode)(const void *) = fHashFunc;
@@ -270,10 +277,10 @@ Hashtable::Entry *Hashtable::GetHashEntry(const void *key)
{
Entry **table,*entry;
uint32 hash,(*func)(const void *);
table = fTable;
hash = (func = fHashFunc)(key);
for(entry = table[hash % fCapacity];entry;entry = entry->next)
{
if ((func(entry->key) == hash) && fCompareFunc(entry->key,key))
+2 -1
View File
@@ -33,7 +33,8 @@ class Hashtable
void Rewind();
void MakeEmpty(int8 keyMode = HASH_EMPTY_NONE,int8 valueMode = HASH_EMPTY_NONE);
size_t Size() const;
protected:
class Entry
{