66template <
class KeyType,
class ValueType>
class SbMapItem
74 , mRightChild(nullptr)
154 return mParent ==
nullptr;
158 return mParent !=
nullptr && mParent->getLeftChild() ==
this;
162 return mParent !=
nullptr && mParent->getRightChild() ==
this;
166 return mLeftChild ==
nullptr && mRightChild ==
nullptr;
197template <
class KeyType,
class ValueType>
class SbMap
230 mCur = (atLowest) ? minNode(mRoot) : maxNode(mRoot);
236 return mCur ==
nullptr;
271 throw "Iterator at end";
289 while (n && n->getRightChild())
301 if (mCur->getRightChild()) {
304 mCur = minNode(mCur->getRightChild());
306 else if (mCur->isLeftChild()) {
309 mCur = mCur->getParent();
317 while (mCur->isRightChild())
318 mCur = mCur->getParent();
319 mCur = mCur->getParent();
330 if (mCur->getLeftChild()) {
333 mCur = maxNode(mCur->getLeftChild());
335 else if (mCur->isRightChild()) {
338 mCur = mCur->getParent();
347 while (mCur->isLeftChild())
348 mCur = mCur->getParent();
349 mCur = mCur->getParent();
387 return mCur ==
nullptr;
416 throw "ParentFirstIterator at end";
439 while (mCur !=
nullptr) {
443 if (mCur->isLeftChild() && mCur->getParent()->getRightChild()) {
444 mCur = mCur->getParent()->getRightChild();
447 mCur = mCur->getParent();
480 mCur = minNode(mRoot);
486 return mCur ==
nullptr;
515 throw "ParentLastIterator at end";
540 if (mCur->isLeftChild() && mCur->getParent()->getRightChild()) {
541 mCur = minNode(mCur->getParent()->getRightChild());
544 mCur = mCur->getParent();
585 , mEndPos(src.mEndPos)
587 if (src.mArray !=
nullptr) {
588 mArray = new Node*[(mSize + 1) / 2];
589 memcpy(mArray, src.mArray, sizeof(Node*) * (mSize + 1) / 2);
598 if (mArray !=
nullptr) {
608 if (mArray ==
nullptr) {
611 mArray =
new Node*[(mSize + 1) / 2];
636 if (src.mArray !=
nullptr) {
637 mArray =
new Node*[(mSize + 1) / 2];
638 memcpy(mArray, src.mArray,
sizeof(
Node*) * (mSize + 1) / 2);
660 throw "ParentLastIterator at end";
671 Node* pNode = mArray[0];
675 for (
unsigned int i = 0; i < mEndPos; i++) {
676 mArray[i] = mArray[i + 1];
682 mArray[mEndPos] = pChild;
688 mArray[mEndPos] = pChild;
696 unsigned int mEndPos;
717 mTree.set(mKey, value);
726 if (node ==
nullptr) {
727 throw "Item not found";
775 set(i->getKey(), i->getValue());
783 Node* newNode =
new Node(keyNew, v);
794 if (newNodesUncle !=
nullptr && newNodesUncle->
isRed()) {
819 if (newNodesUncle !=
nullptr && newNodesUncle->
isRed()) {
833 RotateRight(newNode);
915 return mRoot ==
nullptr;
924 while (pNode !=
nullptr) {
927 if (keyToFind == key) {
931 else if (keyToFind < key) {
982 void setRoot(
Node* newRoot)
985 if (mRoot !=
nullptr)
995 if (mRoot ==
nullptr) {
1000 Node* pNode = mRoot;
1005 if (keyNew == key) {
1009 else if (keyNew < key) {
1010 if (pNode->getLeftChild() == 0) {
1011 pNode->setLeftChild(newNode);
1015 pNode = pNode->getLeftChild();
1020 if (pNode->getRightChild() == 0) {
1021 pNode->setRightChild(newNode);
1025 pNode = pNode->getRightChild();
1040 void RotateLeft(
Node* p)
1042 Node* right = p->getRightChild();
1044 p->setRightChild(right->getLeftChild());
1046 if (p->isLeftChild()) {
1047 p->getParent()->setLeftChild(right);
1049 else if (p->isRightChild()) {
1050 p->getParent()->setRightChild(right);
1055 right->setLeftChild(p);
1060 void RotateRight(
Node* p)
1062 Node* left = p->getLeftChild();
1064 p->setLeftChild(left->getRightChild());
1066 if (p->isLeftChild()) {
1067 p->getParent()->setLeftChild(left);
1069 else if (p->isRightChild()) {
1070 p->getParent()->setRightChild(left);
1075 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)
AccessClass operator[](const KeyType &k)
bool insert(const KeyType &keyNew, const ValueType &v)
SbMapItem< KeyType, ValueType > Node
ParentLastIterator getParentLastIterator()
unsigned int size() const
Node * find(const KeyType &keyToFind) const
SbMap & operator=(const SbMap &src)
bool remove(const KeyType &k)