53 int64_t InlineBufferCapacity = 64,
58 typename Allocator = GuardedAllocator>
61 static constexpr int64_t required_ints_for_bits(
const int64_t number_of_bits)
63 return (number_of_bits + BitsPerInt - 1) / BitsPerInt;
66 static constexpr int64_t IntsInInlineBuffer = required_ints_for_bits(InlineBufferCapacity);
67 static constexpr int64_t BitsInInlineBuffer = IntsInInlineBuffer * BitsPerInt;
68 static constexpr int64_t AllocationAlignment =
alignof(
BitInt);
89 BitVector(Allocator allocator = {})
noexcept : allocator_(allocator)
91 data_ = inline_buffer_;
93 capacity_in_bits_ = BitsInInlineBuffer;
101 const int64_t ints_to_copy = required_ints_for_bits(span.
size());
102 if (span.
size() <= BitsInInlineBuffer) {
104 data_ = inline_buffer_;
105 capacity_in_bits_ = BitsInInlineBuffer;
109 data_ =
static_cast<BitInt *
>(
110 allocator_.allocate(ints_to_copy *
sizeof(
BitInt), AllocationAlignment, __func__));
111 capacity_in_bits_ = ints_to_copy * BitsPerInt;
113 size_in_bits_ = span.
size();
119 allocator_ = other.allocator_;
124 if (other.is_inline()) {
128 int64_t ints_to_copy = IntsInInlineBuffer;
129 if constexpr (IntsInInlineBuffer > 8) {
131 ints_to_copy = other.used_ints_amount();
133 data_ = inline_buffer_;
140 size_in_bits_ = other.size_in_bits_;
141 capacity_in_bits_ = other.capacity_in_bits_;
144 other.data_ = other.inline_buffer_;
145 other.size_in_bits_ = 0;
146 other.capacity_in_bits_ = BitsInInlineBuffer;
155 this->
resize(size_in_bits, value);
170 if (!this->is_inline()) {
171 allocator_.deallocate(data_);
200 return size_in_bits_;
208 return capacity_in_bits_;
213 return size_in_bits_ == 0;
233 return {data_,
index};
243 return {data_,
index};
256 this->ensure_space_for_one();
269 return {data_, size_in_bits_};
279 return {data_, size_in_bits_};
289 const int64_t old_size_in_bits = size_in_bits_;
290 if (new_size_in_bits > old_size_in_bits) {
291 this->
reserve(new_size_in_bits);
293 size_in_bits_ = new_size_in_bits;
294 if (old_size_in_bits < new_size_in_bits) {
314 this->realloc_to_at_least(new_capacity_in_bits);
332 capacity_in_bits_ = 0;
333 if (!this->is_inline()) {
334 allocator_.deallocate(data_);
336 data_ = inline_buffer_;
340 void ensure_space_for_one()
342 if (size_in_bits_ >= capacity_in_bits_) [[unlikely]] {
343 this->realloc_to_at_least(size_in_bits_ + 1);
348 const BitInt initial_value_for_new_ints = 0)
350 if (capacity_in_bits_ >= min_capacity_in_bits) {
354 const int64_t min_capacity_in_ints = this->required_ints_for_bits(min_capacity_in_bits);
357 const int64_t min_new_capacity_in_ints = 2 * this->required_ints_for_bits(capacity_in_bits_);
359 const int64_t new_capacity_in_ints = std::max(min_capacity_in_ints, min_new_capacity_in_ints);
360 const int64_t ints_to_copy = this->used_ints_amount();
363 allocator_.allocate(new_capacity_in_ints *
sizeof(
BitInt), AllocationAlignment, __func__));
369 new_data + ints_to_copy, new_capacity_in_ints - ints_to_copy, initial_value_for_new_ints);
371 if (!this->is_inline()) {
372 allocator_.deallocate(data_);
376 capacity_in_bits_ = new_capacity_in_ints * BitsPerInt;
379 bool is_inline()
const
381 return data_ == inline_buffer_;
384 int64_t used_ints_amount()
const
386 return this->required_ints_for_bits(size_in_bits_);
390template<
int64_t InlineBufferCapacity,
typename Allocator>
396template<
int64_t InlineBufferCapacity,
typename Allocator>
404using bits::BitVector;
#define BLI_NO_UNIQUE_ADDRESS
static constexpr IndexRange from_begin_end(const int64_t begin, const int64_t end)
constexpr IndexRange()=default
constexpr int64_t size() const
const BitInt * data() const
MutableBitIterator begin()
BitVector(const int64_t size_in_bits, const bool value=false, Allocator allocator={})
void resize(const int64_t new_size_in_bits, const bool value=false)
MutableBitRef operator[](const int64_t index)
BitVector(const Span< bool > values, Allocator allocator={})
BitIterator begin() const
void reserve(const int new_capacity_in_bits)
void append(const bool value)
BitVector(const BoundedBitSpan span)
BitVector(Allocator allocator={}) noexcept
BitVector & operator=(BitVector &&other)
BitVector & operator=(const BitVector &other)
BitVector(BitVector &&other) noexcept
BitVector(NoExceptConstructor, Allocator allocator={}) noexcept
void fill(const bool value)
IndexRange index_range() const
BitVector(const BitVector &other)
const BitInt * data() const
BitRef operator[](const int64_t index) const
MutableBoundedBitSpan()=default
bool or_bools_into_bits(Span< bool > bools, MutableBitSpan r_bits, int64_t allowed_overshoot=0)
T to_best_bit_span(const T &data)
BLI_assert(slot->slot_subtype.map==BMO_OP_SLOT_SUBTYPE_MAP_FLT)
BMesh const char void * data
Container & copy_assign_container(Container &dst, const Container &src)
Container & move_assign_container(Container &dst, Container &&src) noexcept(std::is_nothrow_move_constructible_v< Container >)
void uninitialized_fill_n(T *dst, int64_t n, const T &value)
void uninitialized_copy_n(const T *src, int64_t n, T *dst)