sl@0: // Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies). sl@0: // All rights reserved. sl@0: // This component and the accompanying materials are made available sl@0: // under the terms of "Eclipse Public License v1.0" sl@0: // which accompanies this distribution, and is available sl@0: // at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: // sl@0: // Initial Contributors: sl@0: // Nokia Corporation - initial contribution. sl@0: // sl@0: // Contributors: sl@0: // sl@0: // Description: sl@0: // Hexadecimal trees - declaration sl@0: // sl@0: sl@0: #ifndef HEXTREE_H sl@0: #define HEXTREE_H sl@0: sl@0: #include sl@0: sl@0: /** sl@0: Base class that provides the implementation for RHexTree, which is just a thin sl@0: template. sl@0: sl@0: An instance of this class can have up to eight 16-way prefix trees, with heights sl@0: from 1 to 8. All the values are stored in the leaves. To find a value from a sl@0: 32-bit key, first the key is decomposed into 8 hexadecimal digits and then the sl@0: prefix tree with height matching the number of digits in the key (ignoring zeros sl@0: to the left) is traversed using the sequence of digits in the key as the sl@0: indexing string. Offsets are internally used instead of pointers to allow sl@0: instances to be placed in a heap shared between several processes. sl@0: */ sl@0: class RHexTreeBase sl@0: { sl@0: public: sl@0: IMPORT_C void ResetAndDestroy(); sl@0: protected: sl@0: IMPORT_C RHexTreeBase(RHeap* aHeap); sl@0: IMPORT_C TInt SetAt(TUint aKey, TAny* aValue); sl@0: IMPORT_C TAny* At(TUint aKey) const; sl@0: private: sl@0: TInt SetAt(TUint aKey, TAny* aLeaf, TInt aHeight); sl@0: TInt SetAt(TUint aKey, TAny* aLeaf, TInt aHeight, TAny* aNode, TInt aLevel); sl@0: TAny* At(TUint aKey, TInt aHeight) const; sl@0: void ResetAndDestroy(TInt aHeight, TAny* aNode, TInt aLevel); sl@0: private: sl@0: enum { EMaxNumHexDigits = 8 }; sl@0: private: sl@0: RHeap* iHeap; sl@0: TInt iRootOffsets[EMaxNumHexDigits]; sl@0: }; sl@0: sl@0: /** sl@0: An associative array implementation optimised for the case where the keys are sl@0: 32-bit codes with spatial locality of reference. The values can be of any sl@0: self-contained data type (that is, without destructor or clean-up functions). sl@0: It allows multiple-readers, single-writer concurrent access from different sl@0: processes in an SMP-safe manner without locking, excluding deletion of sl@0: individual key-value pairs. sl@0: */ sl@0: template sl@0: class RHexTree : public RHexTreeBase sl@0: { sl@0: public: sl@0: inline RHexTree(RHeap* aHeap); sl@0: inline TInt SetAt(TUint aKey, T* aValue); sl@0: inline const T* At(TUint aKey) const; sl@0: inline T* At(TUint aKey); sl@0: }; sl@0: sl@0: #include sl@0: sl@0: #endif // HEXTREE_H