Added TableSize(), CountElements(), and Clear() methods.
git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@29428 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
@@ -90,6 +90,16 @@ public:
|
|||||||
return B_OK;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
size_t TableSize() const
|
||||||
|
{
|
||||||
|
return fTableSize;
|
||||||
|
}
|
||||||
|
|
||||||
|
size_t CountElements() const
|
||||||
|
{
|
||||||
|
return fItemCount;
|
||||||
|
}
|
||||||
|
|
||||||
ValueType *Lookup(const KeyType &key) const
|
ValueType *Lookup(const KeyType &key) const
|
||||||
{
|
{
|
||||||
if (fTableSize == 0)
|
if (fTableSize == 0)
|
||||||
@@ -182,6 +192,42 @@ public:
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*! Removes all elements from the hash table. No resizing happens. The
|
||||||
|
elements are not deleted. If \a returnElements is \c true, the method
|
||||||
|
returns all elements chained via their hash table link.
|
||||||
|
*/
|
||||||
|
ValueType* Clear(bool returnElements = false)
|
||||||
|
{
|
||||||
|
if (this->fItemCount == 0)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
ValueType* result = NULL;
|
||||||
|
|
||||||
|
if (returnElements) {
|
||||||
|
ValueType** nextPointer = &result;
|
||||||
|
|
||||||
|
// iterate through all buckets
|
||||||
|
for (size_t i = 0; i < fTableSize; i++) {
|
||||||
|
ValueType* element = fTable[i];
|
||||||
|
if (element != NULL) {
|
||||||
|
// add the bucket to the list
|
||||||
|
*nextPointer = element;
|
||||||
|
|
||||||
|
// update nextPointer to point to the fNext of the last
|
||||||
|
// element in the bucket
|
||||||
|
while (element != NULL) {
|
||||||
|
nextPointer = &_Link(element)->fNext;
|
||||||
|
element = *nextPointer;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
memset(this->fTable, 0, sizeof(ValueType*) * this->fTableSize);
|
||||||
|
|
||||||
|
return result;
|
||||||
|
}
|
||||||
|
|
||||||
/*! If the table needs resizing, the number of bytes for the required
|
/*! If the table needs resizing, the number of bytes for the required
|
||||||
allocation is returned. If no resizing is needed, 0 is returned.
|
allocation is returned. If no resizing is needed, 0 is returned.
|
||||||
*/
|
*/
|
||||||
|
|||||||
Reference in New Issue
Block a user