Skip to content

Commit

Permalink
variable_size_binary_layout inner ref (#119)
Browse files Browse the repository at this point in the history
* Add vs_binary_reference

---------

Co-authored-by: Johan Mabille <[email protected]>
  • Loading branch information
Hind-M and JohanMabille authored Jul 19, 2024
1 parent 57abc2d commit c3c39c8
Show file tree
Hide file tree
Showing 9 changed files with 591 additions and 85 deletions.
4 changes: 2 additions & 2 deletions include/sparrow/data_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,15 @@ namespace sparrow
{
static constexpr data_type type_id = data_type::STRING;
using value_type = std::string;
using default_layout = variable_size_binary_layout<value_type, std::string_view, const std::string_view>; // FIXME: this is incorrect, change when we have the right types
using default_layout = variable_size_binary_layout<value_type, const std::string_view>;
};

template <>
struct arrow_traits<std::vector<byte_t>>
{
static constexpr data_type type_id = data_type::STRING;
using value_type = std::vector<byte_t>;
using default_layout = variable_size_binary_layout<value_type, std::span<byte_t>, const std::span<byte_t>>; // FIXME: this is incorrect, change when we have the right types
using default_layout = variable_size_binary_layout<value_type, const std::span<byte_t>>;
};

template <>
Expand Down
41 changes: 33 additions & 8 deletions include/sparrow/dictionary_encoded_layout.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -221,7 +221,11 @@ namespace sparrow

private:

const indexes_layout& get_const_indexes_layout() const;
indexes_layout& get_indexes_layout();
const indexes_layout& get_indexes_layout() const;

sub_layout& get_sub_layout();
const sub_layout& get_sub_layout() const;

const_value_iterator value_cbegin() const;
const_value_iterator value_cend() const;
Expand Down Expand Up @@ -355,10 +359,10 @@ namespace sparrow
auto dictionary_encoded_layout<T, SL, OT>::operator[](size_type i) const -> const_reference
{
SPARROW_ASSERT_TRUE(i < size());
const auto index = (*m_indexes_layout)[i];
const auto index = get_indexes_layout()[i];
if (index.has_value())
{
return (*m_sub_layout)[index.value()];
return get_sub_layout()[index.value()];
}
else
{
Expand Down Expand Up @@ -391,34 +395,55 @@ namespace sparrow
return const_value_range(value_cbegin(), value_cend());
}

template <std::integral T, class SL, layout_offset OT>
typename dictionary_encoded_layout<T, SL, OT>::indexes_layout&
dictionary_encoded_layout<T, SL, OT>::get_indexes_layout()
{
return *(m_indexes_layout.get());
}

template <std::integral T, class SL, layout_offset OT>
const typename dictionary_encoded_layout<T, SL, OT>::indexes_layout&
dictionary_encoded_layout<T, SL, OT>::get_const_indexes_layout() const
dictionary_encoded_layout<T, SL, OT>::get_indexes_layout() const
{
return *const_cast<const indexes_layout*>(m_indexes_layout.get());
}

template <std::integral T, class SL, layout_offset OT>
typename dictionary_encoded_layout<T, SL, OT>::sub_layout&
dictionary_encoded_layout<T, SL, OT>::get_sub_layout()
{
return *(m_sub_layout.get());
}

template <std::integral T, class SL, layout_offset OT>
const typename dictionary_encoded_layout<T, SL, OT>::sub_layout&
dictionary_encoded_layout<T, SL, OT>::get_sub_layout() const
{
return *const_cast<const sub_layout*>(m_sub_layout.get());
}

template <std::integral T, class SL, layout_offset OT>
auto dictionary_encoded_layout<T, SL, OT>::value_cbegin() const -> const_value_iterator
{
return const_value_iterator(get_const_indexes_layout().cbegin(), *m_sub_layout);
return const_value_iterator(get_indexes_layout().cbegin(), *m_sub_layout);
}

template <std::integral T, class SL, layout_offset OT>
auto dictionary_encoded_layout<T, SL, OT>::value_cend() const -> const_value_iterator
{
return const_value_iterator(get_const_indexes_layout().cend(), *m_sub_layout);
return const_value_iterator(get_indexes_layout().cend(), *m_sub_layout);
}
template <std::integral T, class SL, layout_offset OT>
auto dictionary_encoded_layout<T, SL, OT>::bitmap_cbegin() const -> const_bitmap_iterator
{
return const_bitmap_iterator(get_const_indexes_layout().cbegin(), *m_sub_layout);
return const_bitmap_iterator(get_indexes_layout().cbegin(), get_sub_layout());
}

template <std::integral T, class SL, layout_offset OT>
auto dictionary_encoded_layout<T, SL, OT>::bitmap_cend() const -> const_bitmap_iterator
{
return const_bitmap_iterator(get_const_indexes_layout().cend(), *m_sub_layout);
return const_bitmap_iterator(get_indexes_layout().cend(), get_sub_layout());
}

template <std::integral T, class SL, layout_offset OT>
Expand Down
4 changes: 4 additions & 0 deletions include/sparrow/mp_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,4 +424,8 @@ namespace sparrow::mpl
template <class T>
concept boolean_like = std::is_assignable_v<std::add_lvalue_reference_t<std::decay_t<T>>, bool> and
requires { static_cast<bool>(std::declval<T>()); };

/// Matches range types From whose elements are convertible to elements of range type To.
template <class From, class To>
concept convertible_ranges = std::convertible_to<std::ranges::range_value_t<From>, std::ranges::range_value_t<To>>;
}
Loading

0 comments on commit c3c39c8

Please sign in to comment.