* Replaced the useless InitCheck() method in {Open,Multi}HashTable (it

always returned B_OK) by a Init() method, which sets the initial size
  and returns an error, if that fails.
* Adjusted code using the classes accordingly. Replaced a few
  InitCheck() methods in the network code by Init().


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@26127 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Ingo Weinhold
2008-06-24 22:23:57 +00:00
parent 55c692b304
commit 276aa463ef
12 changed files with 47 additions and 43 deletions
+15 -9
View File
@@ -31,14 +31,16 @@ public:
typedef typename Definition::KeyType KeyType;
typedef typename Definition::ValueType ValueType;
MultiHashTable(size_t initialSize = HashTable::kMinimumSize)
: HashTable(initialSize) {}
MultiHashTable()
: HashTable() {}
MultiHashTable(const Definition& definition,
size_t initialSize = HashTable::kMinimumSize)
: HashTable(definition, initialSize) {}
MultiHashTable(const Definition& definition)
: HashTable(definition) {}
status_t InitCheck() const { return HashTable::InitCheck(); }
status_t Init(size_t initialSize = HashTable::kMinimumSize)
{
return HashTable::Init(initialSize);
}
void Insert(ValueType *value)
{
@@ -103,9 +105,13 @@ public:
ValueIterator Lookup(const KeyType &key) const
{
size_t index = HashTable::fDefinition.HashKey(key)
& (HashTable::fTableSize - 1);
ValueType *slot = HashTable::fTable[index];
size_t index = 0;
ValueType *slot = NULL;
if (HashTable::fTableSize > 0) {
index = HashTable::fDefinition.HashKey(key)
& (HashTable::fTableSize - 1);
slot = HashTable::fTable[index];
}
while (slot) {
if (HashTable::fDefinition.Compare(key, slot))
+6 -9
View File
@@ -59,26 +59,21 @@ public:
// regrowth factor: 200 / 256 = 78.125%
// 50 / 256 = 19.53125%
OpenHashTable(size_t initialSize = kMinimumSize)
OpenHashTable()
:
fTableSize(0),
fItemCount(0),
fTable(NULL)
{
if (initialSize > 0)
_Resize(initialSize);
}
OpenHashTable(const Definition& definition,
size_t initialSize = kMinimumSize)
OpenHashTable(const Definition& definition)
:
fDefinition(definition),
fTableSize(0),
fItemCount(0),
fTable(NULL)
{
if (initialSize > 0)
_Resize(initialSize);
}
~OpenHashTable()
@@ -86,9 +81,11 @@ public:
delete [] fTable;
}
status_t InitCheck() const
status_t Init(size_t initialSize = kMinimumSize)
{
return (fTableSize == 0 || fTable) ? B_OK : B_NO_MEMORY;
if (initialSize > 0 && !_Resize(initialSize))
return B_NO_MEMORY;
return B_OK;
}
ValueType *Lookup(const KeyType &key) const