-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathRStarVisitor.h
123 lines (93 loc) · 3.52 KB
/
RStarVisitor.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
#ifndef RSTARVISITOR_H
#define RSTARVISITOR_H
#include "RStarBoundingBox.h"
#include "skylineCores.h"
// returns true if the node overlaps the specified bound
template<typename Node, typename Leaf>
struct RStarAcceptOverlapping {
const typename Node::BoundingBox &m_bound;
explicit RStarAcceptOverlapping(const typename Node::BoundingBox &bound) : m_bound(bound) {}
bool operator()(const Node *const node) const {
return m_bound.overlaps(node->bound);
}
bool operator()(const Leaf *const leaf) const {
return m_bound.overlaps(leaf->bound);
}
private:
RStarAcceptOverlapping() {}
};
// returns true if the compared boundary is within the specified bound
template<typename Node, typename Leaf>
struct RStarAcceptEnclosing {
const typename Node::BoundingBox &m_bound;
explicit RStarAcceptEnclosing(const typename Node::BoundingBox &bound) : m_bound(bound) {}
bool operator()(const Node *const node) const {
return m_bound.overlaps(node->bound);
}
bool operator()(const Leaf *const leaf) const {
return m_bound.encloses(leaf->bound);
}
bool isEnclose(const Node *const node) const {
return m_bound.encloses(node->bound);
}
private:
RStarAcceptEnclosing() {}
};
// will always return true, no matter what
template<typename Node, typename Leaf>
struct RStarAcceptAny {
bool operator()(const Node *const node) const { return true; }
bool operator()(const Leaf *const leaf) const { return true; }
};
/********************************************************************
* These are all 'visitor' styled functions -- even though these are
* specifically targeted for removal tasks, visitor classes are
* specified exactly the same way.
*
* bool operator()(RStarLeaf<LeafType, dimensions> * leaf)
* -- Removal: if returns true, then remove the node
* -- Visitor: return can actually be void, not used
*
* bool ContinueVisiting; (not a function)
* -- if false, then the query will end as soon as possible. It
* is not guaranteed that the operator() will not be called, so
* items may be removed/visited after this is set to false
*
* You may modify the items that the leaf points to, but under no
* circumstance should the bounds of the item be modified (since
* that would screw up the tree).
*
********************************************************************/
/*
Default functor used to delete nodes from the R* tree. You can specify
a different functor to use, as long as it has the same signature as this.
*/
template<typename Leaf>
struct RStarRemoveLeaf {
const bool ContinueVisiting;
RStarRemoveLeaf() : ContinueVisiting(true) {}
bool operator()(const Leaf *const leaf) const {
return true;
}
};
// returns true if the specific leaf is matched. If remove duplicates is true,
// then it searches for all possible instances of the item
template<typename Leaf>
struct RStarRemoveSpecificLeaf {
mutable bool ContinueVisiting;
bool m_remove_duplicates;
const typename Leaf::leaf_type &m_leaf;
explicit RStarRemoveSpecificLeaf(const typename Leaf::leaf_type &leaf, bool remove_duplicates = false) :
ContinueVisiting(true), m_remove_duplicates(remove_duplicates), m_leaf(leaf) {}
bool operator()(const Leaf *const leaf) const {
if (ContinueVisiting && m_leaf == leaf->leaf) {
if (!m_remove_duplicates)
ContinueVisiting = false;
return true;
}
return false;
}
private:
RStarRemoveSpecificLeaf() {}
};
#endif