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