📄 e32hashtab.h
字号:
@return A pointer to the value object corresponding to the current position of the
iterator.
NULL if the iterator has just been constructed or reset, or if it has
previously reached the end of an iteration.
*/
inline const V* CurrentValue() const
{ return (const V*)THashTableIterBase::Current(_FOFF(SFullElement,iV)); }
/**
Steps the iterator to the next position and returns the corresponding value.
@return A pointer to the value object corresponding to the next position of the
iterator.
NULL if the iterator has exhausted all the available key-value pairs.
*/
inline const V* NextValue()
{ return (const V*)THashTableIterBase::Next(_FOFF(SFullElement,iV)); }
/**
Removes the element at the current iterator position from the hash table.
If the iterator does not currently point to a valid element, no action is taken.
Note that the iterator position is not altered so it no longer points to a valid
element following the Remove(). It is illegal to call either CurrentKey() or
CurrentValue() on the iterator after calling Remove() - the only legal
operations are Reset(), NextKey() or NextValue().
*/
inline void RemoveCurrent()
{ THashTableIterBase::RemoveCurrent(); }
};
template <class K, class V> class TPtrHashMapIter;
/**
@publishedAll
@released
A templated class which implements an associative array with key type K and value type V,
using a probe-sequence hash table. Neither the key nor value objects are copied into the
table when they are added - only pointers are stored.
*/
template <class K, class V>
class RPtrHashMap : public RHashTableBase
{
private:
friend class TPtrHashMapIter<K,V>;
struct SFullElement /**< @internalComponent */
{
TUint32 iHash;
K* iK;
V* iV;
};
public:
/**
Construct an associative array of key-value pairs of type (K,V) using a
specified hash function and identity relation.
The array initially contains no key-value pairs.
@param aHash The hash function used to hash the key objects of type K.
@param aIdentity The identity relation used to determine if two key objects
of type K should be considered identical.
*/
inline RPtrHashMap(const THashFunction32<K>& aHash, const TIdentityRelation<K>& aIdentity)
: RHashTableBase(aHash, aIdentity, sizeof(SFullElement), 0)
{}
/**
Construct an associative array of key-value pairs of type (K,V) using a
default hash function and identity relation.
The array initially contains no key-value pairs.
*/
inline RPtrHashMap()
: RHashTableBase(Defaults<K,EDefaultSpecifier_Normal>::Hash(), Defaults<K,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), 0)
{}
/**
Free all memory used by this array.
Returns the array to the same state it had following construction.
*/
inline void Close()
{ RHashTableBase::Close(); }
/**
Look up a specified key in the associative array and return a pointer to the
corresponding value.
@param aKey The key object of type K to look up.
@return A pointer to corresponding value object if the specified key
object was found. The value object may not be modified via
this pointer.
NULL if the specified key object was not found.
*/
inline const V* Find(const K& aKey) const
{ return (const V*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iV)); }
/**
Look up a specified key in the associative array and return a pointer to the
corresponding value.
@param aKey The key object of type K to look up.
@return A reference to corresponding value object if the specified key
object was found. The value object may not be modified via
this reference.
@leave KErrNotFound if the specified key object was not found.
*/
inline const V& FindL(const K& aKey) const
{ return *(const V*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iV)); }
/**
Look up a specified key in the associative array and return a pointer to the
corresponding value.
@param aKey The key object of type K to look up.
@return A pointer to corresponding value object if the specified key
object was found. The value object may be modified via
this pointer.
NULL if the specified key object was not found.
*/
inline V* Find(const K& aKey)
{ return (V*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iV)); }
/**
Look up a specified key in the associative array and return a pointer to the
corresponding value.
@param aKey The key object of type K to look up.
@return A reference to corresponding value object if the specified key
object was found. The value object may be modified via
this reference.
@leave KErrNotFound if the specified key object was not found.
*/
inline V& FindL(const K& aKey)
{ return *(V*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iV)); }
/**
Insert a key-value pair into the array.
If the specified key object is not found in the array, a pointer to the
key object along with a pointer to the value object are added to the array
and KErrNone is returned.
If the specified key object is found in the array, the existing pointers
to both the key and value objects are replaced by the provided pointers
and KErrNone is returned.
In both cases only pointers are stored in the array - the objects themselves
are not copied.
@param aKey A pointer to the key object of type K to add to the array.
@param aValue A pointer to the value object of type V to associate with aKey.
@return KErrNone if the key-value pair was added successfully.
KErrNoMemory if memory could not be allocated to store
the pointers aKey and aValue.
*/
inline TInt Insert(const K* aKey, const V* aValue)
{ return RHashTableBase::PtrInsert(aKey, aValue); }
/**
Insert a key-value pair into the array.
If the specified key object is not found in the array, a pointer to the
key object along with a pointer to the value object are added to the array
and KErrNone is returned.
If the specified key object is found in the array, the existing pointers
to both the key and value objects are replaced by the provided pointers
and KErrNone is returned.
In both cases only pointers are stored in the array - the objects themselves
are not copied.
@param aKey A pointer to the key object of type K to add to the array.
@param aValue A pointer to the value object of type V to associate with aKey.
@leave KErrNoMemory if memory could not be allocated to store the pointers aKey and aValue.
*/
inline void InsertL(const K* aKey, const V* aValue)
{ RHashTableBase::PtrInsertL(aKey, aValue); }
/**
Remove a key-value pair from the array.
@param aKey A pointer to the key to be removed.
@return KErrNone if the pointers to the key object and corresponding
value object were removed successfully.
KErrNotFound if the key object was not present in the array.
*/
inline TInt Remove(const K* aKey)
{ return RHashTableBase::Remove(aKey); }
/**
Query the number of key-value pairs in the array.
@return The number of key-value pairs currently in the array.
*/
inline TInt Count() const
{ return RHashTableBase::Count(); }
/**
Expand the array to accommodate a specified number of key-value pairs.
If the set already has enough space for the specified number of elements, no
action is taken. Any elements already in the set are retained.
@param aCount The number of key-value pairs for which space should be allocated.
@return KErrNone if the operation completed successfully.
@return KErrNoMemory if sufficient memory could not be allocated.
*/
inline TInt Reserve(TInt aCount)
{ return RHashTableBase::Reserve(aCount); }
/**
Expand the array to accommodate a specified number of key-value pairs.
If the set already has enough space for the specified number of elements, no
action is taken. Any elements already in the set are retained.
@param aCount The number of key-value pairs for which space should be allocated.
@leave KErrNoMemory if sufficient memory could not be allocated.
*/
inline void ReserveL(TInt aCount)
{ RHashTableBase::ReserveL(aCount); }
void ResetAndDestroy();
};
/**
@publishedAll
@released
A templated class which allows iteration over the elements of a RPtrHashMap<K,V>
class.
The array being iterated over may not be modified while an iteration is in progress
or the iteration operations may malfunction or panic.
@see RPtrHashMap<K,V>
*/
template <class K, class V>
class TPtrHashMapIter : public THashTableIterBase
{
private:
struct SFullElement /**< @internalComponent */
{
TUint32 iHash;
K* iK;
V* iV;
};
public:
/**
Construct an iterator over the specified associative array.
The iterator starts at conceptual position one before the beginning of the list
being iterated.
@param aMap The array to be iterated over.
*/
inline TPtrHashMapIter(const RPtrHashMap<K,V>& aMap)
: THashTableIterBase(aMap)
{}
/**
Reset the iterator to its initial state.
@param aSet The set to be iterated over.
*/
inline void Reset()
{ THashTableIterBase::Reset(); }
/**
Return the key corresponding to the current position of the iterator.
@return A pointer to the key object corresponding to the current position of the
iterator.
NULL if the iterator has just been constructed or reset, or if it has
previously reached the end of an iteration.
*/
inline const K* CurrentKey() const
{ return (const K*)THashTableIterBase::Current(-_FOFF(SFullElement,iK)); }
/**
Steps the iterator to the next position and returns the corresponding key.
@return A pointer to the key object corresponding to the next position of the
iterator.
NULL if the iterator has exhausted all the available key-value pairs.
*/
inline const K* NextKey()
{ return (const K*)THashTableIterBase::Next(-_FOFF(SFullElement,iK)); }
/**
Return the value corresponding to the current position of the iterator.
@return A pointer to the value object corresponding to the current position of the
iterator.
NULL if the iterator has just been constructed or reset, or if it has
previously reached the end of an iteration.
*/
inline const V* CurrentValue() const
{ return (const V*)THashTableIterBase::Current(-_FOFF(SFullElement,iV)); }
/**
Steps the iterator to the next position and returns the corresponding value.
@return A pointer to the value object corresponding to the next position of the
iterator.
NULL if the iterator has exhausted all the available key-value pairs.
*/
inline const V* NextValue()
{ return (const V*)THashTableIterBase::Next(-_FOFF(SFullElement,iV)); }
/**
Removes the element at the current iterator position from the hash table.
If the iterator does not currently point to a valid element, no action is taken.
Note that the iterator position is not altered so it no longer points to a valid
element following the Remove(). It is illegal to call either CurrentKey() or
CurrentValue() on the iterator after calling Remove() - the only legal
operations are Reset(), NextKey() or NextValue().
*/
inline void RemoveCurrent()
{ THashTableIterBase::RemoveCurrent(); }
};
/**
Deletes all the objects of type T to which pointers are stored in this set.
Then frees all the memory used by the set and returns the set to the same state
as immediately following construction.
*/
template <class T>
void RPtrHashSet<T>::ResetAndDestroy()
{
TPtrHashSetIter<T> iter(*this);
T* p;
do {
p = (T*)iter.Next();
delete p;
} while(p);
Close();
}
/**
Deletes all the key objects of type K and corresponding value objects of type V
to which pointers are stored in this array.
Then frees all the memory used by the array and returns the array to the same
state as immediately following construction.
*/
template <class K, class V>
void RPtrHashMap<K,V>::ResetAndDestroy()
{
TPtrHashMapIter<K,V> iter(*this);
K* p;
V* q;
do {
p = (K*)iter.NextKey();
q = (V*)iter.CurrentValue();
delete p;
delete q;
} while(p);
Close();
}
#endif
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -