os/kernelhwsrv/kernel/eka/include/e32hashtab.h
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of the License "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
// e32/include/e32hashtab.h
sl@0
    15
// 
sl@0
    16
//
sl@0
    17
sl@0
    18
#ifndef __E32HASHTAB_H__
sl@0
    19
#define __E32HASHTAB_H__
sl@0
    20
#include <e32cmn.h>
sl@0
    21
sl@0
    22
/**
sl@0
    23
@publishedAll
sl@0
    24
@released
sl@0
    25
sl@0
    26
Defines a function type used by a THashFunction32 object. 
sl@0
    27
sl@0
    28
A function of this type implements an algorithm for producing a 32 bit hash
sl@0
    29
value from a key.
sl@0
    30
sl@0
    31
@see THashFunction32
sl@0
    32
*/
sl@0
    33
typedef TUint32 (*TGeneralHashFunction32)(const TAny*);
sl@0
    34
sl@0
    35
sl@0
    36
/**
sl@0
    37
@publishedAll
sl@0
    38
@released
sl@0
    39
sl@0
    40
A templated class which packages a function that calculates a 32 bit hash
sl@0
    41
value from a key of templated type.
sl@0
    42
sl@0
    43
A THashFunction32<T> object is constructed and passed as a parameter to 
sl@0
    44
member functions of the hash table classes RHashSet<T>, RPtrHashSet<T>,
sl@0
    45
RHashMap<T,V> and RPtrHashMap<T,V>.
sl@0
    46
sl@0
    47
@see RHashSet
sl@0
    48
@see RPtrHashSet
sl@0
    49
@see RHashMap
sl@0
    50
@see RPtrHashMap
sl@0
    51
*/
sl@0
    52
template <class T>
sl@0
    53
class THashFunction32
sl@0
    54
	{
sl@0
    55
public:
sl@0
    56
	inline THashFunction32( TUint32 (*aHashFunc)(const T&) )
sl@0
    57
		{ iHashFunction = (TGeneralHashFunction32)aHashFunc; }
sl@0
    58
	inline operator TGeneralHashFunction32() const
sl@0
    59
		{ return iHashFunction; }
sl@0
    60
	inline TUint32 Hash(const T& aKey) const
sl@0
    61
		{ return (*iHashFunction)(&aKey); }
sl@0
    62
private:
sl@0
    63
	TGeneralHashFunction32 iHashFunction;
sl@0
    64
	};
sl@0
    65
sl@0
    66
sl@0
    67
/**
sl@0
    68
@publishedAll
sl@0
    69
@released
sl@0
    70
sl@0
    71
A set of common hashing functions for frequently occurring types.
sl@0
    72
sl@0
    73
@see RHashSet
sl@0
    74
@see RPtrHashSet
sl@0
    75
@see RHashMap
sl@0
    76
@see RPtrHashMap
sl@0
    77
*/
sl@0
    78
class DefaultHash
sl@0
    79
	{
sl@0
    80
public:
sl@0
    81
	IMPORT_C static TUint32 Integer(const TInt&);
sl@0
    82
	IMPORT_C static TUint32 Des8(const TDesC8&);
sl@0
    83
	IMPORT_C static TUint32 Des16(const TDesC16&);
sl@0
    84
	IMPORT_C static TUint32 IntegerPtr(TInt* const &);
sl@0
    85
	IMPORT_C static TUint32 Des8Ptr(TDesC8* const &);
sl@0
    86
	IMPORT_C static TUint32 Des16Ptr(TDesC16* const &);
sl@0
    87
	};
sl@0
    88
sl@0
    89
sl@0
    90
sl@0
    91
class THashTableIterBase;
sl@0
    92
sl@0
    93
/**
sl@0
    94
@internalComponent
sl@0
    95
sl@0
    96
Base class used in the derivation of RHashSet<T>, RPtrHashSet<T>,
sl@0
    97
RHashMap<K,V> and RPtrHashMap<K,V>.
sl@0
    98
sl@0
    99
This class provides a general hash table implementation using probe sequences
sl@0
   100
generated by pseudo-double hashing.
sl@0
   101
The class is internal and is not intended for use.
sl@0
   102
*/
sl@0
   103
class RHashTableBase
sl@0
   104
	{
sl@0
   105
public:
sl@0
   106
	enum TDefaultSpecifier
sl@0
   107
		{
sl@0
   108
		EDefaultSpecifier_Normal,
sl@0
   109
		};
sl@0
   110
sl@0
   111
protected:
sl@0
   112
	template<class K, TDefaultSpecifier S>
sl@0
   113
	class Defaults
sl@0
   114
		{
sl@0
   115
	public:
sl@0
   116
		inline static TGeneralHashFunction32 Hash();
sl@0
   117
		inline static TGeneralIdentityRelation Id();
sl@0
   118
		};
sl@0
   119
sl@0
   120
protected:
sl@0
   121
	enum TElementState
sl@0
   122
		{
sl@0
   123
		EEmpty=0,		// entry is vacant
sl@0
   124
		EDeleted=1,		// entry has been deleted
sl@0
   125
		EGen0=2,		// entry is occupied, generation number 0
sl@0
   126
		EGen1=3,		// entry is occupied, generation number 1
sl@0
   127
		EStateMask=3,
sl@0
   128
		EOccupiedMask=2,
sl@0
   129
		};
sl@0
   130
sl@0
   131
	struct SElement
sl@0
   132
		{
sl@0
   133
		inline void SetEmpty() {iHash=EEmpty;}
sl@0
   134
		inline void SetDeleted() {iHash=EDeleted;}
sl@0
   135
		inline TBool IsEmpty() const {return (iHash&EStateMask)==EEmpty;}
sl@0
   136
		inline TBool IsDeleted() const {return (iHash&EStateMask)==EDeleted;}
sl@0
   137
		inline TBool IsEmptyOrDeleted() const {return !(iHash&EOccupiedMask);}
sl@0
   138
sl@0
   139
		TUint32	iHash;			// bits 2-31 = 30 bit hash value, bits 0,1 = state
sl@0
   140
		};
sl@0
   141
sl@0
   142
protected:
sl@0
   143
	IMPORT_C RHashTableBase(TGeneralHashFunction32, TGeneralIdentityRelation, TInt aElementSize, TInt aKeyOffset);
sl@0
   144
	IMPORT_C void Close();
sl@0
   145
	IMPORT_C TAny* Find(const TAny* aKey, TInt aOffset=0) const;
sl@0
   146
	IMPORT_C TAny* FindL(const TAny* aKey, TInt aOffset=0) const;
sl@0
   147
	TInt Insert(const TAny* aKey, TAny*& aElement);
sl@0
   148
	IMPORT_C TInt PtrInsert(const TAny* aKey, const TAny* aValue);
sl@0
   149
	IMPORT_C void PtrInsertL(const TAny* aKey, const TAny* aValue);
sl@0
   150
	IMPORT_C TInt ValueInsert(const TAny* aKey, TInt aKeySize, const TAny* aValue, TInt aValueOffset, TInt aValueSize);
sl@0
   151
	IMPORT_C void ValueInsertL(const TAny* aKey, TInt aKeySize, const TAny* aValue, TInt aValueOffset, TInt aValueSize);
sl@0
   152
	IMPORT_C TInt Remove(const TAny* aKey);
sl@0
   153
	IMPORT_C TInt Count() const;
sl@0
   154
	IMPORT_C TInt Reserve(TInt aCount);
sl@0
   155
	IMPORT_C void ReserveL(TInt aCount);
sl@0
   156
	IMPORT_C void ConsistencyCheck(TUint32* aDeleted=0, TUint32* aComparisons=0, TUint32 aChainLimit=0, TUint32* aChainInfo=0);
sl@0
   157
private:
sl@0
   158
	void SetThresholds();
sl@0
   159
	TInt ExpandTable(TInt aNewIndexBits);
sl@0
   160
	void ShrinkTable();
sl@0
   161
	void ReformTable(TUint aNewIndexBits);
sl@0
   162
	void VerifyReform();
sl@0
   163
private:
sl@0
   164
	inline SElement* Element(TInt aIndex)
sl@0
   165
		{return (SElement*)(((TUint8*)iElements) + aIndex*iElementSize);}
sl@0
   166
	inline const SElement* ElementC(TInt aIndex) const
sl@0
   167
		{return (const SElement*)(((TUint8*)iElements) + aIndex*iElementSize);}
sl@0
   168
	inline TAny* GetKey(const SElement* aElement) const
sl@0
   169
		{return iKeyOffset ? ((TUint8*)aElement + iKeyOffset) : (TAny*)((TUint32*)aElement)[1];}
sl@0
   170
private:
sl@0
   171
	TGeneralHashFunction32 iHashFunc;	// generates the hash from a given key
sl@0
   172
	TGeneralIdentityRelation iIdFunc;	// compare two keys for equality
sl@0
   173
	TUint8 iIndexBits;					// number of bits used to index the table
sl@0
   174
	TUint8 iGeneration;					// 2 or 3, generation number used when traversing entire table
sl@0
   175
	TUint8 iKeyOffset;					// offset to key
sl@0
   176
	TUint8 iPad0;
sl@0
   177
	TAny* iElements;
sl@0
   178
	TUint32 iCount;						// number of valid entries
sl@0
   179
	TUint32 iEmptyCount;				// number of empty entries
sl@0
   180
	TUint32 iLowerThreshold;			// shrink if count drops below this
sl@0
   181
	TUint32 iUpperThreshold;			// expand if count rises above this
sl@0
   182
	TUint32 iCleanThreshold;			// clean table if count of empty entries falls below this
sl@0
   183
	TInt iElementSize;
sl@0
   184
	TInt iPad1;							// expansion room
sl@0
   185
	TInt iPad2;
sl@0
   186
sl@0
   187
	friend struct RHashTableBase::SElement;
sl@0
   188
	friend class THashTableIterBase;
sl@0
   189
	friend class HashTest;
sl@0
   190
	};
sl@0
   191
sl@0
   192
sl@0
   193
/**
sl@0
   194
@internalComponent
sl@0
   195
*/
sl@0
   196
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TInt*, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   197
	{
sl@0
   198
public:
sl@0
   199
	inline static TGeneralHashFunction32 Hash();
sl@0
   200
	inline static TGeneralIdentityRelation Id();
sl@0
   201
	};
sl@0
   202
sl@0
   203
/**
sl@0
   204
@internalComponent
sl@0
   205
*/
sl@0
   206
inline TGeneralHashFunction32 RHashTableBase::Defaults<TInt*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   207
	{return (TGeneralHashFunction32)&DefaultHash::IntegerPtr;}
