1.1 --- a/epoc32/include/e32hashtab.h Tue Nov 24 13:55:44 2009 +0000
1.2 +++ b/epoc32/include/e32hashtab.h Tue Mar 16 16:12:26 2010 +0000
1.3 @@ -1,1 +1,1748 @@
1.4 -e32hashtab.h
1.5 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.6 +// All rights reserved.
1.7 +// This component and the accompanying materials are made available
1.8 +// under the terms of the License "Symbian Foundation License v1.0" to Symbian Foundation members and "Symbian Foundation End User License Agreement v1.0" to non-members
1.9 +// which accompanies this distribution, and is available
1.10 +// at the URL "http://www.symbianfoundation.org/legal/licencesv10.html".
1.11 +//
1.12 +// Initial Contributors:
1.13 +// Nokia Corporation - initial contribution.
1.14 +//
1.15 +// Contributors:
1.16 +//
1.17 +// Description:
1.18 +// e32/include/e32hashtab.h
1.19 +//
1.20 +//
1.21 +
1.22 +#ifndef __E32HASHTAB_H__
1.23 +#define __E32HASHTAB_H__
1.24 +#include <e32cmn.h>
1.25 +
1.26 +/**
1.27 +@publishedAll
1.28 +@released
1.29 +
1.30 +Defines a function type used by a THashFunction32 object.
1.31 +
1.32 +A function of this type implements an algorithm for producing a 32 bit hash
1.33 +value from a key.
1.34 +
1.35 +@see THashFunction32
1.36 +*/
1.37 +typedef TUint32 (*TGeneralHashFunction32)(const TAny*);
1.38 +
1.39 +
1.40 +/**
1.41 +@publishedAll
1.42 +@released
1.43 +
1.44 +A templated class which packages a function that calculates a 32 bit hash
1.45 +value from a key of templated type.
1.46 +
1.47 +A THashFunction32<T> object is constructed and passed as a parameter to
1.48 +member functions of the hash table classes RHashSet<T>, RPtrHashSet<T>,
1.49 +RHashMap<T,V> and RPtrHashMap<T,V>.
1.50 +
1.51 +@see RHashSet
1.52 +@see RPtrHashSet
1.53 +@see RHashMap
1.54 +@see RPtrHashMap
1.55 +*/
1.56 +template <class T>
1.57 +class THashFunction32
1.58 + {
1.59 +public:
1.60 + inline THashFunction32( TUint32 (*aHashFunc)(const T&) )
1.61 + { iHashFunction = (TGeneralHashFunction32)aHashFunc; }
1.62 + inline operator TGeneralHashFunction32() const
1.63 + { return iHashFunction; }
1.64 + inline TUint32 Hash(const T& aKey) const
1.65 + { return (*iHashFunction)(&aKey); }
1.66 +private:
1.67 + TGeneralHashFunction32 iHashFunction;
1.68 + };
1.69 +
1.70 +
1.71 +/**
1.72 +@publishedAll
1.73 +@released
1.74 +
1.75 +A set of common hashing functions for frequently occurring types.
1.76 +
1.77 +@see RHashSet
1.78 +@see RPtrHashSet
1.79 +@see RHashMap
1.80 +@see RPtrHashMap
1.81 +*/
1.82 +class DefaultHash
1.83 + {
1.84 +public:
1.85 + IMPORT_C static TUint32 Integer(const TInt&);
1.86 + IMPORT_C static TUint32 Des8(const TDesC8&);
1.87 + IMPORT_C static TUint32 Des16(const TDesC16&);
1.88 + IMPORT_C static TUint32 IntegerPtr(TInt* const &);
1.89 + IMPORT_C static TUint32 Des8Ptr(TDesC8* const &);
1.90 + IMPORT_C static TUint32 Des16Ptr(TDesC16* const &);
1.91 + };
1.92 +
1.93 +
1.94 +
1.95 +class THashTableIterBase;
1.96 +
1.97 +/**
1.98 +@internalComponent
1.99 +
1.100 +Base class used in the derivation of RHashSet<T>, RPtrHashSet<T>,
1.101 +RHashMap<K,V> and RPtrHashMap<K,V>.
1.102 +
1.103 +This class provides a general hash table implementation using probe sequences
1.104 +generated by pseudo-double hashing.
1.105 +The class is internal and is not intended for use.
1.106 +*/
1.107 +class RHashTableBase
1.108 + {
1.109 +public:
1.110 + enum TDefaultSpecifier
1.111 + {
1.112 + EDefaultSpecifier_Normal,
1.113 + };
1.114 +
1.115 +protected:
1.116 + template<class K, TDefaultSpecifier S>
1.117 + class Defaults
1.118 + {
1.119 + public:
1.120 + inline static TGeneralHashFunction32 Hash();
1.121 + inline static TGeneralIdentityRelation Id();
1.122 + };
1.123 +
1.124 +protected:
1.125 + enum TElementState
1.126 + {
1.127 + EEmpty=0, // entry is vacant
1.128 + EDeleted=1, // entry has been deleted
1.129 + EGen0=2, // entry is occupied, generation number 0
1.130 + EGen1=3, // entry is occupied, generation number 1
1.131 + EStateMask=3,
1.132 + EOccupiedMask=2,
1.133 + };
1.134 +
1.135 + struct SElement
1.136 + {
1.137 + inline void SetEmpty() {iHash=EEmpty;}
1.138 + inline void SetDeleted() {iHash=EDeleted;}
1.139 + inline TBool IsEmpty() const {return (iHash&EStateMask)==EEmpty;}
1.140 + inline TBool IsDeleted() const {return (iHash&EStateMask)==EDeleted;}
1.141 + inline TBool IsEmptyOrDeleted() const {return !(iHash&EOccupiedMask);}
1.142 +
1.143 + TUint32 iHash; // bits 2-31 = 30 bit hash value, bits 0,1 = state
1.144 + };
1.145 +
1.146 +protected:
1.147 + IMPORT_C RHashTableBase(TGeneralHashFunction32, TGeneralIdentityRelation, TInt aElementSize, TInt aKeyOffset);
1.148 + IMPORT_C void Close();
1.149 + IMPORT_C TAny* Find(const TAny* aKey, TInt aOffset=0) const;
1.150 + IMPORT_C TAny* FindL(const TAny* aKey, TInt aOffset=0) const;
1.151 + TInt Insert(const TAny* aKey, TAny*& aElement);
1.152 + IMPORT_C TInt PtrInsert(const TAny* aKey, const TAny* aValue);
1.153 + IMPORT_C void PtrInsertL(const TAny* aKey, const TAny* aValue);
1.154 + IMPORT_C TInt ValueInsert(const TAny* aKey, TInt aKeySize, const TAny* aValue, TInt aValueOffset, TInt aValueSize);
1.155 + IMPORT_C void ValueInsertL(const TAny* aKey, TInt aKeySize, const TAny* aValue, TInt aValueOffset, TInt aValueSize);
1.156 + IMPORT_C TInt Remove(const TAny* aKey);
1.157 + IMPORT_C TInt Count() const;
1.158 + IMPORT_C TInt Reserve(TInt aCount);
1.159 + IMPORT_C void ReserveL(TInt aCount);
1.160 + IMPORT_C void ConsistencyCheck(TUint32* aDeleted=0, TUint32* aComparisons=0, TUint32 aChainLimit=0, TUint32* aChainInfo=0);
1.161 +private:
1.162 + void SetThresholds();
1.163 + TInt ExpandTable(TInt aNewIndexBits);
1.164 + void ShrinkTable();
1.165 + void ReformTable(TUint aNewIndexBits);
1.166 + void VerifyReform();
1.167 +private:
1.168 + inline SElement* Element(TInt aIndex)
1.169 + {return (SElement*)(((TUint8*)iElements) + aIndex*iElementSize);}
1.170 + inline const SElement* ElementC(TInt aIndex) const
1.171 + {return (const SElement*)(((TUint8*)iElements) + aIndex*iElementSize);}
1.172 + inline TAny* GetKey(const SElement* aElement) const
1.173 + {return iKeyOffset ? ((TUint8*)aElement + iKeyOffset) : (TAny*)((TUint32*)aElement)[1];}
1.174 +private:
1.175 + TGeneralHashFunction32 iHashFunc; // generates the hash from a given key
1.176 + TGeneralIdentityRelation iIdFunc; // compare two keys for equality
1.177 + TUint8 iIndexBits; // number of bits used to index the table
1.178 + TUint8 iGeneration; // 2 or 3, generation number used when traversing entire table
1.179 + TUint8 iKeyOffset; // offset to key
1.180 + TUint8 iPad0;
1.181 + TAny* iElements;
1.182 + TUint32 iCount; // number of valid entries
1.183 + TUint32 iEmptyCount; // number of empty entries
1.184 + TUint32 iLowerThreshold; // shrink if count drops below this
1.185 + TUint32 iUpperThreshold; // expand if count rises above this
1.186 + TUint32 iCleanThreshold; // clean table if count of empty entries falls below this
1.187 + TInt iElementSize;
1.188 + TInt iPad1; // expansion room
1.189 + TInt iPad2;
1.190 +
1.191 + friend struct RHashTableBase::SElement;
1.192 + friend class THashTableIterBase;
1.193 + friend class HashTest;
1.194 + };
1.195 +
1.196 +
1.197 +/**
1.198 +@internalComponent
1.199 +*/
1.200 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TInt*, RHashTableBase::EDefaultSpecifier_Normal>
1.201 + {
1.202 +public:
1.203 + inline static TGeneralHashFunction32 Hash();
1.204 + inline static TGeneralIdentityRelation Id();
1.205 + };
1.206 +
1.207 +/**
1.208 +@internalComponent
1.209 +*/
1.210 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TInt*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.211 + {return (TGeneralHashFunction32)&DefaultHash::IntegerPtr;}
1.212 +
1.213 +/**
1.214 +@internalComponent
1.215 +*/
1.216 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TInt*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.217 + {return (TGeneralIdentityRelation)&DefaultIdentity::IntegerPtr;}
1.218 +
1.219 +/**
1.220 +@internalComponent
1.221 +*/
1.222 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TInt32*, RHashTableBase::EDefaultSpecifier_Normal>
1.223 + {
1.224 +public:
1.225 + inline static TGeneralHashFunction32 Hash();
1.226 + inline static TGeneralIdentityRelation Id();
1.227 + };
1.228 +
1.229 +/**
1.230 +@internalComponent
1.231 +*/
1.232 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TInt32*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.233 + {return (TGeneralHashFunction32)&DefaultHash::IntegerPtr;}
1.234 +
1.235 +/**
1.236 +@internalComponent
1.237 +*/
1.238 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TInt32*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.239 + {return (TGeneralIdentityRelation)&DefaultIdentity::IntegerPtr;}
1.240 +
1.241 +/**
1.242 +@internalComponent
1.243 +*/
1.244 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TUint*, RHashTableBase::EDefaultSpecifier_Normal>
1.245 + {
1.246 +public:
1.247 + inline static TGeneralHashFunction32 Hash();
1.248 + inline static TGeneralIdentityRelation Id();
1.249 + };
1.250 +/**
1.251 +@internalComponent
1.252 +*/
1.253 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TUint*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.254 + {return (TGeneralHashFunction32)&DefaultHash::IntegerPtr;}
1.255 +
1.256 +/**
1.257 +@internalComponent
1.258 +*/
1.259 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TUint*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.260 + {return (TGeneralIdentityRelation)&DefaultIdentity::IntegerPtr;}
1.261 +
1.262 +
1.263 +/**
1.264 +@internalComponent
1.265 +*/
1.266 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TUint32*, RHashTableBase::EDefaultSpecifier_Normal>
1.267 + {
1.268 +public:
1.269 + inline static TGeneralHashFunction32 Hash();
1.270 + inline static TGeneralIdentityRelation Id();
1.271 + };
1.272 +/**
1.273 +@internalComponent
1.274 +*/
1.275 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TUint32*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.276 + {return (TGeneralHashFunction32)&DefaultHash::IntegerPtr;}
1.277 +
1.278 +/**
1.279 +@internalComponent
1.280 +*/
1.281 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TUint32*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.282 + {return (TGeneralIdentityRelation)&DefaultIdentity::IntegerPtr;}
1.283 +
1.284 +/**
1.285 +@internalComponent
1.286 +*/
1.287 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TDesC8*, RHashTableBase::EDefaultSpecifier_Normal>
1.288 + {
1.289 +public:
1.290 + inline static TGeneralHashFunction32 Hash();
1.291 + inline static TGeneralIdentityRelation Id();
1.292 + };
1.293 +/**
1.294 +@internalComponent
1.295 +*/
1.296 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TDesC8*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.297 + {return (TGeneralHashFunction32)&DefaultHash::Des8Ptr;}
1.298 +
1.299 +/**
1.300 +@internalComponent
1.301 +*/
1.302 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TDesC8*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.303 + {return (TGeneralIdentityRelation)&DefaultIdentity::Des8Ptr;}
1.304 +
1.305 +/**
1.306 +@internalComponent
1.307 +*/
1.308 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TDesC16*, RHashTableBase::EDefaultSpecifier_Normal>
1.309 + {
1.310 +public:
1.311 + inline static TGeneralHashFunction32 Hash();
1.312 + inline static TGeneralIdentityRelation Id();
1.313 + };
1.314 +/**
1.315 +@internalComponent
1.316 +*/
1.317 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TDesC16*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.318 + {return (TGeneralHashFunction32)&DefaultHash::Des16Ptr;}
1.319 +
1.320 +/**
1.321 +@internalComponent
1.322 +*/
1.323 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TDesC16*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.324 + {return (TGeneralIdentityRelation)&DefaultIdentity::Des16Ptr;}
1.325 +
1.326 +/**
1.327 +@internalComponent
1.328 +*/
1.329 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TInt, RHashTableBase::EDefaultSpecifier_Normal>
1.330 + {
1.331 +public:
1.332 + inline static TGeneralHashFunction32 Hash();
1.333 + inline static TGeneralIdentityRelation Id();
1.334 + };
1.335 +
1.336 +/**
1.337 +@internalComponent
1.338 +*/
1.339 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TInt, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.340 + {return (TGeneralHashFunction32)&DefaultHash::Integer;}
1.341 +
1.342 +/**
1.343 +@internalComponent
1.344 +*/
1.345 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TInt, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.346 + {return (TGeneralIdentityRelation)&DefaultIdentity::Integer;}
1.347 +
1.348 +/**
1.349 +@internalComponent
1.350 +*/
1.351 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TInt32, RHashTableBase::EDefaultSpecifier_Normal>
1.352 + {
1.353 +public:
1.354 + inline static TGeneralHashFunction32 Hash();
1.355 + inline static TGeneralIdentityRelation Id();
1.356 + };
1.357 +
1.358 +/**
1.359 +@internalComponent
1.360 +*/
1.361 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TInt32, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.362 + {return (TGeneralHashFunction32)&DefaultHash::Integer;}
1.363 +
1.364 +/**
1.365 +@internalComponent
1.366 +*/
1.367 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TInt32, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.368 + {return (TGeneralIdentityRelation)&DefaultIdentity::Integer;}
1.369 +
1.370 +/**
1.371 +@internalComponent
1.372 +*/
1.373 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TUint, RHashTableBase::EDefaultSpecifier_Normal>
1.374 + {
1.375 +public:
1.376 + inline static TGeneralHashFunction32 Hash();
1.377 + inline static TGeneralIdentityRelation Id();
1.378 + };
1.379 +
1.380 +/**
1.381 +@internalComponent
1.382 +*/
1.383 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TUint, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.384 + {return (TGeneralHashFunction32)&DefaultHash::Integer;}
1.385 +
1.386 +/**
1.387 +@internalComponent
1.388 +*/
1.389 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TUint, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.390 + {return (TGeneralIdentityRelation)&DefaultIdentity::Integer;}
1.391 +
1.392 +
1.393 +/**
1.394 +@internalComponent
1.395 +*/
1.396 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TUint32, RHashTableBase::EDefaultSpecifier_Normal>
1.397 + {
1.398 +public:
1.399 + inline static TGeneralHashFunction32 Hash();
1.400 + inline static TGeneralIdentityRelation Id();
1.401 + };
1.402 +
1.403 +/**
1.404 +@internalComponent
1.405 +*/
1.406 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TUint32, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.407 + {return (TGeneralHashFunction32)&DefaultHash::Integer;}
1.408 +
1.409 +/**
1.410 +@internalComponent
1.411 +*/
1.412 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TUint32, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.413 + {return (TGeneralIdentityRelation)&DefaultIdentity::Integer;}
1.414 +
1.415 +
1.416 +/**
1.417 +@internalComponent
1.418 +*/
1.419 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TDesC8, RHashTableBase::EDefaultSpecifier_Normal>
1.420 + {
1.421 +public:
1.422 + inline static TGeneralHashFunction32 Hash();
1.423 + inline static TGeneralIdentityRelation Id();
1.424 + };
1.425 +
1.426 +/**
1.427 +@internalComponent
1.428 +*/
1.429 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TDesC8, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.430 + {return (TGeneralHashFunction32)&DefaultHash::Des8;}
1.431 +
1.432 +/**
1.433 +@internalComponent
1.434 +*/
1.435 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TDesC8, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.436 + {return (TGeneralIdentityRelation)&DefaultIdentity::Des8;}
1.437 +
1.438 +
1.439 +/**
1.440 +@internalComponent
1.441 +*/
1.442 +TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TDesC16, RHashTableBase::EDefaultSpecifier_Normal>
1.443 + {
1.444 +public:
1.445 + inline static TGeneralHashFunction32 Hash();
1.446 + inline static TGeneralIdentityRelation Id();
1.447 + };
1.448 +
1.449 +/**
1.450 +@internalComponent
1.451 +*/
1.452 +inline TGeneralHashFunction32 RHashTableBase::Defaults<TDesC16, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
1.453 + {return (TGeneralHashFunction32)&DefaultHash::Des16;}
1.454 +
1.455 +/**
1.456 +@internalComponent
1.457 +*/
1.458 +inline TGeneralIdentityRelation RHashTableBase::Defaults<TDesC16, RHashTableBase::EDefaultSpecifier_Normal>::Id()
1.459 + {return (TGeneralIdentityRelation)&DefaultIdentity::Des16;}
1.460 +
1.461 +
1.462 +
1.463 +
1.464 +/**
1.465 +@internalComponent
1.466 +
1.467 +Base class used in the derivation of THashSetIter<T>, TPtrHashSetIter<T>,
1.468 +THashMapIter<K,V> and TPtrHashMapIter<K,V>.
1.469 +
1.470 +This class provides iteration capability for the hash table classes derived
1.471 +from RHashTableBase.
1.472 +The class is internal and is not intended for use.
1.473 +*/
1.474 +class THashTableIterBase
1.475 + {
1.476 +protected:
1.477 + IMPORT_C THashTableIterBase(const RHashTableBase& aTable);
1.478 + IMPORT_C void Reset();
1.479 + IMPORT_C const TAny* Next(TInt aOffset=0);
1.480 + IMPORT_C const TAny* Current(TInt aOffset=0) const;
1.481 + IMPORT_C void RemoveCurrent();
1.482 +private:
1.483 + const RHashTableBase& iTbl;
1.484 + TInt iIndex;
1.485 + TInt iPad1; // expansion room
1.486 + TInt iPad2;
1.487 + };
1.488 +
1.489 +
1.490 +
1.491 +template <class T> class THashSetIter;
1.492 +
1.493 +/**
1.494 +@publishedAll
1.495 +@released
1.496 +
1.497 +A templated class which implements an unordered extensional set of objects of
1.498 +type T using a probe-sequence hash table. The objects are copied into the set
1.499 +when they are added. A bitwise binary copy is used here, so the type T must
1.500 +not implement a nontrivial copy constructor.
1.501 +
1.502 +*/
1.503 +template <class T>
1.504 +class RHashSet : public RHashTableBase
1.505 + {
1.506 +private:
1.507 + friend class THashSetIter<T>;
1.508 + /** @internalComponent */
1.509 + struct SFullElement
1.510 + {
1.511 + TUint32 iHash;
1.512 + T iT;
1.513 + };
1.514 +
1.515 +public:
1.516 +
1.517 +/**
1.518 +A class which allows iteration over the elements of a RHashSet<T> class.
1.519 +
1.520 +The set being iterated over may not be modified while an iteration is in progress
1.521 +or the iteration operations may malfunction or panic.
1.522 +
1.523 +@see THashSetIter<T>
1.524 +*/
1.525 + typedef THashSetIter<T> TIter;
1.526 +
1.527 +/**
1.528 +Construct a set of objects of type T using a specified hash function and identity relation.
1.529 +The set is initially empty.
1.530 +
1.531 +@param aHash The hash function used to hash the objects of type T.
1.532 +@param aIdentity The identity relation used to determine if two objects of type T
1.533 + should be considered identical.
1.534 +*/
1.535 + inline RHashSet(const THashFunction32<T>& aHash, const TIdentityRelation<T>& aIdentity)
1.536 + : RHashTableBase(aHash, aIdentity, sizeof(SFullElement), _FOFF(SFullElement,iT))
1.537 + {}
1.538 +
1.539 +
1.540 +/**
1.541 +Construct a set of objects of type T using a default hash function and identity relation.
1.542 +The set is initially empty.
1.543 +*/
1.544 + inline RHashSet()
1.545 + : RHashTableBase(Defaults<T,EDefaultSpecifier_Normal>::Hash(), Defaults<T,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), _FOFF(SFullElement,iT))
1.546 + {}
1.547 +
1.548 +
1.549 +/**
1.550 +Free all memory used by this set.
1.551 +Returns the set to the same state it had following construction.
1.552 +*/
1.553 + inline void Close()
1.554 + { RHashTableBase::Close(); }
1.555 +
1.556 +
1.557 +/**
1.558 +Locate a specified element in the set.
1.559 +
1.560 +@param aKey The object of type T to search for.
1.561 +@return A pointer to the copy of the specified object in the set, if it
1.562 + exists. The object may not be modified via this pointer.
1.563 + NULL if the specified object is not a member of this set.
1.564 +*/
1.565 + inline const T* Find(const T& aKey) const
1.566 + { return (const T*)RHashTableBase::Find(&aKey, _FOFF(SFullElement,iT)); }
1.567 +
1.568 +
1.569 +/**
1.570 +Locate a specified element in the set.
1.571 +
1.572 +@param aKey The object of type T to search for.
1.573 +@return A reference to the copy of the specified object in the set, if it
1.574 + exists. The object may not be modified via this reference.
1.575 +@leave KErrNotFound if the specified object is not a member of this set.
1.576 +*/
1.577 + inline const T& FindL(const T& aKey) const
1.578 + { return *(const T*)RHashTableBase::FindL(&aKey, _FOFF(SFullElement,iT)); }
1.579 +
1.580 +
1.581 +/**
1.582 +Locate a specified element in the set.
1.583 +
1.584 +@param aKey The object of type T to search for.
1.585 +@return A pointer to the copy of the specified object in the set, if it
1.586 + exists. The object may be modified via this pointer. Care should
1.587 + be taken not to modify any parts of the object which are used by
1.588 + either the hash function or the identity relation for this set.
1.589 + If this is done the set may become inconsistent, resulting in
1.590 + malfunctions and/or panics at a later time.
1.591 + NULL if the specified object is not a member of this set.
1.592 +*/
1.593 + inline T* Find(const T& aKey)
1.594 + { return (T*)RHashTableBase::Find(&aKey, _FOFF(SFullElement,iT)); }
1.595 +
1.596 +
1.597 +/**
1.598 +Locate a specified element in the set.
1.599 +
1.600 +@param aKey The object of type T to search for.
1.601 +@return A reference to the copy of the specified object in the set, if it
1.602 + exists. The object may be modified via this reference. Care should
1.603 + be taken not to modify any parts of the object which are used by
1.604 + either the hash function or the identity relation for this set.
1.605 + If this is done the set may become inconsistent, resulting in
1.606 + malfunctions and/or panics at a later time.
1.607 +@leave KErrNotFound if the specified object is not a member of this set.
1.608 +*/
1.609 + inline T& FindL(const T& aKey)
1.610 + { return *(T*)RHashTableBase::FindL(&aKey, _FOFF(SFullElement,iT)); }
1.611 +
1.612 +
1.613 +/**
1.614 +Insert an element into the set.
1.615 +
1.616 +If the specified object is not currently a member of the set, a copy of the
1.617 +object is added to the set and KErrNone is returned.
1.618 +If the specified object is currently a member of the set, the existing copy
1.619 +of the object is replaced by the provided object and KErrNone is
1.620 +returned.
1.621 +In both cases the object is copied bitwise into the set.
1.622 +
1.623 +@param aKey The object of type T to add to the set.
1.624 +@return KErrNone if the object was added successfully.
1.625 + KErrNoMemory if memory could not be allocated to store
1.626 + the copy of aKey.
1.627 +*/
1.628 + inline TInt Insert(const T& aKey)
1.629 + { return RHashTableBase::ValueInsert(&aKey, sizeof(T), 0, 0, 0); }
1.630 +
1.631 +
1.632 +/**
1.633 +Insert an element into the set.
1.634 +
1.635 +If the specified object is not currently a member of the set, a copy of the
1.636 +object is added to the set and KErrNone is returned.
1.637 +If the specified object is currently a member of the set, the existing copy
1.638 +of the object is replaced by the provided object and KErrNone is
1.639 +returned.
1.640 +In both cases the object is copied bitwise into the set.
1.641 +
1.642 +@param aKey The object of type T to add to the set.
1.643 +@leave KErrNoMemory if memory could not be allocated to store
1.644 + the copy of aKey.
1.645 +*/
1.646 + inline void InsertL(const T& aKey)
1.647 + { RHashTableBase::ValueInsertL(&aKey, sizeof(T), 0, 0, 0); }
1.648 +
1.649 +
1.650 +/**
1.651 +Remove an element from the set.
1.652 +
1.653 +@param aKey The object to be removed.
1.654 +@return KErrNone if the object was removed successfully.
1.655 + KErrNotFound if the object was not present in the set.
1.656 +*/
1.657 + inline TInt Remove(const T& aKey)
1.658 + { return RHashTableBase::Remove(&aKey); }
1.659 +
1.660 +
1.661 +/**
1.662 +Query the number of elements in the set.
1.663 +
1.664 +@return The number of elements currently in the set.
1.665 +*/
1.666 + inline TInt Count() const
1.667 + { return RHashTableBase::Count(); }
1.668 +
1.669 +
1.670 +/**
1.671 +Expand the set to accommodate a specified number of elements.
1.672 +If the set already has enough space for the specified number of elements, no
1.673 +action is taken. Any elements already in the set are retained.
1.674 +
1.675 +@param aCount The number of elements for which space should be allocated.
1.676 +@return KErrNone if the operation completed successfully.
1.677 +@return KErrNoMemory if sufficient memory could not be allocated.
1.678 +*/
1.679 + inline TInt Reserve(TInt aCount)
1.680 + { return RHashTableBase::Reserve(aCount); }
1.681 +
1.682 +
1.683 +/**
1.684 +Expand the set to accommodate a specified number of elements.
1.685 +If the set already has enough space for the specified number of elements, no
1.686 +action is taken. Any elements already in the set are retained.
1.687 +
1.688 +@param aCount The number of elements for which space should be allocated.
1.689 +@leave KErrNoMemory if sufficient memory could not be allocated.
1.690 +*/
1.691 + inline void ReserveL(TInt aCount)
1.692 + { RHashTableBase::ReserveL(aCount); }
1.693 +
1.694 + };
1.695 +
1.696 +
1.697 +/**
1.698 +@publishedAll
1.699 +@released
1.700 +
1.701 +A templated class which allows iteration over the elements of a RHashSet<T>
1.702 +class.
1.703 +
1.704 +The set being iterated over may not be modified while an iteration is in progress
1.705 +or the iteration operations may malfunction or panic.
1.706 +
1.707 +@see RHashSet<T>
1.708 +*/
1.709 +template <class T>
1.710 +class THashSetIter : public THashTableIterBase
1.711 + {
1.712 +private:
1.713 + /** @internalComponent */
1.714 + struct SFullElement
1.715 + {
1.716 + TUint32 iHash;
1.717 + T iT;
1.718 + };
1.719 +
1.720 +public:
1.721 +
1.722 +/**
1.723 +Construct an iterator over the specified set.
1.724 +The iterator starts at conceptual position one before the beginning of the list
1.725 +being iterated.
1.726 +
1.727 +@param aSet The set to be iterated over.
1.728 +*/
1.729 + inline THashSetIter(const RHashSet<T>& aSet)
1.730 + : THashTableIterBase(aSet)
1.731 + {}
1.732 +
1.733 +
1.734 +/**
1.735 +Reset the iterator to its initial state.
1.736 +
1.737 +@param aSet The set to be iterated over.
1.738 +*/
1.739 + inline void Reset()
1.740 + { THashTableIterBase::Reset(); }
1.741 +
1.742 +
1.743 +/**
1.744 +Return the current position of the iterator.
1.745 +
1.746 +@return A pointer to the set member corresponding to the current position of the
1.747 + iterator.
1.748 + NULL if the iterator has just been constructed or reset, or if it has
1.749 + previously reached the end of an iteration.
1.750 +*/
1.751 + inline const T* Current() const
1.752 + { return (const T*)THashTableIterBase::Current(_FOFF(SFullElement,iT)); }
1.753 +
1.754 +
1.755 +/**
1.756 +Steps the iterator to the next position.
1.757 +
1.758 +@return A pointer to the set member corresponding to the next position of the
1.759 + iterator.
1.760 + NULL if the iterator has exhausted all the available set elements.
1.761 +*/
1.762 + inline const T* Next()
1.763 + { return (const T*)THashTableIterBase::Next(_FOFF(SFullElement,iT)); }
1.764 +
1.765 +
1.766 +/**
1.767 +Removes the element at the current iterator position from the hash table.
1.768 +If the iterator does not currently point to a valid element, no action is taken.
1.769 +Note that the iterator position is not altered so it no longer points to a valid
1.770 +element following the Remove(). It is illegal to call Current() on the iterator
1.771 +after calling Remove() - the only legal operations are Reset() and Next().
1.772 +
1.773 +*/
1.774 + inline void RemoveCurrent()
1.775 + { THashTableIterBase::RemoveCurrent(); }
1.776 + };
1.777 +
1.778 +
1.779 +
1.780 +template <class T> class TPtrHashSetIter;
1.781 +
1.782 +/**
1.783 +@publishedAll
1.784 +@released
1.785 +
1.786 +A templated class which implements an unordered extensional set of objects of
1.787 +type T using a probe-sequence hash table. The objects are not copied into the set
1.788 +when they are added; rather the set stores pointers to the contained objects.
1.789 +
1.790 +*/
1.791 +template <class T>
1.792 +class RPtrHashSet : public RHashTableBase
1.793 + {
1.794 +private:
1.795 + friend class TPtrHashSetIter<T>;
1.796 + /** @internalComponent */
1.797 + struct SFullElement
1.798 + {
1.799 + TUint32 iHash;
1.800 + T* iT;
1.801 + };
1.802 +
1.803 +public:
1.804 +
1.805 +/**
1.806 +A class which allows iteration over the elements of a RPtrHashSet<T> class.
1.807 +
1.808 +The set being iterated over may not be modified while an iteration is in progress
1.809 +or the iteration operations may malfunction or panic.
1.810 +
1.811 +@see TPtrHashSetIter<T>
1.812 +*/
1.813 + typedef TPtrHashSetIter<T> TIter;
1.814 +
1.815 +/**
1.816 +Construct a set of objects of type T using a specified hash function and identity relation.
1.817 +The set is initially empty.
1.818 +
1.819 +@param aHash The hash function used to hash the objects of type T.
1.820 +@param aIdentity The identity relation used to determine if two objects of type T
1.821 + should be considered identical.
1.822 +*/
1.823 + inline RPtrHashSet(const THashFunction32<T>& aHash, const TIdentityRelation<T>& aIdentity)
1.824 + : RHashTableBase(aHash, aIdentity, sizeof(SFullElement), 0)
1.825 + {}
1.826 +
1.827 +
1.828 +/**
1.829 +Construct a set of objects of type T using a default hash function and identity relation.
1.830 +The set is initially empty.
1.831 +*/
1.832 + inline RPtrHashSet()
1.833 + : RHashTableBase(Defaults<T,EDefaultSpecifier_Normal>::Hash(), Defaults<T,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), 0)
1.834 + {}
1.835 +
1.836 +
1.837 +/**
1.838 +Free all memory used by this set.
1.839 +Returns the set to the same state it had following construction.
1.840 +*/
1.841 + inline void Close()
1.842 + { RHashTableBase::Close(); }
1.843 +
1.844 +
1.845 +/**
1.846 +Locate a specified element in the set.
1.847 +
1.848 +@param aKey The object of type T to search for.
1.849 +@return A pointer to the specified object, if it is in the set.
1.850 + The object may not be modified via this pointer.
1.851 + NULL if the specified object is not a member of this set.
1.852 +*/
1.853 + inline const T* Find(const T& aKey) const
1.854 + { return (const T*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iT)); }
1.855 +
1.856 +
1.857 +/**
1.858 +Locate a specified element in the set.
1.859 +
1.860 +@param aKey The object of type T to search for.
1.861 +@return A reference to the specified object, if it is in the set.
1.862 + The object may not be modified via this reference.
1.863 +@leave KErrNotFound if the specified object is not a member of this set.
1.864 +*/
1.865 + inline const T& FindL(const T& aKey) const
1.866 + { return *(const T*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iT)); }
1.867 +
1.868 +
1.869 +/**
1.870 +Locate a specified element in the set.
1.871 +
1.872 +@param aKey The object of type T to search for.
1.873 +@return A pointer to the specified object, if it is in the set.
1.874 + The object may be modified via this pointer. Care should
1.875 + be taken not to modify any parts of the object which are used by
1.876 + either the hash function or the identity relation for this set.
1.877 + If this is done the set may become inconsistent, resulting in
1.878 + malfunctions and/or panics at a later time.
1.879 + NULL if the specified object is not a member of this set.
1.880 +*/
1.881 + inline T* Find(const T& aKey)
1.882 + { return (T*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iT)); }
1.883 +
1.884 +
1.885 +/**
1.886 +Locate a specified element in the set.
1.887 +
1.888 +@param aKey The object of type T to search for.
1.889 +@return A reference to the specified object, if it is in the set.
1.890 + The object may be modified via this reference. Care should
1.891 + be taken not to modify any parts of the object which are used by
1.892 + either the hash function or the identity relation for this set.
1.893 + If this is done the set may become inconsistent, resulting in
1.894 + malfunctions and/or panics at a later time.
1.895 +@leave KErrNotFound if the specified object is not a member of this set.
1.896 +*/
1.897 + inline T& FindL(const T& aKey)
1.898 + { return *(T*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iT)); }
1.899 +
1.900 +
1.901 +/**
1.902 +Insert an element into the set.
1.903 +
1.904 +If the specified object is not currently a member of the set, a pointer to the
1.905 +object is added to the set and KErrNone is returned.
1.906 +If the specified object is currently a member of the set, the existing pointer
1.907 +to the object is replaced by the provided pointer and KErrNone is
1.908 +returned.
1.909 +In both cases only a pointer to the object is stored - the object is never copied.
1.910 +
1.911 +@param aKey A pointer to the object of type T to add to the set.
1.912 +@return KErrNone if the object was added successfully.
1.913 + KErrNoMemory if memory could not be allocated to store
1.914 + the pointer to the new object.
1.915 +*/
1.916 + inline TInt Insert(const T* aKey)
1.917 + { return RHashTableBase::PtrInsert(aKey, 0); }
1.918 +
1.919 +
1.920 +/**
1.921 +Insert an element into the set.
1.922 +
1.923 +If the specified object is not currently a member of the set, a pointer to the
1.924 +object is added to the set and KErrNone is returned.
1.925 +If the specified object is currently a member of the set, the existing pointer
1.926 +to the object is replaced by the provided pointer and KErrNone is
1.927 +returned.
1.928 +In both cases only a pointer to the object is stored - the object is never copied.
1.929 +
1.930 +@param aKey A pointer to the object of type T to add to the set.
1.931 +@leave KErrNoMemory if memory could not be allocated to store the pointer to the new object.
1.932 +*/
1.933 + inline void InsertL(const T* aKey)
1.934 + { RHashTableBase::PtrInsertL(aKey, 0); }
1.935 +
1.936 +
1.937 +/**
1.938 +Remove an element from the set.
1.939 +
1.940 +@param aKey A pointer to the object to be removed.
1.941 +@return KErrNone if the object was removed successfully.
1.942 + KErrNotFound if the object was not present in the set.
1.943 +*/
1.944 + inline TInt Remove(const T* aKey)
1.945 + { return RHashTableBase::Remove(aKey); }
1.946 +
1.947 +
1.948 +/**
1.949 +Query the number of elements in the set.
1.950 +
1.951 +@return The number of elements currently in the set.
1.952 +*/
1.953 + inline TInt Count() const
1.954 + { return RHashTableBase::Count(); }
1.955 +
1.956 +
1.957 +/**
1.958 +Expand the set to accommodate a specified number of elements.
1.959 +If the set already has enough space for the specified number of elements, no
1.960 +action is taken. Any elements already in the set are retained.
1.961 +
1.962 +@param aCount The number of elements for which space should be allocated.
1.963 +@return KErrNone if the operation completed successfully.
1.964 +@return KErrNoMemory if sufficient memory could not be allocated.
1.965 +*/
1.966 + inline TInt Reserve(TInt aCount)
1.967 + { return RHashTableBase::Reserve(aCount); }
1.968 +
1.969 +
1.970 +/**
1.971 +Expand the set to accommodate a specified number of elements.
1.972 +If the set already has enough space for the specified number of elements, no
1.973 +action is taken. Any elements already in the set are retained.
1.974 +
1.975 +@param aCount The number of elements for which space should be allocated.
1.976 +@leave KErrNoMemory if sufficient memory could not be allocated.
1.977 +*/
1.978 + inline void ReserveL(TInt aCount)
1.979 + { RHashTableBase::ReserveL(aCount); }
1.980 +
1.981 +
1.982 + void ResetAndDestroy();
1.983 + };
1.984 +
1.985 +
1.986 +/**
1.987 +@publishedAll
1.988 +@released
1.989 +
1.990 +A templated class which allows iteration over the elements of a RPtrHashSet<T>
1.991 +class.
1.992 +
1.993 +The set being iterated over may not be modified while an iteration is in progress
1.994 +or the iteration operations may malfunction or panic.
1.995 +
1.996 +@see RPtrHashSet<T>
1.997 +*/
1.998 +template <class T>
1.999 +class TPtrHashSetIter : public THashTableIterBase
1.1000 + {
1.1001 +private:
1.1002 + /** @internalComponent */
1.1003 + struct SFullElement
1.1004 + {
1.1005 + TUint32 iHash;
1.1006 + T* iT;
1.1007 + };
1.1008 +
1.1009 +public:
1.1010 +
1.1011 +/**
1.1012 +Construct an iterator over the specified set.
1.1013 +The iterator starts at conceptual position one before the beginning of the list
1.1014 +being iterated.
1.1015 +
1.1016 +@param aSet The set to be iterated over.
1.1017 +*/
1.1018 + inline TPtrHashSetIter(const RPtrHashSet<T>& aSet)
1.1019 + : THashTableIterBase(aSet)
1.1020 + {}
1.1021 +
1.1022 +
1.1023 +/**
1.1024 +Reset the iterator to its initial state.
1.1025 +
1.1026 +@param aSet The set to be iterated over.
1.1027 +*/
1.1028 + inline void Reset()
1.1029 + { THashTableIterBase::Reset(); }
1.1030 +
1.1031 +
1.1032 +/**
1.1033 +Return the current position of the iterator.
1.1034 +
1.1035 +@return A pointer to the set member corresponding to the current position of the
1.1036 + iterator.
1.1037 + NULL if the iterator has just been constructed or reset, or if it has
1.1038 + previously reached the end of an iteration.
1.1039 +*/
1.1040 + inline const T* Current() const
1.1041 + { return (const T*)THashTableIterBase::Current(-_FOFF(SFullElement,iT)); }
1.1042 +
1.1043 +
1.1044 +/**
1.1045 +Steps the iterator to the next position.
1.1046 +
1.1047 +@return A pointer to the set member corresponding to the next position of the
1.1048 + iterator.
1.1049 + NULL if the iterator has exhausted all the available set elements.
1.1050 +*/
1.1051 + inline const T* Next()
1.1052 + { return (const T*)THashTableIterBase::Next(-_FOFF(SFullElement,iT)); }
1.1053 +
1.1054 +
1.1055 +/**
1.1056 +Removes the element at the current iterator position from the hash table.
1.1057 +If the iterator does not currently point to a valid element, no action is taken.
1.1058 +Note that the iterator position is not altered so it no longer points to a valid
1.1059 +element following the Remove(). It is illegal to call Current() on the iterator
1.1060 +after calling Remove() - the only legal operations are Reset() and Next().
1.1061 +
1.1062 +*/
1.1063 + inline void RemoveCurrent()
1.1064 + { THashTableIterBase::RemoveCurrent(); }
1.1065 + };
1.1066 +
1.1067 +
1.1068 +
1.1069 +template <class K, class V> class THashMapIter;
1.1070 +
1.1071 +/**
1.1072 +@publishedAll
1.1073 +@released
1.1074 +
1.1075 +A templated class which implements an associative array with key type K and value type V,
1.1076 +using a probe-sequence hash table. Both the key and value objects are copied into the
1.1077 +table when they are added. A bitwise binary copy is used here, so neither of the types
1.1078 +K and V may implement a nontrivial copy constructor.
1.1079 +
1.1080 +*/
1.1081 +template <class K, class V>
1.1082 +class RHashMap : public RHashTableBase
1.1083 + {
1.1084 +private:
1.1085 + friend class THashMapIter<K,V>;
1.1086 + /** @internalComponent */
1.1087 + struct SFullElement
1.1088 + {
1.1089 + TUint32 iHash;
1.1090 + K iK;
1.1091 + V iV;
1.1092 + };
1.1093 +
1.1094 +public:
1.1095 +
1.1096 +/**
1.1097 +A class which allows iteration over the elements of a RHashMap<K,V> class.
1.1098 +
1.1099 +The array being iterated over may not be modified while an iteration is in progress
1.1100 +or the iteration operations may malfunction or panic.
1.1101 +
1.1102 +@see THashMapIter<K,V>
1.1103 +*/
1.1104 + typedef THashMapIter<K,V> TIter;
1.1105 +
1.1106 +/**
1.1107 +Construct an associative array of key-value pairs of type (K,V) using a
1.1108 +specified hash function and identity relation.
1.1109 +The array initially contains no key-value pairs.
1.1110 +
1.1111 +@param aHash The hash function used to hash the key objects of type K.
1.1112 +@param aIdentity The identity relation used to determine if two key objects
1.1113 + of type K should be considered identical.
1.1114 +*/
1.1115 + inline RHashMap(const THashFunction32<K>& aHash, const TIdentityRelation<K>& aIdentity)
1.1116 + : RHashTableBase(aHash, aIdentity, sizeof(SFullElement), _FOFF(SFullElement,iK))
1.1117 + {}
1.1118 +
1.1119 +
1.1120 +/**
1.1121 +Construct an associative array of key-value pairs of type (K,V) using a
1.1122 +default hash function and identity relation.
1.1123 +The array initially contains no key-value pairs.
1.1124 +*/
1.1125 + inline RHashMap()
1.1126 + : RHashTableBase(Defaults<K,EDefaultSpecifier_Normal>::Hash(), Defaults<K,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), _FOFF(SFullElement,iK))
1.1127 + {}
1.1128 +
1.1129 +
1.1130 +/**
1.1131 +Free all memory used by this array.
1.1132 +Returns the array to the same state it had following construction.
1.1133 +*/
1.1134 + inline void Close()
1.1135 + { RHashTableBase::Close(); }
1.1136 +
1.1137 +
1.1138 +/**
1.1139 +Look up a specified key in the associative array and return a pointer to the
1.1140 +corresponding value.
1.1141 +
1.1142 +@param aKey The key object of type K to look up.
1.1143 +@return A pointer to the copy of the corresponding value object in the
1.1144 + array, if the specified key object was found.
1.1145 + The value object may not be modified via this pointer.
1.1146 + NULL if the specified key object was not found.
1.1147 +*/
1.1148 + inline const V* Find(const K& aKey) const
1.1149 + { return (const V*)RHashTableBase::Find(&aKey, _FOFF(SFullElement,iV)); }
1.1150 +
1.1151 +
1.1152 +/**
1.1153 +Look up a specified key in the associative array and return a pointer to the
1.1154 +corresponding value.
1.1155 +
1.1156 +@param aKey The key object of type K to look up.
1.1157 +@return A reference to the copy of the corresponding value object in the
1.1158 + array, if the specified key object was found.
1.1159 + The value object may not be modified via this reference.
1.1160 +@leave KErrNotFound if the specified key object was not found.
1.1161 +*/
1.1162 + inline const V& FindL(const K& aKey) const
1.1163 + { return *(const V*)RHashTableBase::FindL(&aKey, _FOFF(SFullElement,iV)); }
1.1164 +
1.1165 +
1.1166 +/**
1.1167 +Look up a specified key in the associative array and return a pointer to the
1.1168 +corresponding value.
1.1169 +
1.1170 +@param aKey The key object of type K to look up.
1.1171 +@return A pointer to the copy of the corresponding value object in the
1.1172 + array, if the specified key object was found.
1.1173 + The value object may be modified via this pointer.
1.1174 + NULL if the specified key object was not found.
1.1175 +*/
1.1176 + inline V* Find(const K& aKey)
1.1177 + { return (V*)RHashTableBase::Find(&aKey, _FOFF(SFullElement,iV)); }
1.1178 +
1.1179 +
1.1180 +/**
1.1181 +Look up a specified key in the associative array and return a pointer to the
1.1182 +corresponding value.
1.1183 +
1.1184 +@param aKey The key object of type K to look up.
1.1185 +@return A reference to the copy of the corresponding value object in the
1.1186 + array, if the specified key object was found.
1.1187 + The value object may be modified via this reference.
1.1188 +@leave KErrNotFound if the specified key object was not found.
1.1189 +*/
1.1190 + inline V& FindL(const K& aKey)
1.1191 + { return *(V*)RHashTableBase::FindL(&aKey, _FOFF(SFullElement,iV)); }
1.1192 +
1.1193 +
1.1194 +/**
1.1195 +Insert a key-value pair into the array.
1.1196 +
1.1197 +If the specified key object is not found in the array, a copy of the
1.1198 +key object along with a copy of the value object are added to the array
1.1199 +and KErrNone is returned.
1.1200 +If the specified key object is found in the array, the existing copies
1.1201 +of both the key and value objects are replaced by the provided objects
1.1202 +and KErrNone is returned.
1.1203 +In both cases the objects are copied bitwise into the array.
1.1204 +
1.1205 +@param aKey The key object of type K to add to the array.
1.1206 +@param aValue The value object of type V to associate with aKey.
1.1207 +@return KErrNone if the key-value pair was added successfully.
1.1208 + KErrNoMemory if memory could not be allocated to store
1.1209 + the copies of aKey and aValue.
1.1210 +*/
1.1211 + inline TInt Insert(const K& aKey, const V& aValue)
1.1212 + { return RHashTableBase::ValueInsert(&aKey, sizeof(K), &aValue, _FOFF(SFullElement,iV), sizeof(V)); }
1.1213 +
1.1214 +
1.1215 +/**
1.1216 +Insert a key-value pair into the array.
1.1217 +
1.1218 +If the specified key object is not found in the array, a copy of the
1.1219 +key object along with a copy of the value object are added to the array
1.1220 +and KErrNone is returned.
1.1221 +If the specified key object is found in the array, the existing copies
1.1222 +of both the key and value objects are replaced by the provided objects
1.1223 +and KErrNone is returned.
1.1224 +In both cases the objects are copied bitwise into the array.
1.1225 +
1.1226 +@param aKey The key object of type K to add to the array.
1.1227 +@param aValue The value object of type V to associate with aKey.
1.1228 +@leave KErrNoMemory if memory could not be allocated to store the copies of aKey and aValue.
1.1229 +*/
1.1230 + inline void InsertL(const K& aKey, const V& aValue)
1.1231 + { RHashTableBase::ValueInsertL(&aKey, sizeof(K), &aValue, _FOFF(SFullElement,iV), sizeof(V)); }
1.1232 +
1.1233 +
1.1234 +/**
1.1235 +Remove a key-value pair from the array.
1.1236 +
1.1237 +@param aKey The key to be removed.
1.1238 +@return KErrNone if the key object and corresponding value object were
1.1239 + removed successfully.
1.1240 + KErrNotFound if the key object was not present in the array.
1.1241 +*/
1.1242 + inline TInt Remove(const K& aKey)
1.1243 + { return RHashTableBase::Remove(&aKey); }
1.1244 +
1.1245 +
1.1246 +/**
1.1247 +Query the number of key-value pairs in the array.
1.1248 +
1.1249 +@return The number of key-value pairs currently in the array.
1.1250 +*/
1.1251 + inline TInt Count() const
1.1252 + { return RHashTableBase::Count(); }
1.1253 +
1.1254 +
1.1255 +/**
1.1256 +Expand the array to accommodate a specified number of key-value pairs.
1.1257 +If the set already has enough space for the specified number of elements, no
1.1258 +action is taken. Any elements already in the set are retained.
1.1259 +
1.1260 +@param aCount The number of key-value pairs for which space should be allocated.
1.1261 +@return KErrNone if the operation completed successfully.
1.1262 +@return KErrNoMemory if sufficient memory could not be allocated.
1.1263 +*/
1.1264 + inline TInt Reserve(TInt aCount)
1.1265 + { return RHashTableBase::Reserve(aCount); }
1.1266 +
1.1267 +
1.1268 +/**
1.1269 +Expand the array to accommodate a specified number of key-value pairs.
1.1270 +If the set already has enough space for the specified number of elements, no
1.1271 +action is taken. Any elements already in the set are retained.
1.1272 +
1.1273 +@param aCount The number of key-value pairs for which space should be allocated.
1.1274 +@leave KErrNoMemory if sufficient memory could not be allocated.
1.1275 +*/
1.1276 + inline void ReserveL(TInt aCount)
1.1277 + { RHashTableBase::ReserveL(aCount); }
1.1278 +
1.1279 + };
1.1280 +
1.1281 +
1.1282 +/**
1.1283 +@publishedAll
1.1284 +@released
1.1285 +
1.1286 +A templated class which allows iteration over the elements of a RHashMap<K,V>
1.1287 +class.
1.1288 +
1.1289 +The array being iterated over may not be modified while an iteration is in progress
1.1290 +or the iteration operations may malfunction or panic.
1.1291 +
1.1292 +@see RHashMap<K,V>
1.1293 +*/
1.1294 +template <class K, class V>
1.1295 +class THashMapIter : public THashTableIterBase
1.1296 + {
1.1297 +private:
1.1298 + /** @internalComponent */
1.1299 + struct SFullElement
1.1300 + {
1.1301 + TUint32 iHash;
1.1302 + K iK;
1.1303 + V iV;
1.1304 + };
1.1305 +
1.1306 +public:
1.1307 +
1.1308 +/**
1.1309 +Construct an iterator over the specified associative array.
1.1310 +The iterator starts at conceptual position one before the beginning of the list
1.1311 +being iterated.
1.1312 +
1.1313 +@param aMap The array to be iterated over.
1.1314 +*/
1.1315 + inline THashMapIter(const RHashMap<K,V>& aMap)
1.1316 + : THashTableIterBase(aMap)
1.1317 + {}
1.1318 +
1.1319 +
1.1320 +/**
1.1321 +Reset the iterator to its initial state.
1.1322 +
1.1323 +@param aSet The set to be iterated over.
1.1324 +*/
1.1325 + inline void Reset()
1.1326 + { THashTableIterBase::Reset(); }
1.1327 +
1.1328 +
1.1329 +/**
1.1330 +Return the key corresponding to the current position of the iterator.
1.1331 +
1.1332 +@return A pointer to the key object corresponding to the current position of the
1.1333 + iterator.
1.1334 + NULL if the iterator has just been constructed or reset, or if it has
1.1335 + previously reached the end of an iteration.
1.1336 +*/
1.1337 + inline const K* CurrentKey() const
1.1338 + { return (const K*)THashTableIterBase::Current(_FOFF(SFullElement,iK)); }
1.1339 +
1.1340 +
1.1341 +/**
1.1342 +Steps the iterator to the next position and returns the corresponding key.
1.1343 +
1.1344 +@return A pointer to the key object corresponding to the next position of the
1.1345 + iterator.
1.1346 + NULL if the iterator has exhausted all the available key-value pairs.
1.1347 +*/
1.1348 + inline const K* NextKey()
1.1349 + { return (const K*)THashTableIterBase::Next(_FOFF(SFullElement,iK)); }
1.1350 +
1.1351 +
1.1352 +/**
1.1353 +Return the value corresponding to the current position of the iterator.
1.1354 +
1.1355 +@return A pointer to the value object corresponding to the current position of the
1.1356 + iterator.
1.1357 + NULL if the iterator has just been constructed or reset, or if it has
1.1358 + previously reached the end of an iteration.
1.1359 +*/
1.1360 + inline V* CurrentValue()
1.1361 + { return (V*)THashTableIterBase::Current(_FOFF(SFullElement,iV)); }
1.1362 +
1.1363 +
1.1364 +/**
1.1365 +Steps the iterator to the next position and returns the corresponding value.
1.1366 +
1.1367 +@return A pointer to the value object corresponding to the next position of the
1.1368 + iterator.
1.1369 + NULL if the iterator has exhausted all the available key-value pairs.
1.1370 +*/
1.1371 + inline const V* NextValue()
1.1372 + { return (const V*)THashTableIterBase::Next(_FOFF(SFullElement,iV)); }
1.1373 +
1.1374 +
1.1375 +/**
1.1376 +Removes the element at the current iterator position from the hash table.
1.1377 +If the iterator does not currently point to a valid element, no action is taken.
1.1378 +Note that the iterator position is not altered so it no longer points to a valid
1.1379 +element following the Remove(). It is illegal to call either CurrentKey() or
1.1380 +CurrentValue() on the iterator after calling Remove() - the only legal
1.1381 +operations are Reset(), NextKey() or NextValue().
1.1382 +
1.1383 +*/
1.1384 + inline void RemoveCurrent()
1.1385 + { THashTableIterBase::RemoveCurrent(); }
1.1386 + };
1.1387 +
1.1388 +
1.1389 +
1.1390 +template <class K, class V> class TPtrHashMapIter;
1.1391 +
1.1392 +/**
1.1393 +@publishedAll
1.1394 +@released
1.1395 +
1.1396 +A templated class which implements an associative array with key type K and value type V,
1.1397 +using a probe-sequence hash table. Neither the key nor value objects are copied into the
1.1398 +table when they are added - only pointers are stored.
1.1399 +
1.1400 +*/
1.1401 +template <class K, class V>
1.1402 +class RPtrHashMap : public RHashTableBase
1.1403 + {
1.1404 +private:
1.1405 + friend class TPtrHashMapIter<K,V>;
1.1406 + /** @internalComponent */
1.1407 + struct SFullElement
1.1408 + {
1.1409 + TUint32 iHash;
1.1410 + K* iK;
1.1411 + V* iV;
1.1412 + };
1.1413 +public:
1.1414 +
1.1415 +/**
1.1416 +A class which allows iteration over the elements of a RPtrHashMap<K,V> class.
1.1417 +
1.1418 +The array being iterated over may not be modified while an iteration is in progress
1.1419 +or the iteration operations may malfunction or panic.
1.1420 +
1.1421 +@see TPtrHashMapIter<K,V>
1.1422 +*/
1.1423 + typedef TPtrHashMapIter<K,V> TIter;
1.1424 +
1.1425 +/**
1.1426 +Construct an associative array of key-value pairs of type (K,V) using a
1.1427 +specified hash function and identity relation.
1.1428 +The array initially contains no key-value pairs.
1.1429 +
1.1430 +@param aHash The hash function used to hash the key objects of type K.
1.1431 +@param aIdentity The identity relation used to determine if two key objects
1.1432 + of type K should be considered identical.
1.1433 +*/
1.1434 + inline RPtrHashMap(const THashFunction32<K>& aHash, const TIdentityRelation<K>& aIdentity)
1.1435 + : RHashTableBase(aHash, aIdentity, sizeof(SFullElement), 0)
1.1436 + {}
1.1437 +
1.1438 +
1.1439 +/**
1.1440 +Construct an associative array of key-value pairs of type (K,V) using a
1.1441 +default hash function and identity relation.
1.1442 +The array initially contains no key-value pairs.
1.1443 +*/
1.1444 + inline RPtrHashMap()
1.1445 + : RHashTableBase(Defaults<K,EDefaultSpecifier_Normal>::Hash(), Defaults<K,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), 0)
1.1446 + {}
1.1447 +
1.1448 +
1.1449 +/**
1.1450 +Free all memory used by this array.
1.1451 +Returns the array to the same state it had following construction.
1.1452 +*/
1.1453 + inline void Close()
1.1454 + { RHashTableBase::Close(); }
1.1455 +
1.1456 +
1.1457 +/**
1.1458 +Look up a specified key in the associative array and return a pointer to the
1.1459 +corresponding value.
1.1460 +
1.1461 +@param aKey The key object of type K to look up.
1.1462 +@return A pointer to corresponding value object if the specified key
1.1463 + object was found. The value object may not be modified via
1.1464 + this pointer.
1.1465 + NULL if the specified key object was not found.
1.1466 +*/
1.1467 + inline const V* Find(const K& aKey) const
1.1468 + { return (const V*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iV)); }
1.1469 +
1.1470 +
1.1471 +/**
1.1472 +Look up a specified key in the associative array and return a pointer to the
1.1473 +corresponding value.
1.1474 +
1.1475 +@param aKey The key object of type K to look up.
1.1476 +@return A reference to corresponding value object if the specified key
1.1477 + object was found. The value object may not be modified via
1.1478 + this reference.
1.1479 +@leave KErrNotFound if the specified key object was not found.
1.1480 +*/
1.1481 + inline const V& FindL(const K& aKey) const
1.1482 + { return *(const V*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iV)); }
1.1483 +
1.1484 +
1.1485 +/**
1.1486 +Look up a specified key in the associative array and return a pointer to the
1.1487 +corresponding value.
1.1488 +
1.1489 +@param aKey The key object of type K to look up.
1.1490 +@return A pointer to corresponding value object if the specified key
1.1491 + object was found. The value object may be modified via
1.1492 + this pointer.
1.1493 + NULL if the specified key object was not found.
1.1494 +*/
1.1495 + inline V* Find(const K& aKey)
1.1496 + { return (V*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iV)); }
1.1497 +
1.1498 +
1.1499 +/**
1.1500 +Look up a specified key in the associative array and return a pointer to the
1.1501 +corresponding value.
1.1502 +
1.1503 +@param aKey The key object of type K to look up.
1.1504 +@return A reference to corresponding value object if the specified key
1.1505 + object was found. The value object may be modified via
1.1506 + this reference.
1.1507 +@leave KErrNotFound if the specified key object was not found.
1.1508 +*/
1.1509 + inline V& FindL(const K& aKey)
1.1510 + { return *(V*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iV)); }
1.1511 +
1.1512 +
1.1513 +/**
1.1514 +Insert a key-value pair into the array.
1.1515 +
1.1516 +If the specified key object is not found in the array, a pointer to the
1.1517 +key object along with a pointer to the value object are added to the array
1.1518 +and KErrNone is returned.
1.1519 +If the specified key object is found in the array, the existing pointers
1.1520 +to both the key and value objects are replaced by the provided pointers
1.1521 +and KErrNone is returned.
1.1522 +In both cases only pointers are stored in the array - the objects themselves
1.1523 +are not copied.
1.1524 +
1.1525 +@param aKey A pointer to the key object of type K to add to the array.
1.1526 +@param aValue A pointer to the value object of type V to associate with aKey.
1.1527 +@return KErrNone if the key-value pair was added successfully.
1.1528 + KErrNoMemory if memory could not be allocated to store
1.1529 + the pointers aKey and aValue.
1.1530 +*/
1.1531 + inline TInt Insert(const K* aKey, const V* aValue)
1.1532 + { return RHashTableBase::PtrInsert(aKey, aValue); }
1.1533 +
1.1534 +
1.1535 +/**
1.1536 +Insert a key-value pair into the array.
1.1537 +
1.1538 +If the specified key object is not found in the array, a pointer to the
1.1539 +key object along with a pointer to the value object are added to the array
1.1540 +and KErrNone is returned.
1.1541 +If the specified key object is found in the array, the existing pointers
1.1542 +to both the key and value objects are replaced by the provided pointers
1.1543 +and KErrNone is returned.
1.1544 +In both cases only pointers are stored in the array - the objects themselves
1.1545 +are not copied.
1.1546 +
1.1547 +@param aKey A pointer to the key object of type K to add to the array.
1.1548 +@param aValue A pointer to the value object of type V to associate with aKey.
1.1549 +@leave KErrNoMemory if memory could not be allocated to store the pointers aKey and aValue.
1.1550 +*/
1.1551 + inline void InsertL(const K* aKey, const V* aValue)
1.1552 + { RHashTableBase::PtrInsertL(aKey, aValue); }
1.1553 +
1.1554 +
1.1555 +/**
1.1556 +Remove a key-value pair from the array.
1.1557 +
1.1558 +@param aKey A pointer to the key to be removed.
1.1559 +@return KErrNone if the pointers to the key object and corresponding
1.1560 + value object were removed successfully.
1.1561 + KErrNotFound if the key object was not present in the array.
1.1562 +*/
1.1563 + inline TInt Remove(const K* aKey)
1.1564 + { return RHashTableBase::Remove(aKey); }
1.1565 +
1.1566 +
1.1567 +/**
1.1568 +Query the number of key-value pairs in the array.
1.1569 +
1.1570 +@return The number of key-value pairs currently in the array.
1.1571 +*/
1.1572 + inline TInt Count() const
1.1573 + { return RHashTableBase::Count(); }
1.1574 +
1.1575 +
1.1576 +/**
1.1577 +Expand the array to accommodate a specified number of key-value pairs.
1.1578 +If the set already has enough space for the specified number of elements, no
1.1579 +action is taken. Any elements already in the set are retained.
1.1580 +
1.1581 +@param aCount The number of key-value pairs for which space should be allocated.
1.1582 +@return KErrNone if the operation completed successfully.
1.1583 +@return KErrNoMemory if sufficient memory could not be allocated.
1.1584 +*/
1.1585 + inline TInt Reserve(TInt aCount)
1.1586 + { return RHashTableBase::Reserve(aCount); }
1.1587 +
1.1588 +
1.1589 +/**
1.1590 +Expand the array to accommodate a specified number of key-value pairs.
1.1591 +If the set already has enough space for the specified number of elements, no
1.1592 +action is taken. Any elements already in the set are retained.
1.1593 +
1.1594 +@param aCount The number of key-value pairs for which space should be allocated.
1.1595 +@leave KErrNoMemory if sufficient memory could not be allocated.
1.1596 +*/
1.1597 + inline void ReserveL(TInt aCount)
1.1598 + { RHashTableBase::ReserveL(aCount); }
1.1599 +
1.1600 +
1.1601 + void ResetAndDestroy();
1.1602 + };
1.1603 +
1.1604 +
1.1605 +/**
1.1606 +@publishedAll
1.1607 +@released
1.1608 +
1.1609 +A templated class which allows iteration over the elements of a RPtrHashMap<K,V>
1.1610 +class.
1.1611 +
1.1612 +The array being iterated over may not be modified while an iteration is in progress
1.1613 +or the iteration operations may malfunction or panic.
1.1614 +
1.1615 +@see RPtrHashMap<K,V>
1.1616 +*/
1.1617 +template <class K, class V>
1.1618 +class TPtrHashMapIter : public THashTableIterBase
1.1619 + {
1.1620 +private:
1.1621 + /** @internalComponent */
1.1622 + struct SFullElement
1.1623 + {
1.1624 + TUint32 iHash;
1.1625 + K* iK;
1.1626 + V* iV;
1.1627 + };
1.1628 +public:
1.1629 +
1.1630 +/**
1.1631 +Construct an iterator over the specified associative array.
1.1632 +The iterator starts at conceptual position one before the beginning of the list
1.1633 +being iterated.
1.1634 +
1.1635 +@param aMap The array to be iterated over.
1.1636 +*/
1.1637 + inline TPtrHashMapIter(const RPtrHashMap<K,V>& aMap)
1.1638 + : THashTableIterBase(aMap)
1.1639 + {}
1.1640 +
1.1641 +
1.1642 +/**
1.1643 +Reset the iterator to its initial state.
1.1644 +
1.1645 +@param aSet The set to be iterated over.
1.1646 +*/
1.1647 + inline void Reset()
1.1648 + { THashTableIterBase::Reset(); }
1.1649 +
1.1650 +
1.1651 +/**
1.1652 +Return the key corresponding to the current position of the iterator.
1.1653 +
1.1654 +@return A pointer to the key object corresponding to the current position of the
1.1655 + iterator.
1.1656 + NULL if the iterator has just been constructed or reset, or if it has
1.1657 + previously reached the end of an iteration.
1.1658 +*/
1.1659 + inline const K* CurrentKey() const
1.1660 + { return (const K*)THashTableIterBase::Current(-_FOFF(SFullElement,iK)); }
1.1661 +
1.1662 +
1.1663 +/**
1.1664 +Steps the iterator to the next position and returns the corresponding key.
1.1665 +
1.1666 +@return A pointer to the key object corresponding to the next position of the
1.1667 + iterator.
1.1668 + NULL if the iterator has exhausted all the available key-value pairs.
1.1669 +*/
1.1670 + inline const K* NextKey()
1.1671 + { return (const K*)THashTableIterBase::Next(-_FOFF(SFullElement,iK)); }
1.1672 +
1.1673 +
1.1674 +/**
1.1675 +Return the value corresponding to the current position of the iterator.
1.1676 +
1.1677 +@return A pointer to the value object corresponding to the current position of the
1.1678 + iterator.
1.1679 + NULL if the iterator has just been constructed or reset, or if it has
1.1680 + previously reached the end of an iteration.
1.1681 +*/
1.1682 + inline const V* CurrentValue() const
1.1683 + { return (const V*)THashTableIterBase::Current(-_FOFF(SFullElement,iV)); }
1.1684 +
1.1685 +
1.1686 +/**
1.1687 +Steps the iterator to the next position and returns the corresponding value.
1.1688 +
1.1689 +@return A pointer to the value object corresponding to the next position of the
1.1690 + iterator.
1.1691 + NULL if the iterator has exhausted all the available key-value pairs.
1.1692 +*/
1.1693 + inline const V* NextValue()
1.1694 + { return (const V*)THashTableIterBase::Next(-_FOFF(SFullElement,iV)); }
1.1695 +
1.1696 +
1.1697 +/**
1.1698 +Removes the element at the current iterator position from the hash table.
1.1699 +If the iterator does not currently point to a valid element, no action is taken.
1.1700 +Note that the iterator position is not altered so it no longer points to a valid
1.1701 +element following the Remove(). It is illegal to call either CurrentKey() or
1.1702 +CurrentValue() on the iterator after calling Remove() - the only legal
1.1703 +operations are Reset(), NextKey() or NextValue().
1.1704 +
1.1705 +*/
1.1706 + inline void RemoveCurrent()
1.1707 + { THashTableIterBase::RemoveCurrent(); }
1.1708 + };
1.1709 +
1.1710 +
1.1711 +
1.1712 +/**
1.1713 +Deletes all the objects of type T to which pointers are stored in this set.
1.1714 +Then frees all the memory used by the set and returns the set to the same state
1.1715 +as immediately following construction.
1.1716 +*/
1.1717 +template <class T>
1.1718 +void RPtrHashSet<T>::ResetAndDestroy()
1.1719 + {
1.1720 + TPtrHashSetIter<T> iter(*this);
1.1721 + T* p;
1.1722 + do {
1.1723 + p = (T*)iter.Next();
1.1724 + delete p;
1.1725 + } while(p);
1.1726 + Close();
1.1727 + }
1.1728 +
1.1729 +
1.1730 +/**
1.1731 +Deletes all the key objects of type K and corresponding value objects of type V
1.1732 +to which pointers are stored in this array.
1.1733 +Then frees all the memory used by the array and returns the array to the same
1.1734 +state as immediately following construction.
1.1735 +*/
1.1736 +template <class K, class V>
1.1737 +void RPtrHashMap<K,V>::ResetAndDestroy()
1.1738 + {
1.1739 + TPtrHashMapIter<K,V> iter(*this);
1.1740 + K* p;
1.1741 + V* q;
1.1742 + do {
1.1743 + p = (K*)iter.NextKey();
1.1744 + q = (V*)iter.CurrentValue();
1.1745 + delete p;
1.1746 + delete q;
1.1747 + } while(p);
1.1748 + Close();
1.1749 + }
1.1750 +
1.1751 +
1.1752 +#endif