void compare_libraries(std::size_t         data_size,
                       const Distribution& distribution) {
    std::cout << "\t" << N << " dimensions, " << data_size
              << " objects:" << std::endl;
    std::vector<Point> data;
    data.reserve(data_size);
    for (std::size_t i = 0; i < data_size; ++i)
        data.push_back(Point(distribution));
    {
        // Mapping begin into an idle_point_multiset
        spatial::idle_point_multiset<N, Point> cobaye;
        cobaye.insert_rebalance(data.begin(), data.end());
        std::cout << "\t\tidle_point_multiset (maximum):\t" << std::flush;
        utils::time_point start = utils::process_timer_now();
        for (int j = 0; j != N; ++j) {
            spatial::mapping_iterator<spatial::idle_point_multiset<N, Point> >
                i = mapping_end(cobaye, 0);
            --i;
        }
        utils::time_point stop = utils::process_timer_now();
        std::cout << (stop - start) << "sec" << std::endl;
        std::cout << "\t\tidle_point_multiset:\t" << std::flush;
        start = utils::process_timer_now();
        for (int j = 0; j != N; ++j) {
            spatial::mapping_iterator<spatial::idle_point_multiset<N, Point> >
                i = mapping_begin(cobaye, 0);
            ++i;
        }
        stop = utils::process_timer_now();
        std::cout << (stop - start) << "sec" << std::endl;
    }
    {
        // Mapping begin into a point_multiset
        spatial::point_multiset<N, Point> cobaye;
        cobaye.insert(data.begin(), data.end());
        std::cout << "\t\tpoint_multiset:\t" << std::flush;
        utils::time_point start = utils::process_timer_now();
        for (int j = 0; j != N; ++j) {
            spatial::mapping_iterator<spatial::point_multiset<N, Point> > i =
                mapping_begin(cobaye, 0);
            ++i;
        }
        utils::time_point stop = utils::process_timer_now();
        std::cout << (stop - start) << "sec" << std::endl;
        std::cout << "\t\tpoint_multiset (reverse):\t" << std::flush;
        start = utils::process_timer_now();
        for (int j = 0; j != N; ++j) {
            spatial::mapping_iterator<spatial::point_multiset<N, Point> > i =
                mapping_end(cobaye, 0);
            --i;
        }
        stop = utils::process_timer_now();
        std::cout << (stop - start) << "sec" << std::endl;
    }
}
예제 #2
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_mapping_minimum, Tp, int2_sets )
{
  {
    Tp fix(100, randomize(-20, 20));
    // Prove that you can find the min value with N nodes, down to 1 nodes
    while (!fix.container.empty())
      {
        unsigned int count = 0;
        int min_value_0 = (*fix.container.begin())[0];
        int min_value_1 = (*fix.container.begin())[1];
        for(typename Tp::container_type::iterator
              i = fix.container.begin(); i != fix.container.end(); ++i)
          {
            int tmp = (*i)[0];
            if (tmp < min_value_0) { min_value_0 = tmp; }
            tmp = (*i)[1];
            if (tmp < min_value_1) { min_value_1 = tmp; }
            ++count;
          }
        BOOST_CHECK_EQUAL(count, fix.container.size());
        mapping_iterator<typename Tp::container_type> iter;
        dimension_type mapping_dim = 0;
        iter = mapping_begin(fix.container, mapping_dim);
        BOOST_CHECK_EQUAL((*iter)[mapping_dim], min_value_0);
        mapping_dim = 1;
        iter = mapping_begin(fix.container, mapping_dim);
        BOOST_CHECK_EQUAL((*iter)[mapping_dim], min_value_1);
        fix.container.erase(iter);
      }
  }
  { // A tree where all elements are the same!
    Tp fix(100, same());
    // Prove that you can find the min value with N nodes, down to 1 nodes
    while (!fix.container.empty())
      {
        unsigned int count = 0;
        for(typename Tp::container_type::iterator
              i = fix.container.begin(); i != fix.container.end(); ++i)
          { ++count; }
        BOOST_CHECK_EQUAL(count, fix.container.size());
        mapping_iterator<typename Tp::container_type> iter;
        iter = mapping_begin(fix.container, 0);
        BOOST_CHECK_EQUAL((*iter)[0], 100);
        iter = mapping_begin(fix.container, 1);
        BOOST_CHECK_EQUAL((*iter)[1], 100);
        fix.container.erase(iter);
      }
  }
  { // test at the limit: a tree with 1 element
    Tp fix(1, same());
    mapping_iterator<const typename Tp::container_type> iter;
    iter = mapping_cbegin(fix.container, 0);
    BOOST_CHECK_EQUAL((*iter)[0], 1); // should be (1, 1);
    BOOST_CHECK_EQUAL((*iter)[1], 1);
    iter = mapping_cbegin(fix.container, 1);
    BOOST_CHECK_EQUAL((*iter)[0], 1); // should be (1, 1);
    BOOST_CHECK_EQUAL((*iter)[1], 1);
  }
  { // test at the limit: an unbalanced tree (i.e. insertions in order)!
    Tp fix(100, decrease());
    mapping_iterator<typename Tp::container_type> iter;
    dimension_type mapping_dim = 0;
    iter = mapping_begin(fix.container, mapping_dim);
    BOOST_CHECK_EQUAL((*iter)[0], 1); // should be (1, 1);
    BOOST_CHECK_EQUAL((*iter)[1], 1);
  }
  { // test at the limit: an unbalanced tree (i.e insertions in order)!
    Tp fix(100, increase());
    mapping_iterator<typename Tp::container_type> iter;
    dimension_type mapping_dim = 1;
    iter = mapping_begin(fix.container, mapping_dim);
    BOOST_CHECK_EQUAL((*iter)[0], 0); // should be (0, 0);
    BOOST_CHECK_EQUAL((*iter)[1], 0);
  }
}
예제 #3
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_mapping_upper_bound, Tp, quad_maps )
{
  { // find the smallest element that is greater than key
    Tp fix(100, randomize(-2, 2));
    quad lower (-3, -3, -3, -3);
    quad in (-1, -1, -1, -1);
    quad upper (1, 1, 1, 1);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<typename Tp::container_type>
          iter (mapping_upper_bound(fix.container, mapping_dim, in));
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim)
                    || quad_less()(mapping_dim, in, iter->first));
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim)
                    || !quad_less()(mapping_dim, (--iter)->first, in));
        iter = mapping_upper_bound(fix.container, mapping_dim, lower);
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
      }
  }
  { // same test with a tree filled with similar values
    Tp fix(100, same());
    quad lower (99, 99, 99, 99);
    quad in (100, 100, 100, 100);
    quad upper (101, 101, 101, 101);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<typename Tp::container_type>
          iter (mapping_upper_bound(fix.container, mapping_dim, lower));
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, in);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
      }
  }
  { // test at the limit: tree with 1 value
    Tp fix(1, same());
    quad lower (0, 0, 0, 0);
    quad in (1, 1, 1, 1);
    quad upper (2, 2, 2, 2);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<const typename Tp::container_type>
          iter (mapping_cupper_bound(fix.container, mapping_dim, lower));
        BOOST_CHECK(iter == mapping_cbegin(fix.container, mapping_dim));
        iter = mapping_cupper_bound(fix.container, mapping_dim, in);
        BOOST_CHECK(iter == mapping_cend(fix.container, mapping_dim));
        iter = mapping_cupper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_cend(fix.container, mapping_dim));
      }
  }
  { // test at the limit: tree filled with decreasing values
    Tp fix(100, decrease()); // first (100, 100, 100, 100), last (1, 1, 1, 1)
    quad lower(0, 0, 0, 0);
    quad in (99, 99, 99, 99);
    quad upper(100, 100, 100, 100);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<typename Tp::container_type>
          iter (mapping_upper_bound(fix.container, mapping_dim, lower));
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, in);
        BOOST_CHECK(iter != mapping_end(fix.container, mapping_dim)
                    && ++iter == mapping_end(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
      }
  }
  { // test at the limit: tree filled with increasing values
    Tp fix(100, increase()); // first (0, 0, 0, 0), last (99, 99, 99, 99)
    quad lower(-1, -1, -1, -1);
    quad in(98, 98, 98, 98);
    quad upper (99, 99, 99, 99);
    for (dimension_type mapping_dim = 0; mapping_dim < 4;
         ++mapping_dim)
      {
        mapping_iterator<typename Tp::container_type>
          iter (mapping_upper_bound(fix.container, mapping_dim, lower));
        BOOST_CHECK(iter == mapping_begin(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, in);
        BOOST_CHECK(iter != mapping_end(fix.container, mapping_dim)
                    && ++iter == mapping_end(fix.container, mapping_dim));
        iter = mapping_upper_bound(fix.container, mapping_dim, upper);
        BOOST_CHECK(iter == mapping_end(fix.container, mapping_dim));
      }
  }
}
예제 #4
0
BOOST_AUTO_TEST_CASE_TEMPLATE
( test_mapping_decrement, Tp, int2_maps )
{
  { // test the invarient of the increment
    Tp fix(100, randomize(-3, 3));
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        std::reverse_iterator
          <mapping_iterator<typename Tp::container_type> >
          iter(mapping_end(fix.container, mapping_dim)),
          end(mapping_begin(fix.container, mapping_dim));
        int count = 0;
        double tmp = iter->first[mapping_dim];
        for (; iter != end; ++iter)
          {
            BOOST_CHECK_GE(tmp, iter->first[mapping_dim]);
            tmp = iter->first[mapping_dim];
            if (++count > 100) break;
          }
        BOOST_CHECK_EQUAL(count, 100);
      }
  }
  { // test at the limit: a tree where all elements are the same
    Tp fix(100, same());
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        std::reverse_iterator
          <mapping_iterator<typename Tp::container_type> >
          iter(mapping_end(fix.container, mapping_dim)),
          end(mapping_begin(fix.container, mapping_dim));
        int count = 0;
        for (; iter != end; ++iter)
          {
            BOOST_CHECK_EQUAL(100, iter->first[mapping_dim]);
            if (++count > 100) break;
          }
        BOOST_CHECK_EQUAL(count, 100);
      }
  }
  { // test at the limit: a tree with 2 elements
    Tp fix(2, same());
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        mapping_iterator<const typename Tp::container_type>
          pre = mapping_cend(fix.container, mapping_dim),
          post = mapping_cend(fix.container, mapping_dim),
          begin = mapping_cbegin(fix.container, mapping_dim);
        BOOST_CHECK(pre != begin);
        BOOST_CHECK(--pre != post--);
        BOOST_CHECK(pre == post);
        BOOST_CHECK(post-- != begin);
        BOOST_CHECK(--pre == begin);
        BOOST_CHECK(post == begin);
      }
  }
  { // test at the limit: a right-unbalanced tree (pre-increment)
    Tp fix(100, increase());
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        std::reverse_iterator
          <mapping_iterator<typename Tp::container_type> >
          iter(mapping_end(fix.container, mapping_dim)),
          end(mapping_begin(fix.container, mapping_dim));
        int count = 0;
        double tmp = iter->first[mapping_dim];
        for (; iter != end; ++iter)
          {
            BOOST_CHECK_GE(tmp, iter->first[mapping_dim]);
            tmp = iter->first[mapping_dim];
            if (++count > 100) break;
          }
        BOOST_CHECK_EQUAL(count, 100);
      }
  }
  { // test at the limit: a left-unbalanced tree (post-increment)
    Tp fix(100, decrease());
    for (dimension_type mapping_dim = 0; mapping_dim < 2;
         ++mapping_dim)
      {
        std::reverse_iterator
          <mapping_iterator<typename Tp::container_type> >
          iter(mapping_end(fix.container, mapping_dim)),
          end(mapping_begin(fix.container, mapping_dim));
        int count = 0;
        double tmp = iter->first[mapping_dim];
        for (; iter != end; iter++)
          {
            BOOST_CHECK_GE(tmp, iter->first[mapping_dim]);
            tmp = iter->first[mapping_dim];
            if (++count > 100) break;
          }
        BOOST_CHECK_EQUAL(count, 100);
      }
  }
}