version 1.5, 2001/04/29 18:57:33
|
version 1.13, 2002/06/01 00:56:33
|
|
|
//%///////////////////////////////////////////////////////////////////////////// | //%///////////////////////////////////////////////////////////////////////////// |
// | // |
// Copyright (c) 2000 The Open Group, BMC Software, Tivoli Systems, IBM |
// Copyright (c) 2000, 2001, 2002 BMC Software, Hewlett-Packard Company, IBM, |
|
// The Open Group, Tivoli Systems |
// | // |
// Permission is hereby granted, free of charge, to any person obtaining a |
// Permission is hereby granted, free of charge, to any person obtaining a copy |
// copy of this software and associated documentation files (the "Software"), |
// of this software and associated documentation files (the "Software"), to |
// to deal in the Software without restriction, including without limitation |
// deal in the Software without restriction, including without limitation the |
// the rights to use, copy, modify, merge, publish, distribute, sublicense, |
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or |
// and/or sell copies of the Software, and to permit persons to whom the |
// sell copies of the Software, and to permit persons to whom the Software is |
// Software is furnished to do so, subject to the following conditions: |
// furnished to do so, subject to the following conditions: |
// | // |
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
// THE ABOVE COPYRIGHT NOTICE AND THIS PERMISSION NOTICE SHALL BE INCLUDED IN |
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
// ALL COPIES OR SUBSTANTIAL PORTIONS OF THE SOFTWARE. THE SOFTWARE IS PROVIDED |
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
// "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT |
// THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
// LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR |
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING |
// PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT |
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER |
// HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN |
// DEALINGS IN THE SOFTWARE. |
// ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION |
|
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. |
// | // |
//============================================================================== | //============================================================================== |
// | // |
|
|
{ | { |
}; | }; |
| |
template<> struct PEGASUS_COMMON_LINKAGE HashFunc<String> |
PEGASUS_TEMPLATE_SPECIALIZATION struct PEGASUS_COMMON_LINKAGE HashFunc<String> |
{ | { |
static Uint32 hash(const String& str); | static Uint32 hash(const String& str); |
}; | }; |
| |
template<> struct HashFunc<Uint32> |
PEGASUS_TEMPLATE_SPECIALIZATION struct HashFunc<Uint32> |
{ | { |
static Uint32 hash(Uint32 x) { return x + 13; } | static Uint32 hash(Uint32 x) { return x + 13; } |
}; | }; |
|
|
| |
_HashTableIteratorBase() : _first(0), _last(0), _bucket(0) { } | _HashTableIteratorBase() : _first(0), _last(0), _bucket(0) { } |
| |
operator Boolean() const { return _bucket != 0; } |
operator int() const { return _bucket != 0; } |
| |
_HashTableIteratorBase operator++(int); | _HashTableIteratorBase operator++(int); |
| |
|
|
_BucketBase** _first; | _BucketBase** _first; |
_BucketBase** _last; | _BucketBase** _last; |
_BucketBase* _bucket; | _BucketBase* _bucket; |
friend _HashTableRep; |
friend class _HashTableRep; |
}; | }; |
| |
// ATTN: reorganization not supported yet. | // ATTN: reorganization not supported yet. |
|
|
@param key void pointer to key. | @param key void pointer to key. |
@return pointer to bucket with that key or zero otherwise. | @return pointer to bucket with that key or zero otherwise. |
*/ | */ |
const _BucketBase* lookup(Uint32 hashCode, const void* key); |
const _BucketBase* lookup(Uint32 hashCode, const void* key) const; |
| |
/*- Removes the bucket with the given key. This method uses the | /*- Removes the bucket with the given key. This method uses the |
_BucketBase::equal() method to compare keys. | _BucketBase::equal() method to compare keys. |
|
|
the pathalogical case in which all entries are placed in the first | the pathalogical case in which all entries are placed in the first |
chain. | chain. |
*/ | */ |
template<class K, class V, class E = EqualFunc<K>, class H = HashFunc<K> > |
template<class K, class V, class E , class H > |
class HashTable | class HashTable |
{ | { |
public: | public: |
|
|
} | } |
| |
/** Copy constructor. */ | /** Copy constructor. */ |
HashTable(const HashTable& x) : _rep(x._rep) |
HashTable(const HashTable<K,V,E,H>& x) : _rep(x._rep) |
{ | { |
| |
} | } |
| |
/** Assignment operator. */ | /** Assignment operator. */ |
HashTable& operator=(const HashTable& x) |
HashTable<K,V,E,H>& operator=(const HashTable<K,V,E,H>& x) |
{ | { |
if (this != &x) | if (this != &x) |
_rep = x._rep; | _rep = x._rep; |
|
|
@param key key to be searched for | @param key key to be searched for |
@return true if hash table contains an entry with the given key. | @return true if hash table contains an entry with the given key. |
*/ | */ |
Boolean contains(const K& key) |
Boolean contains(const K& key) const |
{ | { |
V value; | V value; |
return lookup(key, value); | return lookup(key, value); |
|
|
@param value output value. | @param value output value. |
@return true if found; false otherwise. | @return true if found; false otherwise. |
*/ | */ |
Boolean lookup(const K& key, V& value); |
Boolean lookup(const K& key, V& value) const; |
| |
/** Removes the entry with the given key. | /** Removes the entry with the given key. |
@param key key of entry to be removed. | @param key key of entry to be removed. |
|
|
}; | }; |
| |
template<class K, class V, class E, class H> | template<class K, class V, class E, class H> |
inline Boolean HashTable<K, V, E, H>::lookup(const K& key, V& value) |
inline Boolean HashTable<K, V, E, H>::lookup(const K& key, V& value) const |
{ | { |
_Bucket<K, V, E>* bucket | _Bucket<K, V, E>* bucket |
= (_Bucket<K, V, E>*)_rep.lookup(H::hash(key), &key); | = (_Bucket<K, V, E>*)_rep.lookup(H::hash(key), &key); |