os/textandloc/fontservices/textbase/inc/hextree.h
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2010 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 "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
// Hexadecimal trees - declaration
sl@0
    15
//
sl@0
    16
sl@0
    17
#ifndef HEXTREE_H
sl@0
    18
#define HEXTREE_H
sl@0
    19
sl@0
    20
#include <e32std.h>
sl@0
    21
sl@0
    22
/**
sl@0
    23
Base class that provides the implementation for RHexTree, which is just a thin
sl@0
    24
template.
sl@0
    25
sl@0
    26
An instance of this class can have up to eight 16-way prefix trees, with heights
sl@0
    27
from 1 to 8. All the values are stored in the leaves. To find a value from a
sl@0
    28
32-bit key, first the key is decomposed into 8 hexadecimal digits and then the
sl@0
    29
prefix tree with height matching the number of digits in the key (ignoring zeros
sl@0
    30
to the left) is traversed using the sequence of digits in the key as the
sl@0
    31
indexing string. Offsets are internally used instead of pointers to allow
sl@0
    32
instances to be placed in a heap shared between several processes.
sl@0
    33
*/
sl@0
    34
class RHexTreeBase
sl@0
    35
    {
sl@0
    36
public:
sl@0
    37
    IMPORT_C void ResetAndDestroy();
sl@0
    38
protected:
sl@0
    39
    IMPORT_C RHexTreeBase(RHeap* aHeap);
sl@0
    40
    IMPORT_C TInt SetAt(TUint aKey, TAny* aValue);
sl@0
    41
    IMPORT_C TAny* At(TUint aKey) const;
sl@0
    42
private:
sl@0
    43
    TInt SetAt(TUint aKey, TAny* aLeaf, TInt aHeight);
sl@0
    44
    TInt SetAt(TUint aKey, TAny* aLeaf, TInt aHeight, TAny* aNode, TInt aLevel);
sl@0
    45
    TAny* At(TUint aKey, TInt aHeight) const;
sl@0
    46
    void ResetAndDestroy(TInt aHeight, TAny* aNode, TInt aLevel);
sl@0
    47
private:
sl@0
    48
    enum { EMaxNumHexDigits = 8 };
sl@0
    49
private:
sl@0
    50
    RHeap* iHeap;
sl@0
    51
    TInt iRootOffsets[EMaxNumHexDigits];
sl@0
    52
    };
sl@0
    53
sl@0
    54
/**
sl@0
    55
An associative array implementation optimised for the case where the keys are
sl@0
    56
32-bit codes with spatial locality of reference. The values can be of any
sl@0
    57
self-contained data type (that is, without destructor or clean-up functions).
sl@0
    58
It allows multiple-readers, single-writer concurrent access from different
sl@0
    59
processes in an SMP-safe manner without locking, excluding deletion of
sl@0
    60
individual key-value pairs.
sl@0
    61
*/
sl@0
    62
template<class T>
sl@0
    63
class RHexTree : public RHexTreeBase
sl@0
    64
    {
sl@0
    65
public:
sl@0
    66
    inline RHexTree(RHeap* aHeap);
sl@0
    67
    inline TInt SetAt(TUint aKey, T* aValue);
sl@0
    68
    inline const T* At(TUint aKey) const;
sl@0
    69
    inline T* At(TUint aKey);
sl@0
    70
    };
sl@0
    71
sl@0
    72
#include <hextree.inl>
sl@0
    73
sl@0
    74
#endif // HEXTREE_H