Skip to content

Commit

Permalink
Revert KDTREE_SIZE_T to size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
sbougerel committed Nov 17, 2008
1 parent e49baba commit 652a0e4
Show file tree
Hide file tree
Showing 7 changed files with 159 additions and 179 deletions.
241 changes: 120 additions & 121 deletions examples/test_kdtree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,34 +15,34 @@ struct triplet
{
typedef int value_type;

triplet(value_type a, value_type b, value_type c)
{
d[0] = a;
d[1] = b;
d[2] = c;
// bool reg_ok = (registered.find(this) == registered.end());
// assert(reg_ok);
// registered.insert(this).second;
}

triplet(const triplet & x)
{
d[0] = x.d[0];
d[1] = x.d[1];
d[2] = x.d[2];
// bool reg_ok = (registered.find(this) == registered.end());
// assert(reg_ok);
// registered.insert(this).second;
}

~triplet()
{
// bool unreg_ok = (registered.find(this) != registered.end());
// assert(unreg_ok);
// registered.erase(this);
}

inline value_type operator[](KDTree::size_type const N) const { return d[N]; }
triplet(value_type a, value_type b, value_type c)
{
d[0] = a;
d[1] = b;
d[2] = c;
// bool reg_ok = (registered.find(this) == registered.end());
// assert(reg_ok);
// registered.insert(this).second;
}

triplet(const triplet & x)
{
d[0] = x.d[0];
d[1] = x.d[1];
d[2] = x.d[2];
// bool reg_ok = (registered.find(this) == registered.end());
// assert(reg_ok);
// registered.insert(this).second;
}

~triplet()
{
// bool unreg_ok = (registered.find(this) != registered.end());
// assert(unreg_ok);
// registered.erase(this);
}

inline value_type operator[](size_t const N) const { return d[N]; }

value_type d[3];
};
Expand All @@ -53,14 +53,14 @@ inline bool operator==(triplet const& A, triplet const& B) {

std::ostream& operator<<(std::ostream& out, triplet const& T)
{
// assert(registered.find(&T) != registered.end());
// assert(registered.find(&T) != registered.end());
return out << '(' << T.d[0] << ',' << T.d[1] << ',' << T.d[2] << ')';
}

inline double tac( triplet t, KDTree::size_type k ) { return t[k]; }
inline double tac( triplet t, size_t k ) { return t[k]; }


typedef KDTree::KDTree<3, triplet, std::pointer_to_binary_function<triplet,KDTree::size_type,double> > tree_type;
typedef KDTree::KDTree<3, triplet, std::pointer_to_binary_function<triplet,size_t,double> > tree_type;

int main()
{
Expand Down Expand Up @@ -90,105 +90,104 @@ int main()
std::cout << std::endl << src << std::endl;

tree_type copied(src);
copied.clear();
std::cout << copied << std::endl;
tree_type assigned;
assigned = src;
std::cout << assigned << std::endl;

for (int loop = 0; loop != 1; ++loop)
{
tree_type * target;
for (int loop = 0; loop != 3; ++loop)
{
tree_type * target = &src; // Get rid of a warning on uninitialized value
switch (loop)
{
case 0: std::cout << "Testing plain construction" << std::endl;
target = &src;
break;

case 1: std::cout << "Testing copy-construction" << std::endl;
target = &copied;
break;

case 2: std::cout << "Testing assign-construction" << std::endl;
target = &assigned;
break;
}
tree_type & t = *target;

int i=0;
for (tree_type::const_iterator iter=t.begin(); iter!=t.end(); ++iter, ++i);
std::cout << "iterator walked through " << i << " nodes in total" << std::endl;
if (i!=6)
{
std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
return 1;
}
i=0;
for (tree_type::const_reverse_iterator iter=t.rbegin(); iter!=t.rend(); ++iter, ++i);
std::cout << "reverse_iterator walked through " << i << " nodes in total" << std::endl;
if (i!=6)
{
std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
return 1;
}

triplet s(5, 4, 3);
std::vector<triplet> v;
unsigned int const RANGE = 3;

size_t count = t.count_within_range(s, RANGE);
std::cout << "counted " << count
<< " nodes within range " << RANGE << " of " << s << ".\n";
t.find_within_range(s, RANGE, std::back_inserter(v));

std::cout << "found " << v.size() << " nodes within range " << RANGE
<< " of " << s << ":\n";
std::vector<triplet>::const_iterator ci = v.begin();
for (; ci != v.end(); ++ci)
std::cout << *ci << " ";
std::cout << "\n" << std::endl;

std::cout << std::endl << t << std::endl;

std::cout << "Nearest to " << s << ": " <<
*t.find_nearest(s,std::numeric_limits<double>::max()).first << std::endl;

triplet s2(10, 10, 2);
std::cout << "Nearest to " << s2 << ": " <<
*t.find_nearest(s2,std::numeric_limits<double>::max()).first << std::endl;

std::cout << std::endl;

std::cout << t << std::endl;

// Testing iterators
{
case 0: std::cout << "Testing plain construction" << std::endl;
target = &src;
break;

case 1: std::cout << "Testing copy-construction" << std::endl;
target = &copied;
break;

case 2: std::cout << "Testing assign-construction" << std::endl;
target = &assigned;
break;
std::cout << "Testing iterators" << std::endl;

t.erase(c2);
t.erase(c4);
t.erase(c6);
t.erase(c7);
t.erase(c8);
// t.erase(c9);

std::cout << std::endl << t << std::endl;

std::cout << "Forward iterator test..." << std::endl;
std::vector<triplet> forwards;
for (tree_type::iterator i = t.begin(); i != t.end(); ++i)
{ std::cout << *i << " " << std::flush; forwards.push_back(*i); }
std::cout << std::endl;
std::cout << "Reverse iterator test..." << std::endl;
std::vector<triplet> backwards;
for (tree_type::reverse_iterator i = t.rbegin(); i != t.rend(); ++i)
{ std::cout << *i << " " << std::flush; backwards.push_back(*i); }
std::cout << std::endl;
std::reverse(backwards.begin(),backwards.end());
assert(backwards == forwards);
}

tree_type & t = *target;

int i=0;
for (tree_type::const_iterator iter=t.begin(); iter!=t.end(); ++iter, ++i);
std::cout << "iterator walked through " << i << " nodes in total" << std::endl;
if (i!=6)
{
std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
return 1;
}
i=0;
for (tree_type::const_reverse_iterator iter=t.rbegin(); iter!=t.rend(); ++iter, ++i);
std::cout << "reverse_iterator walked through " << i << " nodes in total" << std::endl;
if (i!=6)
{
std::cerr << "Error: does not tally with the expected number of nodes (6)" << std::endl;
return 1;
}

triplet s(5, 4, 3);
std::vector<triplet> v;
unsigned int const RANGE = 3;

KDTree::size_type count = t.count_within_range(s, RANGE);
std::cout << "counted " << count
<< " nodes within range " << RANGE << " of " << s << ".\n";
t.find_within_range(s, RANGE, std::back_inserter(v));

std::cout << "found " << v.size() << " nodes within range " << RANGE
<< " of " << s << ":\n";
std::vector<triplet>::const_iterator ci = v.begin();
for (; ci != v.end(); ++ci)
std::cout << *ci << " ";
std::cout << "\n" << std::endl;

std::cout << std::endl << t << std::endl;

std::cout << "Nearest to " << s << ": " <<
*t.find_nearest(s,std::numeric_limits<double>::max()).first << std::endl;

triplet s2(10, 10, 2);
std::cout << "Nearest to " << s2 << ": " <<
*t.find_nearest(s2,std::numeric_limits<double>::max()).first << std::endl;

std::cout << std::endl;

std::cout << t << std::endl;

// Testing iterators
{
std::cout << "Testing iterators" << std::endl;

t.erase(c2);
t.erase(c4);
t.erase(c6);
t.erase(c7);
t.erase(c8);
// t.erase(c9);

std::cout << std::endl << t << std::endl;

std::cout << "Forward iterator test..." << std::endl;
std::vector<triplet> forwards;
for (tree_type::iterator i = t.begin(); i != t.end(); ++i)
{ std::cout << *i << " " << std::flush; forwards.push_back(*i); }
std::cout << std::endl;
std::cout << "Reverse iterator test..." << std::endl;
std::vector<triplet> backwards;
for (tree_type::reverse_iterator i = t.rbegin(); i != t.rend(); ++i)
{ std::cout << *i << " " << std::flush; backwards.push_back(*i); }
std::cout << std::endl;
std::reverse(backwards.begin(),backwards.end());
assert(backwards == forwards);
}
}

return 0;
}

Expand Down
3 changes: 1 addition & 2 deletions kdtree++/function.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
#define INCLUDE_KDTREE_ACCESSOR_HPP

#include <cstddef>
#include "kdtree_size_t.hpp"

namespace KDTree
{
Expand All @@ -19,7 +18,7 @@ namespace KDTree
typedef typename _Val::value_type result_type;

result_type
operator()(_Val const& V, size_type const N) const
operator()(_Val const& V, size_t const N) const
{
return V[N];
}
Expand Down
2 changes: 1 addition & 1 deletion kdtree++/iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ namespace KDTree
}
}

template <size_type const __K, typename _Val, typename _Acc,
template <size_t const __K, typename _Val, typename _Acc,
typename _Dist, typename _Cmp, typename _Alloc>
friend class KDTree;
};
Expand Down
4 changes: 2 additions & 2 deletions kdtree++/kdtree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ namespace KDTree
unsigned long long num_dist_calcs = 0;
#endif

template <size_type const __K, typename _Val,
template <size_t const __K, typename _Val,
typename _Acc = _Bracket_accessor<_Val>,
typename _Dist = squared_difference<typename _Acc::result_type,
typename _Acc::result_type>,
Expand Down Expand Up @@ -104,7 +104,7 @@ namespace KDTree
typedef value_type const& const_reference;
typedef typename _Acc::result_type subvalue_type;
typedef typename _Dist::distance_type distance_type;
typedef ::KDTree::size_type size_type;
typedef size_t size_type;
typedef ptrdiff_t difference_type;

KDTree(_Acc const& __acc = _Acc(), _Dist const& __dist = _Dist(),
Expand Down
17 changes: 0 additions & 17 deletions kdtree++/kdtree_size_t.hpp

This file was deleted.

Loading

0 comments on commit 652a0e4

Please sign in to comment.