diff --git a/include/sparrow/layout/dictionary_encoded_array.hpp b/include/sparrow/layout/dictionary_encoded_array.hpp index b5b2cf19..0028cdea 100644 --- a/include/sparrow/layout/dictionary_encoded_array.hpp +++ b/include/sparrow/layout/dictionary_encoded_array.hpp @@ -104,6 +104,12 @@ namespace sparrow explicit dictionary_encoded_array(arrow_proxy); + dictionary_encoded_array(const self_type&); + self_type& operator=(const self_type&); + + dictionary_encoded_array(self_type&&); + self_type& operator=(self_type&&); + size_type size() const; const_reference operator[](size_type i) const; @@ -139,6 +145,9 @@ namespace sparrow friend class array_wrapper_impl; }; + template + bool operator==(const dictionary_encoded_array& lhs, const dictionary_encoded_array& rhs); + /******************************************* * dictionary_encoded_array implementation * *******************************************/ @@ -152,6 +161,47 @@ namespace sparrow SPARROW_ASSERT_TRUE(data_type_is_integer(m_proxy.data_type())); } + template + dictionary_encoded_array::dictionary_encoded_array(const self_type& rhs) + : m_proxy(rhs.m_proxy) + , m_keys_layout(create_keys_layout(m_proxy)) + , p_values_layout(create_values_layout(m_proxy)) + { + } + + template + auto dictionary_encoded_array::operator=(const self_type& rhs) -> self_type& + { + if (this != &rhs) + { + m_proxy = rhs.m_proxy; + m_keys_layout = create_keys_layout(m_proxy); + p_values_layout = create_values_layout(m_proxy); + } + return *this; + } + + template + dictionary_encoded_array::dictionary_encoded_array(self_type&& rhs) + : m_proxy(std::move(rhs.m_proxy)) + , m_keys_layout(create_keys_layout(m_proxy)) + , p_values_layout(create_values_layout(m_proxy)) + { + } + + template + auto dictionary_encoded_array::operator=(self_type&& rhs) -> self_type& + { + if (this != &rhs) + { + using std::swap; + swap(m_proxy, rhs.m_proxy); + m_keys_layout = create_keys_layout(m_proxy); + p_values_layout = create_values_layout(m_proxy); + } + return *this; + } + template auto dictionary_encoded_array::size() const -> size_type { @@ -257,4 +307,10 @@ namespace sparrow { return m_proxy; } + + template + bool operator==(const dictionary_encoded_array& lhs, const dictionary_encoded_array& rhs) + { + return std::ranges::equal(lhs, rhs); + } } diff --git a/src/arrow_array_schema_proxy.cpp b/src/arrow_array_schema_proxy.cpp index 56ccd586..41ad516d 100644 --- a/src/arrow_array_schema_proxy.cpp +++ b/src/arrow_array_schema_proxy.cpp @@ -160,7 +160,7 @@ namespace sparrow { other.m_array = {}; other.m_schema = {}; - other.m_buffers.clear(); + other.reset(); update_buffers(); update_children(); update_dictionary(); diff --git a/test/test_dictionary_encoded_array.cpp b/test/test_dictionary_encoded_array.cpp index 869f0817..ae9c3697 100644 --- a/test/test_dictionary_encoded_array.cpp +++ b/test/test_dictionary_encoded_array.cpp @@ -71,6 +71,29 @@ namespace sparrow CHECK_NOTHROW(layout_type{make_arrow_proxy()}); } + TEST_CASE("copy") + { + layout_type ar(make_arrow_proxy()); + layout_type ar2(ar); + CHECK_EQ(ar, ar2); + + layout_type ar3(make_arrow_proxy()); + ar3 = ar; + CHECK_EQ(ar, ar3); + } + + TEST_CASE("move") + { + layout_type ar(make_arrow_proxy()); + layout_type ar2(ar); + layout_type ar3(std::move(ar)); + CHECK_EQ(ar2, ar3); + + layout_type ar4(make_arrow_proxy()); + ar4 = std::move(ar3); + CHECK_EQ(ar2, ar4); + } + TEST_CASE("size") { const layout_type dict(make_arrow_proxy()); diff --git a/test/test_null_array.cpp b/test/test_null_array.cpp index d8bb6437..4a1287e6 100644 --- a/test/test_null_array.cpp +++ b/test/test_null_array.cpp @@ -34,6 +34,33 @@ namespace sparrow CHECK_EQ(ar.size(), size); } + TEST_CASE("copy") + { + constexpr std::size_t size = 10u; + null_array ar(make_arrow_proxy(size)); + null_array ar2(ar); + CHECK_EQ(ar, ar2); + + null_array ar3(make_arrow_proxy(size + 2u)); + CHECK_NE(ar, ar3); + ar3 = ar; + CHECK_EQ(ar, ar3); + } + + TEST_CASE("move") + { + constexpr std::size_t size = 10u; + null_array ar(make_arrow_proxy(size)); + null_array ar2(ar); + null_array ar3(std::move(ar)); + CHECK_EQ(ar3, ar2); + + null_array ar4(make_arrow_proxy(size + 3u)); + CHECK_NE(ar4, ar2); + ar4 = std::move(ar3); + CHECK_EQ(ar2, ar4); + } + TEST_CASE("operator[]") { constexpr std::size_t size = 10u; diff --git a/test/test_primitive_array.cpp b/test/test_primitive_array.cpp index e84b4dff..63393552 100644 --- a/test/test_primitive_array.cpp +++ b/test/test_primitive_array.cpp @@ -35,6 +35,33 @@ namespace sparrow CHECK_EQ(ar.size(), size - offset); } + TEST_CASE("copy") + { + array_test_type ar(make_arrow_proxy(size, offset)); + array_test_type ar2(ar); + + CHECK_EQ(ar, ar2); + + array_test_type ar3(make_arrow_proxy(size + 3u, offset)); + CHECK_NE(ar, ar3); + ar3 = ar; + CHECK_EQ(ar, ar3); + } + + TEST_CASE("move") + { + array_test_type ar(make_arrow_proxy(size, offset)); + array_test_type ar2(ar); + + array_test_type ar3(std::move(ar)); + CHECK_EQ(ar2, ar3); + + array_test_type ar4(make_arrow_proxy(size + 3u, offset)); + CHECK_NE(ar2, ar4); + ar4 = std::move(ar2); + CHECK_EQ(ar3, ar4); + } + TEST_CASE("const operator[]") { auto pr = make_arrow_proxy(size, offset); diff --git a/test/test_variable_size_binary_array.cpp b/test/test_variable_size_binary_array.cpp index 7cbcdd0c..0f677823 100644 --- a/test/test_variable_size_binary_array.cpp +++ b/test/test_variable_size_binary_array.cpp @@ -71,6 +71,29 @@ namespace sparrow } } + TEST_CASE_FIXTURE(variable_size_binary_fixture, "copy") + { + layout_type ar(m_arrow_proxy); + layout_type ar2(ar); + CHECK_EQ(ar, ar2); + + layout_type ar3(std::move(m_arrow_proxy)); + ar3 = ar2; + CHECK_EQ(ar2, ar3); + } + + TEST_CASE_FIXTURE(variable_size_binary_fixture, "move") + { + layout_type ar(m_arrow_proxy); + layout_type ar2(ar); + layout_type ar3(std::move(ar)); + CHECK_EQ(ar2, ar3); + + layout_type ar4(std::move(m_arrow_proxy)); + ar4 = std::move(ar3); + CHECK_EQ(ar2, ar4); + } + TEST_CASE_FIXTURE(variable_size_binary_fixture, "size") { const layout_type array(std::move(m_arrow_proxy));