libspatialindex API Reference  (git-trunk)
rtree/Statistics.cc
Go to the documentation of this file.
1 /******************************************************************************
2  * Project: libspatialindex - A C++ library for spatial indexing
3  * Author: Marios Hadjieleftheriou, mhadji@gmail.com
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 
29 
30 #include "Statistics.h"
31 
32 using namespace SpatialIndex::RTree;
33 
35 {
36  reset();
37 }
38 
40 {
41  m_u64Reads = s.m_u64Reads;
42  m_u64Writes = s.m_u64Writes;
43  m_u64Splits = s.m_u64Splits;
44  m_u64Hits = s.m_u64Hits;
45  m_u64Misses = s.m_u64Misses;
46  m_u32Nodes = s.m_u32Nodes;
47  m_u64Adjustments = s.m_u64Adjustments;
48  m_u64QueryResults = s.m_u64QueryResults;
49  m_u64Data = s.m_u64Data;
50  m_u32TreeHeight = s.m_u32TreeHeight;
51  m_nodesInLevel = s.m_nodesInLevel;
52 }
53 
55 = default;
56 
58 {
59  if (this != &s)
60  {
61  m_u64Reads = s.m_u64Reads;
62  m_u64Writes = s.m_u64Writes;
63  m_u64Splits = s.m_u64Splits;
64  m_u64Hits = s.m_u64Hits;
65  m_u64Misses = s.m_u64Misses;
66  m_u32Nodes = s.m_u32Nodes;
67  m_u64Adjustments = s.m_u64Adjustments;
68  m_u64QueryResults = s.m_u64QueryResults;
69  m_u64Data = s.m_u64Data;
70  m_u32TreeHeight = s.m_u32TreeHeight;
71  m_nodesInLevel = s.m_nodesInLevel;
72  }
73 
74  return *this;
75 }
76 
77 uint64_t Statistics::getReads() const
78 {
79  return m_u64Reads;
80 }
81 
82 uint64_t Statistics::getWrites() const
83 {
84  return m_u64Writes;
85 }
86 
88 {
89  return m_u32Nodes;
90 }
91 
93 {
94  return m_u64Data;
95 }
96 
97 uint64_t Statistics::getSplits() const
98 {
99  return m_u64Splits;
100 }
101 
102 uint64_t Statistics::getHits() const
103 {
104  return m_u64Hits;
105 }
106 
107 uint64_t Statistics::getMisses() const
108 {
109  return m_u64Misses;
110 }
111 
113 {
114  return m_u64Adjustments;
115 }
116 
118 {
119  return m_u64QueryResults;
120 }
121 
123 {
124  return m_u32TreeHeight;
125 }
126 
127 uint32_t Statistics::getNumberOfNodesInLevel(uint32_t l) const
128 {
129  uint32_t u32Nodes;
130  try
131  {
132  u32Nodes = m_nodesInLevel.at(l);
133  }
134  catch (...)
135  {
137  }
138 
139  return u32Nodes;
140 }
141 
142 void Statistics::reset()
143 {
144  m_u64Reads = 0;
145  m_u64Writes = 0;
146  m_u64Splits = 0;
147  m_u64Hits = 0;
148  m_u64Misses = 0;
149  m_u32Nodes = 0;
150  m_u64Adjustments = 0;
151  m_u64QueryResults = 0;
152  m_u64Data = 0;
153  m_u32TreeHeight = 0;
154  m_nodesInLevel.clear();
155 }
156 
157 std::ostream& SpatialIndex::RTree::operator<<(std::ostream& os, const Statistics& s)
158 {
159  os << "Reads: " << s.m_u64Reads << std::endl
160  << "Writes: " << s.m_u64Writes << std::endl
161  << "Hits: " << s.m_u64Hits << std::endl
162  << "Misses: " << s.m_u64Misses << std::endl
163  << "Tree height: " << s.m_u32TreeHeight << std::endl
164  << "Number of data: " << s.m_u64Data << std::endl
165  << "Number of nodes: " << s.m_u32Nodes << std::endl;
166 
167  for (uint32_t u32Level = 0; u32Level < s.m_u32TreeHeight; ++u32Level)
168  {
169  os << "Level " << u32Level << " pages: " << s.m_nodesInLevel[u32Level] << std::endl;
170  }
171 
172  os << "Splits: " << s.m_u64Splits << std::endl
173  << "Adjustments: " << s.m_u64Adjustments << std::endl
174  << "Query results: " << s.m_u64QueryResults << std::endl;
175 
176  return os;
177 }
virtual uint64_t getAdjustments() const
uint32_t getNumberOfNodes() const override
virtual uint32_t getTreeHeight() const
virtual uint64_t getSplits() const
uint64_t getNumberOfData() const override
virtual uint64_t getMisses() const
uint64_t getWrites() const override
Statistics & operator=(const Statistics &)
virtual uint32_t getNumberOfNodesInLevel(uint32_t l) const
virtual uint64_t getHits() const
virtual uint64_t getQueryResults() const
uint64_t getReads() const override
std::ostream & operator<<(std::ostream &os, const RTree &t)
Definition: RTree.cc:1547