[PATCH] Dynamic dimensions

Willi Richert w.richert at gmx.net
Fri Mar 27 18:32:15 UTC 2009


commit 75b3bc24d068ee55c1f9373e0d5fab947469156b
Author: Willi Richert <w.richert at gmx.net>
Date:   Fri Mar 27 19:23:28 2009 +0100

    first version with dynamic dimensions

    has lots of debugging information

Signed-off-by: Willi Richert <w.richert at gmx.net>
---
 examples/Makefile        |    4 +-
 examples/test_kdtree.cpp |   29 +++++++++-----
 kdtree++/iterator.hpp    |    2 +-
 kdtree++/kdtree.hpp      |   93 ++++++++++++++++++++++++++--------------------
 kdtree++/node.hpp        |    4 +-
 kdtree++/region.hpp      |   71 ++++++++++++++++++++++++++--------
 6 files changed, 130 insertions(+), 73 deletions(-)

diff --git a/examples/Makefile b/examples/Makefile
index b73b40a..3e3ad3c 100644
--- a/examples/Makefile
+++ b/examples/Makefile
@@ -1,6 +1,6 @@
-all: test_kdtree test_hayne
+all: test_kdtree #test_hayne
 
-test_kdtree: test_kdtree.cpp
+test_kdtree: test_kdtree.cpp ../kdtree++/*.hpp
 	g++ -I.. -Wall -ansi -pedantic -g -O2 -o test_kdtree test_kdtree.cpp
 
 test_hayne: test_hayne.cpp
diff --git a/examples/test_kdtree.cpp b/examples/test_kdtree.cpp
index 4a0b05e..c169adf 100644
--- a/examples/test_kdtree.cpp
+++ b/examples/test_kdtree.cpp
@@ -100,7 +100,7 @@ struct alternate_tac
 };
 
 
-typedef KDTree::KDTree<3, triplet, std::pointer_to_binary_function<triplet,size_t,double> > tree_type;
+typedef KDTree::KDTree<triplet, std::pointer_to_binary_function<triplet,size_t,double> > tree_type;
 
 struct Predicate
 {
@@ -120,7 +120,7 @@ int main()
 {
    // check that it'll find nodes exactly MAX away
    {
-      tree_type exact_dist(std::ptr_fun(tac));
+     tree_type exact_dist(3, std::ptr_fun(tac));
         triplet c0(5, 4, 0);
         exact_dist.insert(c0);
         triplet target(7,4,0);
@@ -134,11 +134,11 @@ int main()
    // do the same test, except use alternate_triplet as the search key
    {
       // NOTE: stores triplet, but we search with alternate_triplet
-      typedef KDTree::KDTree<3, triplet, alternate_tac> alt_tree;
+      typedef KDTree::KDTree<triplet, alternate_tac> alt_tree;
 
       triplet actual_target(7,0,0);
 
-      alt_tree tree;
+      alt_tree tree(3);
       tree.insert( triplet(0, 0, 7) );
       tree.insert( triplet(0, 0, 7) );
       tree.insert( triplet(0, 0, 7) );
@@ -157,7 +157,7 @@ int main()
 
 
    {
-      tree_type exact_dist(std::ptr_fun(tac));
+     tree_type exact_dist(3, std::ptr_fun(tac));
         triplet c0(5, 2, 0);
         exact_dist.insert(c0);
         triplet target(7,4,0);
@@ -170,7 +170,7 @@ int main()
    }
 
    {
-      tree_type exact_dist(std::ptr_fun(tac));
+     tree_type exact_dist(3, std::ptr_fun(tac));
         triplet c0(5, 2, 0);
         exact_dist.insert(c0);
         triplet target(7,4,0);
@@ -181,7 +181,7 @@ int main()
       assert(found.second == sqrt(8));
    }
 
-  tree_type src(std::ptr_fun(tac));
+   tree_type src(3, std::ptr_fun(tac));
 
   triplet c0(5, 4, 0); src.insert(c0);
   triplet c1(4, 2, 1); src.insert(c1);
@@ -193,17 +193,16 @@ int main()
   triplet c7(9, 7, 3); src.insert(c7);
   triplet c8(2, 2, 6); src.insert(c8);
   triplet c9(2, 0, 6); src.insert(c9);
-
   std::cout << src << std::endl;
 
   src.erase(c0);
   src.erase(c1);
   src.erase(c3);
   src.erase(c5);
-
   src.optimise();
 
 
+
   // test the efficient_replace_and_optimise()
   tree_type eff_repl = src;
   {
@@ -223,12 +222,20 @@ int main()
      eff_repl.efficient_replace_and_optimise(vec);
   }
 
+  triplet sx(5, 4, 3);
+  unsigned int const RANGEx = 3;
+  
+  size_t count = src.count_within_range(sx, RANGEx);
+  std::cout << "########## count " << count << std::endl;
 
   std::cout << std::endl << src << std::endl;
+  std::cout << "##########" << 1 << std::endl;
 
   tree_type copied(src);
+  std::cout << "##########" << 2 << std::endl;
   std::cout << copied << std::endl;
-  tree_type assigned;
+  tree_type assigned(3);
+  std::cout << "##########" << 3 << std::endl;
   assigned = src;
   std::cout << assigned << std::endl;
 
@@ -381,7 +388,7 @@ int main()
   // Walter reported that the find_within_range() wasn't giving results that were within
   // the specified range... this is the test.
   {
-     tree_type tree(std::ptr_fun(tac));
+     tree_type tree(3, std::ptr_fun(tac));
      tree.insert( triplet(28.771200,16.921600,-2.665970) );
      tree.insert( triplet(28.553101,18.649700,-2.155560) );
      tree.insert( triplet(28.107500,20.341400,-1.188940) );
diff --git a/kdtree++/iterator.hpp b/kdtree++/iterator.hpp
index 1c42bf7..5f46492 100644
--- a/kdtree++/iterator.hpp
+++ b/kdtree++/iterator.hpp
@@ -106,7 +106,7 @@ namespace KDTree
         }
     }
 
-    template <size_t const __K, typename _Val, typename _Acc,
+    template <typename _Val, typename _Acc,
               typename _Dist, typename _Cmp, typename _Alloc>
     friend class KDTree;
   };
diff --git a/kdtree++/kdtree.hpp b/kdtree++/kdtree.hpp
index 8e27ab0..b24c054 100644
--- a/kdtree++/kdtree.hpp
+++ b/kdtree++/kdtree.hpp
@@ -53,13 +53,14 @@
 //  KDTREE_VERSION % 100 is the patch level
 //  KDTREE_VERSION / 100 % 1000 is the minor version
 //  KDTREE_VERSION / 100000 is the major version
-#define KDTREE_VERSION 701                      \
+#define KDTREE_VERSION 701                      
 //
 //  KDTREE_LIB_VERSION must be defined to be the same as KDTREE_VERSION
 //  but as a *string* in the form "x_y[_z]" where x is the major version
 //  number, y is the minor version number, and z is the patch level if not 0.
 #define KDTREE_LIB_VERSION "0_7_1"
 
+#include <iostream>
 
 #include <vector>
 
@@ -86,11 +87,11 @@
 namespace KDTree
 {
 
-#ifdef KDTREE_CHECK_PERFORMANCE                 \
-  unsigned long long num_dist_calcs = 0;
+#ifdef KDTREE_CHECK_PERFORMANCE
+   unsigned long long num_dist_calcs = 0;
 #endif
 
-  template <size_t const __K, typename _Val,
+  template <typename _Val,
             typename _Acc = _Bracket_accessor<_Val>,
             typename _Dist = squared_difference<typename _Acc::result_type,
                                                 typename _Acc::result_type>,
@@ -108,31 +109,32 @@ namespace KDTree
     typedef _Node<_Val> const* _Link_const_type;
 
     typedef _Node_compare<_Val, _Acc, _Cmp> _Node_compare_;
+    size_t const _dim;
 
   public:
-    typedef _Region<__K, _Val, typename _Acc::result_type, _Acc, _Cmp>
-    _Region_;
+    typedef _Region<_Val, typename _Acc::result_type, _Acc, _Cmp> _Region_;
     typedef _Val value_type;
     typedef value_type* pointer;
     typedef value_type const* const_pointer;
     typedef value_type& reference;
     typedef value_type const& const_reference;
-    typedef typename _Acc::result_type subvalue_type;
+    //typedef typename _Acc::result_type subvalue_type;
+    typedef float subvalue_type;
     typedef typename _Dist::distance_type distance_type;
     typedef size_t size_type;
     typedef ptrdiff_t difference_type;
 
-    KDTree(_Acc const& __acc = _Acc(), _Dist const& __dist = _Dist(),
+    KDTree(size_t const __K, _Acc const& __acc = _Acc(), _Dist const& __dist = _Dist(),
            _Cmp const& __cmp = _Cmp(), const allocator_type& __a = allocator_type())
-      : _Base(__a), _M_header(),
+      : _Base(__a), _dim(__K), _M_header(),
         _M_count(0), _M_acc(__acc), _M_cmp(__cmp), _M_dist(__dist)
     {
       _M_empty_initialise();
     }
 
     KDTree(const KDTree& __x)
-      : _Base(__x.get_allocator()), _M_header(), _M_count(0),
-        _M_acc(__x._M_acc), _M_cmp(__x._M_cmp), _M_dist(__x._M_dist)
+      : _Base(__x.get_allocator()), _dim(__x._dim), _M_header(), _M_count(0),
+        _M_acc(__x._M_acc), _M_cmp(__x._M_cmp), _M_dist(__x._M_dist) 
     {
       _M_empty_initialise();
       // this is slow:
@@ -145,16 +147,25 @@ namespace KDTree
       // sorts the data in the passed iterators directly.
       std::vector<value_type> temp;
       temp.reserve(__x.size());
+      std::cout << "__x.size() "<< __x.size() << std::endl;
+
+      /*
+      const_iterator pos;
+      for(pos = __x.begin(); pos != __x.end(); ++pos)
+        {
+          std::cout<<*pos<<' '<<std::endl;
+        }
+      */
       std::copy(__x.begin(),__x.end(),std::back_inserter(temp));
