Boost logo

Boost-Commit :

Subject: [Boost-commit] svn:boost r85392 - in sandbox/geometry/boost/geometry/index: . detail/rtree
From: adam.wulkiewicz_at_[hidden]
Date: 2013-08-18 11:34:47


Author: awulkiew
Date: 2013-08-18 11:34:45 EDT (Sun, 18 Aug 2013)
New Revision: 85392
URL: http://svn.boost.org/trac/boost/changeset/85392

Log:
[sandbox][geometry][index] added: Storage template parameter to the rtree, empty rtree_storage, some fixes and comments

Text files modified:
   sandbox/geometry/boost/geometry/index/detail/rtree/adaptors.hpp | 9 ++----
   sandbox/geometry/boost/geometry/index/detail/rtree/storage_manager.hpp | 59 +++++++++++++++++++++++++++++++++++----
   sandbox/geometry/boost/geometry/index/rtree.hpp | 23 ++++++++++++++
   3 files changed, 77 insertions(+), 14 deletions(-)

Modified: sandbox/geometry/boost/geometry/index/detail/rtree/adaptors.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/index/detail/rtree/adaptors.hpp Sun Aug 18 11:10:24 2013 (r85391)
+++ sandbox/geometry/boost/geometry/index/detail/rtree/adaptors.hpp 2013-08-18 11:34:45 EDT (Sun, 18 Aug 2013) (r85392)
@@ -18,13 +18,10 @@
 
 namespace boost { namespace geometry { namespace index {
 
-template <typename Value, typename Options, typename IndexableGetter, typename EqualTo, typename Allocator>
-class rtree;
-
 namespace adaptors { namespace detail {
 
-template <typename Value, typename Options, typename IndexableGetter, typename EqualTo, typename Allocator>
-class query_range< index::rtree<Value, Options, IndexableGetter, EqualTo, Allocator> >
+template <typename Value, typename Options, typename IndexableGetter, typename EqualTo, typename Allocator, typename Storage>
+class query_range< index::rtree<Value, Options, IndexableGetter, EqualTo, Allocator, Storage> >
 {
 public:
     typedef std::vector<Value> result_type;
@@ -32,7 +29,7 @@
     typedef typename result_type::const_iterator const_iterator;
 
     template <typename Predicates> inline
- query_range(index::rtree<Value, Options, IndexableGetter, EqualTo, Allocator> const& rtree,
+ query_range(index::rtree<Value, Options, IndexableGetter, EqualTo, Allocator, Storage> const& rtree,
                 Predicates const& pred)
     {
         rtree.query(pred, std::back_inserter(m_result));

Modified: sandbox/geometry/boost/geometry/index/detail/rtree/storage_manager.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/index/detail/rtree/storage_manager.hpp Sun Aug 18 11:10:24 2013 (r85391)
+++ sandbox/geometry/boost/geometry/index/detail/rtree/storage_manager.hpp 2013-08-18 11:34:45 EDT (Sun, 18 Aug 2013) (r85392)
@@ -139,7 +139,7 @@
     }
 
 // INFO
-// Nodes aren't stored during acquire
+// Nodes aren't stored during acquire - dismiss
 
     template <typename Node>
     void acquire(storage_node_pointer & ptr)
@@ -157,7 +157,8 @@
 // WARNING!
 // Can't destroy node in dismiss if it were modified
 
-// is dismiss really needed since nodes will be unloaded in flush()
+// Dismiss will probably be used only in nonmodyfying operations, like queries
+// If cacheing were used, acquire and dismiss should also store nodes in the map
 
     template <typename Node>
     void dismiss(storage_node_pointer & ptr)
@@ -165,6 +166,8 @@
 // TODO - not thread safe
 
         BOOST_GEOMETRY_INDEX_ASSERT(ptr.get(), "node should be acquired before dismiss");
+// TODO - Later disable this assertion?
+ BOOST_GEOMETRY_INDEX_ASSERT(m_nodes.find(ptr) == m_nodes.end(), "can't dismiss modified node");
 
         rtree::destroy_node<Allocators, Node>(allocators(), ptr.get()); // shouldn't throw
         storage().unload_node(ptr.id()); // may throw?
@@ -172,8 +175,6 @@
         ptr = storage_node_pointer(node_pointer(0), ptr.id());
     }
 
- //enum operation { none, query, insert, remove, copy };
- // or
     enum operation { none, nonmodifying, incremental, immediate };
 
     void operation_begin(operation o) {}
@@ -212,7 +213,7 @@
 
     storage_node_pointer root() { return null(); }
 
- storage_node_pointer null() { return storage_node_pointer(node_pointer(0), 0); }
+ storage_node_pointer null() { return storage_node_pointer(node_pointer(0), storage().null_id()); }
 
 private:
     enum flag { unloaded, loaded, modified, destroyed };
@@ -285,6 +286,52 @@
     operation m_current_operation;
 };
 
+}}}}} // namespace boost::geometry::index::detail::rtree
+
+namespace boost { namespace geometry { namespace index {
+
+struct none {};
+
+// rtree empty storage
+class rtree_storage
+{
+ // TODO
+ // there must be a way to load the header and retrieve needed data
+
+public:
+ typedef uintptr_t node_id;
+ typedef std::size_t size_type;
+
+ node_id null_id() { return 0; }
+
+ // or maybe return header?
+ node_id root_id() { return null_id(); }
+
+ template <typename T>
+ node_id new_id(T seed)
+ {
+ BOOST_STATIC_ASSERT(sizeof(T) <= sizeof(node_id));
+ return static_cast<node_id>(seed);
+ }
+
+ void destroy_node(node_id id) {}
+
+ template <typename Node> // leaf or internal_node
+ void save_node(node_id id, Node const& n) {}
+
+ template <typename Node> // leaf or internal_node
+ void load_node(node_id id, Node & n) {}
+
+ void save_begin() {}
+ void save_end() {}
+ // ?
+ void load_begin() {}
+ void load_end() {}
+ // or operation_begin(nonmodifying|incremental|immediate)s
+};
+
+}}} // namespace boost::geometry::index
+
 // Also the header must be loaded/saved
 
 // rename to serializing_storage
@@ -400,6 +447,4 @@
 // v v
 // some_nodes_data_manager
 
-}}}}} // namespace boost::geometry::index::detail::rtree
-
 #endif // BOOST_GEOMETRY_INDEX_DETAIL_RTREE_STORAGE_MANAGER_HPP

Modified: sandbox/geometry/boost/geometry/index/rtree.hpp
==============================================================================
--- sandbox/geometry/boost/geometry/index/rtree.hpp Sun Aug 18 11:10:24 2013 (r85391)
+++ sandbox/geometry/boost/geometry/index/rtree.hpp 2013-08-18 11:34:45 EDT (Sun, 18 Aug 2013) (r85392)
@@ -19,6 +19,15 @@
 
 #include <boost/geometry/geometry.hpp>
 
+// forward declaration
+
+namespace boost { namespace geometry { namespace index {
+
+template <typename Value, typename Options, typename IndexableGetter, typename EqualTo, typename Allocator, typename Storage>
+class rtree;
+
+}}} // namespace boost::geometry::index
+
 #include <boost/geometry/index/detail/config_begin.hpp>
 
 #include <boost/geometry/index/detail/assert.hpp>
@@ -39,6 +48,8 @@
 #include <boost/geometry/index/detail/utilities.hpp>
 #include <boost/geometry/index/detail/rtree/node/node.hpp>
 
+#include <boost/geometry/index/detail/rtree/storage_manager.hpp>
+
 #include <boost/geometry/index/detail/algorithms/is_valid.hpp>
 
 #include <boost/geometry/index/detail/rtree/visitors/insert.hpp>
@@ -121,7 +132,8 @@
     typename Parameters,
     typename IndexableGetter = index::indexable<Value>,
     typename EqualTo = index::equal_to<Value>,
- typename Allocator = std::allocator<Value>
+ typename Allocator = std::allocator<Value>,
+ typename Storage = index::none
>
 class rtree
 {
@@ -172,6 +184,15 @@
     typedef ::boost::container::allocator_traits<Allocator> allocator_traits_type;
     typedef detail::rtree::node_auto_ptr<value_type, options_type, translator_type, box_type, allocators_type> node_auto_ptr;
 
+ typedef detail::rtree::storage_manager<Value, options_type, translator_type, box_type, allocators_type, Storage> storage_manager;
+
+ // storage_node_pointer must be stored in nodes
+ // so storage or storage manager must be passed as node's template parameter
+ // also to all visitors and other classes/structs
+ // storage_size_type must be used to count rtree values
+ // this may be different type than allocator::size_type
+ // value of this type will be returned by size(), count() and probably query()
+
     friend class detail::rtree::utilities::view<rtree>;
 
 public:


Boost-Commit list run by bdawes at acm.org, david.abrahams at rcn.com, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk