diff --git a/headers/private/kernel/util/MultiHashTable.h b/headers/private/kernel/util/MultiHashTable.h index 85ddbd73fe..9cedf8d1f1 100644 --- a/headers/private/kernel/util/MultiHashTable.h +++ b/headers/private/kernel/util/MultiHashTable.h @@ -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 #include #include + // 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 diff --git a/headers/private/kernel/util/OpenHashTable.h b/headers/private/kernel/util/OpenHashTable.h index d378868ac0..04247d186e 100644 --- a/headers/private/kernel/util/OpenHashTable.h +++ b/headers/private/kernel/util/OpenHashTable.h @@ -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 #include -// 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 { -// int bar; -// -// HashTableLink 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 *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 { + int bar; + + HashTableLink 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 *GetLink(Foo *value) const { return value; } + }; +*/ template 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 diff --git a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp index 7081311624..1c5c5bc146 100644 --- a/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp +++ b/src/add-ons/kernel/network/protocols/ipv4/ipv4.cpp @@ -131,7 +131,6 @@ typedef MulticastGroupInterface IPv4GroupInterface; typedef MulticastFilter IPv4MulticastFilter; struct MulticastStateHash { - typedef void ParentType; typedef std::pair KeyType; typedef IPv4GroupInterface ValueType; diff --git a/src/add-ons/kernel/network/protocols/ipv4/multicast.h b/src/add-ons/kernel/network/protocols/ipv4/multicast.h index 5a2e799c93..7b98498fd4 100644 --- a/src/add-ons/kernel/network/protocols/ipv4/multicast.h +++ b/src/add-ons/kernel/network/protocols/ipv4/multicast.h @@ -5,10 +5,10 @@ * Authors: * Hugo Santos, hugosantos@gmail.com */ - #ifndef _PRIVATE_MULTICAST_H_ #define _PRIVATE_MULTICAST_H_ + #include #include @@ -18,6 +18,7 @@ #include + 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 KeyType; typedef ThisType ValueType; diff --git a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp index 511f9167fc..f91eab620c 100644 --- a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp +++ b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.cpp @@ -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 diff --git a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h index 04c7365c0e..e47d78adf1 100644 --- a/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h +++ b/src/add-ons/kernel/network/protocols/tcp/EndpointManager.h @@ -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 @@ -27,12 +29,16 @@ class TCPEndpoint; struct ConnectionHashDefinition { public: - typedef EndpointManager ParentType; typedef std::pair 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; diff --git a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h index 839fff0316..4fd74b867a 100644 --- a/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h +++ b/src/add-ons/kernel/network/protocols/tcp/TCPEndpoint.h @@ -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 #include #include diff --git a/src/add-ons/kernel/network/protocols/udp/udp.cpp b/src/add-ons/kernel/network/protocols/udp/udp.cpp index 5ade4c31bb..7510aa3a33 100644 --- a/src/add-ons/kernel/network/protocols/udp/udp.cpp +++ b/src/add-ons/kernel/network/protocols/udp/udp.cpp @@ -115,8 +115,10 @@ struct UdpHashDefinition { typedef std::pair 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 { diff --git a/src/system/kernel/slab/Slab.cpp b/src/system/kernel/slab/Slab.cpp index 0fd5ce8405..d1a5781d6d 100644 --- a/src/system/kernel/slab/Slab.cpp +++ b/src/system/kernel/slab/Slab.cpp @@ -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 {