简体   繁体   English

C ++空间索引库:从磁盘加载/存储主内存RTree

[英]C++ spatialindex library: loading/storing main memory RTree from/to disk

I have created a main memory R* index with the help of spatialindex library in the following way (DBStream implements the interface for bulkLoading) 我已通过以下方式借助spatialindex库创建了一个主内存R *索引(DBStream实现了bulkLoading的接口)

// creating a main memory RTree
memStorage = StorageManager::createNewMemoryStorageManager();

size_t capacity = 1024;
bool bWriteThrough = false;
fileInMem = StorageManager
   ::createNewRandomEvictionsBuffer(*memStorage, capacity, bWriteThrough);

DBStream dstream(streets);

tree = RTree::createAndBulkLoadNewRTree(SpatialIndex::RTree::BLM_STR, dstream,
   *fileInMem,
   fillFactor, indexCapacity,
   leafCapacity, dimension, rv, indexIdentifier);

My data is read-only, ie, I want to build the tree only once, save it, and reload from persistent storage every time I use my program. 我的数据是只读的,即,我只想构建一次树,保存它,并在每次使用程序时从持久性存储中重新加载。 Clearly, I can save and load the memStorage myself, but how to recreate the RTree from it? 显然,我可以自己保存和加载memStorage,但是如何从中重新创建RTree?

Since you are bulk-loading the tree anyway, there is little to gain here, actually. 因为无论如何都是批量加载树,所以实际上没有什么好处。 All that a STR bulk load does is sort the data. STR批量加载所做的只是对数据进行排序。 This is O(n log n) theoretically, but if you have the data sorted appropriately it will actually be in O(n) with most sorting implementations. 理论上,这是O(n log n) ,但是如果您对数据进行了适当的排序,则在大多数排序实现中,它实际上都将位于O(n)

So most likely, serializing the tree into a file and back is not much cheaper than bulk-loading it again each time. 因此,最有可能的是,将树序列化为文件并返回并不比每次再次批量加载便宜。 It does take away some flexibility though. 不过,它确实失去了一些灵活性。

R-Trees in general are meant for dynamic data IMHO. R树通常用于动态数据恕我直言。 Sure, they do work for static data. 当然,它们确实适用于静态数据。 But their key strength (opposed to other structures) is that the tree supports balancing on insert. 但是它们的关键优势(与其他结构相反)是树支持插入时的平衡。

After extensive research I must conclude that it is possible to save the MainMemoryStorage object but it is impossible to load it. 经过广泛研究,我必须得出结论,可以保存MainMemoryStorage对象,但无法加载它。 Saving the object is possible through a derived class, that keeps track of all used page IDs (and later saving them to the file). 可以通过派生类保存对象,该派生类跟踪所有已使用的页面ID(以后将它们保存到文件中)。 Loading these pages is very problematic as one needs a direct access to 加载这些页面非常麻烦,因为需要直接访问

std::vector<Entry*> m_buffer;
std::stack<id_type> m_emptyPages;

from MemoryStorageManager.h. 从MemoryStorageManager.h。 These guys are private, and the MemoryStorageManager.h is not available as this is a private include available only to spatiallibrary. 这些人是私有的,MemoryStorageManager.h不可用,因为这是仅适用于空间库的私有包含。

What a depressing answer. 真是令人沮丧的答案。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM