Classes | Public Types | Public Member Functions | Protected Types

FbxMap< Key, Type, Compare, Allocator > Class Template Reference

Search for all occurrences

Detailed Description

template<typename Key, typename Type, typename Compare = FbxLessCompare<Key>, typename Allocator = FbxBaseAllocator>
class FbxMap< Key, Type, Compare, Allocator >

This class implements an efficient map based on key comparison, which stores key-value pairs.

It executes insertion, deletion and query operations in O(log(n)) time.

Definition at line 68 of file fbxmap.h.

#include <fbxmap.h>

List of all members.

Classes

class  KeyValuePair
 This class defines the key-value pairs used by the map. More...

Public Types

typedef Type ValueType
typedef Key KeyType
typedef StorageType::RecordType RecordType
typedef StorageType::IteratorType Iterator
typedef
StorageType::ConstIteratorType 
ConstIterator

Public Member Functions

void Reserve (unsigned int pRecordCount)
 Preallocate memory.
int GetSize () const
 Retrieve the number of key-value pairs it holds.
FbxPair< RecordType *, bool > Insert (const KeyType &pKey, const ValueType &pValue)
 Insert a key-value pair.
int Remove (const KeyType &pKey)
 Delete a key-value pair.
void Clear ()
 Clear the map.
bool Empty () const
 Query whether the map is empty.
Iterator Begin ()
 Retrieve the begin iterator of the map.
Iterator End ()
 Retrieve the end iterator of the map.
ConstIterator Begin () const
 Retrieve the begin iterator of the map.
ConstIterator End () const
 Retrieve the end iterator of the map.
const RecordTypeFind (const KeyType &pKey) const
 Query a key.
RecordTypeFind (const KeyType &pKey)
 Query a key.
const RecordTypeUpperBound (const KeyType &pKey) const
 Find the key-value pair with the smallest key greater than a specified key.
RecordTypeUpperBound (const KeyType &pKey)
 Find the key-value pair with the smallest key greater than a specified key.
ValueTypeoperator[] (const KeyType &pKey)
 Retrieve the reference of the value in the key-value pairs in map.
const RecordTypeMinimum () const
 Retrieve the key-value pair which is the minimum key in map.
RecordTypeMinimum ()
 Retrieve the key-value pair which is the minimum key in map.
const RecordTypeMaximum () const
 Retrieve the key-value pair which is the maximum key in map.
RecordTypeMaximum ()
 Retrieve the key-value pair which is the maximum key in map.
 FbxMap ()
 FbxMap (const FbxMap &pMap)
 ~FbxMap ()

Protected Types

typedef FbxRedBlackTree
< KeyValuePair, Compare,
Allocator > 
StorageType
 Declaration of the storage type used by the map.

Member Typedef Documentation

typedef FbxRedBlackTree<KeyValuePair, Compare, Allocator> StorageType [protected]

Declaration of the storage type used by the map.

Definition at line 93 of file fbxmap.h.

typedef Type ValueType

Definition at line 96 of file fbxmap.h.

typedef Key KeyType

Definition at line 97 of file fbxmap.h.

typedef StorageType::RecordType RecordType

Definition at line 98 of file fbxmap.h.

Definition at line 99 of file fbxmap.h.

Definition at line 100 of file fbxmap.h.


Constructor & Destructor Documentation

FbxMap ( ) [inline]

Definition at line 244 of file fbxmap.h.

{}
FbxMap ( const FbxMap< Key, Type, Compare, Allocator > &  pMap) [inline]

Definition at line 245 of file fbxmap.h.

: mTree(pMap.mTree){}
~FbxMap ( ) [inline]

Definition at line 246 of file fbxmap.h.

{ Clear(); }

Member Function Documentation

void Reserve ( unsigned int  pRecordCount) [inline]

Preallocate memory.

Parameters:
pRecordCountThe number of elements.

Definition at line 104 of file fbxmap.h.

    {
        mTree.Reserve(pRecordCount);
    }
int GetSize ( ) const [inline]

Retrieve the number of key-value pairs it holds.

Definition at line 110 of file fbxmap.h.

    {
        return mTree.GetSize();
    }
