Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed copy semantic of arrays #244

Merged
merged 7 commits into from
Oct 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions include/sparrow/arrow_interface/arrow_array_schema_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ namespace sparrow
child->release(child);
}
}
// TODO: We assume Arrow structures allocated inside sparrow always use operator new
//delete child;
//t.children[i] = nullptr;
}
delete[] t.children;
t.children = nullptr;
Expand Down
56 changes: 56 additions & 0 deletions include/sparrow/layout/dictionary_encoded_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -139,6 +145,9 @@ namespace sparrow
friend class array_wrapper_impl;
};

template <class IT>
bool operator==(const dictionary_encoded_array<IT>& lhs, const dictionary_encoded_array<IT>& rhs);

/*******************************************
* dictionary_encoded_array implementation *
*******************************************/
Expand All @@ -152,6 +161,47 @@ namespace sparrow
SPARROW_ASSERT_TRUE(data_type_is_integer(m_proxy.data_type()));
}

template <std::integral IT>
dictionary_encoded_array<IT>::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 <std::integral IT>
auto dictionary_encoded_array<IT>::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 <std::integral IT>
dictionary_encoded_array<IT>::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 <std::integral IT>
auto dictionary_encoded_array<IT>::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 <std::integral IT>
auto dictionary_encoded_array<IT>::size() const -> size_type
{
Expand Down Expand Up @@ -257,4 +307,10 @@ namespace sparrow
{
return m_proxy;
}

template <class IT>
bool operator==(const dictionary_encoded_array<IT>& lhs, const dictionary_encoded_array<IT>& rhs)
{
return std::ranges::equal(lhs, rhs);
}
}
56 changes: 25 additions & 31 deletions include/sparrow/layout/layout_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,45 +18,31 @@

namespace sparrow::detail
{

template<class LAYOUT_TYPE>
class layout_functor_base
{
public:
using layout_type = LAYOUT_TYPE;
constexpr layout_functor_base() = default;
constexpr layout_functor_base& operator=(layout_functor_base&&) = default;
constexpr layout_functor_base(const layout_functor_base&) = default;
constexpr layout_functor_base(layout_functor_base&&) = default;
constexpr layout_functor_base& operator=(const layout_functor_base&) = default;

constexpr layout_functor_base(layout_type * layout)
: p_layout(layout)
{
}

protected:
layout_type * p_layout = nullptr;
};


// Functor to get the value of the layout at index i.
//
// This is usefull to create a iterator over the values of a layout.
// This functor will be passed to the functor_index_iterator.
template<class LAYOUT_TYPE, class VALUE_TYPE>
class layout_value_functor : public layout_functor_base<LAYOUT_TYPE>
class layout_value_functor
{
public:
using base_type = layout_functor_base<LAYOUT_TYPE>;
using base_type::base_type;
using base_type::operator=;
public:

using value_type = VALUE_TYPE;
using layout_type = LAYOUT_TYPE;

constexpr explicit layout_value_functor(layout_type* layout = nullptr)
: p_layout(layout)
{
}

value_type operator()(std::size_t i) const
{
return this->p_layout->value(i);
}

private:

layout_type* p_layout;
};


Expand All @@ -65,18 +51,26 @@ namespace sparrow::detail
// This is usefull to create a iterator over the nullable-values of a layout.
// This functor will be passed to the functor_index_iterator.
template<class LAYOUT_TYPE, class VALUE_TYPE>
class layout_bracket_functor : public layout_functor_base<LAYOUT_TYPE>
class layout_bracket_functor
{
public:
using base_type = layout_functor_base<LAYOUT_TYPE>;
using base_type::base_type;
using base_type::operator=;

using value_type = VALUE_TYPE;
using layout_type = LAYOUT_TYPE;

constexpr explicit layout_bracket_functor(layout_type* layout = nullptr)
: p_layout(layout)
{
}

value_type operator()(std::size_t i) const
{
return this->p_layout->operator[](i);
}

private:

layout_type* p_layout;
};

}; // namespace sparrow::detail
Loading
Loading