libspatialindex API Reference  (git-trunk)
BulkLoader.h
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 
28 #pragma once
29 
30 #include <memory>
31 
32 namespace SpatialIndex
33 {
34  namespace RTree
35  {
37  {
38  public:
39  class Record
40  {
41  public:
42  Record();
43  Record(const Region& r, id_type id, uint32_t len, uint8_t* pData, uint32_t s);
44  ~Record();
45 
46  bool operator<(const Record& r) const;
47 
50 
52  {
53  bool operator()(Record* const r1, Record* const r2)
54  {
55  if (*r1 < *r2) return true;
56  else return false;
57  }
58  };
59 
60  public:
63  uint32_t m_len;
64  uint8_t* m_pData{nullptr};
65  uint32_t m_s;
66  };
67 
68  public:
69  ExternalSorter(uint32_t u32PageSize, uint32_t u32BufferPages);
70  virtual ~ExternalSorter();
71 
72  void insert(Record* r);
73  void sort();
75  uint64_t getTotalEntries() const;
76 
77  private:
78  class PQEntry
79  {
80  public:
81  PQEntry(Record* r, uint32_t u32Index) : m_r(r), m_u32Index(u32Index) {}
82 
84  {
85  bool operator()(const PQEntry& e1, const PQEntry& e2)
86  {
87  if (*(e1.m_r) < *(e2.m_r)) return true;
88  else return false;
89  }
90  };
91 
92  Record* m_r;
93  uint32_t m_u32Index;
94  };
95 
96  private:
97  bool m_bInsertionPhase;
98  uint32_t m_u32PageSize;
99  uint32_t m_u32BufferPages;
100  std::shared_ptr<Tools::TemporaryFile> m_sortedFile;
101  std::list<std::shared_ptr<Tools::TemporaryFile> > m_runs;
102  std::vector<Record*> m_buffer;
103  uint64_t m_u64TotalEntries;
104  uint32_t m_stI;
105  };
106 
108  {
109  public:
110  void bulkLoadUsingSTR(
111  RTree* pTree,
112  IDataStream& stream,
113  uint32_t bindex,
114  uint32_t bleaf,
115  uint32_t pageSize, // The number of node entries per page.
116  uint32_t numberOfPages // The total number of pages to use.
117  );
118 
119  protected:
120  void createLevel(
121  RTree* pTree,
122  std::shared_ptr<ExternalSorter> es,
123  uint32_t dimension,
124  uint32_t indexSize,
125  uint32_t leafSize,
126  uint32_t level,
127  std::shared_ptr<ExternalSorter> es2,
128  uint32_t pageSize,
129  uint32_t numberOfPages
130  );
131 
132  Node* createNode(
133  RTree* pTree,
134  std::vector<ExternalSorter::Record*>& e,
135  uint32_t level
136  );
137  };
138  }
139 }
void createLevel(RTree *pTree, std::shared_ptr< ExternalSorter > es, uint32_t dimension, uint32_t indexSize, uint32_t leafSize, uint32_t level, std::shared_ptr< ExternalSorter > es2, uint32_t pageSize, uint32_t numberOfPages)
Definition: BulkLoader.cc:381
void bulkLoadUsingSTR(RTree *pTree, IDataStream &stream, uint32_t bindex, uint32_t bleaf, uint32_t pageSize, uint32_t numberOfPages)
Definition: BulkLoader.cc:320
Node * createNode(RTree *pTree, std::vector< ExternalSorter::Record * > &e, uint32_t level)
Definition: BulkLoader.cc:449
bool operator<(const Record &r) const
Definition: BulkLoader.cc:62
void loadFromFile(Tools::TemporaryFile &f)
Definition: BulkLoader.cc:89
void storeToFile(Tools::TemporaryFile &f)
Definition: BulkLoader.cc:73
ExternalSorter(uint32_t u32PageSize, uint32_t u32BufferPages)
Definition: BulkLoader.cc:118
int64_t id_type
Definition: SpatialIndex.h:41
bool operator()(const PQEntry &e1, const PQEntry &e2)
Definition: BulkLoader.h:85
bool operator()(Record *const r1, Record *const r2)
Definition: BulkLoader.h:53