sl@0
   208
sl@0
   209
/**
sl@0
   210
@internalComponent
sl@0
   211
*/
sl@0
   212
inline TGeneralIdentityRelation RHashTableBase::Defaults<TInt*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   213
	{return (TGeneralIdentityRelation)&DefaultIdentity::IntegerPtr;}
sl@0
   214
sl@0
   215
/**
sl@0
   216
@internalComponent
sl@0
   217
*/
sl@0
   218
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TInt32*, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   219
	{
sl@0
   220
public:
sl@0
   221
	inline static TGeneralHashFunction32 Hash();
sl@0
   222
	inline static TGeneralIdentityRelation Id();
sl@0
   223
	};
sl@0
   224
sl@0
   225
/**
sl@0
   226
@internalComponent
sl@0
   227
*/
sl@0
   228
inline TGeneralHashFunction32 RHashTableBase::Defaults<TInt32*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   229
	{return (TGeneralHashFunction32)&DefaultHash::IntegerPtr;}
sl@0
   230
sl@0
   231
/**
sl@0
   232
@internalComponent
sl@0
   233
*/
sl@0
   234
inline TGeneralIdentityRelation RHashTableBase::Defaults<TInt32*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   235
	{return (TGeneralIdentityRelation)&DefaultIdentity::IntegerPtr;}
sl@0
   236
sl@0
   237
/**
sl@0
   238
@internalComponent
sl@0
   239
*/
sl@0
   240
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TUint*, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   241
	{
sl@0
   242
public:
sl@0
   243
	inline static TGeneralHashFunction32 Hash();
sl@0
   244
	inline static TGeneralIdentityRelation Id();
sl@0
   245
	};
sl@0
   246
/**
sl@0
   247
@internalComponent
sl@0
   248
*/
sl@0
   249
inline TGeneralHashFunction32 RHashTableBase::Defaults<TUint*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   250
	{return (TGeneralHashFunction32)&DefaultHash::IntegerPtr;}
sl@0
   251
sl@0
   252
/**
sl@0
   253
@internalComponent
sl@0
   254
*/
sl@0
   255
inline TGeneralIdentityRelation RHashTableBase::Defaults<TUint*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   256
	{return (TGeneralIdentityRelation)&DefaultIdentity::IntegerPtr;}
sl@0
   257
sl@0
   258
sl@0
   259
/**
sl@0
   260
@internalComponent
sl@0
   261
*/
sl@0
   262
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TUint32*, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   263
	{
sl@0
   264
public:
sl@0
   265
	inline static TGeneralHashFunction32 Hash();
sl@0
   266
	inline static TGeneralIdentityRelation Id();
sl@0
   267
	};
sl@0
   268
/**
sl@0
   269
@internalComponent
sl@0
   270
*/
sl@0
   271
inline TGeneralHashFunction32 RHashTableBase::Defaults<TUint32*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   272
	{return (TGeneralHashFunction32)&DefaultHash::IntegerPtr;}
sl@0
   273
sl@0
   274
/**
sl@0
   275
@internalComponent
sl@0
   276
*/
sl@0
   277
inline TGeneralIdentityRelation RHashTableBase::Defaults<TUint32*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   278
	{return (TGeneralIdentityRelation)&DefaultIdentity::IntegerPtr;}
sl@0
   279
sl@0
   280
/**
sl@0
   281
@internalComponent
sl@0
   282
*/
sl@0
   283
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TDesC8*, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   284
	{
sl@0
   285
public:
sl@0
   286
	inline static TGeneralHashFunction32 Hash();
sl@0
   287
	inline static TGeneralIdentityRelation Id();
sl@0
   288
	};
sl@0
   289
/**
sl@0
   290
@internalComponent
sl@0
   291
*/
sl@0
   292
inline TGeneralHashFunction32 RHashTableBase::Defaults<TDesC8*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   293
	{return (TGeneralHashFunction32)&DefaultHash::Des8Ptr;}
sl@0
   294
sl@0
   295
/**
sl@0
   296
@internalComponent
sl@0
   297
*/
sl@0
   298
inline TGeneralIdentityRelation RHashTableBase::Defaults<TDesC8*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   299
	{return (TGeneralIdentityRelation)&DefaultIdentity::Des8Ptr;}
sl@0
   300
sl@0
   301
/**
sl@0
   302
@internalComponent
sl@0
   303
*/
sl@0
   304
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TDesC16*, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   305
	{
sl@0
   306
public:
sl@0
   307
	inline static TGeneralHashFunction32 Hash();
sl@0
   308
	inline static TGeneralIdentityRelation Id();
sl@0
   309
	};
sl@0
   310
/**
sl@0
   311
@internalComponent
sl@0
   312
*/
sl@0
   313
inline TGeneralHashFunction32 RHashTableBase::Defaults<TDesC16*, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   314
	{return (TGeneralHashFunction32)&DefaultHash::Des16Ptr;}
sl@0
   315
sl@0
   316
/**
sl@0
   317
@internalComponent
sl@0
   318
*/
sl@0
   319
inline TGeneralIdentityRelation RHashTableBase::Defaults<TDesC16*, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   320
	{return (TGeneralIdentityRelation)&DefaultIdentity::Des16Ptr;}
sl@0
   321
sl@0
   322
/**
sl@0
   323
@internalComponent
sl@0
   324
*/
sl@0
   325
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TInt, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   326
	{
sl@0
   327
public:
sl@0
   328
	inline static TGeneralHashFunction32 Hash();
sl@0
   329
	inline static TGeneralIdentityRelation Id();
sl@0
   330
	};
sl@0
   331
sl@0
   332
/**
sl@0
   333
@internalComponent
sl@0
   334
*/
sl@0
   335
inline TGeneralHashFunction32 RHashTableBase::Defaults<TInt, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   336
	{return (TGeneralHashFunction32)&DefaultHash::Integer;}
sl@0
   337
sl@0
   338
/**
sl@0
   339
@internalComponent
sl@0
   340
*/
sl@0
   341
inline TGeneralIdentityRelation RHashTableBase::Defaults<TInt, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   342
	{return (TGeneralIdentityRelation)&DefaultIdentity::Integer;}
sl@0
   343
sl@0
   344
/**
sl@0
   345
@internalComponent
sl@0
   346
*/
sl@0
   347
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TInt32, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   348
	{
sl@0
   349
public:
sl@0
   350
	inline static TGeneralHashFunction32 Hash();
sl@0
   351
	inline static TGeneralIdentityRelation Id();
sl@0
   352
	};
sl@0
   353
sl@0
   354
/**
sl@0
   355
@internalComponent
sl@0
   356
*/
sl@0
   357
inline TGeneralHashFunction32 RHashTableBase::Defaults<TInt32, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   358
	{return (TGeneralHashFunction32)&DefaultHash::Integer;}
sl@0
   359
sl@0
   360
/**
sl@0
   361
@internalComponent
sl@0
   362
*/
sl@0
   363
inline TGeneralIdentityRelation RHashTableBase::Defaults<TInt32, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   364
	{return (TGeneralIdentityRelation)&DefaultIdentity::Integer;}
sl@0
   365
sl@0
   366
/**
sl@0
   367
@internalComponent
sl@0
   368
*/
sl@0
   369
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TUint, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   370
	{
sl@0
   371
public:
sl@0
   372
	inline static TGeneralHashFunction32 Hash();
sl@0
   373
	inline static TGeneralIdentityRelation Id();
sl@0
   374
	};
sl@0
   375
sl@0
   376
/**
sl@0
   377
@internalComponent
sl@0
   378
*/
sl@0
   379
inline TGeneralHashFunction32 RHashTableBase::Defaults<TUint, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   380
	{return (TGeneralHashFunction32)&DefaultHash::Integer;}
sl@0
   381
sl@0
   382
/**
sl@0
   383
@internalComponent
sl@0
   384
*/
sl@0
   385
inline TGeneralIdentityRelation RHashTableBase::Defaults<TUint, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   386
	{return (TGeneralIdentityRelation)&DefaultIdentity::Integer;}
sl@0
   387
sl@0
   388
sl@0
   389
/**
sl@0
   390
@internalComponent
sl@0
   391
*/
sl@0
   392
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TUint32, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   393
	{
sl@0
   394
public:
sl@0
   395
	inline static TGeneralHashFunction32 Hash();
sl@0
   396
	inline static TGeneralIdentityRelation Id();
sl@0
   397
	};
sl@0
   398
sl@0
   399
/**
sl@0
   400
@internalComponent
sl@0
   401
*/
sl@0
   402
inline TGeneralHashFunction32 RHashTableBase::Defaults<TUint32, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   403
	{return (TGeneralHashFunction32)&DefaultHash::Integer;}
sl@0
   404
sl@0
   405
/**
sl@0
   406
@internalComponent
sl@0
   407
*/
sl@0
   408
inline TGeneralIdentityRelation RHashTableBase::Defaults<TUint32, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   409
	{return (TGeneralIdentityRelation)&DefaultIdentity::Integer;}
sl@0
   410
sl@0
   411
sl@0
   412
/**
sl@0
   413
@internalComponent
sl@0
   414
*/
sl@0
   415
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TDesC8, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   416
	{
sl@0
   417
public:
sl@0
   418
	inline static TGeneralHashFunction32 Hash();
sl@0
   419
	inline static TGeneralIdentityRelation Id();
sl@0
   420
	};
sl@0
   421
sl@0
   422
/**
sl@0
   423
@internalComponent
sl@0
   424
*/
sl@0
   425
inline TGeneralHashFunction32 RHashTableBase::Defaults<TDesC8, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   426
	{return (TGeneralHashFunction32)&DefaultHash::Des8;}
sl@0
   427
sl@0
   428
/**
sl@0
   429
@internalComponent
sl@0
   430
*/
sl@0
   431
inline TGeneralIdentityRelation RHashTableBase::Defaults<TDesC8, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   432
	{return (TGeneralIdentityRelation)&DefaultIdentity::Des8;}
sl@0
   433
sl@0
   434
sl@0
   435
/**
sl@0
   436
@internalComponent
sl@0
   437
*/
sl@0
   438
TEMPLATE_SPECIALIZATION class RHashTableBase::Defaults<TDesC16, RHashTableBase::EDefaultSpecifier_Normal>
sl@0
   439
	{
sl@0
   440
public:
sl@0
   441
	inline static TGeneralHashFunction32 Hash();
sl@0
   442
	inline static TGeneralIdentityRelation Id();
sl@0
   443
	};
sl@0
   444
