Skip to content

Commit

Permalink
fix: Layout builders clean and length bug fixes (#2171)
Browse files Browse the repository at this point in the history
* fix: Layout builders extensive tests; clean and length bugfixes

* fix: typo
  • Loading branch information
ianna authored Jan 30, 2023
1 parent 7734bde commit 3bab57d
Show file tree
Hide file tree
Showing 3 changed files with 416 additions and 196 deletions.
2 changes: 2 additions & 0 deletions header-only/include/awkward/GrowableBuffer.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ namespace awkward {
reserved_(reserved),
next_(nullptr) {}

~Panel() = default;

/// @brief Overloads [] operator to access elements like an array.
PRIMITIVE& operator[](size_t i) { return ptr_.get()[i]; }

Expand Down
12 changes: 8 additions & 4 deletions header-only/include/awkward/LayoutBuilder.h
Original file line number Diff line number Diff line change
Expand Up @@ -1067,14 +1067,14 @@ namespace awkward {
clear() noexcept {
for (size_t i = 0; i < fields_count_; i++)
visit_at(contents, i, [](auto& content) {
content.builder.clear();
content.clear();
});
}

/// @brief Current number of records in the first index of the tuple.
size_t
length() const noexcept {
return (std::get<0>(contents).builder.length());
return (std::get<0>(contents).length());
}

/// @brief Checks for validity and consistency.
Expand Down Expand Up @@ -2248,12 +2248,16 @@ namespace awkward {
clear() noexcept {
mask_.clear();
content_.clear();
current_byte_ = 0;
current_byte_ref_ = mask_.append_and_get_ref(current_byte_);
current_index_ = 0;
}

/// @brief Current length of the `mask` buffer.
size_t
length() const noexcept {
return (mask_.length() - 1) * 8 + current_index_;
return mask_.length() > 0 ?
(mask_.length() - 1) * 8 + current_index_ : current_index_;
}

/// @brief Checks for validity and consistency.
Expand Down Expand Up @@ -2495,7 +2499,7 @@ namespace awkward {
tags_.clear();
index_.clear();
auto clear_contents = [](auto& content) {
content.builder.clear();
content.clear();
};
for (size_t i = 0; i < contents_count_; i++)
visit_at(contents_, i, clear_contents);
Expand Down
Loading

0 comments on commit 3bab57d

Please sign in to comment.