From 8521b5501f487aab57d5f6cff0f08b3f3bcf7e91 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 3558fad9a..c3e89408d 100644 --- a/DataStructures/StaticGraph.h +++ b/DataStructures/StaticGraph.h @@ -85,8 +85,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(); @@ -196,8 +196,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 82e4f726a..702022848 100644 --- a/DataStructures/StaticRTree.h +++ b/DataStructures/StaticRTree.h @@ -21,11 +21,15 @@ or see http://www.gnu.org/licenses/agpl.txt. #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" @@ -41,6 +45,7 @@ or see http://www.gnu.org/licenses/agpl.txt. #include #include #include +#include #include #include @@ -59,7 +64,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 { @@ -276,7 +281,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; @@ -429,7 +434,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");