Skip to content

Commit

Permalink
paged_vecvec::insert, generic vecvec::view
Browse files Browse the repository at this point in the history
  • Loading branch information
felixguendling committed Dec 16, 2024
1 parent 989b7d5 commit 85a7b2a
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
10 changes: 10 additions & 0 deletions include/cista/containers/paged_vecvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,16 @@ struct paged_vecvec {
return emplace_back(std::string_view{s});
}

template <typename Container,
typename = std::enable_if_t<std::is_convertible_v<
decltype(*std::declval<Container>().begin()), data_value_type>>>
void insert(Key const& k, Container&& bucket) {
auto p = paged_.create_page(
static_cast<typename Paged::page_size_type>(bucket.size()));
paged_.copy(p, std::begin(bucket), std::end(bucket));
idx_.insert(idx_.begin() + to_idx(k), p);
}

void resize(size_type const size) {
for (auto i = size; i < idx_.size(); ++i) {
paged_.free_page(idx_[i]);
Expand Down
12 changes: 6 additions & 6 deletions include/cista/containers/vecvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@ struct basic_vecvec {
data_value_type const* data() const { return empty() ? nullptr : &front(); }

template <typename T = std::decay_t<data_value_type>,
typename Traits = std::char_traits<T>>
std::basic_string_view<T, Traits> view() const {
return std::basic_string_view<T, Traits>{begin(), size()};
typename = std::enable_if_t<std::is_trivially_copyable_v<T>>>
std::basic_string_view<T> view() const {
return {begin(), size()};
}

value_type& front() {
Expand Down Expand Up @@ -191,9 +191,9 @@ struct basic_vecvec {
data_value_type const* data() const { return empty() ? nullptr : &front(); }

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 {
return std::string_view{begin(), size()};
typename = std::enable_if_t<std::is_trivially_copyable_v<T>>>
std::basic_string_view<T> view() const {
return {begin(), size()};
}

value_type const& front() const {
Expand Down

0 comments on commit 85a7b2a

Please sign in to comment.