axeld+bonefish: Got rid of the ParentType in the HashTableDefinition; it doesn't really

belong there.


git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21766 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2007-07-31 16:14:58 +00:00
parent b1c07d8165
commit 8405223037
9 changed files with 67 additions and 47 deletions
+38 -30
View File
@@ -5,36 +5,37 @@
* Authors:
* Hugo Santos, [email protected]
*/
#ifndef _KERNEL_UTIL_OPEN_HASH_TABLE_H
#define _KERNEL_UTIL_OPEN_HASH_TABLE_H
#ifndef _OPEN_HASH_TABLE_H_
#define _OPEN_HASH_TABLE_H_
#include <KernelExport.h>
#include <util/kernel_cpp.h>
// the Definition template must have four methods: `HashKey', `Hash',
// `Compare' and `GetLink;. It must also define several types as shown in the
// following example:
//
// struct Foo : HashTableLink<Foo> {
// int bar;
//
// HashTableLink<Foo> otherLink;
// };
//
// struct HashTableDefinition {
// typedef void ParentType;
// typedef int KeyType;
// typedef Foo ValueType;
//
// HashTableDefinition(void *parent) {}
//
// size_t HashKey(int key) const { return key >> 1; }
// size_t Hash(Foo *value) const { return HashKey(value->bar); }
// bool Compare(int key, Foo *value) const { return value->bar == key; }
// HashTableLink<Foo> *GetLink(Foo *value) const { return value; }
// };
/*!
The Definition template must have four methods: `HashKey', `Hash',
`Compare' and `GetLink;. It must also define several types as shown in the
following example:
struct Foo : HashTableLink<Foo> {
int bar;
HashTableLink<Foo> otherLink;
};
struct HashTableDefinition {
typedef int KeyType;
typedef Foo ValueType;
HashTableDefinition(const HashTableDefinition&) {}
size_t HashKey(int key) const { return key >> 1; }
size_t Hash(Foo *value) const { return HashKey(value->bar); }
bool Compare(int key, Foo *value) const { return value->bar == key; }
HashTableLink<Foo> *GetLink(Foo *value) const { return value; }
};
*/
template<typename Type>
struct HashTableLink {
@@ -59,15 +60,22 @@ public:
// 50 / 256 = 19.53125%
OpenHashTable(size_t initialSize = kMinimumSize)
: fTableSize(0), fItemCount(0), fTable(NULL)
:
fTableSize(0),
fItemCount(0),
fTable(NULL)
{
if (initialSize > 0)
_Resize(initialSize);
}
OpenHashTable(typename Definition::ParentType *parent,
size_t initialSize = kMinimumSize)
: fDefinition(parent), fTableSize(0), fItemCount(0), fTable(NULL)
OpenHashTable(const Definition& definition,
size_t initialSize = kMinimumSize)
:
fDefinition(definition),
fTableSize(0),
fItemCount(0),
fTable(NULL)
{
if (initialSize > 0)
_Resize(initialSize);
@@ -273,4 +281,4 @@ protected:
ValueType **fTable;
};
#endif
#endif // _KERNEL_UTIL_OPEN_HASH_TABLE_H