Flutter Engine
The Flutter Engine
Public Types | Public Member Functions | List of all members
SkBitSet Class Reference

#include <SkBitSet.h>

Public Types

using OptionalIndex = std::optional< size_t >
 

Public Member Functions

 SkBitSet (size_t size)
 
 SkBitSet (const SkBitSet &)=delete
 
SkBitSetoperator= (const SkBitSet &)=delete
 
 SkBitSet (SkBitSet &&that)
 
SkBitSetoperator= (SkBitSet &&that)
 
 ~SkBitSet ()=default
 
void set (size_t index)
 
void set ()
 
void reset (size_t index)
 
void reset ()
 
bool test (size_t index) const
 
size_t size () const
 
template<typename FN >
void forEachSetIndex (FN f) const
 
OptionalIndex findFirst ()
 
OptionalIndex findFirstUnset ()
 

Detailed Description

Definition at line 21 of file SkBitSet.h.

Member Typedef Documentation

◆ OptionalIndex

using SkBitSet::OptionalIndex = std::optional<size_t>

Definition at line 92 of file SkBitSet.h.

Constructor & Destructor Documentation

◆ SkBitSet() [1/3]

SkBitSet::SkBitSet ( size_t  size)
inlineexplicit

Definition at line 23 of file SkBitSet.h.

24 : fSize(size)
25 , fChunks((Chunk*)sk_calloc_throw(NumChunksFor(fSize) * sizeof(Chunk))) {}
static void * sk_calloc_throw(size_t size)
Definition: SkMalloc.h:71
size_t size() const
Definition: SkBitSet.h:71

◆ SkBitSet() [2/3]

SkBitSet::SkBitSet ( const SkBitSet )
delete

◆ SkBitSet() [3/3]

SkBitSet::SkBitSet ( SkBitSet &&  that)
inline

Definition at line 29 of file SkBitSet.h.

29{ *this = std::move(that); }

◆ ~SkBitSet()

SkBitSet::~SkBitSet ( )
default

Member Function Documentation

◆ findFirst()

OptionalIndex SkBitSet::findFirst ( )
inline

Definition at line 95 of file SkBitSet.h.

95 {
96 const Chunk* chunks = fChunks.get();
97 const size_t numChunks = NumChunksFor(fSize);
98 for (size_t i = 0; i < numChunks; ++i) {
99 if (Chunk chunk = chunks[i]) { // There are set bits
100 static_assert(kChunkBits <= std::numeric_limits<uint32_t>::digits, "SkCTZ");
101 const size_t bitIndex = i * kChunkBits + SkCTZ(chunk);
102 return OptionalIndex(bitIndex);
103 }
104 }
105 return OptionalIndex();
106 }
static int SkCTZ(uint32_t mask)
Definition: SkMathPriv.h:224
std::optional< size_t > OptionalIndex
Definition: SkBitSet.h:92

◆ findFirstUnset()

OptionalIndex SkBitSet::findFirstUnset ( )
inline

Definition at line 109 of file SkBitSet.h.

109 {
110 const Chunk* chunks = fChunks.get();
111 const size_t numChunks = NumChunksFor(fSize);
112 for (size_t i = 0; i < numChunks; ++i) {
113 if (Chunk chunk = ~chunks[i]) { // if there are unset bits ...
114 static_assert(kChunkBits <= std::numeric_limits<uint32_t>::digits, "SkCTZ");
115 const size_t bitIndex = i * kChunkBits + SkCTZ(chunk);
116 if (bitIndex >= fSize) {
117 break;
118 }
119 return OptionalIndex(bitIndex);
120 }
121 }
122 return OptionalIndex();
123 }

◆ forEachSetIndex()

template<typename FN >
void SkBitSet::forEachSetIndex ( FN  f) const
inline

Definition at line 77 of file SkBitSet.h.

77 {
78 const Chunk* chunks = fChunks.get();
79 const size_t numChunks = NumChunksFor(fSize);
80 for (size_t i = 0; i < numChunks; ++i) {
81 if (Chunk chunk = chunks[i]) { // There are set bits
82 const size_t index = i * kChunkBits;
83 for (size_t j = 0; j < kChunkBits; ++j) {
84 if (0x1 & (chunk >> j)) {
85 f(index + j);
86 }
87 }
88 }
89 }
90 }

◆ operator=() [1/2]

SkBitSet & SkBitSet::operator= ( const SkBitSet )
delete

◆ operator=() [2/2]

SkBitSet & SkBitSet::operator= ( SkBitSet &&  that)
inline

Definition at line 30 of file SkBitSet.h.

30 {
31 if (this != &that) {
32 this->fSize = that.fSize;
33 this->fChunks = std::move(that.fChunks);
34 that.fSize = 0;
35 }
36 return *this;
37 }

◆ reset() [1/2]

void SkBitSet::reset ( )
inline

Sets every bit in the bitset to false.

Definition at line 60 of file SkBitSet.h.

60 {
61 Chunk* chunks = fChunks.get();
62 const size_t numChunks = NumChunksFor(fSize);
63 std::memset(chunks, 0, sizeof(Chunk) * numChunks);
64 }

◆ reset() [2/2]

void SkBitSet::reset ( size_t  index)
inline

Set the value of the index-th bit to false.

Definition at line 54 of file SkBitSet.h.

54 {
55 SkASSERT(index < fSize);
56 *this->chunkFor(index) &= ~ChunkMaskFor(index);
57 }
#define SkASSERT(cond)
Definition: SkAssert.h:116

◆ set() [1/2]

void SkBitSet::set ( )
inline

Sets every bit in the bitset to true.

Definition at line 47 of file SkBitSet.h.

47 {
48 Chunk* chunks = fChunks.get();
49 const size_t numChunks = NumChunksFor(fSize);
50 std::memset(chunks, 0xFF, sizeof(Chunk) * numChunks);
51 }

◆ set() [2/2]

void SkBitSet::set ( size_t  index)
inline

Set the value of the index-th bit to true.

Definition at line 41 of file SkBitSet.h.

41 {
42 SkASSERT(index < fSize);
43 *this->chunkFor(index) |= ChunkMaskFor(index);
44 }

◆ size()

size_t SkBitSet::size ( ) const
inline

Definition at line 71 of file SkBitSet.h.

71 {
72 return fSize;
73 }

◆ test()

bool SkBitSet::test ( size_t  index) const
inline

Definition at line 66 of file SkBitSet.h.

66 {
67 SkASSERT(index < fSize);
68 return SkToBool(*this->chunkFor(index) & ChunkMaskFor(index));
69 }
static constexpr bool SkToBool(const T &x)
Definition: SkTo.h:35

The documentation for this class was generated from the following file: