Blender V4.5
blender::bits Namespace Reference

Namespaces

namespace  detail
namespace  tests

Classes

class  BitGroupVector
class  BitIterator
class  BitIteratorBase
class  BitRef
class  BitSpan
class  BitVector
struct  BoolToBit
class  BoundedBitSpan
class  MutableBitIterator
class  MutableBitRef
class  MutableBitSpan
class  MutableBoundedBitSpan

Typedefs

using BitInt = uint64_t

Functions

bool or_bools_into_bits (Span< bool > bools, MutableBitSpan r_bits, int64_t allowed_overshoot=0)
BitInt mask_first_n_bits (const int64_t n)
BitInt mask_last_n_bits (const int64_t n)
BitInt mask_range_bits (const int64_t start, const int64_t size)
BitInt mask_single_bit (const int64_t bit_index)
BitIntint_containing_bit (BitInt *data, const int64_t bit_index)
const BitIntint_containing_bit (const BitInt *data, const int64_t bit_index)
std::ostream & operator<< (std::ostream &stream, const BitRef &bit)
std::ostream & operator<< (std::ostream &stream, const MutableBitRef &bit)
bool is_bounded_span (const BitSpan span)
std::optional< BoundedBitSpantry_get_bounded_span (const BitSpan span)
template<typename T>
T to_best_bit_span (const T &data)
std::ostream & operator<< (std::ostream &stream, const BitSpan &span)
std::ostream & operator<< (std::ostream &stream, const MutableBitSpan &span)
template<typename ExprFn, typename FirstBitSpanT, typename... BitSpanT>
void mix_into_first_expr (ExprFn &&expr, FirstBitSpanT &&first_arg, const BitSpanT &...args)
template<typename ExprFn, typename FirstBitSpanT, typename... BitSpanT>
bool any_set_expr (ExprFn &&expr, const FirstBitSpanT &first_arg, const BitSpanT &...args)
template<typename ExprFn, typename HandleFn, typename FirstBitSpanT, typename... BitSpanT>
void foreach_1_index_expr (ExprFn &&expr, HandleFn &&handle, const FirstBitSpanT &first_arg, const BitSpanT &...args)
template<typename BitSpanT>
void invert (BitSpanT &&data)
template<typename FirstBitSpanT, typename... BitSpanT>
void inplace_or (FirstBitSpanT &first_arg, const BitSpanT &...args)
template<typename FirstBitSpanT, typename MaskBitSpanT, typename... BitSpanT>
void inplace_or_masked (FirstBitSpanT &&first_arg, const MaskBitSpanT &mask, const BitSpanT &...args)
template<typename FirstBitSpanT, typename... BitSpanT>
void copy_from_or (FirstBitSpanT &first_arg, const BitSpanT &...args)
template<typename FirstBitSpanT, typename... BitSpanT>
void inplace_and (FirstBitSpanT &first_arg, const BitSpanT &...args)
template<typename... BitSpanT>
void operator|= (MutableBitSpan first_arg, const BitSpanT &...args)
template<typename... BitSpanT>
void operator|= (MutableBoundedBitSpan first_arg, const BitSpanT &...args)
template<typename... BitSpanT>
void operator&= (MutableBitSpan first_arg, const BitSpanT &...args)
template<typename... BitSpanT>
void operator&= (MutableBoundedBitSpan first_arg, const BitSpanT &...args)
template<typename... BitSpanT>
bool has_common_set_bits (const BitSpanT &...args)
template<typename BitSpanT>
bool any_bit_set (const BitSpanT &arg)
template<typename... BitSpanT>
bool has_common_unset_bits (const BitSpanT &...args)
template<typename BitSpanT>
bool any_bit_unset (const BitSpanT &arg)
template<typename BitSpanT, typename Fn>
void foreach_1_index (const BitSpanT &data, Fn &&fn)
template<typename BitSpanT, typename Fn>
void foreach_0_index (const BitSpanT &data, Fn &&fn)
template<typename ExprFn, typename FirstBitSpanT, typename... BitSpanT>
std::optional< int64_tfind_first_1_index_expr (ExprFn &&Expr, const FirstBitSpanT &first_arg, const BitSpanT &...args)
template<typename BitSpanT>
std::optional< int64_tfind_first_1_index (const BitSpanT &data)
template<typename BitSpanT>
std::optional< int64_tfind_first_0_index (const BitSpanT &data)
template<typename BitSpanT1, typename BitSpanT2>
bool spans_equal (const BitSpanT1 &a, const BitSpanT2 &b)
template<typename BitSpanT1, typename BitSpanT2, typename BitSpanT3>
bool spans_equal_masked (const BitSpanT1 &a, const BitSpanT2 &b, const BitSpanT3 &mask)
template<typename IntT>
void bits_to_index_ranges (const BitSpan bits, IndexRangesBuilder< IntT > &builder)
template<int64_t InlineBufferCapacity, typename Allocator>
BoundedBitSpan to_best_bit_span (const BitVector< InlineBufferCapacity, Allocator > &data)
template<int64_t InlineBufferCapacity, typename Allocator>
MutableBoundedBitSpan to_best_bit_span (BitVector< InlineBufferCapacity, Allocator > &data)
template<typename ByteToBit>
bool or_bytes_into_bits (const Span< char > bytes, MutableBitSpan r_bits, const int64_t allowed_overshoot, const ByteToBit &byte_to_bit)

