⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 e32hashtab.h

📁 symbian下读取服务的程序
💻 H
📖 第 1 页 / 共 4 页
字号:
*/
	inline TInt Count() const
		{ return RHashTableBase::Count(); }


/**
Expand the set to accommodate a specified number of elements.
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 elements 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 set to accommodate a specified number of elements.
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 elements 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 RPtrHashSet<T>
class.

The set being iterated over may not be modified while an iteration is in progress
or the iteration operations may malfunction or panic.

@see RPtrHashSet<T>
*/
template <class T>
class TPtrHashSetIter : public THashTableIterBase
	{
private:
	struct SFullElement		/**< @internalComponent */
		{
		TUint32 iHash;
		T* iT;
		};

public:

/**
Construct an iterator over the specified set.
The iterator starts at conceptual position one before the beginning of the list
being iterated.

@param	aSet	The set to be iterated over.
*/
	inline TPtrHashSetIter(const RPtrHashSet<T>& aSet)
		:	THashTableIterBase(aSet)
		{}


/**
Reset the iterator to its initial state.

@param	aSet	The set to be iterated over.
*/
	inline void Reset()
		{ THashTableIterBase::Reset(); }


/**
Return the current position of the iterator.

@return	A pointer to the set member 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 T* Current() const
		{ return (const T*)THashTableIterBase::Current(-_FOFF(SFullElement,iT)); }


/**
Steps the iterator to the next position.

@return	A pointer to the set member corresponding to the next position of the
		iterator.
		NULL if the iterator has exhausted all the available set elements.
*/
	inline const T* Next()
		{ return (const T*)THashTableIterBase::Next(-_FOFF(SFullElement,iT)); }


/**
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 Current() on the iterator
after calling Remove() - the only legal operations are Reset() and Next().

*/
	inline void RemoveCurrent()
		{ THashTableIterBase::RemoveCurrent(); }
	};



template <class K, class V> class THashMapIter;

/**
@publishedAll
@released

A templated class which implements an associative array with key type K and value type V,
using a probe-sequence hash table. Both the key and value objects are copied into the
table when they are added. A bitwise binary copy is used here, so neither of the types
K and V may implement a nontrivial copy constructor.

*/
template <class K, class V>
class RHashMap : public RHashTableBase
	{
private:
	friend class THashMapIter<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 RHashMap(const THashFunction32<K>& aHash, const TIdentityRelation<K>& aIdentity)
		:	RHashTableBase(aHash, aIdentity, sizeof(SFullElement), _FOFF(SFullElement,iK))
		{}


/**
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 RHashMap()
		:	RHashTableBase(Defaults<K,EDefaultSpecifier_Normal>::Hash(), Defaults<K,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), _FOFF(SFullElement,iK))
		{}


/**
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 the copy of the corresponding value object in the
				array, 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 the copy of the corresponding value object in the
				array, 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 the copy of the corresponding value object in the
				array, 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 the copy of the corresponding value object in the
				array, 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 copy of the
key object along with a copy of the value object are added to the array
and KErrNone is returned.
If the specified key object is found in the array, the existing copies
of both the key and value objects are replaced by the provided objects
and KErrNone is returned.
In both cases the objects are copied bitwise into the array.

@param	aKey	The key object of type K to add to the array.
@param	aValue	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 copies of aKey and aValue.
*/
	inline TInt Insert(const K& aKey, const V& aValue)
		{ return RHashTableBase::ValueInsert(&aKey, sizeof(K), &aValue, _FOFF(SFullElement,iV), sizeof(V)); }


/**
Insert a key-value pair into the array.

If the specified key object is not found in the array, a copy of the
key object along with a copy of the value object are added to the array
and KErrNone is returned.
If the specified key object is found in the array, the existing copies
of both the key and value objects are replaced by the provided objects
and KErrNone is returned.
In both cases the objects are copied bitwise into the array.

@param	aKey	The key object of type K to add to the array.
@param	aValue	The value object of type V to associate with aKey.
@leave	KErrNoMemory if memory could not be allocated to store the copies of aKey and aValue.
*/
	inline void InsertL(const K& aKey, const V& aValue)
		{ RHashTableBase::ValueInsertL(&aKey, sizeof(K), &aValue, _FOFF(SFullElement,iV), sizeof(V)); }


/**
Remove a key-value pair from the array.

@param	aKey	The key to be removed.
@return			KErrNone if 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); }

	};


/**
@publishedAll
@released

A templated class which allows iteration over the elements of a RHashMap<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 RHashMap<K,V>
*/
template <class K, class V>
class THashMapIter : public THashTableIterBase
	{
private:
	struct SFullElement
		{
		TUint32 iHash;	/**< @internalComponent */
		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 THashMapIter(const RHashMap<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.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -