QCAD
Open Source 2D CAD
Loading...
Searching...
No Matches
BulkLoader.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 RTree
33 {
35 {
36 public:
37 class Record
38 {
39 public:
41 Record(const Region& r, id_type id, uint32_t len, byte* pData, uint32_t s);
43
44 bool operator<(const Record& r) const;
45
48
49 struct SortAscending : public std::binary_function<Record* const, Record* const, bool>
50 {
51 bool operator()(Record* const r1, Record* const r2)
52 {
53 if (*r1 < *r2) return true;
54 else return false;
55 }
56 };
57
58 public:
61 uint32_t m_len;
62 byte* m_pData;
63 uint32_t m_s;
64 };
65
66 public:
67 ExternalSorter(uint32_t u32PageSize, uint32_t u32BufferPages);
68 virtual ~ExternalSorter();
69
70 void insert(Record* r);
71 void sort();
73 uint64_t getTotalEntries() const;
74
75 private:
76 class PQEntry
77 {
78 public:
79 PQEntry(Record* r, uint32_t u32Index) : m_r(r), m_u32Index(u32Index) {}
80
81 struct SortAscending : public std::binary_function<const PQEntry&, const PQEntry&, bool>
82 {
83 bool operator()(const PQEntry& e1, const PQEntry& e2)
84 {
85 if (*(e1.m_r) < *(e2.m_r)) return true;
86 else return false;
87 }
88 };
89
91 uint32_t m_u32Index;
92 };
93
94 private:
96 uint32_t m_u32PageSize;
99 std::list<Tools::SmartPointer<Tools::TemporaryFile> > m_runs;
100 std::vector<Record*> m_buffer;
102 uint32_t m_stI;
103 };
104
106 {
107 public:
109 RTree* pTree,
110 IDataStream& stream,
111 uint32_t bindex,
112 uint32_t bleaf,
113 uint32_t pageSize, // The number of node entries per page.
114 uint32_t numberOfPages // The total number of pages to use.
115 );
116
117 protected:
119 RTree* pTree,
121 uint32_t dimension,
122 uint32_t indexSize,
123 uint32_t leafSize,
124 uint32_t level,
126 uint32_t pageSize,
127 uint32_t numberOfPages
128 );
129
131 RTree* pTree,
132 std::vector<ExternalSorter::Record*>& e,
133 uint32_t level
134 );
135 };
136 }
137}
Definition SpatialIndex.h:134
Definition BulkLoader.h:106
Node * createNode(RTree *pTree, std::vector< ExternalSorter::Record * > &e, uint32_t level)
void createLevel(RTree *pTree, Tools::SmartPointer< ExternalSorter > es, uint32_t dimension, uint32_t indexSize, uint32_t leafSize, uint32_t level, Tools::SmartPointer< ExternalSorter > es2, uint32_t pageSize, uint32_t numberOfPages)
void bulkLoadUsingSTR(RTree *pTree, IDataStream &stream, uint32_t bindex, uint32_t bleaf, uint32_t pageSize, uint32_t numberOfPages)
Definition BulkLoader.h:77
PQEntry(Record *r, uint32_t u32Index)
Definition BulkLoader.h:79
Record * m_r
Definition BulkLoader.h:90
uint32_t m_u32Index
Definition BulkLoader.h:91
id_type m_id
Definition BulkLoader.h:60
byte * m_pData
Definition BulkLoader.h:62
Region m_r
Definition BulkLoader.h:59
Record(const Region &r, id_type id, uint32_t len, byte *pData, uint32_t s)
uint32_t m_s
Definition BulkLoader.h:63
void storeToFile(Tools::TemporaryFile &f)
uint32_t m_len
Definition BulkLoader.h:61
bool operator<(const Record &r) const
void loadFromFile(Tools::TemporaryFile &f)
Definition BulkLoader.h:35
uint32_t m_stI
Definition BulkLoader.h:102
std::list< Tools::SmartPointer< Tools::TemporaryFile > > m_runs
Definition BulkLoader.h:99
uint32_t m_u32BufferPages
Definition BulkLoader.h:97
ExternalSorter(uint32_t u32PageSize, uint32_t u32BufferPages)
uint32_t m_u32PageSize
Definition BulkLoader.h:96
Tools::SmartPointer< Tools::TemporaryFile > m_sortedFile
Definition BulkLoader.h:98
std::vector< Record * > m_buffer
Definition BulkLoader.h:100
uint64_t m_u64TotalEntries
Definition BulkLoader.h:101
bool m_bInsertionPhase
Definition BulkLoader.h:95
Definition Node.h:42
Definition RTree.h:39
Definition Region.h:33
Definition SmartPointer.h:33
Definition Tools.h:475
Definition CustomStorage.h:34
int64_t id_type
Definition SpatialIndex.h:43
char s
Definition opennurbs_string.cpp:32
Definition BulkLoader.h:82
bool operator()(const PQEntry &e1, const PQEntry &e2)
Definition BulkLoader.h:83
bool operator()(Record *const r1, Record *const r2)
Definition BulkLoader.h:51