Variables

static constexpr int64_t BitsPerInt = int64_t(sizeof(BitInt) * 8)
static constexpr int64_t BitToIntIndexShift
static constexpr BitInt BitIndexMask = (BitInt(1) << BitToIntIndexShift) - 1
template<typename... Args>
constexpr bool all_bounded_spans

Typedef Documentation

◆ BitInt

Using a large integer type is better because then it's easier to process many bits at once.

Definition at line 27 of file BLI_bit_ref.hh.

Function Documentation

◆ any_bit_set()

template<typename BitSpanT>
bool blender::bits::any_bit_set ( const BitSpanT & arg)
inline

Definition at line 304 of file BLI_bit_span_ops.hh.

References any_bit_set(), and has_common_set_bits().

Referenced by any_bit_set().

◆ any_bit_unset()

template<typename BitSpanT>
bool blender::bits::any_bit_unset ( const BitSpanT & arg)
inline

Definition at line 314 of file BLI_bit_span_ops.hh.

References any_bit_unset(), and has_common_unset_bits().

Referenced by any_bit_unset().

◆ any_set_expr()

template<typename ExprFn, typename FirstBitSpanT, typename... BitSpanT>
bool blender::bits::any_set_expr ( ExprFn && expr,
const FirstBitSpanT & first_arg,
const BitSpanT &... args )
inline

◆ bits_to_index_ranges()

◆ copy_from_or()

template<typename FirstBitSpanT, typename... BitSpanT>
void blender::bits::copy_from_or ( FirstBitSpanT & first_arg,
const BitSpanT &... args )
inline

◆ find_first_0_index()

template<typename BitSpanT>
std::optional< int64_t > blender::bits::find_first_0_index ( const BitSpanT & data)
inline

◆ find_first_1_index()

template<typename BitSpanT>
std::optional< int64_t > blender::bits::find_first_1_index ( const BitSpanT & data)
inline

◆ find_first_1_index_expr()

template<typename ExprFn, typename FirstBitSpanT, typename... BitSpanT>
std::optional< int64_t > blender::bits::find_first_1_index_expr ( ExprFn && Expr,
const FirstBitSpanT & first_arg,
const BitSpanT &... args )
inline

◆ foreach_0_index()

template<typename BitSpanT, typename Fn>
void blender::bits::foreach_0_index ( const BitSpanT & data,
Fn && fn )
inline

◆ foreach_1_index()

◆ foreach_1_index_expr()

template<typename ExprFn, typename HandleFn, typename FirstBitSpanT, typename... BitSpanT>
void blender::bits::foreach_1_index_expr ( ExprFn && expr,
HandleFn && handle,
const FirstBitSpanT & first_arg,
const BitSpanT &... args )
inline

◆ has_common_set_bits()

template<typename... BitSpanT>
bool blender::bits::has_common_set_bits ( const BitSpanT &... args)
inline

◆ has_common_unset_bits()

template<typename... BitSpanT>
bool blender::bits::has_common_unset_bits ( const BitSpanT &... args)
inline

Definition at line 309 of file BLI_bit_span_ops.hh.

References any_set_expr(), has_common_unset_bits(), and x.

Referenced by any_bit_unset(), and has_common_unset_bits().

◆ inplace_and()

template<typename FirstBitSpanT, typename... BitSpanT>
void blender::bits::inplace_and ( FirstBitSpanT & first_arg,
const BitSpanT &... args )
inline

Definition at line 270 of file BLI_bit_span_ops.hh.

References inplace_and(), mix_into_first_expr(), and x.

Referenced by inplace_and(), operator&=(), and operator&=().

◆ inplace_or()

