Skip to content

Commit

Permalink
Moved bitmap instantiation in its own crtp base (#242)
Browse files Browse the repository at this point in the history
  • Loading branch information
JohanMabille authored Oct 17, 2024
1 parent ced2bed commit 2781ccc
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 38 deletions.
110 changes: 80 additions & 30 deletions include/sparrow/layout/array_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,8 +105,8 @@ namespace sparrow

array_crtp_base(arrow_proxy);

array_crtp_base(const array_crtp_base&);
array_crtp_base& operator=(const array_crtp_base&);
array_crtp_base(const array_crtp_base&) = default;
array_crtp_base& operator=(const array_crtp_base&) = default;

array_crtp_base(array_crtp_base&&) = default;
array_crtp_base& operator=(array_crtp_base&&) = default;
Expand All @@ -125,13 +125,9 @@ namespace sparrow

private:

static constexpr std::size_t m_bitmap_buffer_index = 0;

arrow_proxy& get_arrow_proxy();
bitmap_type make_bitmap();

arrow_proxy m_proxy;
bitmap_type m_bitmap;

// friend classes
friend class layout_iterator<self_type, false>;
Expand All @@ -143,6 +139,39 @@ namespace sparrow
template <class D>
bool operator==(const array_crtp_base<D>& lhs, const array_crtp_base<D>& rhs);

/*
* Base class for arrays using a validity buffer for
* defining their bitmap.
*/
template <class D>
class array_bitmap_base : public array_crtp_base<D>
{
public:

using base_type = array_crtp_base<D>;
using bitmap_type = typename base_type::bitmap_type;

protected:

array_bitmap_base(arrow_proxy);

array_bitmap_base(const array_bitmap_base&);
array_bitmap_base& operator=(const array_bitmap_base&);

array_bitmap_base(array_bitmap_base&&) = default;
array_bitmap_base& operator=(array_bitmap_base&&) = default;

bitmap_type& get_bitmap();
const bitmap_type& get_bitmap() const;

private:

static constexpr std::size_t m_bitmap_buffer_index = 0;

bitmap_type make_bitmap();
bitmap_type m_bitmap;
};

/**********************************
* array_crtp_base implementation *
**********************************/
Expand Down Expand Up @@ -224,23 +253,7 @@ namespace sparrow
template <class D>
array_crtp_base<D>::array_crtp_base(arrow_proxy proxy)
: m_proxy(std::move(proxy))
, m_bitmap(make_bitmap())
{
}

template <class D>
array_crtp_base<D>::array_crtp_base(const array_crtp_base& rhs)
: m_proxy(rhs.m_proxy)
, m_bitmap(make_bitmap())
{
}

template <class D>
array_crtp_base<D>& array_crtp_base<D>::operator=(const array_crtp_base& rhs)
{
m_proxy = rhs.m_proxy;
m_bitmap = make_bitmap();
return *this;
}

template <class D>
Expand Down Expand Up @@ -272,7 +285,7 @@ namespace sparrow
template <class D>
auto array_crtp_base<D>::bitmap_begin() -> bitmap_iterator
{
return sparrow::next(m_bitmap.begin(), storage().offset());
return sparrow::next(this->derived_cast().get_bitmap().begin(), storage().offset());
}

template <class D>
Expand All @@ -284,7 +297,7 @@ namespace sparrow
template <class D>
auto array_crtp_base<D>::bitmap_begin() const -> const_bitmap_iterator
{
return sparrow::next(m_bitmap.cbegin(), storage().offset());
return sparrow::next(this->derived_cast().get_bitmap().cbegin(), storage().offset());
}

template <class D>
Expand All @@ -300,16 +313,53 @@ namespace sparrow
}

template <class D>
auto array_crtp_base<D>::make_bitmap() -> bitmap_type
bool operator==(const array_crtp_base<D>& lhs, const array_crtp_base<D>& rhs)
{
SPARROW_ASSERT_TRUE(storage().buffers().size() > m_bitmap_buffer_index);
const auto bitmap_size = static_cast<std::size_t>(storage().length() + storage().offset());
return bitmap_type(storage().buffers()[m_bitmap_buffer_index].data(), bitmap_size);
return std::ranges::equal(lhs, rhs);
}

