update numeric key interface
This commit is contained in:
parent
3148e2c020
commit
13bcbcb23f
3 changed files with 25 additions and 23 deletions
|
|
@ -30,7 +30,7 @@ namespace tp {
|
||||||
inline const IntervalKey& keyInLeftSubtree(const IntervalKey& in) const { return in; }
|
inline const IntervalKey& keyInLeftSubtree(const IntervalKey& in) const { return in; }
|
||||||
|
|
||||||
template <typename tTreeNodeType>
|
template <typename tTreeNodeType>
|
||||||
inline void updateTreeCacheCallBack(const tTreeNodeType* node) {
|
inline void updateNodeCache(const tTreeNodeType* node) {
|
||||||
mMax = 0;
|
mMax = 0;
|
||||||
if (node->mRight && node->mRight->key.mMax > mMax) mMax = node->mRight->key.mMax;
|
if (node->mRight && node->mRight->key.mMax > mMax) mMax = node->mRight->key.mMax;
|
||||||
if (node->mLeft && node->mLeft->key.mMax > mMax) mMax = node->mLeft->key.mMax;
|
if (node->mLeft && node->mLeft->key.mMax > mMax) mMax = node->mLeft->key.mMax;
|
||||||
|
|
|
||||||
|
|
@ -6,26 +6,27 @@ namespace tp {
|
||||||
|
|
||||||
template <typename NumericType>
|
template <typename NumericType>
|
||||||
struct AvlNumericKey {
|
struct AvlNumericKey {
|
||||||
|
public:
|
||||||
NumericType val;
|
|
||||||
|
|
||||||
AvlNumericKey() = default;
|
AvlNumericKey() = default;
|
||||||
AvlNumericKey(NumericType val) :
|
AvlNumericKey(NumericType val) :
|
||||||
val(val) {}
|
val(val) {}
|
||||||
|
|
||||||
inline bool descentRight(AvlNumericKey in) const { return in.val > val; }
|
inline bool descentRight(const AvlNumericKey& in) const { return in.val > val; }
|
||||||
inline bool exactNode(AvlNumericKey in) const { return in.val == val; }
|
inline bool exactNode(const AvlNumericKey& in) const { return in.val == val; }
|
||||||
|
|
||||||
|
inline const AvlNumericKey& keyInRightSubtree(const AvlNumericKey& in) const { return in; }
|
||||||
|
inline const AvlNumericKey& keyInLeftSubtree(const AvlNumericKey& in) const { return in; }
|
||||||
|
|
||||||
template <typename NodeType>
|
template <typename NodeType>
|
||||||
inline AvlNumericKey getFindKey(const NodeType*) const {
|
inline void updateNodeCache(const NodeType*) {}
|
||||||
|
|
||||||
|
template <typename NodeType>
|
||||||
|
inline const AvlNumericKey& getFindKey(const NodeType*) const {
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline AvlNumericKey keyInRightSubtree(AvlNumericKey in) const { return in; }
|
public:
|
||||||
inline AvlNumericKey keyInLeftSubtree(AvlNumericKey in) const { return in; }
|
NumericType val;
|
||||||
|
|
||||||
template <typename NodeType>
|
|
||||||
inline void updateTreeCacheCallBack(const NodeType*) {}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
template <typename Key, typename Data, class Allocator = DefaultAllocator>
|
template <typename Key, typename Data, class Allocator = DefaultAllocator>
|
||||||
|
|
@ -229,8 +230,8 @@ namespace tp {
|
||||||
right->mHeight = 1 + max(getNodeHeight(right->mLeft), getNodeHeight(right->mRight));
|
right->mHeight = 1 + max(getNodeHeight(right->mLeft), getNodeHeight(right->mRight));
|
||||||
|
|
||||||
// cache
|
// cache
|
||||||
head->key.updateTreeCacheCallBack(head);
|
head->key.updateNodeCache(head);
|
||||||
right->key.updateTreeCacheCallBack(right);
|
right->key.updateNodeCache(right);
|
||||||
|
|
||||||
return right;
|
return right;
|
||||||
}
|
}
|
||||||
|
|
@ -257,8 +258,8 @@ namespace tp {
|
||||||
left->mHeight = 1 + max(getNodeHeight(left->mLeft), getNodeHeight(left->mRight));
|
left->mHeight = 1 + max(getNodeHeight(left->mLeft), getNodeHeight(left->mRight));
|
||||||
|
|
||||||
// cache
|
// cache
|
||||||
head->key.updateTreeCacheCallBack(head);
|
head->key.updateNodeCache(head);
|
||||||
left->key.updateTreeCacheCallBack(left);
|
left->key.updateNodeCache(left);
|
||||||
|
|
||||||
return left;
|
return left;
|
||||||
}
|
}
|
||||||
|
|
@ -271,7 +272,7 @@ namespace tp {
|
||||||
if (head == nullptr) {
|
if (head == nullptr) {
|
||||||
mSize++;
|
mSize++;
|
||||||
Node* out = newNode(key, data);
|
Node* out = newNode(key, data);
|
||||||
out->key.updateTreeCacheCallBack(out);
|
out->key.updateNodeCache(out);
|
||||||
return out;
|
return out;
|
||||||
} else if (head->key.exactNode(key)) {
|
} else if (head->key.exactNode(key)) {
|
||||||
return head;
|
return head;
|
||||||
|
|
@ -306,7 +307,7 @@ namespace tp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
head->key.updateTreeCacheCallBack(head);
|
head->key.updateNodeCache(head);
|
||||||
|
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
@ -362,7 +363,7 @@ namespace tp {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
head->key.updateTreeCacheCallBack(head);
|
head->key.updateNodeCache(head);
|
||||||
|
|
||||||
return head;
|
return head;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -12,12 +12,13 @@ namespace tp {
|
||||||
template <typename Type>
|
template <typename Type>
|
||||||
using InitialierList = std::initializer_list<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
|
// Selects whether to pass by constant reference or by value
|
||||||
template <typename tType>
|
template <typename tType>
|
||||||
using SelectValueOrReference = typename TypeSelect<(sizeof(tType) > sizeof(tp::alni)), const tType&, tType>::Result;
|
using SelectValueOrReference = typename TypeSelect<(sizeof(tType) > sizeof(void*)), const tType&, tType>::Result;
|
||||||
|
|
||||||
|
template <typename tType, typename tTypeResult>
|
||||||
|
using SelectValueOrReferenceOf =
|
||||||
|
typename TypeSelect<(sizeof(tType) > sizeof(void*)), const tTypeResult&, tTypeResult>::Result;
|
||||||
|
|
||||||
template <typename tType>
|
template <typename tType>
|
||||||
using VoidType = void;
|
using VoidType = void;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue