Skip to content

Commit

Permalink
refs #121 Полупересечение разнотипных диапазонов
Browse files Browse the repository at this point in the history
  • Loading branch information
izvolov committed Jul 24, 2020
1 parent 8b2fe18 commit 0e8d057
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 2 deletions.
8 changes: 6 additions & 2 deletions include/burst/iterator/semiintersect_iterator.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <burst/container/access/front.hpp>
#include <burst/functional/each.hpp>
#include <burst/iterator/detail/prevent_writing.hpp>
#include <burst/iterator/detail/uniform_range_tuple_please.hpp>
#include <burst/iterator/end_tag.hpp>
#include <burst/range/make_range_vector.hpp>
#include <burst/range/own_as_range.hpp>
Expand All @@ -26,6 +27,7 @@
#include <cstddef>
#include <functional>
#include <iterator>
#include <tuple>
#include <type_traits>
#include <utility>

Expand Down Expand Up @@ -474,10 +476,11 @@ namespace burst
Compare compare
)
{
auto common_ranges = detail::uniform_range_tuple_please(ranges);
return
make_semiintersect_iterator
(
burst::own_as_range(burst::apply(burst::make_range_vector, ranges)),
burst::own_as_range(burst::apply(burst::make_range_vector, common_ranges)),
min_items,
std::move(compare)
);
Expand All @@ -496,10 +499,11 @@ namespace burst
template <typename ... Ranges, typename Integral>
auto make_semiintersect_iterator (std::tuple<Ranges &...> ranges, Integral min_items)
{
auto common_ranges = detail::uniform_range_tuple_please(ranges);
return
make_semiintersect_iterator
(
burst::own_as_range(burst::apply(burst::make_range_vector, ranges)),
burst::own_as_range(burst::apply(burst::make_range_vector, common_ranges)),
min_items
);
}
Expand Down
13 changes: 13 additions & 0 deletions test/burst/range/adaptor/semiintersected.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -58,4 +58,17 @@ TEST_SUITE("semiintersected")
const auto expected = {3, 1};
CHECK(semiintersected == expected);
}

TEST_CASE("Может работать с кортежем диапазонов")
{
const auto first = burst::make_vector ({0, 0, 1, 1, 2, 2 });
const auto second = burst::make_vector ({0, 1, 2, 2 });
const auto third = burst::make_forward_list({ 1, 2, 3, 4});
// ^ ^ ^ ^

const auto semiintersected = std::tie(first, second, third) | burst::semiintersected(2);

const auto expected = {0, 1, 2, 2};
CHECK(semiintersected == expected);
}
}
30 changes: 30 additions & 0 deletions test/burst/range/semiintersect.cpp
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
#include <burst/container/make_deque.hpp>
#include <burst/container/make_list.hpp>
#include <burst/container/make_vector.hpp>
#include <burst/range/make_range_vector.hpp>
#include <burst/range/semiintersect.hpp>

Expand Down Expand Up @@ -231,4 +234,31 @@ TEST_SUITE("semiintersect")
const auto expected_collection = {0, 1, 2};
CHECK(semiintersection == expected_collection);
}

TEST_CASE("Возможно полупересечение диапазонов разных типов")
{
auto one = burst::make_vector({1, 2, 3, 4, 5, 6, 7 });
auto two = burst::make_list ({1, 3, 5, 7, 9 });
auto three = burst::make_deque ({1, 4, 7, 10});
// ^ ^ ^ ^ ^

auto semiintersection = burst::semiintersect(std::tie(one, two, three), 2);

auto expected_collection = {1, 3, 4, 5, 7};
CHECK(semiintersection == expected_collection);
}

TEST_CASE("Возможно полупересечение с предикатом диапазонов разных типов")
{
auto one = burst::make_vector({ 7, 6, 5, 4, 3, 2, 1, 0});
auto two = burst::make_list ({ 8, 6, 4, 2, 0});
auto three = burst::make_deque ({9, 6, 3, 0});
// ^ ^

auto semiintersection =
burst::semiintersect(std::tie(one, two, three), 3, std::greater<>{});

auto expected_collection = {6, 0};
CHECK(semiintersection == expected_collection);
}
}

0 comments on commit 0e8d057

Please sign in to comment.