template<typename FirstBitSpanT, typename... BitSpanT>
void blender::bits::inplace_or ( FirstBitSpanT & first_arg,
const BitSpanT &... args )
inline

Definition at line 245 of file BLI_bit_span_ops.hh.

References inplace_or(), mix_into_first_expr(), and x.

Referenced by inplace_or(), operator|=(), and operator|=().

◆ inplace_or_masked()

template<typename FirstBitSpanT, typename MaskBitSpanT, typename... BitSpanT>
void blender::bits::inplace_or_masked ( FirstBitSpanT && first_arg,
const MaskBitSpanT & mask,
const BitSpanT &... args )
inline

◆ int_containing_bit() [1/2]

◆ int_containing_bit() [2/2]

const BitInt * blender::bits::int_containing_bit ( const BitInt * data,
const int64_t bit_index )
inline

Definition at line 75 of file BLI_bit_ref.hh.

References BitToIntIndexShift, data, and int_containing_bit().

◆ invert()

◆ is_bounded_span()

bool blender::bits::is_bounded_span ( const BitSpan span)
inline

Checks if the span fulfills the requirements for a bounded span. Bounded spans can often be processed more efficiently, because fewer cases have to be considered when aligning multiple such spans.

See comments in the function for the exact requirements.

Don't allow small sized spans to cross BitInt boundaries.

Definition at line 166 of file BLI_bit_span.hh.

References blender::bits::BitSpan::bit_range(), is_bounded_span(), blender::bits::BitSpan::size(), and blender::IndexRange::start().

Referenced by blender::bits::BoundedBitSpan::BoundedBitSpan(), blender::bits::BoundedBitSpan::BoundedBitSpan(), blender::bits::BoundedBitSpan::BoundedBitSpan(), is_bounded_span(), blender::bits::MutableBoundedBitSpan::MutableBoundedBitSpan(), blender::bits::MutableBoundedBitSpan::MutableBoundedBitSpan(), blender::bits::MutableBoundedBitSpan::MutableBoundedBitSpan(), blender::bits::tests::TEST(), and try_get_bounded_span().

◆ mask_first_n_bits()

◆ mask_last_n_bits()

BitInt blender::bits::mask_last_n_bits ( const int64_t n)
inline

◆ mask_range_bits()

◆ mask_single_bit()

◆ mix_into_first_expr()

template<typename ExprFn, typename FirstBitSpanT, typename... BitSpanT>
void blender::bits::mix_into_first_expr ( ExprFn && expr,
FirstBitSpanT && first_arg,
const BitSpanT &... args )
inline

◆ operator&=() [1/2]

template<typename... BitSpanT>
void blender::bits::operator&= ( MutableBitSpan first_arg,
const BitSpanT &... args )
inline

Definition at line 288 of file BLI_bit_span_ops.hh.

References inplace_and(), and operator&=().

Referenced by operator&=(), and operator&=().

◆ operator&=() [2/2]

template<typename... BitSpanT>
void blender::bits::operator&= ( MutableBoundedBitSpan first_arg,
const BitSpanT &... args )
inline

Definition at line 294 of file BLI_bit_span_ops.hh.

References inplace_and(), and operator&=().

◆ operator<<() [1/4]

std::ostream & blender::bits::operator<< ( std::ostream & stream,
const BitRef & bit )

Definition at line 15 of file bit_ref.cc.

References operator<<().

Referenced by operator<<(), operator<<(), operator<<(), and operator<<().

◆ operator<<() [2/4]

std::ostream & blender::bits::operator<< ( std::ostream & stream,
const BitSpan & span )

Definition at line 90 of file bit_span.cc.

References operator<<(), and blender::bits::BitSpan::size().

◆ operator<<() [3/4]

std::ostream & blender::bits::operator<< ( std::ostream & stream,
const MutableBitRef & bit )

Definition at line 20 of file bit_ref.cc.

References blender::bits::BitRef::BitRef(), and operator<<().

◆ operator<<() [4/4]

std::ostream & blender::bits::operator<< ( std::ostream & stream,
const MutableBitSpan & span )

Definition at line 100 of file bit_span.cc.

References blender::bits::BitSpan::BitSpan(), and operator<<().

◆ operator|=() [1/2]

template<typename... BitSpanT>
void blender::bits::operator|= ( MutableBitSpan first_arg,
const BitSpanT &... args )
inline

Definition at line 276 of file BLI_bit_span_ops.hh.

References inplace_or(), and operator|=().

Referenced by operator|=(), and operator|=().