sl@0
   445
/**
sl@0
   446
@internalComponent
sl@0
   447
*/
sl@0
   448
inline TGeneralHashFunction32 RHashTableBase::Defaults<TDesC16, RHashTableBase::EDefaultSpecifier_Normal>::Hash()
sl@0
   449
	{return (TGeneralHashFunction32)&DefaultHash::Des16;}
sl@0
   450
sl@0
   451
/**
sl@0
   452
@internalComponent
sl@0
   453
*/
sl@0
   454
inline TGeneralIdentityRelation RHashTableBase::Defaults<TDesC16, RHashTableBase::EDefaultSpecifier_Normal>::Id()
sl@0
   455
	{return (TGeneralIdentityRelation)&DefaultIdentity::Des16;}
sl@0
   456
sl@0
   457
sl@0
   458
sl@0
   459
sl@0
   460
/**
sl@0
   461
@internalComponent
sl@0
   462
sl@0
   463
Base class used in the derivation of THashSetIter<T>, TPtrHashSetIter<T>,
sl@0
   464
THashMapIter<K,V> and TPtrHashMapIter<K,V>.
sl@0
   465
sl@0
   466
This class provides iteration capability for the hash table classes derived
sl@0
   467
from RHashTableBase.
sl@0
   468
The class is internal and is not intended for use.
sl@0
   469
*/
sl@0
   470
class THashTableIterBase
sl@0
   471
	{
sl@0
   472
protected:
sl@0
   473
	IMPORT_C THashTableIterBase(const RHashTableBase& aTable);
sl@0
   474
	IMPORT_C void Reset();
sl@0
   475
	IMPORT_C const TAny* Next(TInt aOffset=0);
sl@0
   476
	IMPORT_C const TAny* Current(TInt aOffset=0) const;
sl@0
   477
	IMPORT_C void RemoveCurrent();
sl@0
   478
private:
sl@0
   479
	const RHashTableBase& iTbl;
sl@0
   480
	TInt iIndex;
sl@0
   481
	TInt iPad1;							// expansion room
sl@0
   482
	TInt iPad2;
sl@0
   483
	};
sl@0
   484
sl@0
   485
sl@0
   486
sl@0
   487
template <class T> class THashSetIter;
sl@0
   488
sl@0
   489
/**
sl@0
   490
@publishedAll
sl@0
   491
@released
sl@0
   492
sl@0
   493
A templated class which implements an unordered extensional set of objects of
sl@0
   494
type T using a probe-sequence hash table. The objects are copied into the set
sl@0
   495
when they are added. A bitwise binary copy is used here, so the type T must
sl@0
   496
not implement a nontrivial copy constructor.
sl@0
   497
sl@0
   498
*/
sl@0
   499
template <class T>
sl@0
   500
class RHashSet : public RHashTableBase
sl@0
   501
	{
sl@0
   502
private:
sl@0
   503
	friend class THashSetIter<T>;
sl@0
   504
	
sl@0
   505
	struct SFullElement
sl@0
   506
		{
sl@0
   507
		TUint32 iHash;
sl@0
   508
		T iT;
sl@0
   509
		};
sl@0
   510
sl@0
   511
public:
sl@0
   512
sl@0
   513
/**
sl@0
   514
A class which allows iteration over the elements of a RHashSet<T> class.
sl@0
   515
sl@0
   516
The set being iterated over may not be modified while an iteration is in progress
sl@0
   517
or the iteration operations may malfunction or panic.
sl@0
   518
sl@0
   519
@see THashSetIter<T>
sl@0
   520
*/
sl@0
   521
	typedef THashSetIter<T> TIter;
sl@0
   522
	
sl@0
   523
/**
sl@0
   524
Construct a set of objects of type T using a specified hash function and identity relation.
sl@0
   525
The set is initially empty.
sl@0
   526
sl@0
   527
@param	aHash		The hash function used to hash the objects of type T.
sl@0
   528
@param	aIdentity	The identity relation used to determine if two objects of type T
sl@0
   529
					should be considered identical.
sl@0
   530
*/
sl@0
   531
	inline RHashSet(const THashFunction32<T>& aHash, const TIdentityRelation<T>& aIdentity)
sl@0
   532
		:	RHashTableBase(aHash, aIdentity, sizeof(SFullElement), _FOFF(SFullElement,iT))
sl@0
   533
		{}
sl@0
   534
sl@0
   535
sl@0
   536
/**
sl@0
   537
Construct a set of objects of type T using a default hash function and identity relation.
sl@0
   538
The set is initially empty.
sl@0
   539
*/
sl@0
   540
	inline RHashSet()
sl@0
   541
		:	RHashTableBase(Defaults<T,EDefaultSpecifier_Normal>::Hash(), Defaults<T,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), _FOFF(SFullElement,iT))
sl@0
   542
		{}
sl@0
   543
sl@0
   544
sl@0
   545
/**
sl@0
   546
Free all memory used by this set.
sl@0
   547
Returns the set to the same state it had following construction.
sl@0
   548
*/
sl@0
   549
	inline void Close()
sl@0
   550
		{ RHashTableBase::Close(); }
sl@0
   551
sl@0
   552
sl@0
   553
/**
sl@0
   554
Locate a specified element in the set.
sl@0
   555
sl@0
   556
@param	aKey	The object of type T to search for.
sl@0
   557
@return			A pointer to the copy of the specified object in the set, if it
sl@0
   558
				exists. The object may not be modified via this pointer.
sl@0
   559
				NULL if the specified object is not a member of this set.
sl@0
   560
*/
sl@0
   561
	inline const T* Find(const T& aKey) const
sl@0
   562
		{ return (const T*)RHashTableBase::Find(&aKey, _FOFF(SFullElement,iT)); }
sl@0
   563
sl@0
   564
sl@0
   565
/**
sl@0
   566
Locate a specified element in the set.
sl@0
   567
sl@0
   568
@param	aKey	The object of type T to search for.
sl@0
   569
@return			A reference to the copy of the specified object in the set, if it
sl@0
   570
				exists. The object may not be modified via this reference.
sl@0
   571
@leave			KErrNotFound if the specified object is not a member of this set.
sl@0
   572
*/
sl@0
   573
	inline const T& FindL(const T& aKey) const
sl@0
   574
		{ return *(const T*)RHashTableBase::FindL(&aKey, _FOFF(SFullElement,iT)); }
sl@0
   575
sl@0
   576
sl@0
   577
/**
sl@0
   578
Locate a specified element in the set.
sl@0
   579
sl@0
   580
@param	aKey	The object of type T to search for.
sl@0
   581
@return			A pointer to the copy of the specified object in the set, if it
sl@0
   582
				exists. The object may be modified via this pointer. Care should
sl@0
   583
				be taken not to modify any parts of the object which are used by
sl@0
   584
				either the hash function or the identity relation for this set.
sl@0
   585
				If this is done the set may become inconsistent, resulting in
sl@0
   586
				malfunctions and/or panics at a later time.
sl@0
   587
				NULL if the specified object is not a member of this set.
sl@0
   588
*/
sl@0
   589
	inline T* Find(const T& aKey)
sl@0
   590
		{ return (T*)RHashTableBase::Find(&aKey, _FOFF(SFullElement,iT)); }
sl@0
   591
sl@0
   592
sl@0
   593
/**
sl@0
   594
Locate a specified element in the set.
sl@0
   595
sl@0
   596
@param	aKey	The object of type T to search for.
sl@0
   597
@return			A reference to the copy of the specified object in the set, if it
sl@0
   598
				exists. The object may be modified via this reference. Care should
sl@0
   599
				be taken not to modify any parts of the object which are used by
sl@0
   600
				either the hash function or the identity relation for this set.
sl@0
   601
				If this is done the set may become inconsistent, resulting in
sl@0
   602
				malfunctions and/or panics at a later time.
sl@0
   603
@leave			KErrNotFound if the specified object is not a member of this set.
sl@0
   604
*/
sl@0
   605
	inline T& FindL(const T& aKey)
sl@0
   606
		{ return *(T*)RHashTableBase::FindL(&aKey, _FOFF(SFullElement,iT)); }
sl@0
   607
sl@0
   608
sl@0
   609
/**
sl@0
   610
Insert an element into the set.
sl@0
   611
sl@0
   612
If the specified object is not currently a member of the set, a copy of the
sl@0
   613
object is added to the set and KErrNone is returned.
sl@0
   614
If the specified object is currently a member of the set, the existing copy
sl@0
   615
of the object is replaced by the provided object and KErrNone is
sl@0
   616
returned.
sl@0
   617
In both cases the object is copied bitwise into the set.
sl@0
   618
sl@0
   619
@param	aKey	The object of type T to add to the set.
sl@0
   620
@return			KErrNone if the object was added successfully.
sl@0
   621
				KErrNoMemory if memory could not be allocated to store
sl@0
   622
					the copy of aKey.
sl@0
   623
*/
sl@0
   624
	inline TInt Insert(const T& aKey)
sl@0
   625
		{ return RHashTableBase::ValueInsert(&aKey, sizeof(T), 0, 0, 0); }
sl@0
   626
sl@0
   627
sl@0
   628
/**
sl@0
   629
Insert an element into the set.
sl@0
   630
sl@0
   631
If the specified object is not currently a member of the set, a copy of the
sl@0
   632
object is added to the set and KErrNone is returned.
sl@0
   633
If the specified object is currently a member of the set, the existing copy
sl@0
   634
of the object is replaced by the provided object and KErrNone is
sl@0
   635
returned.
sl@0
   636
In both cases the object is copied bitwise into the set.
sl@0
   637
sl@0
   638
@param	aKey	The object of type T to add to the set.
sl@0
   639
@leave			KErrNoMemory if memory could not be allocated to store
sl@0
   640
					the copy of aKey.
sl@0
   641
*/
sl@0
   642
	inline void InsertL(const T& aKey)
sl@0
   643
		{ RHashTableBase::ValueInsertL(&aKey, sizeof(T), 0, 0, 0); }
sl@0
   644
sl@0
   645
sl@0
   646
/**
sl@0
   647
Remove an element from the set.
sl@0
   648
sl@0
   649
@param	aKey	The object to be removed.
sl@0
   650
@return			KErrNone if the object was removed successfully.
sl@0
   651
				KErrNotFound if the object was not present in the set.
sl@0
   652
*/
sl@0
   653
	inline TInt Remove(const T& aKey)
sl@0
   654
		{ return RHashTableBase::Remove(&aKey); }
sl@0
   655
sl@0
   656
sl@0
   657