+      std::cout << "after copying"<<std::endl;
       _M_optimise(temp.begin(), temp.end(), 0);
     }
 
     template<typename _InputIterator>
-    KDTree(_InputIterator __first, _InputIterator __last,
+    KDTree(size_t const __K, _InputIterator __first, _InputIterator __last,
 	       _Acc const& acc = _Acc(), _Dist const& __dist = _Dist(),
 	       _Cmp const& __cmp = _Cmp(), const allocator_type& __a = allocator_type())
-      : _Base(__a), _M_header(), _M_count(0),
-        _M_acc(acc), _M_cmp(__cmp), _M_dist(__dist)
+      : _Base(__a), _dim(__K), _M_header(), _M_count(0), _M_acc(acc), _M_cmp(__cmp), _M_dist(__dist)
     {
       _M_empty_initialise();
       // this is slow:
@@ -277,7 +288,7 @@ namespace KDTree
     value_acc() const
     { return _M_acc; }
 
-    /*! \brief Distance calculator between 2 value's element.
+    /*! \Brief Distance calculator between 2 value's element.
 
       This functor can be modified. It's modification will only affect the
       behavior of the find and find_nearest functions.
@@ -437,7 +448,9 @@ namespace KDTree
     count_within_range(const_reference __V, subvalue_type const __R) const
     {
       if (!_M_get_root()) return 0;
-      _Region_ __region(__V, __R, _M_acc, _M_cmp);
+      std::cout << "count_within_range(const_reference __V, subvalue_type const __R) const" << std::endl;
+      _Region_ __region(_dim, __V, __R, _M_acc, _M_cmp);
+
       return this->count_within_range(__region);
     }
 
@@ -445,7 +458,7 @@ namespace KDTree
     count_within_range(_Region_ const& __REGION) const
     {
       if (!_M_get_root()) return 0;
-
+      std::cout << "count_within_range(_Region_ const& __REGION) const" << std::endl;
       _Region_ __bounds(__REGION);
       return _M_count_within_range(_M_get_root(),
                                    __REGION, __bounds, 0);
@@ -456,7 +469,7 @@ namespace KDTree
     visit_within_range(SearchVal const& V, subvalue_type const R, Visitor visitor) const
     {
       if (!_M_get_root()) return visitor;
-      _Region_ region(V, R, _M_acc, _M_cmp);
+      _Region_ region(_dim, V, R, _M_acc, _M_cmp);
       return this->visit_within_range(region, visitor);
     }
 
@@ -484,7 +497,7 @@ namespace KDTree
                       _OutputIterator out) const
     {
       if (!_M_get_root()) return out;
-      _Region_ region(val, range, _M_acc, _M_cmp);
+      _Region_ region(_dim, val, range, _M_acc, _M_cmp);
       return this->find_within_range(region, out);
     }
 
@@ -510,10 +523,10 @@ namespace KDTree
         {
           std::pair<const _Node<_Val>*,
             std::pair<size_type, typename _Acc::result_type> >
-            best = _S_node_nearest (__K, 0, __val,
+            best = _S_node_nearest (_dim, 0, __val,
                                     _M_get_root(), &_M_header, _M_get_root(),
                                     sqrt(_S_accumulate_node_distance
-                                         (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val)),
+                                         (_dim, _M_dist, _M_acc, _M_get_root()->_M_value, __val)),
                                     _M_cmp, _M_acc, _M_dist,
                                     always_true<value_type>());
           return std::pair<const_iterator, distance_type>
@@ -532,7 +545,7 @@ namespace KDTree
           const _Node<_Val>* node = _M_get_root();
           { // scope to ensure we don't use 'root_dist' anywhere else
             distance_type root_dist = sqrt(_S_accumulate_node_distance
-                                           (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val));
+                                           (_dim, _M_dist, _M_acc, _M_get_root()->_M_value, __val));
             if (root_dist <= __max)
               {
                 root_is_candidate = true;
@@ -541,7 +554,7 @@ namespace KDTree
           }
           std::pair<const _Node<_Val>*,
             std::pair<size_type, typename _Acc::result_type> >
-            best = _S_node_nearest (__K, 0, __val, _M_get_root(), &_M_header,
+            best = _S_node_nearest (_dim, 0, __val, _M_get_root(), &_M_header,
                                     node, __max, _M_cmp, _M_acc, _M_dist,
                                     always_true<value_type>());
           // make sure we didn't just get stuck with the root node...
@@ -565,7 +578,7 @@ namespace KDTree
             {
               { // scope to ensure we don't use root_dist anywhere else
                 distance_type root_dist = sqrt(_S_accumulate_node_distance
-                                               (__K, _M_dist, _M_acc, _M_get_root()->_M_value, __val));
+                                               (_dim, _M_dist, _M_acc, _M_get_root()->_M_value, __val));
                 if (root_dist <= __max)
                   {
                     root_is_candidate = true;
@@ -575,7 +588,7 @@ namespace KDTree
             }
           std::pair<const _Node<_Val>*,
             std::pair<size_type, typename _Acc::result_type> >
-            best = _S_node_nearest (__K, 0, __val, _M_get_root(), &_M_header,
+            best = _S_node_nearest (_dim, 0, __val, _M_get_root(), &_M_header,
                                     node, __max, _M_cmp, _M_acc, _M_dist, __p);
           // make sure we didn't just get stuck with the root node...
           if (root_is_candidate || best.first != _M_get_root())
@@ -611,7 +624,7 @@ namespace KDTree
       assert(parent);
       if (child)
         {
-          _Node_compare_ compare(level % __K, _M_acc, _M_cmp);
+          _Node_compare_ compare(level % _dim, _M_acc, _M_cmp);
           // REMEMBER! its a <= relationship for BOTH branches
           // for left-case (true), child<=node --> !(node<child)
           // for right-case (false), node<=child --> !(child<node)
@@ -670,7 +683,7 @@ namespace KDTree
     _M_insert(_Link_type __N, const_reference __V,
               size_type const __L)
     {
-      if (_Node_compare_(__L % __K, _M_acc, _M_cmp)(__V, __N->_M_value))
+      if (_Node_compare_(__L % _dim, _M_acc, _M_cmp)(__V, __N->_M_value))
         {
           if (!_S_left(__N))
             return _M_insert_left(__N, __V);
@@ -750,7 +763,7 @@ namespace KDTree
           // staying balanced.
           // If this were a true binary tree, we would always hunt down the right branch.
           // See top for notes.
-          _Node_compare_ compare(level % __K, _M_acc, _M_cmp);
+          _Node_compare_ compare(level % _dim, _M_acc, _M_cmp);
           // compare the children based on this level's criteria...
           // (this gives virtually random results)
           if (compare(_S_right(node)->_M_value, _S_left(node)->_M_value))
@@ -781,7 +794,7 @@ namespace KDTree
       if (_S_is_leaf(node.first))
         return Result(node.first,level);
 
-      _Node_compare_ compare(node.second % __K, _M_acc, _M_cmp);
+      _Node_compare_ compare(node.second % _dim, _M_acc, _M_cmp);
       Result candidate = node;
       if (_S_left(node.first))
         {
@@ -811,7 +824,7 @@ namespace KDTree
       if (_S_is_leaf(node.first))
         return Result(node.first,level);
 
-      _Node_compare_ compare(node.second % __K, _M_acc, _M_cmp);
+      _Node_compare_ compare(node.second % _dim, _M_acc, _M_cmp);
       Result candidate = node;
       if (_S_left(node.first))
         {
@@ -854,7 +867,7 @@ namespace KDTree
       // in different branches.
       const_iterator found = this->end();
 
-	  _Node_compare_ compare(level % __K, _M_acc, _M_cmp);
+	  _Node_compare_ compare(level % _dim, _M_acc, _M_cmp);
       if (!compare(node->_M_value,value))   // note, this is a <= test
         {
           // this line is the only difference between _M_find_exact() and _M_find()
@@ -877,7 +890,7 @@ namespace KDTree
       // in different branches.
       const_iterator found = this->end();
 
-	  _Node_compare_ compare(level % __K, _M_acc, _M_cmp);
+	  _Node_compare_ compare(level % _dim, _M_acc, _M_cmp);
       if (!compare(node->_M_value,value))  // note, this is a <= test
         {
           // this line is the only difference between _M_find_exact() and _M_find()
@@ -897,7 +910,7 @@ namespace KDTree
     _M_matches_node_in_d(_Link_const_type __N, const_reference __V,
                          size_type const __L) const
     {
-      _Node_compare_ compare(__L % __K, _M_acc, _M_cmp);
+      _Node_compare_ compare(__L % _dim, _M_acc, _M_cmp);
       return !(compare(__N->_M_value, __V) || compare(__V, __N->_M_value));
     }
 
@@ -906,7 +919,7 @@ namespace KDTree
                                 size_type const __L = 0) const
     {
       size_type __i = __L;
-      while ((__i = (__i + 1) % __K) != __L % __K)
+      while ((__i = (__i + 1) % _dim) != __L % _dim)
         if (!_M_matches_node_in_d(__N, __V, __i)) return false;
       return true;
     }
@@ -1021,7 +1034,7 @@ namespace KDTree
                 size_type const __L)
     {
       if (__A == __B) return;
-      _Node_compare_ compare(__L % __K, _M_acc, _M_cmp);
+      _Node_compare_ compare(__L % _dim, _M_acc, _M_cmp);
       _Iter __m = __A + (__B - __A) / 2;
       std::nth_element(__A, __m, __B, compare);
       this->insert(*__m);
@@ -1192,21 +1205,21 @@ namespace KDTree
     _Cmp _M_cmp;
     _Dist _M_dist;
 
-#ifdef KDTREE_DEFINE_OSTREAM_OPERATORS          \
+#ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
     friend std::ostream&
     operator<<(std::ostream& o,
-               KDTree<__K, _Val, _Acc, _Dist, _Cmp, _Alloc> const& tree)
+               KDTree<_Val, _Acc, _Dist, _Cmp, _Alloc> const& tree)
     {
       o << "meta node:   " << tree._M_header << std::endl;
       o << "root node:   " << tree._M_root << std::endl;
 
       if (tree.empty())
-        return o << "[empty " << __K << "d-tree " << &tree << "]";
+        return o << "[empty " << tree._dim << "d-tree " << &tree << "]";
 
       o << "nodes total: " << tree.size() << std::endl;
-      o << "dimensions:  " << __K << std::endl;
+      o << "dimensions:  " << tree._dim << std::endl;
 
-      typedef KDTree<__K, _Val, _Acc, _Dist, _Cmp, _Alloc> _Tree;
+      typedef KDTree<_Val, _Acc, _Dist, _Cmp, _Alloc> _Tree;
       typedef typename _Tree::_Link_type _Link_type;
 
       std::stack<_Link_const_type> s;
diff --git a/kdtree++/node.hpp b/kdtree++/node.hpp
index e319d35..a161c82 100644
--- a/kdtree++/node.hpp
+++ b/kdtree++/node.hpp
@@ -8,7 +8,7 @@
 #define INCLUDE_KDTREE_NODE_HPP
 
 #ifdef KDTREE_DEFINE_OSTREAM_OPERATORS
-#  include <ostream>
+#include <ostream>
 #endif
 
 #include <cstddef>
@@ -93,7 +93,7 @@ namespace KDTree
       return out;
     }
 
-#endif                                          \
+#endif                                          
   };
 
     template <typename _Val, typename _Acc, typename _Cmp>
diff --git a/kdtree++/region.hpp b/kdtree++/region.hpp
index 76dac5d..49a4df9 100644
--- a/kdtree++/region.hpp
+++ b/kdtree++/region.hpp
@@ -8,54 +8,91 @@
 #define INCLUDE_KDTREE_REGION_HPP
 
 #include <cstddef>
-
+#include <typeinfo>
+#include <iostream>
 #include <kdtree++/node.hpp>
 
 namespace KDTree
 {
 
-  template <size_t const __K, typename _Val, typename _SubVal,
+  template <typename _Val, typename _SubVal,
             typename _Acc, typename _Cmp>
   struct _Region
   {
     typedef _Val value_type;
     typedef _SubVal subvalue_type;
+    size_t const _dim;
 
     // special typedef for checking against a fuzzy point (for find_nearest)
     // Note the region (first) component is not supposed to have an area, its
     // bounds should all be set to a specific point.
     typedef std::pair<_Region,_SubVal> _CenterPt;
 
-    _Region(_Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
-      : _M_cmp(__acc), _M_acc(__cmp) {}
+    _Region(size_t const __K, _Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
+      :  _dim(__K), _M_cmp(__acc), _M_acc(__cmp) {
+      _M_low_bounds = new subvalue_type[_dim];
+      _M_high_bounds = new subvalue_type[_dim];
+    }
+
+    _Region(const _Region& r) : _dim(r._dim), _M_acc(r._M_acc), _M_cmp(r._M_cmp)
+    {
+      std::cout << "copy _Region" << std::endl;
+      _M_low_bounds = new subvalue_type[_dim];
+      _M_high_bounds = new subvalue_type[_dim];
+
+      for (size_t __i = 0; __i != _dim; ++__i)
+        {
+          _M_low_bounds[__i] = r._M_low_bounds[__i];
+          _M_high_bounds[__i] = r._M_high_bounds[__i];
+        }
+    }
 
     template <typename Val>
-    _Region(Val const& __V,
+    _Region(size_t const __K, Val const& __V,
             _Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
-      : _M_acc(__acc), _M_cmp(__cmp)
+      :  _dim(__K), _M_acc(__acc), _M_cmp(__cmp)
     {
-      for (size_t __i = 0; __i != __K; ++__i)
+      std::cout << "____1 __ _M_acc: " << typeid(_M_acc).name() << std::endl;
+      std::cout << "Val="<<typeid(Val).name() << std::endl;
+      std::cout << "in _Region " << typeid(__V).name() << std::endl;
+      _M_low_bounds = new subvalue_type[_dim];
+      _M_high_bounds = new subvalue_type[_dim];
+
+      for (size_t __i = 0; __i != _dim; ++__i)
         {
+          std::cout << "______ __V: " << typeid(__V).name() << std::endl;          
+          std::cout << "______ _M_acc: " << typeid(_M_acc).name() << std::endl;
           _M_low_bounds[__i] = _M_high_bounds[__i] = _M_acc(__V,__i);
         }
-    }
+      
+        }
 
     template <typename Val>
-    _Region(Val const& __V, subvalue_type const& __R,
+    _Region(size_t const __K, Val const& __V, subvalue_type const& __R,
             _Acc const& __acc=_Acc(), const _Cmp& __cmp=_Cmp())
-      : _M_acc(__acc), _M_cmp(__cmp)
+      : _dim(__K), _M_acc(__acc), _M_cmp(__cmp)
     {
-      for (size_t __i = 0; __i != __K; ++__i)
+      _M_low_bounds = new subvalue_type[_dim];
+      _M_high_bounds = new subvalue_type[_dim];
+      std::cout << "____2 __ _M_acc: " << typeid(_M_acc).name() << std::endl;
+      for (size_t __i = 0; __i != _dim; ++__i)
         {
           _M_low_bounds[__i] = _M_acc(__V,__i) - __R;
           _M_high_bounds[__i] = _M_acc(__V,__i) + __R;
         }
     }
 
+    ~_Region()
+    {
+      std::cout << "~~~~~~~~~" << std::endl;
+      delete [] _M_low_bounds;
+      delete [] _M_high_bounds;
+    }
+
     bool
     intersects_with(_CenterPt const& __THAT) const
     {
-      for (size_t __i = 0; __i != __K; ++__i)
+      for (size_t __i = 0; __i != _dim; ++__i)
         {
           // does it fall outside the bounds? 
           // ! low-tolerance <= x <= high+tolerance
@@ -73,7 +110,7 @@ namespace KDTree
     bool
     intersects_with(_Region const& __THAT) const
     {
-      for (size_t __i = 0; __i != __K; ++__i)
+      for (size_t __i = 0; __i != _dim; ++__i)
         {
           if (_M_cmp(__THAT._M_high_bounds[__i], _M_low_bounds[__i])
               || _M_cmp(_M_high_bounds[__i], __THAT._M_low_bounds[__i]))
@@ -85,7 +122,7 @@ namespace KDTree
     bool
     encloses(value_type const& __V) const
     {
-      for (size_t __i = 0; __i != __K; ++__i)
+      for (size_t __i = 0; __i != _dim; ++__i)
         {
           if (_M_cmp(_M_acc(__V, __i), _M_low_bounds[__i])
               || _M_cmp(_M_high_bounds[__i], _M_acc(__V, __i)))
@@ -97,18 +134,18 @@ namespace KDTree
     _Region&
     set_high_bound(value_type const& __V, size_t const __L)
     {
-      _M_high_bounds[__L % __K] = _M_acc(__V, __L % __K);
+      _M_high_bounds[__L % _dim] = _M_acc(__V, __L % _dim);
       return *this;
     }
 
     _Region&
     set_low_bound(value_type const& __V, size_t const __L)
     {
-      _M_low_bounds[__L % __K] = _M_acc(__V, __L % __K);
+      _M_low_bounds[__L % _dim] = _M_acc(__V, __L % _dim);
       return *this;
     }
 
-    subvalue_type _M_low_bounds[__K], _M_high_bounds[__K];
+    subvalue_type *_M_low_bounds, *_M_high_bounds;
     _Acc _M_acc;
     _Cmp _M_cmp;
   };
-- 
1.5.6.3




More information about the libkdtree-devel mailing list