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; }
|
||||
|
||||
template <typename tTreeNodeType>
|
||||
inline void updateTreeCacheCallBack(const tTreeNodeType* node) {
|
||||
inline void updateNodeCache(const tTreeNodeType* node) {
|
||||
mMax = 0;
|
||||
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;
|
||||
|
|
|
|||
|
|
@ -6,26 +6,27 @@ namespace tp {
|
|||
|
||||
template <typename NumericType>
|
||||
struct AvlNumericKey {
|
||||
|
||||
NumericType val;
|
||||
|
||||
public:
|
||||
AvlNumericKey() = default;
|
||||
AvlNumericKey(NumericType val) :
|
||||
val(val) {}
|
||||
|
||||
inline bool descentRight(AvlNumericKey in) const { return in.val > val; }
|
||||
inline bool exactNode(AvlNumericKey in) const { return in.val == val; }
|
||||
inline bool descentRight(const 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>
|
||||
inline AvlNumericKey getFindKey(const NodeType*) const {
|
||||
inline void updateNodeCache(const NodeType*) {}
|
||||
|
||||
template <typename NodeType>
|
||||
inline const AvlNumericKey& getFindKey(const NodeType*) const {
|
||||
return *this;
|
||||
}
|
||||
|
||||
inline AvlNumericKey keyInRightSubtree(AvlNumericKey in) const { return in; }
|
||||
inline AvlNumericKey keyInLeftSubtree(AvlNumericKey in) const { return in; }
|
||||
|
||||
template <typename NodeType>
|
||||
inline void updateTreeCacheCallBack(const NodeType*) {}
|
||||
public:
|
||||
NumericType val;
|
||||
};
|
||||
|
||||
template <typename Key, typename Data, class Allocator = DefaultAllocator>
|
||||
|
|
@ -229,8 +230,8 @@ namespace tp {
|
|||
right->mHeight = 1 + max(getNodeHeight(right->mLeft), getNodeHeight(right->mRight));
|
||||
|
||||
// cache
|
||||
head->key.updateTreeCacheCallBack(head);
|
||||
right->key.updateTreeCacheCallBack(right);
|
||||
head->key.updateNodeCache(head);
|
||||
right->key.updateNodeCache(right);
|
||||
|
||||
return right;
|
||||
}
|
||||
|
|
@ -257,8 +258,8 @@ namespace tp {
|
|||
left->mHeight = 1 + max(getNodeHeight(left->mLeft), getNodeHeight(left->mRight));
|
||||
|
||||
// cache
|
||||
head->key.updateTreeCacheCallBack(head);
|
||||
left->key.updateTreeCacheCallBack(left);
|
||||
head->key.updateNodeCache(head);
|
||||
left->key.updateNodeCache(left);
|
||||
|
||||
return left;
|
||||
}
|
||||
|
|
@ -271,7 +272,7 @@ namespace tp {
|
|||
if (head == nullptr) {
|
||||
mSize++;
|
||||
Node* out = newNode(key, data);
|
||||
out->key.updateTreeCacheCallBack(out);
|
||||
out->key.updateNodeCache(out);
|
||||
return out;
|
||||
} else if (head->key.exactNode(key)) {
|
||||
return head;
|
||||
|
|
@ -306,7 +307,7 @@ namespace tp {
|
|||
}
|
||||
}
|
||||
|
||||
head->key.updateTreeCacheCallBack(head);
|
||||
head->key.updateNodeCache(head);
|
||||
|
||||
return head;
|
||||
}
|
||||
|
|
@ -362,7 +363,7 @@ namespace tp {
|
|||
}
|
||||
}
|
||||
|
||||
head->key.updateTreeCacheCallBack(head);
|
||||
head->key.updateNodeCache(head);
|
||||
|
||||
return head;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,12 +12,13 @@ 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;
|
||||
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>
|
||||
using VoidType = void;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue