OpenBarnyard
 
Loading...
Searching...
No Matches
T2Map< KeyType, ValueType, Comparator > Class Template Reference

#include <T2Map.h>

Public Types

using Pair = T2Pair<KeyType, ValueType, Comparator>
 
using Iterator = T2RedBlackTree<Pair>::Iterator
 
using CIterator = T2RedBlackTree<Pair>::CIterator
 
using Node = T2RedBlackTree<Pair>::Node
 

Public Member Functions

 T2Map (T2Allocator *a_pAllocator=GetGlobalAllocator())
 
 ~T2Map ()
 
void Clear ()
 
TSIZE Size () const
 
template<class... Args>
ValueType * Emplace (const KeyType &key, Args &&... args)
 
ValueType * Insert (const KeyType &key, const ValueType &value)
 
ValueType * Insert (const KeyType &key, ValueType &&value)
 
void Remove (const KeyType &key)
 
void Remove (Iterator &it)
 
Iterator FindByValue (const ValueType &value)
 
Iterator Find (const KeyType &key)
 
Iterator FindNext (Iterator a_oIterator, const KeyType &a_rKey)
 
TBOOL IsValid (Iterator a_oIterator) const
 
Iterator Begin ()
 
Iterator End ()
 
const CIterator Begin () const
 
const CIterator End () const
 
TBOOL IsEmpty () const
 
Iterator operator[] (const KeyType &key)
 
T2AllocatorGetAllocator () const
 

Detailed Description

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
class T2Map< KeyType, ValueType, Comparator >

Definition at line 9 of file T2Map.h.

Member Typedef Documentation

◆ CIterator

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
using T2Map< KeyType, ValueType, Comparator >::CIterator = T2RedBlackTree<Pair>::CIterator

Definition at line 14 of file T2Map.h.

◆ Iterator

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
using T2Map< KeyType, ValueType, Comparator >::Iterator = T2RedBlackTree<Pair>::Iterator

Definition at line 13 of file T2Map.h.

◆ Node

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
using T2Map< KeyType, ValueType, Comparator >::Node = T2RedBlackTree<Pair>::Node

Definition at line 15 of file T2Map.h.

◆ Pair

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
using T2Map< KeyType, ValueType, Comparator >::Pair = T2Pair<KeyType, ValueType, Comparator>

Definition at line 12 of file T2Map.h.

Constructor & Destructor Documentation

◆ T2Map()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
T2Map< KeyType, ValueType, Comparator >::T2Map ( T2Allocator * a_pAllocator = GetGlobalAllocator())
inline

Definition at line 18 of file T2Map.h.

19 : m_RedBlackTree( a_pAllocator )
20 {
21 }
Definition T2Map.h:10

◆ ~T2Map()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
T2Map< KeyType, ValueType, Comparator >::~T2Map ( )
inline

Definition at line 23 of file T2Map.h.

24 {
25 Clear();
26 }
void Clear()
Definition T2Map.h:28

Member Function Documentation

◆ Begin() [1/2]

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
Iterator T2Map< KeyType, ValueType, Comparator >::Begin ( )
inline

Definition at line 102 of file T2Map.h.

103 {
104 return m_RedBlackTree.Begin();
105 }

◆ Begin() [2/2]

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
const CIterator T2Map< KeyType, ValueType, Comparator >::Begin ( ) const
inline

Definition at line 112 of file T2Map.h.

113 {
114 return m_RedBlackTree.Begin();
115 }

◆ Clear()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
void T2Map< KeyType, ValueType, Comparator >::Clear ( )
inline

Definition at line 28 of file T2Map.h.

29 {
30 m_RedBlackTree.DeleteAll();
31 }

◆ Emplace()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
template<class... Args>
ValueType * T2Map< KeyType, ValueType, Comparator >::Emplace ( const KeyType & key,
Args &&... args )
inline

Definition at line 39 of file T2Map.h.

40 {
42 Iterator result = m_RedBlackTree.Insert( std::move( pair ) );
43 return &result.GetValue()->GetSecond();
44 }
T2RedBlackTree< Pair >::Iterator Iterator
Definition T2Map.h:13
ValueType * Insert(const KeyType &key, const ValueType &value)
Definition T2Map.h:46
T2Pair< KeyType, ValueType, Comparator > Pair
Definition T2Map.h:12

◆ End() [1/2]

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
Iterator T2Map< KeyType, ValueType, Comparator >::End ( )
inline

Definition at line 107 of file T2Map.h.

108 {
109 return m_RedBlackTree.End();
110 }

◆ End() [2/2]

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
const CIterator T2Map< KeyType, ValueType, Comparator >::End ( ) const
inline

Definition at line 117 of file T2Map.h.

118 {
119 return m_RedBlackTree.End();
120 }

◆ Find()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
Iterator T2Map< KeyType, ValueType, Comparator >::Find ( const KeyType & key)
inline

Definition at line 87 of file T2Map.h.

88 {
89 return m_RedBlackTree.Find( { key } );
90 }

◆ FindByValue()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
Iterator T2Map< KeyType, ValueType, Comparator >::FindByValue ( const ValueType & value)
inline

Definition at line 74 of file T2Map.h.

75 {
76 for ( auto it = Begin(); it != End(); it++ )
77 {
78 if ( it.GetValue()->GetSecond() == value )
79 {
80 return it;
81 }
82 }
83
84 return End();
85 }
Iterator End()
Definition T2Map.h:107
Iterator Begin()
Definition T2Map.h:102

◆ FindNext()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
Iterator T2Map< KeyType, ValueType, Comparator >::FindNext ( Iterator a_oIterator,
const KeyType & a_rKey )
inline

Definition at line 92 of file T2Map.h.

93 {
94 return m_RedBlackTree.FindNext( a_oIterator.GetNode(), { a_rKey } );
95 }

◆ GetAllocator()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
T2Allocator * T2Map< KeyType, ValueType, Comparator >::GetAllocator ( ) const
inline

Definition at line 132 of file T2Map.h.

133 {
134 return m_RedBlackTree.GetAllocator();
135 }

◆ Insert() [1/2]

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
ValueType * T2Map< KeyType, ValueType, Comparator >::Insert ( const KeyType & key,
const ValueType & value )
inline

Definition at line 46 of file T2Map.h.

47 {
48 Pair pair{ key, value };
49 Iterator result = m_RedBlackTree.Insert( std::move( pair ) );
50 return &result.GetValue()->GetSecond();
51 }

◆ Insert() [2/2]

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
ValueType * T2Map< KeyType, ValueType, Comparator >::Insert ( const KeyType & key,
ValueType && value )
inline

Definition at line 53 of file T2Map.h.

54 {
56 Iterator result = m_RedBlackTree.Insert( std::move( pair ) );
57 return &result.GetValue()->GetSecond();
58 }

◆ IsEmpty()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
TBOOL T2Map< KeyType, ValueType, Comparator >::IsEmpty ( ) const
inline

Definition at line 122 of file T2Map.h.

123 {
124 return Begin() == End();
125 }

◆ IsValid()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
TBOOL T2Map< KeyType, ValueType, Comparator >::IsValid ( Iterator a_oIterator) const
inline

Definition at line 97 of file T2Map.h.

98 {
99 return a_oIterator != End();
100 }

◆ operator[]()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
Iterator T2Map< KeyType, ValueType, Comparator >::operator[] ( const KeyType & key)
inline

Definition at line 127 of file T2Map.h.

128 {
129 return m_RedBlackTree.Find( { key } );
130 }

◆ Remove() [1/2]

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
void T2Map< KeyType, ValueType, Comparator >::Remove ( const KeyType & key)
inline

Definition at line 60 of file T2Map.h.

61 {
62 Iterator result = m_RedBlackTree.Find( { key } );
63
64 TASSERT( result != End() );
65 m_RedBlackTree.Delete( result.GetNode() );
66 }
#define TASSERT(X,...)
Definition Defines.h:138
Iterator Find(const KeyType &key)
Definition T2Map.h:87

◆ Remove() [2/2]

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
void T2Map< KeyType, ValueType, Comparator >::Remove ( Iterator & it)
inline

Definition at line 68 of file T2Map.h.

69 {
70 TASSERT( it != End() );
71 m_RedBlackTree.Delete( it.GetNode() );
72 }

◆ Size()

template<class KeyType, class ValueType, class Comparator = TComparator<KeyType>>
TSIZE T2Map< KeyType, ValueType, Comparator >::Size ( ) const
inline

Definition at line 33 of file T2Map.h.

34 {
35 return m_RedBlackTree.Size();
36 }

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