/**
sl@0
   658
Query the number of elements in the set.
sl@0
   659
sl@0
   660
@return	The number of elements currently in the set.
sl@0
   661
*/
sl@0
   662
	inline TInt Count() const
sl@0
   663
		{ return RHashTableBase::Count(); }
sl@0
   664
sl@0
   665
sl@0
   666
/**
sl@0
   667
Expand the set to accommodate a specified number of elements.
sl@0
   668
If the set already has enough space for the specified number of elements, no
sl@0
   669
action is taken. Any elements already in the set are retained.
sl@0
   670
sl@0
   671
@param	aCount	The number of elements for which space should be allocated.
sl@0
   672
@return	KErrNone if the operation completed successfully.
sl@0
   673
@return	KErrNoMemory if sufficient memory could not be allocated.
sl@0
   674
*/
sl@0
   675
	inline TInt Reserve(TInt aCount)
sl@0
   676
		{ return RHashTableBase::Reserve(aCount); }
sl@0
   677
sl@0
   678
sl@0
   679
/**
sl@0
   680
Expand the set to accommodate a specified number of elements.
sl@0
   681
If the set already has enough space for the specified number of elements, no
sl@0
   682
action is taken. Any elements already in the set are retained.
sl@0
   683
sl@0
   684
@param	aCount	The number of elements for which space should be allocated.
sl@0
   685
@leave	KErrNoMemory if sufficient memory could not be allocated.
sl@0
   686
*/
sl@0
   687
	inline void ReserveL(TInt aCount)
sl@0
   688
		{ RHashTableBase::ReserveL(aCount); }
sl@0
   689
sl@0
   690
	};
sl@0
   691
sl@0
   692
sl@0
   693
/**
sl@0
   694
@publishedAll
sl@0
   695
@released
sl@0
   696
sl@0
   697
A templated class which allows iteration over the elements of a RHashSet<T>
sl@0
   698
class.
sl@0
   699
sl@0
   700
The set being iterated over may not be modified while an iteration is in progress
sl@0
   701
or the iteration operations may malfunction or panic.
sl@0
   702
sl@0
   703
@see RHashSet<T>
sl@0
   704
*/
sl@0
   705
template <class T>
sl@0
   706
class THashSetIter : public THashTableIterBase
sl@0
   707
	{
sl@0
   708
private:
sl@0
   709
	
sl@0
   710
	struct SFullElement
sl@0
   711
		{
sl@0
   712
		TUint32 iHash;
sl@0
   713
		T iT;
sl@0
   714
		};
sl@0
   715
sl@0
   716
public:
sl@0
   717
sl@0
   718
/**
sl@0
   719
Construct an iterator over the specified set.
sl@0
   720
The iterator starts at conceptual position one before the beginning of the list
sl@0
   721
being iterated.
sl@0
   722
sl@0
   723
@param	aSet	The set to be iterated over.
sl@0
   724
*/
sl@0
   725
	inline THashSetIter(const RHashSet<T>& aSet)
sl@0
   726
		:	THashTableIterBase(aSet)
sl@0
   727
		{}
sl@0
   728
sl@0
   729
sl@0
   730
/**
sl@0
   731
Reset the iterator to its initial state.
sl@0
   732
sl@0
   733
@param	aSet	The set to be iterated over.
sl@0
   734
*/
sl@0
   735
	inline void Reset()
sl@0
   736
		{ THashTableIterBase::Reset(); }
sl@0
   737
sl@0
   738
sl@0
   739
/**
sl@0
   740
Return the current position of the iterator.
sl@0
   741
sl@0
   742
@return	A pointer to the set member corresponding to the current position of the
sl@0
   743
		iterator.
sl@0
   744
		NULL if the iterator has just been constructed or reset, or if it has
sl@0
   745
		previously reached the end of an iteration.
sl@0
   746
*/
sl@0
   747
	inline const T* Current() const
sl@0
   748
		{ return (const T*)THashTableIterBase::Current(_FOFF(SFullElement,iT)); }
sl@0
   749
sl@0
   750
sl@0
   751
/**
sl@0
   752
Steps the iterator to the next position.
sl@0
   753
sl@0
   754
@return	A pointer to the set member corresponding to the next position of the
sl@0
   755
		iterator.
sl@0
   756
		NULL if the iterator has exhausted all the available set elements.
sl@0
   757
*/
sl@0
   758
	inline const T* Next()
sl@0
   759
		{ return (const T*)THashTableIterBase::Next(_FOFF(SFullElement,iT)); }
sl@0
   760
sl@0
   761
sl@0
   762
/**
sl@0
   763
Removes the element at the current iterator position from the hash table.
sl@0
   764
If the iterator does not currently point to a valid element, no action is taken.
sl@0
   765
Note that the iterator position is not altered so it no longer points to a valid
sl@0
   766
element following the Remove(). It is illegal to call Current() on the iterator
sl@0
   767
after calling Remove() - the only legal operations are Reset() and Next().
sl@0
   768
sl@0
   769
*/
sl@0
   770
	inline void RemoveCurrent()
sl@0
   771
		{ THashTableIterBase::RemoveCurrent(); }
sl@0
   772
	};
sl@0
   773
sl@0
   774
sl@0
   775
sl@0
   776
template <class T> class TPtrHashSetIter;
sl@0
   777
sl@0
   778
/**
sl@0
   779
@publishedAll
sl@0
   780
@released
sl@0
   781
sl@0
   782
A templated class which implements an unordered extensional set of objects of
sl@0
   783
type T using a probe-sequence hash table. The objects are not copied into the set
sl@0
   784
when they are added; rather the set stores pointers to the contained objects.
sl@0
   785
sl@0
   786
*/
sl@0
   787
template <class T>
sl@0
   788
class RPtrHashSet : public RHashTableBase
sl@0
   789
	{
sl@0
   790
private:
sl@0
   791
	friend class TPtrHashSetIter<T>;
sl@0
   792
	
sl@0
   793
	struct SFullElement
sl@0
   794
		{
sl@0
   795
		TUint32 iHash;
sl@0
   796
		T* iT;
sl@0
   797
		};
sl@0
   798
sl@0
   799
public:
sl@0
   800
sl@0
   801
/**
sl@0
   802
A class which allows iteration over the elements of a RPtrHashSet<T> class.
sl@0
   803
sl@0
   804
The set being iterated over may not be modified while an iteration is in progress
sl@0
   805
or the iteration operations may malfunction or panic.
sl@0
   806
sl@0
   807
@see TPtrHashSetIter<T>
sl@0
   808
*/
sl@0
   809
	typedef TPtrHashSetIter<T> TIter;
sl@0
   810
sl@0
   811
/**
sl@0
   812
Construct a set of objects of type T using a specified hash function and identity relation.
sl@0
   813
The set is initially empty.
sl@0
   814
sl@0
   815
@param	aHash		The hash function used to hash the objects of type T.
sl@0
   816
@param	aIdentity	The identity relation used to determine if two objects of type T
sl@0
   817
					should be considered identical.
sl@0
   818
*/
sl@0
   819
	inline RPtrHashSet(const THashFunction32<T>& aHash, const TIdentityRelation<T>& aIdentity)
sl@0
   820
		:	RHashTableBase(aHash, aIdentity, sizeof(SFullElement), 0)
sl@0
   821
		{}
sl@0
   822
sl@0
   823
sl@0
   824
/**
sl@0
   825
Construct a set of objects of type T using a default hash function and identity relation.
sl@0
   826
The set is initially empty.
sl@0
   827
*/
sl@0
   828
	inline RPtrHashSet()
sl@0
   829
		:	RHashTableBase(Defaults<T,EDefaultSpecifier_Normal>::Hash(), Defaults<T,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), 0)
sl@0
   830
		{}
sl@0
   831
sl@0
   832
sl@0
   833
/**
sl@0
   834
Free all memory used by this set.
sl@0
   835
Returns the set to the same state it had following construction.
sl@0
   836
*/
sl@0
   837
	inline void Close()
sl@0
   838
		{ RHashTableBase::Close(); }
sl@0
   839
sl@0
   840
sl@0
   841
/**
sl@0
   842
Locate a specified element in the set.
sl@0
   843
sl@0
   844
@param	aKey	The object of type T to search for.
sl@0
   845
@return			A pointer to the specified object, if it is in the set.
sl@0
   846
				The object may not be modified via this pointer.
sl@0
   847
				NULL if the specified object is not a member of this set.
sl@0
   848
*/
sl@0
   849
	inline const T* Find(const T& aKey) const
sl@0
   850
		{ return (const T*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iT)); }
sl@0
   851
sl@0
   852
sl@0
   853
/**
sl@0
   854
Locate a specified element in the set.
sl@0
   855
sl@0
   856
@param	aKey	The object of type T to search for.
sl@0
   857
@return			A reference to the specified object, if it is in the set.
sl@0
   858
				The object may not be modified via this reference.
sl@0
   859
@leave	KErrNotFound if the specified object is not a member of this set.
sl@0
   860
*/
sl@0
   861
	inline const T& FindL(const T& aKey) const
sl@0
   862
		{ return *(const T*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iT)); }
sl@0
   863
sl@0
   864
sl@0
   865
/**
sl@0
   866
Locate a specified element in the set.
sl@0
   867
sl@0
   868
@param	aKey	The object of type T to search for.
sl@0
   869
@return			A pointer to the specified object, if it is in the set.
sl@0
   870
				The object may be modified via this pointer. Care should
sl@0
   871
				be taken not to modify any parts of the object which are used by
sl@0
   872
				either the hash function or the identity relation for this set.
sl@0
   873
				If this is done the set may become inconsistent, resulting in
sl@0
   874
				malfunctions and/or panics at a later time.
sl@0
   875
				NULL if the specified object is not a member of this set.
sl@0
   876
*/
sl@0
   877
	inline T* Find(const T& aKey)
sl@0
   878
		{ return (T*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iT)); }
sl@0
   879
sl@0
   880
sl@0
   881
/**
sl@0
   882
Locate a specified element in the set.
sl@0
   883
sl@0
   884
@param	aKey	The object of type T to search for.
sl@0
   885
@return			A reference to the specified object, if it is in the set.
sl@0
   886
				The object may be modified via this reference. Care should
sl@0
   887
				be taken not to modify any parts of the object which are used by
sl@0
   888
				either the hash function or the identity relation for this set.
sl@0
   889
				If this is done the set may become inconsistent, resulting in
sl@0
   890
				malfunctions and/or panics at a later time.
sl@0
   891
@leave	KErrNotFound if the specified object is not a member of this set.
sl@0
   892
*/
sl@0
   893
	inline T& FindL(const T& aKey)
