version 1.23, 2006/11/08 22:24:00
|
version 1.27, 2008/05/02 19:02:56
|
|
|
_BucketBase* next; | _BucketBase* next; |
}; | }; |
| |
class _HashTableRep; |
|
|
|
/* This class implements a simple hash table forward iterator. */ | /* This class implements a simple hash table forward iterator. */ |
class PEGASUS_COMMON_LINKAGE _HashTableIteratorBase | class PEGASUS_COMMON_LINKAGE _HashTableIteratorBase |
{ | { |
public: | public: |
| |
_HashTableIteratorBase() : _first(0), _last(0), _bucket(0) { } |
_HashTableIteratorBase(_BucketBase** first, _BucketBase** last); |
| |
operator int() const { return _bucket != 0; } | operator int() const { return _bucket != 0; } |
| |
|
|
| |
_HashTableIteratorBase& operator++(); | _HashTableIteratorBase& operator++(); |
| |
_HashTableIteratorBase(_BucketBase** first, _BucketBase** last); |
|
|
|
protected: | protected: |
| |
|
// Note: The default copy constructor/assignment operator is used by the |
|
// postfix increment operator. The member pointers may be safely copied |
|
// because they refer to structures that must not change while the iterator |
|
// is in scope. |
|
|
_BucketBase** _first; | _BucketBase** _first; |
_BucketBase** _last; | _BucketBase** _last; |
_BucketBase* _bucket; | _BucketBase* _bucket; |
friend class _HashTableRep; |
|
}; | }; |
| |
// ATTN: reorganization not supported yet. | // ATTN: reorganization not supported yet. |
|
|
{ | { |
public: | public: |
| |
_HashTableIterator() |
|
: _HashTableIteratorBase() { } |
|
|
|
_HashTableIterator(_BucketBase** first, _BucketBase** last) | _HashTableIterator(_BucketBase** first, _BucketBase** last) |
: _HashTableIteratorBase(first, last) { } | : _HashTableIteratorBase(first, last) { } |
| |
|
|
*/ | */ |
Boolean lookup(const K& key, V& value) const; | Boolean lookup(const K& key, V& value) const; |
| |
|
/** Looks up the entry with the given key and returns a pointer to the |
|
value. Note that this pointer may become invalid when the HashTable |
|
is updated. |
|
@param key key of entry to be located. |
|
@param value Output pointer to the value. |
|
@return true if found; false otherwise. |
|
*/ |
|
Boolean lookupReference(const K& key, V*& value); |
|
|
/** 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. |
@return true on success; false otherwise. | @return true on success; false otherwise. |
|
|
return false; | return false; |
} | } |
| |
|
template<class K, class V, class E, class H> |
|
inline Boolean HashTable<K, V, E, H>::lookupReference(const K& key, V*& value) |
|
{ |
|
_Bucket<K, V, E>* bucket = |
|
(_Bucket<K, V, E>*)_rep.lookup(H::hash(key), &key); |
|
|
|
if (bucket) |
|
{ |
|
value = &bucket->getValue(); |
|
return true; |
|
} |
|
|
|
return false; |
|
} |
|
|
PEGASUS_NAMESPACE_END | PEGASUS_NAMESPACE_END |
| |
#endif /* Pegasus_HashTable_h */ | #endif /* Pegasus_HashTable_h */ |