QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
Node.h
Go to the documentation of this file.
1/******************************************************************************
2 * Project: libspatialindex - A C++ library for spatial indexing
3 * Author: Marios Hadjieleftheriou, [email protected]
4 ******************************************************************************
5 * Copyright (c) 2002, Marios Hadjieleftheriou
6 *
7 * All rights reserved.
8 *
9 * Permission is hereby granted, free of charge, to any person obtaining a
10 * copy of this software and associated documentation files (the "Software"),
11 * to deal in the Software without restriction, including without limitation
12 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
13 * and/or sell copies of the Software, and to permit persons to whom the
14 * Software is furnished to do so, subject to the following conditions:
15 *
16 * The above copyright notice and this permission notice shall be included
17 * in all copies or substantial portions of the Software.
18 *
19 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
20 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
21 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
22 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
23 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
24 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
25 * DEALINGS IN THE SOFTWARE.
26******************************************************************************/
27
28#pragma once
29
30namespace SpatialIndex
31{
32 namespace MVRTree
33 {
34 class MVRTree;
35 class Leaf;
36 class Index;
37 class Node;
38
40
42 {
43 public:
44 virtual ~Node();
45
46 //
47 // Tools::IObject interface
48 //
49 virtual IObject* clone();
50
51 //
52 // Tools::ISerializable interface
53 //
54 virtual uint32_t getByteArraySize();
55 virtual void loadFromByteArray(const byte* data);
56 virtual void storeToByteArray(byte** data, uint32_t& len);
57
58 //
59 // SpatialIndex::IEntry interface
60 //
61 virtual id_type getIdentifier() const;
62 virtual void getShape(IShape** out) const;
63
64 //
65 // SpatialIndex::INode interface
66 //
67 virtual uint32_t getChildrenCount() const;
68 virtual id_type getChildIdentifier(uint32_t index) const;
69 virtual void getChildShape(uint32_t index, IShape** out) const;
70 virtual void getChildData(uint32_t index, uint32_t& length, byte** data) const;
71 virtual uint32_t getLevel() const;
72 virtual bool isIndex() const;
73 virtual bool isLeaf() const;
74
75 private:
77 Node(MVRTree* pTree, id_type id, uint32_t level, uint32_t capacity);
78
79 virtual Node& operator=(const Node&);
80
81 virtual void insertEntry(uint32_t dataLength, byte* pData, TimeRegion& mbr, id_type id);
82 virtual bool deleteEntry(uint32_t index);
83
84 virtual bool insertData(
85 uint32_t dataLength, byte* pData, TimeRegion& mbr, id_type id, std::stack<id_type>& pathBuffer,
86 TimeRegion& mbr2, id_type id2, bool bInsertMbr2 = false, bool forceAdjust = false);
87 virtual void insertData(TimeRegion& mbr1, id_type id1, TimeRegion& mbr2, id_type id2, Node* oldVersion, std::stack<id_type>& pathBuffer);
88 virtual bool deleteData(id_type id, double delTime, std::stack<id_type>& pathBuffer, bool adjustMBR = false);
89
90 virtual void rtreeSplit(
91 uint32_t dataLength, byte* pData, TimeRegion& mbr, id_type id, std::vector<uint32_t>& group1, std::vector<uint32_t>& group2,
92 TimeRegion& mbr2, id_type id2, bool bInsertMbr2 = false);
93 virtual void rstarSplit(
94 uint32_t dataLength, byte* pData, TimeRegion& mbr, id_type id, std::vector<uint32_t>& group1, std::vector<uint32_t>& group2,
95 TimeRegion& mbr2, id_type id2, bool bInsertMbr2 = false);
96
97 virtual void pickSeeds(uint32_t& index1, uint32_t& index2, uint32_t total);
98
99 virtual NodePtr chooseSubtree(const TimeRegion& mbr, uint32_t level, std::stack<id_type>& pathBuffer) = 0;
100 virtual NodePtr findLeaf(const TimeRegion& mbr, id_type id, std::stack<id_type>& pathBuffer) = 0;
101 virtual NodePtr findNode(const TimeRegion& mbr, id_type id, std::stack<id_type>& pathBuffer);
102
103 virtual void split(
104 uint32_t dataLength, byte* pData, TimeRegion& mbr, id_type id, NodePtr& left, NodePtr& right,
105 TimeRegion& mbr2, id_type id2, bool bInsertMbr2 = false) = 0;
106
108 // Parent of all nodes.
109
110 uint32_t m_level;
111 // The level of the node in the tree.
112 // Leaves are always at level 0.
113
115 // The unique ID of this node.
116
117 uint32_t m_children;
118 // The number of children pointed by this node.
119
120 uint32_t m_capacity;
121 // Specifies the node capacity.
122
124 // The minimum bounding region enclosing all data contained in the node.
125
126 byte** m_pData;
127 // The data stored in the node.
128
130 // The corresponding data MBRs.
131
133 // The corresponding data identifiers.
134
135 uint32_t* m_pDataLength;
136
138
140 {
141 public:
142 RstarSplitEntry(TimeRegion* pr, uint32_t index, uint32_t dimension) :
143 m_pRegion(pr), m_index(index), m_sortDim(dimension) {}
144
145 static int compareLow(const void* pv1, const void* pv2)
146 {
147 RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
148 RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
149
150 if (pe1->m_pRegion->m_pLow[pe1->m_sortDim] < pe2->m_pRegion->m_pLow[pe2->m_sortDim]) return -1;
151 if (pe1->m_pRegion->m_pLow[pe1->m_sortDim] > pe2->m_pRegion->m_pLow[pe2->m_sortDim]) return 1;
152 return 0;
153 }
154
155 static int compareHigh(const void* pv1, const void* pv2)
156 {
157 RstarSplitEntry* pe1 = * (RstarSplitEntry**) pv1;
158 RstarSplitEntry* pe2 = * (RstarSplitEntry**) pv2;
159
160 if (pe1->m_pRegion->m_pHigh[pe1->m_sortDim] < pe2->m_pRegion->m_pHigh[pe2->m_sortDim]) return -1;
161 if (pe1->m_pRegion->m_pHigh[pe1->m_sortDim] > pe2->m_pRegion->m_pHigh[pe2->m_sortDim]) return 1;
162 return 0;
163 }
164
166 uint32_t m_index;
167 uint32_t m_sortDim;
168 }; // RstarSplitEntry
169
171 {
172 public:
173 DeleteDataEntry(uint32_t index, double d) : m_index(index), m_increase(d) {}
174
175 static bool compare(DeleteDataEntry e1, DeleteDataEntry e2) { return e1.m_increase < e2.m_increase; }
176
177 uint32_t m_index;
179 }; // DeleteDataEntry
180
181 // Needed to access protected members without having to cast from Node.
182 // It is more efficient than using member functions to access protected members.
183 friend class MVRTree;
184 friend class Leaf;
185 friend class Index;
186 friend class Tools::PointerPool<Node>;
187 }; // Node
188 }
189}
190
Definition Index.h:34
Definition SpatialIndex.h:114
Definition SpatialIndex.h:68
Definition Index.h:35
Definition Leaf.h:35
Definition MVRTree.h:39
Definition Node.h:171
double m_increase
Definition Node.h:178
uint32_t m_index
Definition Node.h:177
static bool compare(DeleteDataEntry e1, DeleteDataEntry e2)
Definition Node.h:175
DeleteDataEntry(uint32_t index, double d)
Definition Node.h:173
Definition Node.h:140
static int compareLow(const void *pv1, const void *pv2)
Definition Node.h:145
TimeRegion * m_pRegion
Definition Node.h:165
uint32_t m_index
Definition Node.h:166
RstarSplitEntry(TimeRegion *pr, uint32_t index, uint32_t dimension)
Definition Node.h:142
static int compareHigh(const void *pv1, const void *pv2)
Definition Node.h:155
uint32_t m_sortDim
Definition Node.h:167
Definition Node.h:42
virtual void split(uint32_t dataLength, byte *pData, TimeRegion &mbr, id_type id, NodePtr &left, NodePtr &right, TimeRegion &mbr2, id_type id2, bool bInsertMbr2=false)=0
virtual bool insertData(uint32_t dataLength, byte *pData, TimeRegion &mbr, id_type id, std::stack< id_type > &pathBuffer, TimeRegion &mbr2, id_type id2, bool bInsertMbr2=false, bool forceAdjust=false)
virtual NodePtr chooseSubtree(const TimeRegion &mbr, uint32_t level, std::stack< id_type > &pathBuffer)=0
virtual IObject * clone()
id_type m_identifier
Definition Node.h:114
MVRTree * m_pTree
Definition Node.h:107
uint32_t m_children
Definition Node.h:117
uint32_t * m_pDataLength
Definition Node.h:135
virtual bool deleteEntry(uint32_t index)
virtual uint32_t getByteArraySize()
Node(MVRTree *pTree, id_type id, uint32_t level, uint32_t capacity)
TimeRegion m_nodeMBR
Definition Node.h:123
virtual void pickSeeds(uint32_t &index1, uint32_t &index2, uint32_t total)
virtual void getChildShape(uint32_t index, IShape **out) const
TimeRegionPtr * m_ptrMBR
Definition Node.h:129
virtual void getChildData(uint32_t index, uint32_t &length, byte **data) const
virtual void insertData(TimeRegion &mbr1, id_type id1, TimeRegion &mbr2, id_type id2, Node *oldVersion, std::stack< id_type > &pathBuffer)
virtual bool deleteData(id_type id, double delTime, std::stack< id_type > &pathBuffer, bool adjustMBR=false)
virtual id_type getIdentifier() const
virtual void loadFromByteArray(const byte *data)
virtual Node & operator=(const Node &)
byte ** m_pData
Definition Node.h:126
virtual void getShape(IShape **out) const
virtual uint32_t getLevel() const
virtual id_type getChildIdentifier(uint32_t index) const
uint32_t m_capacity
Definition Node.h:120
virtual void storeToByteArray(byte **data, uint32_t &len)
virtual NodePtr findNode(const TimeRegion &mbr, id_type id, std::stack< id_type > &pathBuffer)
id_type * m_pIdentifier
Definition Node.h:132
virtual void insertEntry(uint32_t dataLength, byte *pData, TimeRegion &mbr, id_type id)
virtual void rstarSplit(uint32_t dataLength, byte *pData, TimeRegion &mbr, id_type id, std::vector< uint32_t > &group1, std::vector< uint32_t > &group2, TimeRegion &mbr2, id_type id2, bool bInsertMbr2=false)
virtual NodePtr findLeaf(const TimeRegion &mbr, id_type id, std::stack< id_type > &pathBuffer)=0
virtual void rtreeSplit(uint32_t dataLength, byte *pData, TimeRegion &mbr, id_type id, std::vector< uint32_t > &group1, std::vector< uint32_t > &group2, TimeRegion &mbr2, id_type id2, bool bInsertMbr2=false)
virtual bool isIndex() const
virtual uint32_t getChildrenCount() const
uint32_t m_level
Definition Node.h:110
virtual bool isLeaf() const
uint32_t m_totalDataLength
Definition Node.h:137
double * m_pHigh
Definition Region.h:99
double * m_pLow
Definition Region.h:98
Definition TimeRegion.h:33
Definition PointerPool.h:35
Definition PoolPointer.h:37
Tools::PoolPointer< Node > NodePtr
Definition Node.h:39
Definition CustomStorage.h:34
int64_t id_type
Definition SpatialIndex.h:43