sl@0
   894
		{ return *(T*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iT)); }
sl@0
   895
sl@0
   896
sl@0
   897
/**
sl@0
   898
Insert an element into the set.
sl@0
   899
sl@0
   900
If the specified object is not currently a member of the set, a pointer to the
sl@0
   901
object is added to the set and KErrNone is returned.
sl@0
   902
If the specified object is currently a member of the set, the existing pointer
sl@0
   903
to the object is replaced by the provided pointer and KErrNone is
sl@0
   904
returned.
sl@0
   905
In both cases only a pointer to the object is stored - the object is never copied.
sl@0
   906
sl@0
   907
@param	aKey	A pointer to the object of type T to add to the set.
sl@0
   908
@return			KErrNone if the object was added successfully.
sl@0
   909
				KErrNoMemory if memory could not be allocated to store
sl@0
   910
					the pointer to the new object.
sl@0
   911
*/
sl@0
   912
	inline TInt Insert(const T* aKey)
sl@0
   913
		{ return RHashTableBase::PtrInsert(aKey, 0); }
sl@0
   914
sl@0
   915
sl@0
   916
/**
sl@0
   917
Insert an element into the set.
sl@0
   918
sl@0
   919
If the specified object is not currently a member of the set, a pointer to the
sl@0
   920
object is added to the set and KErrNone is returned.
sl@0
   921
If the specified object is currently a member of the set, the existing pointer
sl@0
   922
to the object is replaced by the provided pointer and KErrNone is
sl@0
   923
returned.
sl@0
   924
In both cases only a pointer to the object is stored - the object is never copied.
sl@0
   925
sl@0
   926
@param	aKey	A pointer to the object of type T to add to the set.
sl@0
   927
@leave	KErrNoMemory if memory could not be allocated to store the pointer to the new object.
sl@0
   928
*/
sl@0
   929
	inline void InsertL(const T* aKey)
sl@0
   930
		{ RHashTableBase::PtrInsertL(aKey, 0); }
sl@0
   931
sl@0
   932
sl@0
   933
/**
sl@0
   934
Remove an element from the set.
sl@0
   935
sl@0
   936
@param	aKey	A pointer to the object to be removed.
sl@0
   937
@return			KErrNone if the object was removed successfully.
sl@0
   938
				KErrNotFound if the object was not present in the set.
sl@0
   939
*/
sl@0
   940
	inline TInt Remove(const T* aKey)
sl@0
   941
		{ return RHashTableBase::Remove(aKey); }
sl@0
   942
sl@0
   943
sl@0
   944
/**
sl@0
   945
Query the number of elements in the set.
sl@0
   946
sl@0
   947
@return	The number of elements currently in the set.
sl@0
   948
*/
sl@0
   949
	inline TInt Count() const
sl@0
   950
		{ return RHashTableBase::Count(); }
sl@0
   951
sl@0
   952
sl@0
   953
/**
sl@0
   954
Expand the set to accommodate a specified number of elements.
sl@0
   955
If the set already has enough space for the specified number of elements, no
sl@0
   956
action is taken. Any elements already in the set are retained.
sl@0
   957
sl@0
   958
@param	aCount	The number of elements for which space should be allocated.
sl@0
   959
@return	KErrNone if the operation completed successfully.
sl@0
   960
@return	KErrNoMemory if sufficient memory could not be allocated.
sl@0
   961
*/
sl@0
   962
	inline TInt Reserve(TInt aCount)
sl@0
   963
		{ return RHashTableBase::Reserve(aCount); }
sl@0
   964
sl@0
   965
sl@0
   966
/**
sl@0
   967
Expand the set to accommodate a specified number of elements.
sl@0
   968
If the set already has enough space for the specified number of elements, no
sl@0
   969
action is taken. Any elements already in the set are retained.
sl@0
   970
sl@0
   971
@param	aCount	The number of elements for which space should be allocated.
sl@0
   972
@leave	KErrNoMemory if sufficient memory could not be allocated.
sl@0
   973
*/
sl@0
   974
	inline void ReserveL(TInt aCount)
sl@0
   975
		{ RHashTableBase::ReserveL(aCount); }
sl@0
   976
sl@0
   977
sl@0
   978
	void ResetAndDestroy();
sl@0
   979
	};
sl@0
   980
sl@0
   981
sl@0
   982
/**
sl@0
   983
@publishedAll
sl@0
   984
@released
sl@0
   985
sl@0
   986
A templated class which allows iteration over the elements of a RPtrHashSet<T>
sl@0
   987
class.
sl@0
   988
sl@0
   989
The set being iterated over may not be modified while an iteration is in progress
sl@0
   990
or the iteration operations may malfunction or panic.
sl@0
   991
sl@0
   992
@see RPtrHashSet<T>
sl@0
   993
*/
sl@0
   994
template <class T>
sl@0
   995
class TPtrHashSetIter : public THashTableIterBase
sl@0
   996
	{
sl@0
   997
private:
sl@0
   998
	
sl@0
   999
	struct SFullElement		
sl@0
  1000
		{
sl@0
  1001
		TUint32 iHash;
sl@0
  1002
		T* iT;
sl@0
  1003
		};
sl@0
  1004
sl@0
  1005
public:
sl@0
  1006
sl@0
  1007
/**
sl@0
  1008
Construct an iterator over the specified set.
sl@0
  1009
The iterator starts at conceptual position one before the beginning of the list
sl@0
  1010
being iterated.
sl@0
  1011
sl@0
  1012
@param	aSet	The set to be iterated over.
sl@0
  1013
*/
sl@0
  1014
	inline TPtrHashSetIter(const RPtrHashSet<T>& aSet)
sl@0
  1015
		:	THashTableIterBase(aSet)
sl@0
  1016
		{}
sl@0
  1017
sl@0
  1018
sl@0
  1019
/**
sl@0
  1020
Reset the iterator to its initial state.
sl@0
  1021
sl@0
  1022
@param	aSet	The set to be iterated over.
sl@0
  1023
*/
sl@0
  1024
	inline void Reset()
sl@0
  1025
		{ THashTableIterBase::Reset(); }
sl@0
  1026
sl@0
  1027
sl@0
  1028
/**
sl@0
  1029
Return the current position of the iterator.
sl@0
  1030
sl@0
  1031
@return	A pointer to the set member corresponding to the current position of the
sl@0
  1032
		iterator.
sl@0
  1033
		NULL if the iterator has just been constructed or reset, or if it has
sl@0
  1034
		previously reached the end of an iteration.
sl@0
  1035
*/
sl@0
  1036
	inline const T* Current() const
sl@0
  1037
		{ return (const T*)THashTableIterBase::Current(-_FOFF(SFullElement,iT)); }
sl@0
  1038
sl@0
  1039
sl@0
  1040
/**
sl@0
  1041
Steps the iterator to the next position.
sl@0
  1042
sl@0
  1043
@return	A pointer to the set member corresponding to the next position of the
sl@0
  1044
		iterator.
sl@0
  1045
		NULL if the iterator has exhausted all the available set elements.
sl@0
  1046
*/
sl@0
  1047
	inline const T* Next()
sl@0
  1048
		{ return (const T*)THashTableIterBase::Next(-_FOFF(SFullElement,iT)); }
sl@0
  1049
sl@0
  1050
sl@0
  1051
/**
sl@0
  1052
Removes the element at the current iterator position from the hash table.
sl@0
  1053
If the iterator does not currently point to a valid element, no action is taken.
sl@0
  1054
Note that the iterator position is not altered so it no longer points to a valid
sl@0
  1055
element following the Remove(). It is illegal to call Current() on the iterator
sl@0
  1056
after calling Remove() - the only legal operations are Reset() and Next().
sl@0
  1057
sl@0
  1058
*/
sl@0
  1059
	inline void RemoveCurrent()
sl@0
  1060
		{ THashTableIterBase::RemoveCurrent(); }
sl@0
  1061
	};
sl@0
  1062
sl@0
  1063
sl@0
  1064
sl@0
  1065
template <class K, class V> class THashMapIter;
sl@0
  1066
sl@0
  1067
/**
sl@0
  1068
@publishedAll
sl@0
  1069
@released
sl@0
  1070
sl@0
  1071
A templated class which implements an associative array with key type K and value type V,
sl@0
  1072
using a probe-sequence hash table. Both the key and value objects are copied into the
sl@0
  1073
table when they are added. A bitwise binary copy is used here, so neither of the types
sl@0
  1074
K and V may implement a nontrivial copy constructor.
sl@0
  1075
sl@0
  1076
*/
sl@0
  1077
template <class K, class V>
sl@0
  1078
class RHashMap : public RHashTableBase
sl@0
  1079
	{
sl@0
  1080
private:
sl@0
  1081
	friend class THashMapIter<K,V>;
sl@0
  1082
	
sl@0
  1083
	struct SFullElement
sl@0
  1084
		{
sl@0
  1085
		TUint32 iHash;
sl@0
  1086
		K iK;
sl@0
  1087
		V iV;
sl@0
  1088
		};
sl@0
  1089
sl@0
  1090
public:
sl@0
  1091
sl@0
  1092
/**
sl@0
  1093
A class which allows iteration over the elements of a RHashMap<K,V> class.
sl@0
  1094
sl@0
  1095
The array being iterated over may not be modified while an iteration is in progress
sl@0
  1096
or the iteration operations may malfunction or panic.
sl@0
  1097
sl@0
  1098
@see THashMapIter<K,V>
sl@0
  1099
*/
sl@0
  1100
	typedef THashMapIter<K,V> TIter;
sl@0
  1101
sl@0
  1102
/**
sl@0
  1103
Construct an associative array of key-value pairs of type (K,V) using a
sl@0
  1104
specified hash function and identity relation.
sl@0
  1105
The array initially contains no key-value pairs.
sl@0
  1106
sl@0
  1107
@param	aHash		The hash function used to hash the key objects of type K.
sl@0
  1108
@param	aIdentity	The identity relation used to determine if two key objects
sl@0
  1109
					of type K should be considered identical.
sl@0
  1110
*/
sl@0
  1111
	inline RHashMap(const THashFunction32<K>& aHash, const TIdentityRelation<K>& aIdentity)
sl@0
  1112
		:	RHashTableBase(aHash, aIdentity, sizeof(SFullElement), _FOFF(SFullElement,iK))
sl@0
  1113
		{}
sl@0
  1114
sl@0
  1115
sl@0
  1116
/**
sl@0
  1117
Construct an associative array of key-value pairs of type (K,V) using a
sl@0
  1118
default hash function and identity relation.
sl@0
  1119
The array initially contains no key-value pairs.
sl@0
  1120
*/
sl@0
  1121
	inline RHashMap()
sl@0
  1122
		:	RHashTableBase(Defaults<K,EDefaultSpecifier_Normal>::Hash(), Defaults<K,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), _FOFF(SFullElement,iK))