◆ operator|=() [2/2]

template<typename... BitSpanT>
void blender::bits::operator|= ( MutableBoundedBitSpan first_arg,
const BitSpanT &... args )
inline

Definition at line 282 of file BLI_bit_span_ops.hh.

References inplace_or(), and operator|=().

◆ or_bools_into_bits()

bool blender::bits::or_bools_into_bits ( Span< bool > bools,
MutableBitSpan r_bits,
int64_t allowed_overshoot = 0 )

Converts the bools to bits and ors them into the given bits. For pure conversion, the bits should therefore be zero initialized before they are passed into this function.

Parameters
allowed_overshootHow many bools/bits can be read/written after the end of the given spans. This can help with performance because the internal algorithm can process many elements at once.
Returns
True if any of the checked bools were true (this also includes the bools in the overshoot).

Definition at line 88 of file bit_bool_conversion.cc.

References blender::Span< T >::cast(), or_bools_into_bits(), and or_bytes_into_bits().

Referenced by blender::index_mask::IndexMask::from_bools(), or_bools_into_bits(), and blender::bits::tests::TEST().

◆ or_bytes_into_bits()

template<typename ByteToBit>
bool blender::bits::or_bytes_into_bits ( const Span< char > bytes,
MutableBitSpan r_bits,
const int64_t allowed_overshoot,
const ByteToBit & byte_to_bit )

◆ spans_equal()

template<typename BitSpanT1, typename BitSpanT2>
bool blender::bits::spans_equal ( const BitSpanT1 & a,
const BitSpanT2 & b )
inline

◆ spans_equal_masked()

template<typename BitSpanT1, typename BitSpanT2, typename BitSpanT3>
bool blender::bits::spans_equal_masked ( const BitSpanT1 & a,
const BitSpanT2 & b,
const BitSpanT3 & mask )
inline

◆ to_best_bit_span() [1/3]

template<int64_t InlineBufferCapacity, typename Allocator>
MutableBoundedBitSpan blender::bits::to_best_bit_span ( BitVector< InlineBufferCapacity, Allocator > & data)
inline

Definition at line 395 of file BLI_bit_vector.hh.

References data, and to_best_bit_span().

◆ to_best_bit_span() [2/3]

template<int64_t InlineBufferCapacity, typename Allocator>
BoundedBitSpan blender::bits::to_best_bit_span ( const BitVector< InlineBufferCapacity, Allocator > & data)
inline

Definition at line 389 of file BLI_bit_vector.hh.

References data, and to_best_bit_span().

◆ to_best_bit_span() [3/3]

template<typename T>
T blender::bits::to_best_bit_span ( const T & data)
inline

Overloaded in BLI_bit_vector.hh. The purpose is to make passing BitVector into bit span operations more efficient (interpreting it as BoundedBitSpan instead of just BitSpan).

Definition at line 404 of file BLI_bit_span.hh.

References data, blender::is_same_any_v, T, and to_best_bit_span().

Referenced by any_set_expr(), find_first_1_index_expr(), foreach_1_index_expr(), mix_into_first_expr(), to_best_bit_span(), to_best_bit_span(), and to_best_bit_span().

◆ try_get_bounded_span()

Variable Documentation

◆ all_bounded_spans

◆ BitIndexMask

BitInt blender::bits::BitIndexMask = (BitInt(1) << BitToIntIndexShift) - 1
staticconstexpr

Bit mask containing a 1 for the last few bits that index a bit inside of an BitInt.

Definition at line 34 of file BLI_bit_ref.hh.

Referenced by blender::bits::BitRef::BitRef(), and blender::bits::MutableBitRef::MutableBitRef().

◆ BitsPerInt

int64_t blender::bits::BitsPerInt = int64_t(sizeof(BitInt) * 8)
staticconstexpr

Number of bits that fit into BitInt.

Definition at line 29 of file BLI_bit_ref.hh.

Referenced by mask_first_n_bits(), mask_last_n_bits(), mask_range_bits(), and mask_single_bit().

◆ BitToIntIndexShift

int64_t blender::bits::BitToIntIndexShift
staticconstexpr
Initial value:
= 3 + (sizeof(BitInt) >= 2) + (sizeof(BitInt) >= 4) +
(sizeof(BitInt) >= 8)
uint64_t BitInt

Shift amount to get from a bit index to an int index. Equivalent to log(BitsPerInt, 2).

Definition at line 31 of file BLI_bit_ref.hh.

Referenced by int_containing_bit(), and int_containing_bit().