66template <
class KeyType,
class ValueType>
73 :mKey(k), mValue(v), mLeftChild(nullptr), mRightChild(nullptr), mParent(nullptr), mIsRed(true) {
137 return mParent ==
nullptr;
140 return mParent !=
nullptr && mParent->
getLeftChild() ==
this;
143 return mParent !=
nullptr && mParent->
getRightChild() ==
this;
146 return mLeftChild ==
nullptr && mRightChild ==
nullptr;
175template <
class KeyType,
class ValueType>
204 mCur = (atLowest) ? minNode(mRoot) : maxNode(mRoot);
209 return mCur ==
nullptr;
238 throw "Iterator at end";
255 while(n && n->getRightChild())
345 return mCur==
nullptr;
369 throw "ParentFirstIterator at end";
392 while(mCur !=
nullptr) {
428 mCur = minNode(mRoot);
433 return mCur ==
nullptr;
457 throw "ParentLastIterator at end";
518 if(src.mArray !=
nullptr) {
519 mArray =
new Node*[(mSize+1)/2];
520 memcpy(mArray, src.mArray,
sizeof(
Node*)*(mSize+1)/2);
528 if(mArray !=
nullptr) {
537 if(mArray ==
nullptr) {
540 mArray =
new Node*[(mSize+1)/2];
562 if(src.mArray !=
nullptr) {
563 mArray =
new Node*[(mSize+1)/2];
564 memcpy(mArray, src.mArray,
sizeof(
Node*)*(mSize+1)/2);
583 throw "ParentLastIterator at end";
594 Node *pNode = mArray[0];
598 for(
unsigned int i = 0; i < mEndPos; i++) {
599 mArray[i] = mArray[i+1];
605 mArray[mEndPos] = pChild;
611 mArray[mEndPos] = pChild;
620 unsigned int mEndPos;
641 mTree.
set(mKey, value);
645 operator ValueType() {
649 if(node ==
nullptr) {
650 throw "Item not found";
672 SbMap() : mRoot(nullptr), mSize(0) {}
675 explicit SbMap(
const SbMap &src) : mRoot(nullptr), mSize(0) {
689 set(i->getKey(), i->getValue());
696 Node *newNode =
new Node(keyNew, v);
707 if(newNodesUncle !=
nullptr && newNodesUncle->
isRed()) {
732 if(newNodesUncle !=
nullptr && newNodesUncle->
isRed()) {
746 RotateRight(newNode);
824 return mRoot ==
nullptr;
832 while(pNode !=
nullptr) {
835 if(keyToFind == key) {
839 else if(keyToFind < key) {
884 void setRoot(
Node *newRoot) {
895 if(mRoot ==
nullptr) {
909 else if(keyNew < key) {
910 if(pNode->getLeftChild() == 0) {
911 pNode->setLeftChild(newNode);
915 pNode = pNode->getLeftChild();
920 if(pNode->getRightChild() == 0) {
921 pNode->setRightChild(newNode);
925 pNode = pNode->getRightChild();
940 void RotateLeft(
Node *p) {
941 Node *right = p->getRightChild();
943 p->setRightChild(right->getLeftChild());
945 if(p->isLeftChild()) {
946 p->getParent()->setLeftChild(right);
948 else if(p->isRightChild()) {
949 p->getParent()->setRightChild(right);
954 right->setLeftChild(p);
959 void RotateRight(
Node *p) {
960 Node *left = p->getLeftChild();
962 p->setLeftChild(left->getRightChild());
964 if(p->isLeftChild()) {
965 p->getParent()->setLeftChild(left);
967 else if(p->isRightChild()) {
968 p->getParent()->setRightChild(left);
973 left->setRightChild(p);
KeyType
SoKeyGrabber is a general facility to grab keyboard events.
Class SbMapItem is the element type of the SbMap tree.
SbMapItem * getParent() const
const KeyType & getKey() const
SbMapItem(const KeyType &k, const ValueType &v)
bool isRightChild() const
void setLeftChild(SbMapItem *p)
void setRightChild(SbMapItem *p)
void setValue(const ValueType &v)
unsigned int GetLevel() const
void setParent(SbMapItem *p)
const ValueType & getValue() const
SbMapItem * getLeftChild() const
SbMapItem * getRightChild() const
AccessClass is a temporary class used with the [] operator on an SbMap.
operator=(const ValueType &value)
SbMap::ByLevelIterator for an SbMap, traversing the map top to bottom, level by level left to right....
ByLevelIterator(const ByLevelIterator &src)
ByLevelIterator(Node *root, unsigned int size)
ByLevelIterator & operator=(const ByLevelIterator &src)
Regular low->high (++) and high->low (–) iterator class for an SbMap.
Iterator(const Iterator &src)
Iterator & operator=(const Iterator &src)
void reset(bool atLowest=true)
SbMap::ParentFirstIterator for an SbMap, traversing the map from top to bottom.
ParentFirstIterator(Node *root)
ParentFirstIterator & operator=(const ParentFirstIterator &src)
SbMap::ParentFirstIterator for an SbMap, traversing the map from bottom to top.
ParentLastIterator & operator=(const ParentLastIterator &src)
ParentLastIterator(Node *root)
Open Inventor container that associates objects of type KeyType with objects of type ValueType.
ParentFirstIterator getParentFirstIterator()
ByLevelIterator getByLevelIterator()
void set(const KeyType &k, const ValueType &v)
SbMapItem< KeyType, ValueType > Node
AccessClass operator[](const KeyType &k)
bool insert(const KeyType &keyNew, const ValueType &v)
ParentLastIterator getParentLastIterator()
unsigned int size() const
Node * find(const KeyType &keyToFind) const
SbMap & operator=(const SbMap &src)
bool remove(const KeyType &k)