sl@0
  1123
		{}
sl@0
  1124
sl@0
  1125
sl@0
  1126
/**
sl@0
  1127
Free all memory used by this array.
sl@0
  1128
Returns the array to the same state it had following construction.
sl@0
  1129
*/
sl@0
  1130
	inline void Close()
sl@0
  1131
		{ RHashTableBase::Close(); }
sl@0
  1132
sl@0
  1133
sl@0
  1134
/**
sl@0
  1135
Look up a specified key in the associative array and return a pointer to the
sl@0
  1136
corresponding value.
sl@0
  1137
sl@0
  1138
@param	aKey	The key object of type K to look up.
sl@0
  1139
@return			A pointer to the copy of the corresponding value object in the
sl@0
  1140
				array, if the specified key object was found.
sl@0
  1141
				The value object may not be modified via this pointer.
sl@0
  1142
				NULL if the specified key object was not found.
sl@0
  1143
*/
sl@0
  1144
	inline const V* Find(const K& aKey) const
sl@0
  1145
		{ return (const V*)RHashTableBase::Find(&aKey, _FOFF(SFullElement,iV)); }
sl@0
  1146
sl@0
  1147
sl@0
  1148
/**
sl@0
  1149
Look up a specified key in the associative array and return a pointer to the
sl@0
  1150
corresponding value.
sl@0
  1151
sl@0
  1152
@param	aKey	The key object of type K to look up.
sl@0
  1153
@return			A reference to the copy of the corresponding value object in the
sl@0
  1154
				array, if the specified key object was found.
sl@0
  1155
				The value object may not be modified via this reference.
sl@0
  1156
@leave	KErrNotFound if the specified key object was not found.
sl@0
  1157
*/
sl@0
  1158
	inline const V& FindL(const K& aKey) const
sl@0
  1159
		{ return *(const V*)RHashTableBase::FindL(&aKey, _FOFF(SFullElement,iV)); }
sl@0
  1160
sl@0
  1161
sl@0
  1162
/**
sl@0
  1163
Look up a specified key in the associative array and return a pointer to the
sl@0
  1164
corresponding value.
sl@0
  1165
sl@0
  1166
@param	aKey	The key object of type K to look up.
sl@0
  1167
@return			A pointer to the copy of the corresponding value object in the
sl@0
  1168
				array, if the specified key object was found.
sl@0
  1169
				The value object may be modified via this pointer.
sl@0
  1170
				NULL if the specified key object was not found.
sl@0
  1171
*/
sl@0
  1172
	inline V* Find(const K& aKey)
sl@0
  1173
		{ return (V*)RHashTableBase::Find(&aKey, _FOFF(SFullElement,iV)); }
sl@0
  1174
sl@0
  1175
sl@0
  1176
/**
sl@0
  1177
Look up a specified key in the associative array and return a pointer to the
sl@0
  1178
corresponding value.
sl@0
  1179
sl@0
  1180
@param	aKey	The key object of type K to look up.
sl@0
  1181
@return			A reference to the copy of the corresponding value object in the
sl@0
  1182
				array, if the specified key object was found.
sl@0
  1183
				The value object may be modified via this reference.
sl@0
  1184
@leave	KErrNotFound if the specified key object was not found.
sl@0
  1185
*/
sl@0
  1186
	inline V& FindL(const K& aKey)
sl@0
  1187
		{ return *(V*)RHashTableBase::FindL(&aKey, _FOFF(SFullElement,iV)); }
sl@0
  1188
sl@0
  1189
sl@0
  1190
/**
sl@0
  1191
Insert a key-value pair into the array.
sl@0
  1192
sl@0
  1193
If the specified key object is not found in the array, a copy of the
sl@0
  1194
key object along with a copy of the value object are added to the array
sl@0
  1195
and KErrNone is returned.
sl@0
  1196
If the specified key object is found in the array, the existing copies
sl@0
  1197
of both the key and value objects are replaced by the provided objects
sl@0
  1198
and KErrNone is returned.
sl@0
  1199
In both cases the objects are copied bitwise into the array.
sl@0
  1200
sl@0
  1201
@param	aKey	The key object of type K to add to the array.
sl@0
  1202
@param	aValue	The value object of type V to associate with aKey.
sl@0
  1203
@return			KErrNone if the key-value pair was added successfully.
sl@0
  1204
				KErrNoMemory if memory could not be allocated to store
sl@0
  1205
					the copies of aKey and aValue.
sl@0
  1206
*/
sl@0
  1207
	inline TInt Insert(const K& aKey, const V& aValue)
sl@0
  1208
		{ return RHashTableBase::ValueInsert(&aKey, sizeof(K), &aValue, _FOFF(SFullElement,iV), sizeof(V)); }
sl@0
  1209
sl@0
  1210
sl@0
  1211
/**
sl@0
  1212
Insert a key-value pair into the array.
sl@0
  1213
sl@0
  1214
If the specified key object is not found in the array, a copy of the
sl@0
  1215
key object along with a copy of the value object are added to the array
sl@0
  1216
and KErrNone is returned.
sl@0
  1217
If the specified key object is found in the array, the existing copies
sl@0
  1218
of both the key and value objects are replaced by the provided objects
sl@0
  1219
and KErrNone is returned.
sl@0
  1220
In both cases the objects are copied bitwise into the array.
sl@0
  1221
sl@0
  1222
@param	aKey	The key object of type K to add to the array.
sl@0
  1223
@param	aValue	The value object of type V to associate with aKey.
sl@0
  1224
@leave	KErrNoMemory if memory could not be allocated to store the copies of aKey and aValue.
sl@0
  1225
*/
sl@0
  1226
	inline void InsertL(const K& aKey, const V& aValue)
sl@0
  1227
		{ RHashTableBase::ValueInsertL(&aKey, sizeof(K), &aValue, _FOFF(SFullElement,iV), sizeof(V)); }
sl@0
  1228
sl@0
  1229
sl@0
  1230
/**
sl@0
  1231
Remove a key-value pair from the array.
sl@0
  1232
sl@0
  1233
@param	aKey	The key to be removed.
sl@0
  1234
@return			KErrNone if the key object and corresponding value object were
sl@0
  1235
				removed successfully.
sl@0
  1236
				KErrNotFound if the key object was not present in the array.
sl@0
  1237
*/
sl@0
  1238
	inline TInt Remove(const K& aKey)
sl@0
  1239
		{ return RHashTableBase::Remove(&aKey); }
sl@0
  1240
sl@0
  1241
sl@0
  1242
/**
sl@0
  1243
Query the number of key-value pairs in the array.
sl@0
  1244
sl@0
  1245
@return	The number of key-value pairs currently in the array.
sl@0
  1246
*/
sl@0
  1247
	inline TInt Count() const
sl@0
  1248
		{ return RHashTableBase::Count(); }
sl@0
  1249
sl@0
  1250
sl@0
  1251
/**
sl@0
  1252
Expand the array to accommodate a specified number of key-value pairs.
sl@0
  1253
If the set already has enough space for the specified number of elements, no
sl@0
  1254
action is taken. Any elements already in the set are retained.
sl@0
  1255
sl@0
  1256
@param	aCount	The number of key-value pairs for which space should be allocated.
sl@0
  1257
@return	KErrNone if the operation completed successfully.
sl@0
  1258
@return	KErrNoMemory if sufficient memory could not be allocated.
sl@0
  1259
*/
sl@0
  1260
	inline TInt Reserve(TInt aCount)
sl@0
  1261
		{ return RHashTableBase::Reserve(aCount); }
sl@0
  1262
sl@0
  1263
sl@0
  1264
/**
sl@0
  1265
Expand the array to accommodate a specified number of key-value pairs.
sl@0
  1266
If the set already has enough space for the specified number of elements, no
sl@0
  1267
action is taken. Any elements already in the set are retained.
sl@0
  1268
sl@0
  1269
@param	aCount	The number of key-value pairs for which space should be allocated.
sl@0
  1270
@leave	KErrNoMemory if sufficient memory could not be allocated.
sl@0
  1271
*/
sl@0
  1272
	inline void ReserveL(TInt aCount)
sl@0
  1273
		{ RHashTableBase::ReserveL(aCount); }
sl@0
  1274
sl@0
  1275
	};
sl@0
  1276
sl@0
  1277
sl@0
  1278
/**
sl@0
  1279
@publishedAll
sl@0
  1280
@released
sl@0
  1281
sl@0
  1282
A templated class which allows iteration over the elements of a RHashMap<K,V>
sl@0
  1283
class.
sl@0
  1284
sl@0
  1285
The array being iterated over may not be modified while an iteration is in progress
sl@0
  1286
or the iteration operations may malfunction or panic.
sl@0
  1287
sl@0
  1288
@see RHashMap<K,V>
sl@0
  1289
*/
sl@0
  1290
template <class K, class V>
sl@0
  1291
