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

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

#include <fbxmap.h>

Class 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.

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

Protected Types

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

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.

typedef StorageType::IteratorType Iterator

Definition at line 99 of file fbxmap.h.

typedef StorageType::ConstIteratorType ConstIterator

Definition at line 100 of file fbxmap.h.

Member Function Documentation

void Reserve ( unsigned int  pRecordCount)
inline

Preallocate memory.

Parameters
pRecordCountThe number of elements.

Definition at line 104 of file fbxmap.h.

105  {
106  mTree.Reserve(pRecordCount);
107  }
int GetSize ( ) const
inline

Retrieve the number of key-value pairs it holds.

Definition at line 110 of file fbxmap.h.

111  {
112  return mTree.GetSize();
113  }
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.

120  {
121  return mTree.Insert(KeyValuePair(pKey, pValue));
122  }
bool 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.

128  {
129  return mTree.Remove(pKey);
130  }
void Clear ( )
inline

Clear the map.

Definition at line 133 of file fbxmap.h.

134  {
135  mTree.Clear();
136  }
bool Empty ( ) const
inline

Query whether the map is empty.

Definition at line 139 of file fbxmap.h.

140  {
141  return mTree.Empty();
142  }
Iterator Begin ( )
inline

Retrieve the begin iterator of the map.

Definition at line 145 of file fbxmap.h.

146  {
147  return Iterator(Minimum());
148  }
StorageType::IteratorType Iterator
Definition: fbxmap.h:99
const RecordType * Minimum() const
Retrieve the key-value pair which is the minimum key in map.
Definition: fbxmap.h:217
Iterator End ( )
inline

Retrieve the end iterator of the map.

Definition at line 151 of file fbxmap.h.

152  {
153  return Iterator();
154  }
StorageType::IteratorType Iterator
Definition: fbxmap.h:99
ConstIterator Begin ( ) const
inline

Retrieve the begin iterator of the map.

Definition at line 157 of file fbxmap.h.

158  {
159  return ConstIterator(Minimum());
160  }
StorageType::ConstIteratorType ConstIterator
Definition: fbxmap.h:100
const RecordType * Minimum() const
Retrieve the key-value pair which is the minimum key in map.
Definition: fbxmap.h:217
ConstIterator End ( ) const
inline

Retrieve the end iterator of the map.

Definition at line 163 of file fbxmap.h.

164  {
165  return ConstIterator();
166  }
StorageType::ConstIteratorType ConstIterator
Definition: fbxmap.h:100
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.

172  {
173  return mTree.Find(pKey);
174  }
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.

180  {
181  return mTree.Find(pKey);
182  }
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.

188  {
189  return mTree.UpperBound(pKey);
190  }
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.

196  {
197  return mTree.UpperBound(pKey);
198  }
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.

205  {
206  RecordType* lRecord = Find(pKey);
207 
208  if( !lRecord )
209  {
210  lRecord = Insert(pKey, ValueType()).mFirst;
211  }
212 
213  return lRecord->GetValue();
214  }
Type ValueType
Definition: fbxmap.h:96
const RecordType * Find(const KeyType &pKey) const
Query a key.
Definition: fbxmap.h:171
FbxPair< RecordType *, bool > Insert(const KeyType &pKey, const ValueType &pValue)
Insert a key-value pair.
Definition: fbxmap.h:119
StorageType::RecordType RecordType
Definition: fbxmap.h:98
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.

218  {
219  return mTree.Minimum();
220  }
RecordType* Minimum ( )
inline

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

Definition at line 223 of file fbxmap.h.

224  {
225  return mTree.Minimum();
226  }
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.

230  {
231  return mTree.Maximum();
232  }
RecordType* Maximum ( )
inline

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

Definition at line 235 of file fbxmap.h.

236  {
237  return mTree.Maximum();
238  }

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