Skip to content

Commit

Permalink
fix issues with paged_vecvec and vecvec
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Dec 19, 2024
1 parent 85a7b2a commit eecb4be
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 9 deletions.
8 changes: 6 additions & 2 deletions include/cista/containers/paged.h
Original file line number Diff line number Diff line change
Expand Up @@ -97,8 +97,12 @@ struct paged {
std::memcpy(&data_[offset], &x, sizeof(T));
}

value_type* data(page_t const& p) { return &data_[p.start_]; }
value_type const* data(page_t const& p) const { return &data_[p.start_]; }
value_type* data(page_t const& p) {
return data_.empty() ? nullptr : &data_[p.start_];
}
value_type const* data(page_t const& p) const {
return data_.empty() ? nullptr : &data_[p.start_];
}

value_type* begin(page_t const& p) { return data(p); }
value_type const* begin(page_t const& p) const { return data(p); }
Expand Down
14 changes: 11 additions & 3 deletions include/cista/containers/paged_vecvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ struct paged_vecvec {
return (*this)[size() - 1U];
}

reference operator*() const { return *this; }
const_bucket operator*() const { return *this; }

size_type size() const { return pv_->page(i_).size_; }
bool empty() const { return size() == 0U; }
Expand Down Expand Up @@ -161,6 +161,14 @@ struct paged_vecvec {
(*this)[size() - 1U] = x;
}

template <typename Arg>
iterator insert(iterator const it, Arg&& el) {
auto const old_offset = std::distance(begin(), it);
auto const old_size = size();
push_back(data_value_type{el});
return std::rotate(begin() + old_offset, begin() + old_size, end());
}

template <typename T = std::decay_t<data_value_type>,
typename = std::enable_if_t<std::is_same_v<T, char>>>
std::string_view view() const {
Expand Down Expand Up @@ -196,7 +204,7 @@ struct paged_vecvec {
return *(begin() + i);
}

reference operator*() const { return *this; }
bucket operator*() const { return *this; }

operator const_bucket() const { return {pv_, i_}; }

Expand Down Expand Up @@ -286,7 +294,7 @@ struct paged_vecvec {
const_bucket front() const { return at(Key{0}); }
const_bucket back() const { return at(Key{size() - 1}); }

size_type size() const { return idx_.size(); }
base_t<Key> size() const { return idx_.size(); }
bool empty() const { return idx_.empty(); }

bucket begin() { return front(); }
Expand Down
9 changes: 5 additions & 4 deletions include/cista/containers/vecvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,10 +159,12 @@ struct basic_vecvec {

private:
index_value_type bucket_begin_idx() const {
return to_idx(map_->bucket_starts_[i_]);
return map_->empty() ? index_value_type{}
: to_idx(map_->bucket_starts_[i_]);
}
index_value_type bucket_end_idx() const {
return to_idx(map_->bucket_starts_[i_ + 1U]);
return map_->empty() ? index_value_type{}
: to_idx(map_->bucket_starts_[i_ + 1U]);
}
bool is_inside_bucket(std::size_t const i) const {
return bucket_begin_idx() + i < bucket_end_idx();
Expand Down Expand Up @@ -335,11 +337,10 @@ struct basic_vecvec {
if (bucket_starts_.empty()) {
bucket_starts_.emplace_back(index_value_type{0U});
}
bucket_starts_.emplace_back(
static_cast<index_value_type>(data_.size() + bucket.size()));
data_.insert(std::end(data_), //
std::make_move_iterator(std::begin(bucket)),
std::make_move_iterator(std::end(bucket)));
bucket_starts_.emplace_back(data_.size());
}

bucket add_back_sized(std::size_t const bucket_size) {
Expand Down

0 comments on commit eecb4be

Please sign in to comment.