class THashMapIter : public THashTableIterBase
sl@0
  1292
	{
sl@0
  1293
private:
sl@0
  1294
	
sl@0
  1295
	struct SFullElement
sl@0
  1296
		{
sl@0
  1297
		TUint32 iHash;
sl@0
  1298
		K iK;
sl@0
  1299
		V iV;
sl@0
  1300
		};
sl@0
  1301
sl@0
  1302
public:
sl@0
  1303
sl@0
  1304
/**
sl@0
  1305
Construct an iterator over the specified associative array.
sl@0
  1306
The iterator starts at conceptual position one before the beginning of the list
sl@0
  1307
being iterated.
sl@0
  1308
sl@0
  1309
@param	aMap	The array to be iterated over.
sl@0
  1310
*/
sl@0
  1311
	inline THashMapIter(const RHashMap<K,V>& aMap)
sl@0
  1312
		:	THashTableIterBase(aMap)
sl@0
  1313
		{}
sl@0
  1314
sl@0
  1315
sl@0
  1316
/**
sl@0
  1317
Reset the iterator to its initial state.
sl@0
  1318
sl@0
  1319
@param	aSet	The set to be iterated over.
sl@0
  1320
*/
sl@0
  1321
	inline void Reset()
sl@0
  1322
		{ THashTableIterBase::Reset(); }
sl@0
  1323
sl@0
  1324
sl@0
  1325
/**
sl@0
  1326
Return the key corresponding to the current position of the iterator.
sl@0
  1327
sl@0
  1328
@return	A pointer to the key object corresponding to the current position of the
sl@0
  1329
		iterator.
sl@0
  1330
		NULL if the iterator has just been constructed or reset, or if it has
sl@0
  1331
		previously reached the end of an iteration.
sl@0
  1332
*/
sl@0
  1333
	inline const K* CurrentKey() const
sl@0
  1334
		{ return (const K*)THashTableIterBase::Current(_FOFF(SFullElement,iK)); }
sl@0
  1335
sl@0
  1336
sl@0
  1337
/**
sl@0
  1338
Steps the iterator to the next position and returns the corresponding key.
sl@0
  1339
sl@0
  1340
@return	A pointer to the key object corresponding to the next position of the
sl@0
  1341
		iterator.
sl@0
  1342
		NULL if the iterator has exhausted all the available key-value pairs.
sl@0
  1343
*/
sl@0
  1344
	inline const K* NextKey()
sl@0
  1345
		{ return (const K*)THashTableIterBase::Next(_FOFF(SFullElement,iK)); }
sl@0
  1346
sl@0
  1347
sl@0
  1348
/**
sl@0
  1349
Return the value corresponding to the current position of the iterator.
sl@0
  1350
sl@0
  1351
@return	A pointer to the value object corresponding to the current position of the
sl@0
  1352
		iterator.
sl@0
  1353
		NULL if the iterator has just been constructed or reset, or if it has
sl@0
  1354
		previously reached the end of an iteration.
sl@0
  1355
*/
sl@0
  1356
	inline V* CurrentValue() 
sl@0
  1357
		{ return (V*)THashTableIterBase::Current(_FOFF(SFullElement,iV)); }
sl@0
  1358
sl@0
  1359
sl@0
  1360
/**
sl@0
  1361
Steps the iterator to the next position and returns the corresponding value.
sl@0
  1362
sl@0
  1363
@return	A pointer to the value object corresponding to the next position of the
sl@0
  1364
		iterator.
sl@0
  1365
		NULL if the iterator has exhausted all the available key-value pairs.
sl@0
  1366
*/
sl@0
  1367
	inline const V* NextValue()
sl@0
  1368
		{ return (const V*)THashTableIterBase::Next(_FOFF(SFullElement,iV)); }
sl@0
  1369
sl@0
  1370
sl@0
  1371
/**
sl@0
  1372
Removes the element at the current iterator position from the hash table.
sl@0
  1373
If the iterator does not currently point to a valid element, no action is taken.
sl@0
  1374
Note that the iterator position is not altered so it no longer points to a valid
sl@0
  1375
element following the Remove(). It is illegal to call either CurrentKey() or
sl@0
  1376
CurrentValue() on the iterator after calling Remove() - the only legal
sl@0
  1377
operations are Reset(), NextKey() or NextValue().
sl@0
  1378
sl@0
  1379
*/
sl@0
  1380
	inline void RemoveCurrent()
sl@0
  1381
		{ THashTableIterBase::RemoveCurrent(); }
sl@0
  1382
	};
sl@0
  1383
sl@0
  1384
sl@0
  1385
sl@0
  1386
template <class K, class V> class TPtrHashMapIter;
sl@0
  1387
sl@0
  1388
/**
sl@0
  1389
@publishedAll
sl@0
  1390
@released
sl@0
  1391
sl@0
  1392
A templated class which implements an associative array with key type K and value type V,
sl@0
  1393
using a probe-sequence hash table. Neither the key nor value objects are copied into the
sl@0
  1394
table when they are added - only pointers are stored.
sl@0
  1395
sl@0
  1396
*/
sl@0
  1397
template <class K, class V>
sl@0
  1398
class RPtrHashMap : public RHashTableBase
sl@0
  1399
	{
sl@0
  1400
private:
sl@0
  1401
	friend class TPtrHashMapIter<K,V>;
sl@0
  1402
	
sl@0
  1403
	struct SFullElement
sl@0
  1404
		{
sl@0
  1405
		TUint32 iHash;
sl@0
  1406
		K* iK;
sl@0
  1407
		V* iV;
sl@0
  1408
		};
sl@0
  1409
public:
sl@0
  1410
sl@0
  1411
/**
sl@0
  1412
A class which allows iteration over the elements of a RPtrHashMap<K,V> class.
sl@0
  1413
sl@0
  1414
The array being iterated over may not be modified while an iteration is in progress
sl@0
  1415
or the iteration operations may malfunction or panic.
sl@0
  1416
sl@0
  1417
@see TPtrHashMapIter<K,V>
sl@0
  1418
*/
sl@0
  1419
	typedef TPtrHashMapIter<K,V> TIter;
sl@0
  1420
sl@0
  1421
/**
sl@0
  1422
Construct an associative array of key-value pairs of type (K,V) using a
sl@0
  1423
specified hash function and identity relation.
sl@0
  1424
The array initially contains no key-value pairs.
sl@0
  1425
sl@0
  1426
@param	aHash		The hash function used to hash the key objects of type K.
sl@0
  1427
@param	aIdentity	The identity relation used to determine if two key objects
sl@0
  1428
					of type K should be considered identical.
sl@0
  1429
*/
sl@0
  1430
	inline RPtrHashMap(const THashFunction32<K>& aHash, const TIdentityRelation<K>& aIdentity)
sl@0
  1431
		:	RHashTableBase(aHash, aIdentity, sizeof(SFullElement), 0)
sl@0
  1432
		{}
sl@0
  1433
sl@0
  1434
sl@0
  1435
/**
sl@0
  1436
Construct an associative array of key-value pairs of type (K,V) using a
sl@0
  1437
default hash function and identity relation.
sl@0
  1438
The array initially contains no key-value pairs.
sl@0
  1439
*/
sl@0
  1440
	inline RPtrHashMap()
sl@0
  1441
		:	RHashTableBase(Defaults<K,EDefaultSpecifier_Normal>::Hash(), Defaults<K,EDefaultSpecifier_Normal>::Id(), sizeof(SFullElement), 0)
sl@0
  1442
		{}
sl@0
  1443
sl@0
  1444
sl@0
  1445
/**
sl@0
  1446
Free all memory used by this array.
sl@0
  1447
Returns the array to the same state it had following construction.
sl@0
  1448
*/
sl@0
  1449
	inline void Close()
sl@0
  1450
		{ RHashTableBase::Close(); }
sl@0
  1451
sl@0
  1452
sl@0
  1453
/**
sl@0
  1454
Look up a specified key in the associative array and return a pointer to the
sl@0
  1455
corresponding value.
sl@0
  1456
sl@0
  1457
@param	aKey	The key object of type K to look up.
sl@0
  1458
@return			A pointer to corresponding value object if the specified key
sl@0
  1459
				object was found. The value object may not be modified via
sl@0
  1460
				this pointer.
sl@0
  1461
				NULL if the specified key object was not found.
sl@0
  1462
*/
sl@0
  1463
	inline const V* Find(const K& aKey) const
sl@0
  1464
		{ return (const V*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iV)); }
sl@0
  1465
sl@0
  1466
sl@0
  1467
/**
sl@0
  1468
Look up a specified key in the associative array and return a pointer to the
sl@0
  1469
corresponding value.
sl@0
  1470
sl@0
  1471
@param	aKey	The key object of type K to look up.
sl@0
  1472
@return			A reference to corresponding value object if the specified key
sl@0
  1473
				object was found. The value object may not be modified via
sl@0
  1474
				this reference.
sl@0
  1475
@leave	KErrNotFound if the specified key object was not found.
sl@0
  1476
*/
sl@0
  1477
	inline const V& FindL(const K& aKey) const
sl@0
  1478
		{ return *(const V*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iV)); }
sl@0
  1479
sl@0
  1480
sl@0
  1481
/**
sl@0
  1482
Look up a specified key in the associative array and return a pointer to the
sl@0
  1483
corresponding value.
sl@0
  1484
sl@0
  1485
@param	aKey	The key object of type K to look up.
sl@0
  1486
@return			A pointer to corresponding value object if the specified key
sl@0
  1487
				object was found. The value object may be modified via
sl@0
  1488
				this pointer.
sl@0
  1489
				NULL if the specified key object was not found.
sl@0
  1490
*/
sl@0
  1491
	inline V* Find(const K& aKey)
sl@0
  1492
		{ return (V*)RHashTableBase::Find(&aKey, -_FOFF(SFullElement,iV)); }
sl@0
  1493
sl@0
  1494
sl@0
  1495
/**
sl@0
  1496
Look up a specified key in the associative array and return a pointer to the
sl@0
  1497
corresponding value.
sl@0
  1498
sl@0
  1499
@param	aKey	The key object of type K to look up.
sl@0
  1500
@return			A reference to corresponding value object if the specified key
sl@0
  1501
				object was found. The value object may be modified via
sl@0
  1502
				this reference.
sl@0
  1503
@leave	KErrNotFound if the specified key object was not found.
sl@0
  1504
*/
sl@0
  1505
	inline V& FindL(const K& aKey)
sl@0
  1506
		{ return *(V*)RHashTableBase::FindL(&aKey, -_FOFF(SFullElement,iV)); }
sl@0
  1507
sl@0
  1508
sl@0
  1509
/**
sl@0
  1510
Insert a key-value pair into the array.
sl@0
  1511
sl@0
  1512
If the specified key object is not found in the array, a pointer to the
sl@0
  1513
key object along with a pointer to the value object are added to the array
sl@0
  1514
and KErrNone is returned.
sl@0
  1515
If the specified key object is found in the array, the existing pointers
sl@0
  1516
to both the key and value objects are replaced by the provided pointers
sl@0
  1517
and KErrNone is returned.
sl@0
  1518
In both cases only pointers are stored in the array - the objects themselves
sl@0
  1519
are not copied.
sl@0
  1520
sl@0
  1521
@param	aKey	A pointer to the key object of type K to add to the array.
sl@0
  1522
@param	aValue	A pointer to the value object of type V to associate with aKey.
sl@0
  1523
@return			KErrNone if the key-value pair was added successfully.
sl@0
  1524
				KErrNoMemory if memory could not be allocated to store
sl@0
  1525
					the pointers aKey and aValue.
sl@0
  1526
*/
sl@0
  1527
	inline TInt Insert(const K* aKey, const V* aValue)
sl@0
  1528
		{ return RHashTableBase::PtrInsert(aKey, aValue); }
sl@0
  1529
sl@0
  1530
sl@0
  1531
