Blender V5.0
blender::bits Namespace Reference

Namespaces

namespace  detail
namespace  tests

Classes

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

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 has_common_set_bits().

◆ 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 has_common_unset_bits().

◆ 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

Definition at line 343 of file BLI_bit_span_ops.hh.

References data, find_first_1_index_expr(), and x.

Referenced by blender::bits::tests::TEST().

◆ find_first_1_index()

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

Definition at line 338 of file BLI_bit_span_ops.hh.

References data, find_first_1_index_expr(), and x.

Referenced by blender::bits::tests::TEST().

◆ 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

Definition at line 299 of file BLI_bit_span_ops.hh.

References any_set_expr(), and x.

Referenced by any_bit_set(), and blender::bke::discover_tree_zones().

◆ 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(), and x.

Referenced by any_bit_unset().

◆ 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 mix_into_first_expr(), and x.

Referenced by 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 mix_into_first_expr(), and x.

Referenced by 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, and data.

◆ 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(), BitsPerInt, blender::bits::BitSpan::size(), size(), and blender::IndexRange::start().

Referenced by blender::bits::BoundedBitSpan::BoundedBitSpan(), blender::bits::BoundedBitSpan::BoundedBitSpan(), blender::bits::BoundedBitSpan::BoundedBitSpan(), 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

Definition at line 46 of file BLI_bit_ref.hh.

References BitsPerInt, and mask_first_n_bits().

Referenced by mask_range_bits(), and blender::bits::tests::TEST().

◆ mask_range_bits()

◆ mask_single_bit()

BitInt blender::bits::mask_single_bit ( const int64_t bit_index)
inline

◆ 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().

◆ 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().

◆ operator<<() [1/4]

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

Definition at line 15 of file bit_ref.cc.

◆ operator<<() [2/4]

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

Definition at line 90 of file bit_span.cc.

References 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.

◆ operator<<() [4/4]

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

Definition at line 100 of file bit_span.cc.

◆ 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().

◆ 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().

◆ 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(), and or_bytes_into_bits().

Referenced by blender::index_mask::IndexMask::from_bools(), 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.

◆ 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.

◆ 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, and T.

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

◆ try_get_bounded_span()

Variable Documentation

◆ all_bounded_spans

◆ BitIndexMask

◆ BitsPerInt

◆ BitToIntIndexShift