From 37e3ead8e96fd9ac419637a558bfa81048c3e95e Mon Sep 17 00:00:00 2001 From: Dennis Luxen Date: Mon, 23 Sep 2013 18:03:07 +0200 Subject: [PATCH] use flexible shared mem interfaces --- DataStructures/StaticGraph.h | 8 ++++---- DataStructures/StaticRTree.h | 36 ++++++++++++++++++++++++++++++++---- 2 files changed, 36 insertions(+), 8 deletions(-) diff --git a/DataStructures/StaticGraph.h b/DataStructures/StaticGraph.h index 74bfdfac9..eabc062c7 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -92,8 +92,8 @@ public: } StaticGraph( - ShMemVector<_StrNode, UseSharedMemory> & nodes, - ShMemVector<_StrEdge, UseSharedMemory> & edges + typename ShM<_StrNode, UseSharedMemory>::vector & nodes, + typename ShM<_StrEdge, UseSharedMemory>::vector & edges ) { _numNodes = nodes.size(); _numEdges = edges.size(); @@ -203,8 +203,8 @@ private: NodeIterator _numNodes; EdgeIterator _numEdges; - ShMemVector< _StrNode, UseSharedMemory > _nodes; - ShMemVector< _StrEdge, UseSharedMemory > _edges; + typename ShM< _StrNode, UseSharedMemory >::vector _nodes; + typename ShM< _StrEdge, UseSharedMemory >::vector _edges; }; #endif // STATICGRAPH_H_INCLUDED diff --git a/DataStructures/StaticRTree.h b/DataStructures/StaticRTree.h index 3ecd4ad83..636a0af3b 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -28,11 +28,15 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #ifndef STATICRTREE_H_ #define STATICRTREE_H_ -#include "MercatorUtil.h" #include "Coordinate.h" -#include "PhantomNodes.h" #include "DeallocatingVector.h" #include "HilbertValue.h" +#include "MercatorUtil.h" +#include "PhantomNodes.h" +#include "SharedMemoryFactory.h" +#include "SharedMemoryVectorWrapper.h" + +#include "../Server/DataStructures/SharedDataType.h" #include "../Util/OSRMException.h" #include "../Util/SimpleLogger.h" #include "../Util/TimingUtil.h" @@ -48,6 +52,7 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. #include #include #include +#include #include #include @@ -63,7 +68,7 @@ const static uint32_t RTREE_LEAF_NODE_SIZE = 1170; static boost::thread_specific_ptr thread_local_rtree_stream; -template +template class StaticRTree : boost::noncopyable { private: struct RectangleInt2D { @@ -280,7 +285,7 @@ private: } }; - std::vector m_search_tree; + typename ShM::vector m_search_tree; uint64_t m_element_count; const std::string m_leaf_node_filename; @@ -433,7 +438,30 @@ public: m_search_tree.resize(tree_size); tree_node_file.read((char*)&m_search_tree[0], sizeof(TreeNode)*tree_size); tree_node_file.close(); + //open leaf node file and store thread specific pointer + if ( !boost::filesystem::exists( leaf_file ) ) { + throw OSRMException("mem index file does not exist"); + } + if ( 0 == boost::filesystem::file_size( leaf_file ) ) { + throw OSRMException("mem index file is empty"); + } + boost::filesystem::ifstream leaf_node_file( leaf_file, std::ios::binary ); + leaf_node_file.read((char*)&m_element_count, sizeof(uint64_t)); + leaf_node_file.close(); + + //SimpleLogger().Write() << tree_size << " nodes in search tree"; + //SimpleLogger().Write() << m_element_count << " elements in leafs"; + } + + //Read-only operation for queries + explicit StaticRTree( + const TreeNode * tree_node_ptr, + const uint32_t number_of_nodes, + const boost::filesystem::path & leaf_file + ) : m_leaf_node_filename(leaf_file.string()), + m_search_tree(tree_node_ptr, number_of_nodes) + { //open leaf node file and store thread specific pointer if ( !boost::filesystem::exists( leaf_file ) ) { throw OSRMException("mem index file does not exist");