Skip to content

Commit

Permalink
Rebased and adpated dictionary_encoded layout
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille committed Apr 8, 2024
1 parent 64912a4 commit 8d7c2b2
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
13 changes: 2 additions & 11 deletions include/sparrow/dictionary_encoded_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,7 @@ namespace sparrow
using const_value_iterator = dictionary_value_iterator<indexes_layout, sub_layout, true>;
using const_value_range = std::ranges::subrange<const_value_iterator, const_value_iterator>;

explicit dictionary_encoded_layout(array_data&& data);
explicit dictionary_encoded_layout(const array_data& data); // TODO: To remove when #51 will be merged
explicit dictionary_encoded_layout(array_data& data);

size_type size() const;
const_reference operator[](size_type i) const;
Expand Down Expand Up @@ -242,21 +241,13 @@ namespace sparrow
**********************************************/

template <std::integral T, class SL, layout_offset OT>
dictionary_encoded_layout<T, SL, OT>::dictionary_encoded_layout(const array_data& data)
dictionary_encoded_layout<T, SL, OT>::dictionary_encoded_layout(array_data& data)
{
assert(data.dictionary);
m_sub_layout = std::make_unique<SL>(*data.dictionary);
m_indexes_layout = std::make_unique<indexes_layout>(data);
}

template <std::integral T, class SL, layout_offset OT>
dictionary_encoded_layout<T, SL, OT>::dictionary_encoded_layout(array_data&& data)
{
assert(data.dictionary);
m_sub_layout = std::make_unique<SL>(std::move(*data.dictionary));
m_indexes_layout = std::make_unique<indexes_layout>(std::move(data));
}

template <std::integral T, class SL, layout_offset OT>
auto dictionary_encoded_layout<T, SL, OT>::size() const -> size_type
{
Expand Down
15 changes: 12 additions & 3 deletions include/sparrow/variable_size_binary_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -137,10 +137,19 @@ namespace sparrow

using const_value_iterator = vs_binary_value_iterator<self_type, true>;
using const_bitmap_iterator = array_data::bitmap_type::const_iterator;
using const_value_iterator = vs_binary_value_iterator<self_type, true>;

using const_bitmap_range = std::ranges::subrange<const_bitmap_iterator>;
using const_iterator = layout_iterator<self_type, true>;
//
// TODO: required by layout_iterator, replace them with the right types
// when assignment for data in a variable size bienary layout is implemented
// and implement non const overloads of `values` and `bitmap`
using value_iterator = const_value_iterator;
using bitmap_iterator = const_bitmap_iterator;
// TODO: uncomment the following line and implement the non const overloads
// of `begin` and `end`
// using iterator = layout_iterator<self_type, false>;

using const_value_range = std::ranges::subrange<const_value_iterator>;
using const_bitmap_range = std::ranges::subrange<const_bitmap_iterator>;

explicit variable_size_binary_layout(array_data& data);

Expand Down
2 changes: 0 additions & 2 deletions test/test_dictionary_encoded_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -95,8 +95,6 @@ namespace sparrow
CHECK(m_data.buffers.size() == 1);
const layout_type l_copy(m_data);
CHECK(m_data.buffers.size() == 1);
const layout_type l_move(std::move(m_data));
CHECK(m_data.buffers.size() == 0);
}

TEST_CASE_FIXTURE(dictionary_encoded_fixture, "size")
Expand Down
24 changes: 16 additions & 8 deletions test/test_fixed_size_layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,17 @@ namespace sparrow

TEST_CASE("value_iterator_ordering")
{
layout_test_type lt(make_test_array_data(10, 1));
array_data ad = make_test_array_data(10, 1);
layout_test_type lt(ad);
auto lt_values = lt.values();
layout_test_type::const_value_iterator citer = lt_values.begin();
CHECK(citer < lt_values.end());
}

TEST_CASE("value_iterator_equality")
{
layout_test_type lt(make_test_array_data(10, 1));
array_data ad = make_test_array_data(10, 1);
layout_test_type lt(ad);
auto lt_values = lt.values();
layout_test_type::const_value_iterator citer = lt_values.begin();
for (std::size_t i = 0; i < lt.size(); ++i)
Expand All @@ -84,15 +86,17 @@ namespace sparrow

TEST_CASE("const_value_iterator_ordering")
{
layout_test_type lt(make_test_array_data(10, 1));
array_data ad = make_test_array_data(10, 1);
layout_test_type lt(ad);
auto lt_values = lt.values();
layout_test_type::const_value_iterator citer = lt_values.begin();
CHECK(citer < lt_values.end());
}

TEST_CASE("const_value_iterator_equality")
{
layout_test_type lt(make_test_array_data(10, 1));
array_data ad = make_test_array_data(10, 1);
layout_test_type lt(ad);
auto lt_values = lt.values();
for (std::size_t i = 0; i < lt.size(); ++i)
{
Expand All @@ -108,15 +112,17 @@ namespace sparrow

TEST_CASE("const_bitmap_iterator_ordering")
{
layout_test_type lt(make_test_array_data(10, 1));
array_data ad = make_test_array_data(10, 1);
layout_test_type lt(ad);
auto lt_bitmap = lt.bitmap();
layout_test_type::const_bitmap_iterator citer = lt_bitmap.begin();
CHECK(citer < lt_bitmap.end());
}

TEST_CASE("const_bitmap_iterator_equality")
{
layout_test_type lt(make_test_array_data(10, 1));
array_data ad = make_test_array_data(10, 1);
layout_test_type lt(ad);
auto lt_bitmap = lt.bitmap();
for (std::size_t i = 0; i < lt.size(); ++i)
{
Expand All @@ -133,7 +139,8 @@ namespace sparrow

TEST_CASE("iterator")
{
layout_test_type lt(make_test_array_data(10, 1));
array_data ad = make_test_array_data(10, 1);
layout_test_type lt(ad);
auto it = lt.begin();
auto end = lt.end();

Expand All @@ -148,7 +155,8 @@ namespace sparrow
for (auto v: lt)
CHECK(v.has_value());

layout_test_type lt_empty(make_test_array_data(0, 0));
array_data ad_empty = make_test_array_data(0, 0);
layout_test_type lt_empty(ad_empty);
CHECK_EQ(lt_empty.begin(), lt_empty.end());
}

Expand Down

0 comments on commit 8d7c2b2

Please sign in to comment.