/**
sl@0
  1532
Insert a key-value pair into the array.
sl@0
  1533
sl@0
  1534
If the specified key object is not found in the array, a pointer to the
sl@0
  1535
key object along with a pointer to the value object are added to the array
sl@0
  1536
and KErrNone is returned.
sl@0
  1537
If the specified key object is found in the array, the existing pointers
sl@0
  1538
to both the key and value objects are replaced by the provided pointers
sl@0
  1539
and KErrNone is returned.
sl@0
  1540
In both cases only pointers are stored in the array - the objects themselves
sl@0
  1541
are not copied.
sl@0
  1542
sl@0
  1543
@param	aKey	A pointer to the key object of type K to add to the array.
sl@0
  1544
@param	aValue	A pointer to the value object of type V to associate with aKey.
sl@0
  1545
@leave	KErrNoMemory if memory could not be allocated to store the pointers aKey and aValue.
sl@0
  1546
*/
sl@0
  1547
	inline void InsertL(const K* aKey, const V* aValue)
sl@0
  1548
		{ RHashTableBase::PtrInsertL(aKey, aValue); }
sl@0
  1549
sl@0
  1550
sl@0
  1551
/**
sl@0
  1552
Remove a key-value pair from the array.
sl@0
  1553
sl@0
  1554
@param	aKey	A pointer to the key to be removed.
sl@0
  1555
@return			KErrNone if the pointers to the key object and corresponding
sl@0
  1556
				value object were removed successfully.
sl@0
  1557
				KErrNotFound if the key object was not present in the array.
sl@0
  1558
*/
sl@0
  1559
	inline TInt Remove(const K* aKey)
sl@0
  1560
		{ return RHashTableBase::Remove(aKey); }
sl@0
  1561
sl@0
  1562
sl@0
  1563
/**
sl@0
  1564
Query the number of key-value pairs in the array.
sl@0
  1565
sl@0
  1566
@return	The number of key-value pairs currently in the array.
sl@0
  1567
*/
sl@0
  1568
	inline TInt Count() const
sl@0
  1569
		{ return RHashTableBase::Count(); }
sl@0
  1570
sl@0
  1571
sl@0
  1572
/**
sl@0
  1573
Expand the array to accommodate a specified number of key-value pairs.
sl@0
  1574
If the set already has enough space for the specified number of elements, no
sl@0
  1575
action is taken. Any elements already in the set are retained.
sl@0
  1576
sl@0
  1577
@param	aCount	The number of key-value pairs for which space should be allocated.
sl@0
  1578
@return	KErrNone if the operation completed successfully.
sl@0
  1579
@return	KErrNoMemory if sufficient memory could not be allocated.
sl@0
  1580
*/
sl@0
  1581
	inline TInt Reserve(TInt aCount)
sl@0
  1582
		{ return RHashTableBase::Reserve(aCount); }
sl@0
  1583
sl@0
  1584
sl@0
  1585
/**
sl@0
  1586
Expand the array to accommodate a specified number of key-value pairs.
sl@0
  1587
If the set already has enough space for the specified number of elements, no
sl@0
  1588
action is taken. Any elements already in the set are retained.
sl@0
  1589
sl@0
  1590
@param	aCount	The number of key-value pairs for which space should be allocated.
sl@0
  1591
@leave	KErrNoMemory if sufficient memory could not be allocated.
sl@0
  1592
*/
sl@0
  1593
	inline void ReserveL(TInt aCount)
sl@0
  1594
		{ RHashTableBase::ReserveL(aCount); }
sl@0
  1595
sl@0
  1596
sl@0
  1597
	void ResetAndDestroy();
sl@0
  1598
	};
sl@0
  1599
sl@0
  1600
sl@0
  1601
/**
sl@0
  1602
@publishedAll
sl@0
  1603
@released
sl@0
  1604
sl@0
  1605
A templated class which allows iteration over the elements of a RPtrHashMap<K,V>
sl@0
  1606
class.
sl@0
  1607
sl@0
  1608
The array being iterated over may not be modified while an iteration is in progress
sl@0
  1609
or the iteration operations may malfunction or panic.
sl@0
  1610
sl@0
  1611
@see RPtrHashMap<K,V>
sl@0
  1612
*/
sl@0
  1613
template <class K, class V>
sl@0
  1614
class TPtrHashMapIter : public THashTableIterBase
sl@0
  1615
	{
sl@0
  1616
private:
sl@0
  1617
	
sl@0
  1618
	struct SFullElement
sl@0
  1619
		{
sl@0
  1620
		TUint32 iHash;
sl@0
  1621
		K* iK;
sl@0
  1622
		V* iV;
sl@0
  1623
		};
sl@0
  1624
public:
sl@0
  1625
sl@0
  1626
/**
sl@0
  1627
Construct an iterator over the specified associative array.
sl@0
  1628
The iterator starts at conceptual position one before the beginning of the list
sl@0
  1629
being iterated.
sl@0
  1630
sl@0
  1631
@param	aMap	The array to be iterated over.
sl@0
  1632
*/
sl@0
  1633
	inline TPtrHashMapIter(const RPtrHashMap<K,V>& aMap)
sl@0
  1634
		:	THashTableIterBase(aMap)
sl@0
  1635
		{}
sl@0
  1636
sl@0
  1637
sl@0
  1638
/**
sl@0
  1639
Reset the iterator to its initial state.
sl@0
  1640
sl@0
  1641
@param	aSet	The set to be iterated over.
sl@0
  1642
*/
sl@0
  1643
	inline void Reset()
sl@0
  1644
		{ THashTableIterBase::Reset(); }
sl@0
  1645
sl@0
  1646
sl@0
  1647
/**
sl@0
  1648
Return the key corresponding to the current position of the iterator.
sl@0
  1649
sl@0
  1650
@return	A pointer to the key object corresponding to the current position of the
sl@0
  1651
		iterator.
sl@0
  1652
		NULL if the iterator has just been constructed or reset, or if it has
sl@0
  1653
		previously reached the end of an iteration.
sl@0
  1654
*/
sl@0
  1655
	inline const K* CurrentKey() const
sl@0
  1656
		{ return (const K*)THashTableIterBase::Current(-_FOFF(SFullElement,iK)); }
sl@0
  1657
sl@0
  1658
sl@0
  1659
/**
sl@0
  1660
Steps the iterator to the next position and returns the corresponding key.
sl@0
  1661
sl@0
  1662
@return	A pointer to the key object corresponding to the next position of the
sl@0
  1663
		iterator.
sl@0
  1664
		NULL if the iterator has exhausted all the available key-value pairs.
sl@0
  1665
*/
sl@0
  1666
	inline const K* NextKey()
sl@0
  1667
		{ return (const K*)THashTableIterBase::Next(-_FOFF(SFullElement,iK)); }
sl@0
  1668
sl@0
  1669
sl@0
  1670
/**
sl@0
  1671
Return the value corresponding to the current position of the iterator.
sl@0
  1672
sl@0
  1673
@return	A pointer to the value object corresponding to the current position of the
sl@0
  1674
		iterator.
sl@0
  1675
		NULL if the iterator has just been constructed or reset, or if it has
sl@0
  1676
		previously reached the end of an iteration.
sl@0
  1677
*/
sl@0
  1678
	inline const V* CurrentValue() const
sl@0
  1679
		{ return (const V*)THashTableIterBase::Current(-_FOFF(SFullElement,iV)); }
sl@0
  1680
sl@0
  1681
sl@0
  1682
/**
sl@0
  1683
Steps the iterator to the next position and returns the corresponding value.
sl@0
  1684
sl@0
  1685
@return	A pointer to the value object corresponding to the next position of the
sl@0
  1686
		iterator.
sl@0
  1687
		NULL if the iterator has exhausted all the available key-value pairs.
sl@0
  1688
*/
sl@0
  1689
	inline const V* NextValue()
sl@0
  1690
		{ return (const V*)THashTableIterBase::Next(-_FOFF(SFullElement,iV)); }
sl@0
  1691
sl@0
  1692
		
sl@0
  1693
/**
sl@0
  1694
Removes the element at the current iterator position from the hash table.
sl@0
  1695
If the iterator does not currently point to a valid element, no action is taken.
sl@0
  1696
Note that the iterator position is not altered so it no longer points to a valid
sl@0
  1697
element following the Remove(). It is illegal to call either CurrentKey() or
sl@0
  1698
CurrentValue() on the iterator after calling Remove() - the only legal
sl@0
  1699
operations are Reset(), NextKey() or NextValue().
sl@0
  1700
sl@0
  1701
*/
sl@0
  1702
	inline void RemoveCurrent()
sl@0
  1703
		{ THashTableIterBase::RemoveCurrent(); }
sl@0
  1704
	};
sl@0
  1705
sl@0
  1706
sl@0
  1707
sl@0
  1708
/**
sl@0
  1709
Deletes all the objects of type T to which pointers are stored in this set.
sl@0
  1710
Then frees all the memory used by the set and returns the set to the same state
sl@0
  1711
as immediately following construction.
sl@0
  1712
*/
sl@0
  1713
template <class T>
sl@0
  1714
void RPtrHashSet<T>::ResetAndDestroy()
sl@0
  1715
	{
sl@0
  1716
	TPtrHashSetIter<T> iter(*this);
sl@0
  1717
	T* p;
sl@0
  1718
	do	{
sl@0
  1719
		p = (T*)iter.Next();
sl@0
  1720
		delete p;
sl@0
  1721
		} while(p);
sl@0
  1722
	Close();
sl@0
  1723
	}
sl@0
  1724
sl@0
  1725
sl@0
  1726
/**
sl@0
  1727
Deletes all the key objects of type K and corresponding value objects of type V
sl@0
  1728
to which pointers are stored in this array.
sl@0
  1729
Then frees all the memory used by the array and returns the array to the same
sl@0
  1730
state as immediately following construction.
sl@0
  1731
*/
sl@0
  1732
template <class K, class V>
sl@0
  1733
void RPtrHashMap<K,V>::ResetAndDestroy()
sl@0
  1734
	{
sl@0
  1735
	TPtrHashMapIter<K,V> iter(*this);
sl@0
  1736
	K* p;
sl@0
  1737
	V* q;
sl@0
  1738
	do	{
sl@0
  1739
		p = (K*)iter.NextKey();
sl@0
  1740
		q = (V*)iter.CurrentValue();
sl@0
  1741
		delete p;
sl@0
  1742
		delete q;
sl@0
  1743
		} while(p);
sl@0
  1744
	Close();
sl@0
  1745
	}
sl@0
  1746
sl@0
  1747
sl@0
  1748
#endif