graphicsdeviceinterface/gdi/inc/hextree.h
author hgs
Tue, 22 Jun 2010 15:21:29 +0300
changeset 103 2717213c588a
permissions -rw-r--r--
201024
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
103
hgs
parents:
diff changeset
     1
// Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
hgs
parents:
diff changeset
     2
// All rights reserved.
hgs
parents:
diff changeset
     3
// This component and the accompanying materials are made available
hgs
parents:
diff changeset
     4
// under the terms of "Eclipse Public License v1.0"
hgs
parents:
diff changeset
     5
// which accompanies this distribution, and is available
hgs
parents:
diff changeset
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
hgs
parents:
diff changeset
     7
//
hgs
parents:
diff changeset
     8
// Initial Contributors:
hgs
parents:
diff changeset
     9
// Nokia Corporation - initial contribution.
hgs
parents:
diff changeset
    10
//
hgs
parents:
diff changeset
    11
// Contributors:
hgs
parents:
diff changeset
    12
//
hgs
parents:
diff changeset
    13
// Description:
hgs
parents:
diff changeset
    14
// Hexadecimal trees - declaration
hgs
parents:
diff changeset
    15
//
hgs
parents:
diff changeset
    16
hgs
parents:
diff changeset
    17
#ifndef HEXTREE_H
hgs
parents:
diff changeset
    18
#define HEXTREE_H
hgs
parents:
diff changeset
    19
hgs
parents:
diff changeset
    20
#include <e32std.h>
hgs
parents:
diff changeset
    21
hgs
parents:
diff changeset
    22
/**
hgs
parents:
diff changeset
    23
Base class that provides the implementation for RHexTree, which is just a thin
hgs
parents:
diff changeset
    24
template.
hgs
parents:
diff changeset
    25
hgs
parents:
diff changeset
    26
An instance of this class can have up to eight 16-way prefix trees, with heights
hgs
parents:
diff changeset
    27
from 1 to 8. All the values are stored in the leaves. To find a value from a
hgs
parents:
diff changeset
    28
32-bit key, first the key is decomposed into 8 hexadecimal digits and then the
hgs
parents:
diff changeset
    29
prefix tree with height matching the number of digits in the key (ignoring zeros
hgs
parents:
diff changeset
    30
to the left) is traversed using the sequence of digits in the key as the
hgs
parents:
diff changeset
    31
indexing string. Offsets are internally used instead of pointers to allow
hgs
parents:
diff changeset
    32
instances to be placed in a heap shared between several processes.
hgs
parents:
diff changeset
    33
*/
hgs
parents:
diff changeset
    34
class RHexTreeBase
hgs
parents:
diff changeset
    35
    {
hgs
parents:
diff changeset
    36
public:
hgs
parents:
diff changeset
    37
    IMPORT_C void ResetAndDestroy();
hgs
parents:
diff changeset
    38
protected:
hgs
parents:
diff changeset
    39
    IMPORT_C RHexTreeBase(RHeap* aHeap);
hgs
parents:
diff changeset
    40
    IMPORT_C TInt SetAt(TUint aKey, TAny* aValue);
hgs
parents:
diff changeset
    41
    IMPORT_C TAny* At(TUint aKey) const;
hgs
parents:
diff changeset
    42
private:
hgs
parents:
diff changeset
    43
    TInt SetAt(TUint aKey, TAny* aLeaf, TInt aHeight);
hgs
parents:
diff changeset
    44
    TInt SetAt(TUint aKey, TAny* aLeaf, TInt aHeight, TAny* aNode, TInt aLevel);
hgs
parents:
diff changeset
    45
    TAny* At(TUint aKey, TInt aHeight) const;
hgs
parents:
diff changeset
    46
    void ResetAndDestroy(TInt aHeight, TAny* aNode, TInt aLevel);
hgs
parents:
diff changeset
    47
private:
hgs
parents:
diff changeset
    48
    enum { EMaxNumHexDigits = 8 };
hgs
parents:
diff changeset
    49
private:
hgs
parents:
diff changeset
    50
    RHeap* iHeap;
hgs
parents:
diff changeset
    51
    TInt iRootOffsets[EMaxNumHexDigits];
hgs
parents:
diff changeset
    52
    };
hgs
parents:
diff changeset
    53
hgs
parents:
diff changeset
    54
/**
hgs
parents:
diff changeset
    55
An associative array implementation optimised for the case where the keys are
hgs
parents:
diff changeset
    56
32-bit codes with spatial locality of reference. The values can be of any
hgs
parents:
diff changeset
    57
self-contained data type (that is, without destructor or clean-up functions).
hgs
parents:
diff changeset
    58
It allows multiple-readers, single-writer concurrent access from different
hgs
parents:
diff changeset
    59
processes in an SMP-safe manner without locking, excluding deletion of
hgs
parents:
diff changeset
    60
individual key-value pairs.
hgs
parents:
diff changeset
    61
*/
hgs
parents:
diff changeset
    62
template<class T>
hgs
parents:
diff changeset
    63
class RHexTree : public RHexTreeBase
hgs
parents:
diff changeset
    64
    {
hgs
parents:
diff changeset
    65
public:
hgs
parents:
diff changeset
    66
    inline RHexTree(RHeap* aHeap);
hgs
parents:
diff changeset
    67
    inline TInt SetAt(TUint aKey, T* aValue);
hgs
parents:
diff changeset
    68
    inline const T* At(TUint aKey) const;
hgs
parents:
diff changeset
    69
    inline T* At(TUint aKey);
hgs
parents:
diff changeset
    70
    };
hgs
parents:
diff changeset
    71
hgs
parents:
diff changeset
    72
#include <hextree.inl>
hgs
parents:
diff changeset
    73
hgs
parents:
diff changeset
    74
#endif // HEXTREE_H