QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
PointerPoolNode.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#ifndef __spatialindex_rtree_pointer_pool_node_h
29#define __spatialindex_rtree_pointer_pool_node_h
30
31#include "Node.h"
32
33namespace Tools
34{
35 using namespace SpatialIndex;
36 template<> class PointerPool<RTree::Node>
37 {
38 public:
39 explicit PointerPool(uint32_t capacity) : m_capacity(capacity)
40 {
41 #ifndef NDEBUG
42 m_hits = 0;
43 m_misses = 0;
45 #endif
46 }
47
49 {
50 assert(m_pool.size() <= m_capacity);
51
52 while (! m_pool.empty())
53 {
54 RTree::Node* x = m_pool.top(); m_pool.pop();
55 #ifndef NDEBUG
57 #endif
58 delete x;
59 }
60
61 #ifndef NDEBUG
62 std::cerr << "Lost pointers: " << m_pointerCount << std::endl;
63 #endif
64 }
65
67 {
68 if (! m_pool.empty())
69 {
70 RTree::Node* p = m_pool.top(); m_pool.pop();
71 #ifndef NDEBUG
72 ++m_hits;
73 #endif
74
75 return PoolPointer<RTree::Node>(p, this);
76 }
77 #ifndef NDEBUG
78 else
79 {
80 // fixme: well sort of...
82 ++m_misses;
83 }
84 #endif
85
87 }
88
90 {
91 if (p != 0)
92 {
93 if (m_pool.size() < m_capacity)
94 {
95 if (p->m_pData != 0)
96 {
97 for (uint32_t cChild = 0; cChild < p->m_children; ++cChild)
98 {
99 // there is no need to set the pointer to zero, after deleting it,
100 // since it will be redeleted only if it is actually initialized again,
101 // a fact that will be depicted by variable m_children.
102 if (p->m_pData[cChild] != 0) delete[] p->m_pData[cChild];
103 }
104 }
105
106 p->m_level = 0;
107 p->m_identifier = -1;
108 p->m_children = 0;
109 p->m_totalDataLength = 0;
110
111 m_pool.push(p);
112 }
113 else
114 {
115 #ifndef NDEBUG
117 #endif
118 delete p;
119 }
120
121 assert(m_pool.size() <= m_capacity);
122 }
123 }
124
125 uint32_t getCapacity() const { return m_capacity; }
126 void setCapacity(uint32_t c)
127 {
128 assert (c >= 0);
129 m_capacity = c;
130 }
131
132 protected:
133 uint32_t m_capacity;
134 std::stack<RTree::Node*> m_pool;
135
136 #ifndef NDEBUG
137 public:
138 uint64_t m_hits;
139 uint64_t m_misses;
141 #endif
142 };
143}
144
145#endif /* __spatialindex_rtree_pointer_pool_node_h */
Definition Node.h:42
uint32_t m_level
Definition Node.h:102
uint32_t m_totalDataLength
Definition Node.h:129
id_type m_identifier
Definition Node.h:106
byte ** m_pData
Definition Node.h:118
uint32_t m_children
Definition Node.h:109
uint32_t m_capacity
Definition PointerPoolNode.h:133
uint64_t m_hits
Definition PointerPoolNode.h:138
PoolPointer< RTree::Node > acquire()
Definition PointerPoolNode.h:66
PointerPool(uint32_t capacity)
Definition PointerPoolNode.h:39
void setCapacity(uint32_t c)
Definition PointerPoolNode.h:126
std::stack< RTree::Node * > m_pool
Definition PointerPoolNode.h:134
uint32_t getCapacity() const
Definition PointerPoolNode.h:125
~PointerPool()
Definition PointerPoolNode.h:48
uint64_t m_misses
Definition PointerPoolNode.h:139
void release(RTree::Node *p)
Definition PointerPoolNode.h:89
uint64_t m_pointerCount
Definition PointerPoolNode.h:140
Definition PointerPool.h:35
uint32_t m_capacity
Definition PointerPool.h:112
uint64_t m_hits
Definition PointerPool.h:117
uint64_t m_pointerCount
Definition PointerPool.h:119
std::stack< X * > m_pool
Definition PointerPool.h:113
uint64_t m_misses
Definition PointerPool.h:118
Definition PoolPointer.h:37
Definition CustomStorage.h:34
Definition PointerPool.h:33