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

View File

@ -5,15 +5,15 @@
* Authors:
* Hugo Santos, hugosantos@gmail.com
*/
#ifndef _KERNEL_UTIL_MULTI_HASH_TABLE_H
#define _KERNEL_UTIL_MULTI_HASH_TABLE_H
#ifndef _MULTI_HASH_TABLE_H_
#define _MULTI_HASH_TABLE_H_
#include <KernelExport.h>
#include <util/kernel_cpp.h>
#include <util/OpenHashTable.h>
// MultiHashTable is a container which acts a bit like multimap<>
// but with hash table semantics.
@ -34,9 +34,9 @@ public:
MultiHashTable(size_t initialSize = HashTable::kMinimumSize)
: HashTable(initialSize) {}
MultiHashTable(typename Definition::ParentType *parent,
MultiHashTable(const Definition& definition,
size_t initialSize = HashTable::kMinimumSize)
: HashTable(parent, initialSize) {}
: HashTable(definition, initialSize) {}
status_t InitCheck() const { return HashTable::InitCheck(); }
@ -174,4 +174,4 @@ private:
}
};
#endif
#endif // _KERNEL_UTIL_MULTI_HASH_TABLE_H

View File

@ -5,36 +5,37 @@
* Authors:
* Hugo Santos, hugosantos@gmail.com
*/
#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

View File

@ -131,7 +131,6 @@ typedef MulticastGroupInterface<IPv4Multicast> IPv4GroupInterface;
typedef MulticastFilter<IPv4Multicast> IPv4MulticastFilter;
struct MulticastStateHash {
typedef void ParentType;
typedef std::pair<const in_addr *, uint32> KeyType;
typedef IPv4GroupInterface ValueType;

View File

@ -5,10 +5,10 @@
* Authors:
* Hugo Santos, hugosantos@gmail.com
*/
#ifndef _PRIVATE_MULTICAST_H_
#define _PRIVATE_MULTICAST_H_
#include <util/DoublyLinkedList.h>
#include <util/OpenHashTable.h>
@ -18,6 +18,7 @@
#include <utility>
struct net_buffer;
struct net_protocol;
@ -164,7 +165,6 @@ public:
bool FilterAccepts(net_buffer *buffer) const;
struct HashDefinition {
typedef void ParentType;
typedef std::pair<const AddressType *, uint32> KeyType;
typedef ThisType ValueType;

View File

@ -4,6 +4,7 @@
*
* Authors:
* Axel Dörfler, axeld@pinc-software.de
* Hugo Santos, hugosantos@gmail.com
*/
@ -30,7 +31,11 @@ static const uint16 kFirstEphemeralPort = 40000;
ConnectionHashDefinition::ConnectionHashDefinition(EndpointManager *manager)
: fManager(manager) {}
:
fManager(manager)
{
}
size_t
ConnectionHashDefinition::HashKey(const KeyType &key) const

View File

@ -1,13 +1,15 @@
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Axel Dörfler, axeld@pinc-software.de
* Hugo Santos, hugosantos@gmail.com
*/
#ifndef ENDPOINT_MANAGER_H
#define ENDPOINT_MANAGER_H
#include "tcp.h"
#include <AddressUtilities.h>
@ -27,12 +29,16 @@ class TCPEndpoint;
struct ConnectionHashDefinition {
public:
typedef EndpointManager ParentType;
typedef std::pair<const sockaddr *, const sockaddr *> KeyType;
typedef TCPEndpoint ValueType;
ConnectionHashDefinition(EndpointManager *manager);
ConnectionHashDefinition(const ConnectionHashDefinition& definition)
: fManager(definition.fManager)
{
}
size_t HashKey(const KeyType &key) const;
size_t Hash(TCPEndpoint *endpoint) const;
bool Compare(const KeyType &key, TCPEndpoint *endpoint) const;
@ -45,7 +51,6 @@ private:
class EndpointHashDefinition {
public:
typedef EndpointManager ParentType;
typedef uint16 KeyType;
typedef TCPEndpoint ValueType;

View File

@ -1,10 +1,11 @@
/*
* Copyright 2006, Haiku, Inc. All Rights Reserved.
* Copyright 2006-2007, Haiku, Inc. All Rights Reserved.
* Distributed under the terms of the MIT License.
*
* Authors:
* Andrew Galante, haiku.galante@gmail.com
* Axel Dörfler, axeld@pinc-software.de
* Hugo Santos, hugosantos@gmail.com
*/
#ifndef TCP_ENDPOINT_H
#define TCP_ENDPOINT_H
@ -14,7 +15,6 @@
#include "EndpointManager.h"
#include "tcp.h"
#include <ProtocolUtilities.h>
#include <net_protocol.h>
#include <net_stack.h>

View File

@ -115,8 +115,10 @@ struct UdpHashDefinition {
typedef std::pair<const sockaddr *, const sockaddr *> KeyType;
typedef UdpEndpoint ValueType;
UdpHashDefinition(net_address_module_info *parent)
: module(parent) {}
UdpHashDefinition(net_address_module_info *_module)
: module(_module) {}
UdpHashDefinition(const UdpHashDefinition& definition)
: module(definition.module) {}
size_t HashKey(const KeyType &key) const
{

View File

@ -112,6 +112,7 @@ struct HashedObjectCache : object_cache {
typedef Link ValueType;
Definition(HashedObjectCache *_parent) : parent(_parent) {}
Definition(const Definition& definition) : parent(definition.parent) {}
size_t HashKey(const void *key) const
{