/************************************
* array_bitmap_base implementation *
************************************/

template <class D>
bool operator==(const array_crtp_base<D>& lhs, const array_crtp_base<D>& rhs)
array_bitmap_base<D>::array_bitmap_base(arrow_proxy proxy)
: base_type(std::move(proxy))
, m_bitmap(make_bitmap())
{
return std::ranges::equal(lhs, rhs);
}

template <class D>
array_bitmap_base<D>::array_bitmap_base(const array_bitmap_base& rhs)
: base_type(rhs)
, m_bitmap(make_bitmap())
{
}
template <class D>
array_bitmap_base<D>& array_bitmap_base<D>::operator=(const array_bitmap_base& rhs)
{
base_type::operator=(rhs);
m_bitmap = make_bitmap();
return *this;
}

template <class D>
auto array_bitmap_base<D>::get_bitmap() -> bitmap_type&
{
return m_bitmap;
}

template <class D>
auto array_bitmap_base<D>::get_bitmap() const -> const bitmap_type&
{
return m_bitmap;
}

template <class D>
auto array_bitmap_base<D>::make_bitmap() -> bitmap_type
{
SPARROW_ASSERT_TRUE(this->storage().buffers().size() > m_bitmap_buffer_index);
const auto bitmap_size = static_cast<std::size_t>(this->storage().length() + this->storage().offset());
return bitmap_type(this->storage().buffers()[m_bitmap_buffer_index].data(), bitmap_size);
}
}
4 changes: 2 additions & 2 deletions include/sparrow/layout/list_layout/list_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -100,12 +100,12 @@ namespace sparrow
// - big-list-view-array
// - fixed-size-list-array
template <class DERIVED>
class list_array_crtp_base : public array_crtp_base<DERIVED>
class list_array_crtp_base : public array_bitmap_base<DERIVED>
{
public:

using self_type = list_array_crtp_base<DERIVED>;
using base_type = array_crtp_base<DERIVED>;
using base_type = array_bitmap_base<DERIVED>;
using inner_types = array_inner_types<DERIVED>;
using value_iterator = typename inner_types::value_iterator;
using const_value_iterator = typename inner_types::const_value_iterator;
Expand Down
4 changes: 2 additions & 2 deletions include/sparrow/layout/primitive_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ namespace sparrow
};

template <class T>
class primitive_array final : public array_crtp_base<primitive_array<T>>
class primitive_array final : public array_bitmap_base<primitive_array<T>>
{
public:

using self_type = primitive_array<T>;
using base_type = array_crtp_base<self_type>;
using base_type = array_bitmap_base<self_type>;
using inner_types = array_inner_types<self_type>;
using inner_value_type = typename inner_types::inner_value_type;
using inner_reference = typename inner_types::inner_reference;
Expand Down
4 changes: 2 additions & 2 deletions include/sparrow/layout/struct_layout/struct_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ namespace sparrow
using iterator_tag = std::random_access_iterator_tag;
};

class struct_array final : public array_crtp_base<struct_array>
class struct_array final : public array_bitmap_base<struct_array>
{
public:

using self_type = struct_array;
using base_type = array_crtp_base<self_type>;
using base_type = array_bitmap_base<self_type>;
using inner_types = array_inner_types<self_type>;
using value_iterator = typename inner_types::value_iterator;
using const_value_iterator = typename inner_types::const_value_iterator;
Expand Down
4 changes: 2 additions & 2 deletions include/sparrow/layout/variable_size_binary_array.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -179,12 +179,12 @@ namespace sparrow
};

template <std::ranges::sized_range T, class CR, layout_offset OT>
class variable_size_binary_array final : public array_crtp_base<variable_size_binary_array<T, CR, OT>>
class variable_size_binary_array final : public array_bitmap_base<variable_size_binary_array<T, CR, OT>>
{
public:

using self_type = variable_size_binary_array<T, CR, OT>;
using base_type = array_crtp_base<self_type>;
using base_type = array_bitmap_base<self_type>;
using inner_types = array_inner_types<self_type>;
using inner_value_type = typename inner_types::inner_value_type;
using inner_reference = typename inner_types::inner_reference;
Expand Down

0 comments on commit 2781ccc

Please sign in to comment.