Nirtcpp 2.1.0
Nirtcpp is a high-performance c++ graphics engine.
Loading...
Searching...
No Matches
nirt::core::map< KeyType, ValueType > Class Template Reference

map template for associative arrays using a red-black tree More...

#include <nirtcpp/core/engine/irrMap.hpp>

Classes

class  AccessClass
 
class  ConstIterator
 Const Iterator. More...
 
class  Iterator
 Normal Iterator. More...
 
class  ParentFirstIterator
 Parent First Iterator. More...
 
class  ParentLastIterator
 Parent Last Iterator. More...
 

Public Types

using Node = RBTree< KeyType, ValueType >
 
using key_type = KeyType
 
using value_type = ValueType
 
using size_type = u32
 

Public Member Functions

bool insert (const KeyType &keyNew, const ValueType &v)
 Inserts a new node into the tree.
 
void set (const KeyType &k, const ValueType &v)
 Replaces the value if the key already exists, otherwise inserts a new element.
 
Nodedelink (const KeyType &k)
 Removes a node from the tree and returns it.
 
bool remove (const KeyType &k)
 Removes a node from the tree and deletes it.
 
bool remove (Node *p)
 Removes a node from the tree and deletes it.
 
void clear ()
 Clear the entire tree.
 
bool empty () const
 
NIRT_DEPRECATED bool isEmpty () const
 
Nodefind (const KeyType &keyToFind) const
 
NodegetRoot () const
 
u32 size () const
 Returns the number of nodes in the tree.
 
void swap (map< KeyType, ValueType > &other)
 Swap the content of this map container with the content of another map.
 
Iterator getIterator () const
 Returns an iterator.
 
ConstIterator getConstIterator () const
 Returns a Constiterator.
 
ParentFirstIterator getParentFirstIterator () const
 
ParentLastIterator getParentLastIterator () const
 
AccessClass operator[] (const KeyType &k)
 operator [] for access to elements
 

Detailed Description

template<class KeyType, class ValueType>
class nirt::core::map< KeyType, ValueType >

map template for associative arrays using a red-black tree

Member Function Documentation

◆ delink()

template<class KeyType , class ValueType >
Node * nirt::core::map< KeyType, ValueType >::delink ( const KeyType k)
inline

Removes a node from the tree and returns it.

The returned node must be deleted by the user

Parameters
kthe key to remove
Returns
A pointer to the node, or 0 if not found

◆ empty()

template<class KeyType , class ValueType >
bool nirt::core::map< KeyType, ValueType >::empty ( ) const
inline

Is the tree empty?

Returns
Returns true if empty, false if not

◆ find()

template<class KeyType , class ValueType >
Node * nirt::core::map< KeyType, ValueType >::find ( const KeyType keyToFind) const
inline

Search for a node with the specified key.

Parameters
keyToFindThe key to find
Returns
Returns 0 if node couldn't be found.

◆ getParentFirstIterator()

template<class KeyType , class ValueType >
ParentFirstIterator nirt::core::map< KeyType, ValueType >::getParentFirstIterator ( ) const
inline

Returns a ParentFirstIterator. Traverses the tree from top to bottom. Typical usage is when storing the tree class, because when reading it later (and inserting elements) the tree class will be the same.

◆ getParentLastIterator()

template<class KeyType , class ValueType >
ParentLastIterator nirt::core::map< KeyType, ValueType >::getParentLastIterator ( ) const
inline

Returns a ParentLastIterator to traverse the tree from bottom to top. Typical usage is when deleting all elements in the tree because you must delete the children before you delete their parent.

◆ getRoot()

template<class KeyType , class ValueType >
Node * nirt::core::map< KeyType, ValueType >::getRoot ( ) const
inline

Gets the root element.

Returns
Returns a pointer to the root node, or 0 if the tree is empty.

◆ insert()

template<class KeyType , class ValueType >
bool nirt::core::map< KeyType, ValueType >::insert ( const KeyType keyNew,
const ValueType v 
)
inline

Inserts a new node into the tree.

Parameters
keyNewthe index for this value
vthe value to insert
Returns
True if successful, false if it fails (already exists)

◆ isEmpty()

template<class KeyType , class ValueType >
NIRT_DEPRECATED bool nirt::core::map< KeyType, ValueType >::isEmpty ( ) const
inline
Deprecated:
Use empty() instead. This method may be removed by Nirtcpp 1.9

◆ operator[]()

template<class KeyType , class ValueType >
AccessClass nirt::core::map< KeyType, ValueType >::operator[] ( const KeyType k)
inline

operator [] for access to elements

for example myMap["key"]

◆ remove() [1/2]

template<class KeyType , class ValueType >
bool nirt::core::map< KeyType, ValueType >::remove ( const KeyType k)
inline

Removes a node from the tree and deletes it.

Returns
True if the node was found and deleted

◆ remove() [2/2]

template<class KeyType , class ValueType >
bool nirt::core::map< KeyType, ValueType >::remove ( Node p)
inline

Removes a node from the tree and deletes it.

Returns
True if the node was found and deleted

◆ set()

template<class KeyType , class ValueType >
void nirt::core::map< KeyType, ValueType >::set ( const KeyType k,
const ValueType v 
)
inline

Replaces the value if the key already exists, otherwise inserts a new element.

Parameters
kThe index for this value
vThe new value of

◆ swap()

template<class KeyType , class ValueType >
void nirt::core::map< KeyType, ValueType >::swap ( map< KeyType, ValueType > &  other)
inline

Swap the content of this map container with the content of another map.

Afterwards this object will contain the content of the other object and the other object will contain the content of this object. Iterators will afterwards be valid for the swapped object.

Parameters
otherSwap content with this object

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

Nirtcpp    @cppfx.xyz

Esvcpp    esv::print