Skip to content
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
24 changes: 18 additions & 6 deletions include/sparrow/buffer/dynamic_bitset/dynamic_bitset_base.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -334,27 +334,31 @@ namespace sparrow
return std::move(m_buffer);
}

[[nodiscard]] size_t offset() const noexcept;
Copy link

Copilot AI Sep 22, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The offset() method declaration is missing implementation. Add the implementation for this method to return m_offset.

Suggested change
[[nodiscard]] size_t offset() const noexcept;
[[nodiscard]] size_t offset() const noexcept
{
return m_offset;
}

Copilot uses AI. Check for mistakes.

protected:

/**
* @brief Constructs a bitset with the given storage and size.
* @param buffer The storage buffer to use
* @param size The number of bits in the bitset
* @param offset The number of bits to offset from the start of the buffer
* @post size() == size
* @post null_count() is computed by counting unset bits
*/
constexpr dynamic_bitset_base(storage_type buffer, size_type size);
constexpr dynamic_bitset_base(storage_type buffer, size_type size, size_type offset);

/**
* @brief Constructs a bitset with the given storage, size, and null count.
* @param buffer The storage buffer to use
* @param size The number of bits in the bitset
* @param null_count The number of unset bits
* @param offset The number of bits to offset from the start of the buffer
* @pre null_count <= size
* @post size() == size
* @post null_count() == null_count
*/
constexpr dynamic_bitset_base(storage_type buffer, size_type size, size_type null_count);
constexpr dynamic_bitset_base(storage_type buffer, size_type size, size_type null_count, size_type offset);

constexpr ~dynamic_bitset_base() = default;

Expand Down Expand Up @@ -540,6 +544,7 @@ namespace sparrow
storage_type m_buffer; ///< The underlying storage for bit data
size_type m_size; ///< The number of bits in the bitset
size_type m_null_count; ///< The number of bits set to false
size_t m_offset = 0; ///< The number of bits to offset from the start of the buffer

friend class bitset_iterator<self_type, true>; ///< Const iterator needs access to internals
friend class bitset_iterator<self_type, false>; ///< Mutable iterator needs access to internals
Expand Down Expand Up @@ -572,7 +577,7 @@ namespace sparrow
constexpr auto dynamic_bitset_base<B>::operator[](size_type pos) -> reference
{
SPARROW_ASSERT_TRUE(pos < size());
return reference(*this, pos);
return reference(*this, pos + m_offset);
}

template <typename B>
Expand All @@ -598,7 +603,7 @@ namespace sparrow
{
return true;
}
return !m_null_count || buffer().data()[block_index(pos)] & bit_mask(pos);
return !m_null_count || buffer().data()[block_index(pos + m_offset)] & bit_mask(pos + m_offset);
}

template <typename B>
Expand Down Expand Up @@ -790,19 +795,26 @@ namespace sparrow

template <typename B>
requires std::ranges::random_access_range<std::remove_pointer_t<B>>
constexpr dynamic_bitset_base<B>::dynamic_bitset_base(storage_type buf, size_type size)
constexpr dynamic_bitset_base<B>::dynamic_bitset_base(storage_type buf, size_type size, size_type offset)
: m_buffer(std::move(buf))
, m_size(size)
, m_null_count(m_size - count_non_null())
, m_offset(offset)
{
}

template <typename B>
requires std::ranges::random_access_range<std::remove_pointer_t<B>>
constexpr dynamic_bitset_base<B>::dynamic_bitset_base(storage_type buf, size_type size, size_type null_count)
constexpr dynamic_bitset_base<B>::dynamic_bitset_base(
storage_type buf,
size_type size,
size_type null_count,
size_type offset
)
: m_buffer(std::move(buf))
, m_size(size)
, m_null_count(null_count)
, m_offset(offset)
{
}

Expand Down
17 changes: 11 additions & 6 deletions include/sparrow/buffer/dynamic_bitset/dynamic_bitset_view.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ namespace sparrow
* assert(view.test(0) == true); // First bit is set
* @endcode
*/
constexpr dynamic_bitset_view(block_type* p, size_type n);
constexpr dynamic_bitset_view(block_type* p, size_type n, size_type offset);

/**
* @brief Constructs a bitset view from external memory with null count tracking.
Expand Down Expand Up @@ -141,7 +141,7 @@ namespace sparrow
* assert(view.count_non_null() == 10);
* @endcode
*/
constexpr dynamic_bitset_view(block_type* p, size_type n, size_type null_count);
constexpr dynamic_bitset_view(block_type* p, size_type n, size_type null_count, size_type offset);

constexpr ~dynamic_bitset_view() = default;

Expand All @@ -153,14 +153,19 @@ namespace sparrow
};

template <std::integral T>
constexpr dynamic_bitset_view<T>::dynamic_bitset_view(block_type* p, size_type n)
: base_type(storage_type(p, p != nullptr ? this->compute_block_count(n) : 0), n)
constexpr dynamic_bitset_view<T>::dynamic_bitset_view(block_type* p, size_type n, size_type offset)
: base_type(storage_type(p, p != nullptr ? this->compute_block_count(n) : 0), n, offset)
{
}

template <std::integral T>
constexpr dynamic_bitset_view<T>::dynamic_bitset_view(block_type* p, size_type n, size_type null_count)
: base_type(storage_type(p, p != nullptr ? this->compute_block_count(n) : 0), n, null_count)
constexpr dynamic_bitset_view<T>::dynamic_bitset_view(
block_type* p,
size_type n,
size_type null_count,
size_type offset
)
: base_type(storage_type(p, p != nullptr ? this->compute_block_count(n) : 0), n, null_count, offset)
{
}
}
6 changes: 5 additions & 1 deletion src/arrow_interface/arrow_array_schema_proxy.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -847,7 +847,11 @@ namespace sparrow
if (has_bitmap(data_type()))
{
const auto& validity_buffer = buffers().front();
const dynamic_bitset_view<const std::uint8_t> bitmap(validity_buffer.data(), length() + offset());
const dynamic_bitset_view<const std::uint8_t> bitmap(
validity_buffer.data(),
length() + offset(),
offset()
);
const auto null_count = bitmap.null_count();
set_null_count(static_cast<int64_t>(null_count));
}
Expand Down
Loading