Tree. remove redunant function

This commit is contained in:
IlyaShurupov 2024-04-01 13:46:13 +03:00 committed by Ilya Shurupov
parent 715175085e
commit 4d381d62e4
4 changed files with 34 additions and 22 deletions

View file

@ -19,11 +19,6 @@ namespace tp {
return in.mEnd > mEnd;
}
inline bool descentLeft(const IntervalKey& in) const {
if (in.mStart != mStart) return in.mStart < mStart;
return in.mEnd < mEnd;
}
inline bool exactNode(const IntervalKey& in) const { return in.mStart == mStart && in.mEnd == mEnd; }
inline const IntervalKey& getFindKey() const { return *this; }

View file

@ -14,7 +14,6 @@ namespace tp {
val(val) {}
inline bool descentRight(AvlNumericKey in) const { return in.val > val; }
inline bool descentLeft(AvlNumericKey in) const { return in.val < val; }
inline bool exactNode(AvlNumericKey in) const { return in.val == val; }
inline AvlNumericKey getFindKey(/**/) const { return *this; }
@ -51,7 +50,6 @@ namespace tp {
private:
inline bool descentRight(KeyArg aKey) const { return key.descentRight(aKey); }
inline bool descentLeft(KeyArg aKey) const { return key.descentLeft(aKey); }
inline bool exactNode(KeyArg aKey) const { return key.exactNode(aKey); }
inline KeyArg getFindKey(const Node* node = nullptr) const { return key.getFindKey(/*node*/); }
@ -100,12 +98,12 @@ namespace tp {
while (true) {
if (!iter) return nullptr;
if (iter->exactNode(key)) return iter;
if (iter->descentLeft(key)) {
key = iter->keyInLeftSubtree(key);
iter = iter->mLeft;
} else {
if (iter->descentRight(key)) {
key = iter->keyInRightSubtree(key);
iter = iter->mRight;
} else {
key = iter->keyInLeftSubtree(key);
iter = iter->mLeft;
}
}
}
@ -115,17 +113,17 @@ namespace tp {
while (true) {
if (!iter) return nullptr;
if (iter->exactNode(key)) return iter;
if (iter->descentLeft(key)) {
if (iter->mLeft) {
key = iter->keyInLeftSubtree(key);
iter = iter->mLeft;
if (iter->descentRight(key)) {
if (iter->mRight) {
key = iter->keyInRightSubtree(key);
iter = iter->mRight;
} else {
return iter;
}
} else {
if (iter->mRight) {
key = iter->keyInRightSubtree(key);
iter = iter->mRight;
if (iter->mLeft) {
key = iter->keyInLeftSubtree(key);
iter = iter->mLeft;
} else {
return iter;
}
@ -139,7 +137,7 @@ namespace tp {
if (head->mLeft) {
// TODO: incomplete test
if (!head->descentLeft(head->mLeft->getFindKey(head))) return head;
if (head->descentRight(head->mLeft->getFindKey(head))) return head;
if (head->mLeft->mParent != head) return head;
if (!head->mRight && head->mLeft->mHeight != head->mHeight - 1) return head;
}
@ -307,7 +305,7 @@ namespace tp {
return rotateLeft(head);
}
} else if (balance < -1) {
if (head->mLeft->descentLeft(head->keyInLeftSubtree(key))) {
if (!head->mLeft->descentRight(head->keyInLeftSubtree(key))) {
return rotateRight(head);
} else {
head->mLeft = rotateLeft(head->mLeft);
@ -346,7 +344,7 @@ namespace tp {
}
} else if (head->descentRight(key)) {
head->mRight = removeUtil(head->mRight, head->keyInRightSubtree(key));
} else if (head->descentLeft(key)) {
} else {
head->mLeft = removeUtil(head->mLeft, head->keyInLeftSubtree(key));
}

View file

@ -0,0 +1,16 @@
#include "Tree.hpp"
#include "Timing.hpp"
#include "UnitTest++/UnitTest++.h"
#include <map>
TEST(AVLTreeStream) {
tp::Timer timer(1000);
tp::AvlTree<tp::AvlNumericKey<tp::ualni>> tree;
while (!timer.isTimeout()) {
tree.
}
}

View file

@ -12,6 +12,9 @@ namespace tp {
template <typename Type>
using InitialierList = std::initializer_list<Type>;
template <typename tType, typename tTypeResult>
using ShouldPassByValue = typename TypeSelect<(sizeof(tType) > sizeof(tp::alni)), const tType&, tType>::Result;
// Selects whether to pass by constant reference or by value
template <typename tType>
using SelectValueOrReference = typename TypeSelect<(sizeof(tType) > sizeof(tp::alni)), const tType&, tType>::Result;