OrcaSlicer latest
OrcaSlicer
Loading...
Searching...
No Matches
libvgcode::BitSet< T > Struct Template Reference

#include </home/runner/work/OrcaSlicer/OrcaSlicer/src/libvgcode/src/Bitset.hpp>

Collaboration diagram for libvgcode::BitSet< T >:

Public Member Functions

 BitSet ()=default
 BitSet (std::size_t size)
void clear ()
void setAll ()
bool set (std::size_t index)
bool reset (std::size_t index)
bool operator[] (std::size_t index) const
template<typename U>
BitSet & operator&= (const BitSet< U > &other)
template<typename U = T>
std::enable_if< is_atomic< U >, bool >::type set_atomic (std::size_t index)
template<typename U = T>
std::enable_if< is_atomic< U >, bool >::type reset_atomic (std::size_t index)
std::pair< std::size_t, std::size_t > get_coords (std::size_t index) const
std::size_t size_in_bytes_cpu () const

Public Attributes

std::size_t size { 0 }
std::vector< T > blocks { 0 }

Detailed Description

template<typename T = unsigned long long>
struct libvgcode::BitSet< T >

Constructor & Destructor Documentation

◆ BitSet() [1/2]

template<typename T = unsigned long long>
libvgcode::BitSet< T >::BitSet ( )
default

Referenced by operator&=().

Here is the caller graph for this function:

◆ BitSet() [2/2]

template<typename T = unsigned long long>
libvgcode::BitSet< T >::BitSet ( std::size_t size)
inline
26: size(size), blocks(1 + (size / (sizeof(T) * 8))) { clear(); }
Definition Bitset.hpp:24
std::size_t size
Definition Bitset.hpp:100
void clear()
Definition Bitset.hpp:28
std::vector< T > blocks
Definition Bitset.hpp:101

References blocks, clear(), and size.

Here is the call graph for this function:

Member Function Documentation

◆ clear()

template<typename T = unsigned long long>
void libvgcode::BitSet< T >::clear ( )
inline
28 {
29 for (std::size_t i = 0; i < blocks.size(); ++i) {
30 blocks[i] &= T(0);
31 }
32 }

References blocks.

Referenced by BitSet().

Here is the caller graph for this function:

◆ get_coords()

template<typename T = unsigned long long>
std::pair< std::size_t, std::size_t > libvgcode::BitSet< T >::get_coords ( std::size_t index) const
inline
90 {
91 const std::size_t block_idx = index / (sizeof(T) * 8);
92 const std::size_t bit_idx = index % (sizeof(T) * 8);
93 return { block_idx, bit_idx };
94 }

Referenced by operator[](), reset(), reset_atomic(), set(), and set_atomic().

Here is the caller graph for this function:

◆ operator&=()

template<typename T = unsigned long long>
template<typename U>
BitSet & libvgcode::BitSet< T >::operator&= ( const BitSet< U > & other)
inline
64 {
65 static_assert(sizeof(T) == sizeof(U), "Type1 and Type2 must be of the same size.");
66 for (std::size_t i = 0; i < blocks.size(); ++i) {
67 blocks[i] &= other.blocks[i];
68 }
69 return *this;
70 }

References BitSet(), and blocks.

Here is the call graph for this function:

◆ operator[]()

template<typename T = unsigned long long>
bool libvgcode::BitSet< T >::operator[] ( std::size_t index) const
inline
58 {
59 const auto [block_idx, bit_idx] = get_coords(index);
60 return ((blocks[block_idx] >> bit_idx) & 1) != 0;
61 }
std::pair< std::size_t, std::size_t > get_coords(std::size_t index) const
Definition Bitset.hpp:90

References blocks, and get_coords().

Here is the call graph for this function:

◆ reset()

template<typename T = unsigned long long>
bool libvgcode::BitSet< T >::reset ( std::size_t index)
inline
50 {
51 const auto [block_idx, bit_idx] = get_coords(index);
52 const T mask = (T(1) << bit_idx);
53 const bool flip = mask ^ blocks[block_idx];
55 return flip;
56 }

References blocks, and get_coords().

Here is the call graph for this function:

◆ reset_atomic()

template<typename T = unsigned long long>
template<typename U = T>
std::enable_if< is_atomic< U >, bool >::type libvgcode::BitSet< T >::reset_atomic ( std::size_t index)
inline
83 {
84 const auto [block_idx, bit_idx] = get_coords(index);
85 const T mask = ~(static_cast<T>(1) << bit_idx);
87 return oldval ^ (oldval and mask);
88 }

References blocks, and get_coords().

Here is the call graph for this function:

◆ set()

template<typename T = unsigned long long>
bool libvgcode::BitSet< T >::set ( std::size_t index)
inline
41 {
42 const auto [block_idx, bit_idx] = get_coords(index);
43 const T mask = (T(1) << bit_idx);
44 bool flip = mask ^ blocks[block_idx];
46 return flip;
47 }

References blocks, and get_coords().

Here is the call graph for this function:

◆ set_atomic()

template<typename T = unsigned long long>
template<typename U = T>
std::enable_if< is_atomic< U >, bool >::type libvgcode::BitSet< T >::set_atomic ( std::size_t index)
inline
74 {
75 const auto [block_idx, bit_idx] = get_coords(index);
76 const T mask = static_cast<T>(1) << bit_idx;
78 return oldval ^ (oldval or mask);
79 }

References blocks, and get_coords().

Here is the call graph for this function:

◆ setAll()

template<typename T = unsigned long long>
void libvgcode::BitSet< T >::setAll ( )
inline
34 {
35 for (std::size_t i = 0; i < blocks.size(); ++i) {
36 blocks[i] |= ~T(0);
37 }
38 }

References blocks.

◆ size_in_bytes_cpu()

template<typename T = unsigned long long>
std::size_t libvgcode::BitSet< T >::size_in_bytes_cpu ( ) const
inline
96 {
97 return blocks.size() * sizeof(T);
98 }

References blocks.

Member Data Documentation

◆ blocks

template<typename T = unsigned long long>
std::vector<T> libvgcode::BitSet< T >::blocks { 0 }

◆ size

template<typename T = unsigned long long>
std::size_t libvgcode::BitSet< T >::size { 0 }
100{ 0 };

Referenced by BitSet().


The documentation for this struct was generated from the following file:
  • /home/runner/work/OrcaSlicer/OrcaSlicer/src/libvgcode/src/Bitset.hpp