Skip to content

Commit

Permalink
fvec: add append_range() function
Browse files Browse the repository at this point in the history
This allows one to easily append multiple elements to the end at
once.
  • Loading branch information
sebsura committed Feb 12, 2024
1 parent afd7a87 commit effb535
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions core/src/stored/backends/dedup/fvec.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ extern "C" {
}
#include <system_error>
#include <limits>
#include <cstring>

namespace dedup {
struct access {
Expand Down Expand Up @@ -151,6 +152,14 @@ template <typename T> class fvec : access {
}
}

// think of (arr, size) as a span; then the name makes sense
void append_range(const T* arr, std::size_t size)
{
reserve_extra(size);
std::memcpy(end(), arr, size * element_size);
count += size;
}

void reserve_extra(size_type additional) { reserve(additional + count); }

void clear() { count = 0; }
Expand Down

0 comments on commit effb535

Please sign in to comment.