FbxPair<RecordType*, bool> Insert ( const KeyType pKey,
const ValueType pValue 
) [inline]

Insert a key-value pair.

Parameters:
pKeyThe key.
pValueThe value.
Returns:
If the key is already present in the map, returns the existing pair and false; else returns the pointer to the new key-value and true.

Definition at line 119 of file fbxmap.h.

    {
        return mTree.Insert(KeyValuePair(pKey, pValue));
    }
int Remove ( const KeyType pKey) [inline]

Delete a key-value pair.

Parameters:
pKeyThe key.
Returns:
true if success, false if key is not found.

Definition at line 127 of file fbxmap.h.

    {
        return mTree.Remove(pKey);
    }
void Clear ( ) [inline]

Clear the map.

Definition at line 133 of file fbxmap.h.

    {
        mTree.Clear();
    }
bool Empty ( ) const [inline]

Query whether the map is empty.

Definition at line 139 of file fbxmap.h.

    {
        return mTree.Empty();
    }
Iterator Begin ( ) [inline]

Retrieve the begin iterator of the map.

Definition at line 145 of file fbxmap.h.

    {
        return Iterator(Minimum());
    }
Iterator End ( ) [inline]

Retrieve the end iterator of the map.

Definition at line 151 of file fbxmap.h.

    {
        return Iterator();
    }
ConstIterator Begin ( ) const [inline]

Retrieve the begin iterator of the map.

Definition at line 157 of file fbxmap.h.

    {
        return ConstIterator(Minimum());
    }
ConstIterator End ( ) const [inline]

Retrieve the end iterator of the map.

Definition at line 163 of file fbxmap.h.

    {
        return ConstIterator();
    }
const RecordType* Find ( const KeyType pKey) const [inline]

Query a key.

Parameters:
pKeyThe key.
Returns:
A key-value pair if success, NULL if the key is not found.

Definition at line 171 of file fbxmap.h.

    {
        return mTree.Find(pKey);
    }
RecordType* Find ( const KeyType pKey) [inline]

Query a key.

Parameters:
pKeyThe key.
Returns:
A key-value pair if success, NULL if it's not found.

Definition at line 179 of file fbxmap.h.

    {
        return mTree.Find(pKey);
    }
const RecordType* UpperBound ( const KeyType pKey) const [inline]

Find the key-value pair with the smallest key greater than a specified key.

Parameters:
pKeyThe key.
Returns:
The found key-value pair.

Definition at line 187 of file fbxmap.h.

    {
        return mTree.UpperBound(pKey);
    }
RecordType* UpperBound ( const KeyType pKey) [inline]

Find the key-value pair with the smallest key greater than a specified key.

Parameters:
pKeyThe key.
Returns:
The found key-value pair.

Definition at line 195 of file fbxmap.h.

    {
        return mTree.UpperBound(pKey);
    }
ValueType& operator[] ( const KeyType pKey) [inline]

Retrieve the reference of the value in the key-value pairs in map.

Parameters:
pKeyThe key.
Returns:
The reference of the value.
Remarks:
If the key is not found, a new key-value pair will be inserted.

Definition at line 204 of file fbxmap.h.

    {
        RecordType* lRecord = Find(pKey);

        if( !lRecord )
        {
            lRecord = Insert(pKey, ValueType()).mFirst;
        }

        return lRecord->GetValue();
    }
const RecordType* Minimum ( ) const [inline]

Retrieve the key-value pair which is the minimum key in map.

Definition at line 217 of file fbxmap.h.

    {
        return mTree.Minimum();
    }
RecordType* Minimum ( ) [inline]

Retrieve the key-value pair which is the minimum key in map.

Definition at line 223 of file fbxmap.h.

    {
        return mTree.Minimum();
    }
const RecordType* Maximum ( ) const [inline]

Retrieve the key-value pair which is the maximum key in map.

Definition at line 229 of file fbxmap.h.

    {
        return mTree.Maximum();
    }
RecordType* Maximum ( ) [inline]

Retrieve the key-value pair which is the maximum key in map.

Definition at line 235 of file fbxmap.h.

    {
        return mTree.Maximum();
    }

The documentation for this class was generated from the following file: