Boost logo

Geometry :

Subject: [ggl] spacial index construction interface
From: Barend Gehrels (barend)
Date: 2011-03-07 18:37:33


Hi Adam,

On 7-3-2011 22:50, Adam Wulkiewicz wrote:
>> Just brainstorming, maybe virtual methods are unavoidable. Still think
>> in a tree with a fixed amount of levels, its behaviour could be fixed so
>> not virtual. But don't know if that is the best solution.
>
> Another thought. There is always root node which is internal node so
> we may store is_leaf condition outside the node. All methods starts
> with root and traverse tree depending on node type anyway.

Something like that, but the if and the static cast still mean a sort of
virtuality.

With fixed amount of level I mean (inspired on your code - not tested
nor complete, only depicting the idea of levels):

// normal, non-leaf node, having staticly typed collection of child-nodes:
template <int Level>
class node
{
   std::vector< boost::tuple<Box, node<Level - 1> > m_children;
   void some_method() {}
};

// specialization for lowest level, Level == 0 - effectively a leaf
template<>
class node<0>
{
   std::vector<Value> m_values;
   void some_method() {} // == some_leaf_method
}

template <int Level>
class rtree
{

// having collection of nodes of highest level, each having collection
of level - 1, etc, until level == 0 which is the leaf.
   std::vector<boost::tuple<Box, node<Level> > m_children;

   void do_something(Box b)
   {
     BOOST_FOREACH(boost::tuple<...> t, m_children)
     {
          t.some_method();
     }
   }
};

Didn't look up the internals of "do_something", it probably finds a
value or a box, but the idea is that it calls it children with all
non-virtual (so inlined) methods.
Is something this feasable?

Regards, Barend

-- 
Barend Gehrels
http://about.me/barendgehrels

Geometry list run by mateusz at loskot.net