Flutter Engine
The Flutter Engine
Classes | Public Member Functions | Static Public Member Functions | List of all members
dart::BitVector Class Reference

#include <bit_vector.h>

Inheritance diagram for dart::BitVector:
dart::ZoneAllocated

Classes

class  Iterator
 

Public Member Functions

 BitVector (Zone *zone, intptr_t length)
 
void CopyFrom (const BitVector *other)
 
void Add (intptr_t i)
 
void Remove (intptr_t i)
 
void Set (intptr_t i, bool value)
 
bool Equals (const BitVector &other) const
 
bool AddAll (const BitVector *from)
 
bool RemoveAll (const BitVector *from)
 
bool KillAndAdd (BitVector *kill, BitVector *gen)
 
void Intersect (const BitVector *other)
 
bool IsEmpty () const
 
bool Contains (intptr_t i) const
 
bool SubsetOf (const BitVector &other)
 
void Clear ()
 
void SetAll ()
 
intptr_t length () const
 
void Print () const
 
- Public Member Functions inherited from dart::ZoneAllocated
 ZoneAllocated ()
 
void * operator new (size_t size)
 
void * operator new (size_t size, Zone *zone)
 
void operator delete (void *pointer)
 

Static Public Member Functions

static intptr_t SizeFor (intptr_t length)
 

Detailed Description

Definition at line 15 of file bit_vector.h.

Constructor & Destructor Documentation

◆ BitVector()

dart::BitVector::BitVector ( Zone zone,
intptr_t  length 
)
inline

Definition at line 47 of file bit_vector.h.

48 : length_(length),
49 data_length_(SizeFor(length)),
50 data_(zone->Alloc<uword>(data_length_)) {
51 Clear();
52 }
intptr_t length() const
Definition: bit_vector.h:117
static intptr_t SizeFor(intptr_t length)
Definition: bit_vector.h:59
uintptr_t uword
Definition: globals.h:501

Member Function Documentation

◆ Add()

void dart::BitVector::Add ( intptr_t  i)
inline

Definition at line 63 of file bit_vector.h.

63 {
64 ASSERT(i >= 0 && i < length());
65 data_[i / kBitsPerWord] |= (static_cast<uword>(1) << (i % kBitsPerWord));
66 }
#define ASSERT(E)
constexpr intptr_t kBitsPerWord
Definition: globals.h:514

◆ AddAll()

bool dart::BitVector::AddAll ( const BitVector from)

Definition at line 52 of file bit_vector.cc.

52 {
53 ASSERT(data_length_ == from->data_length_);
54 bool changed = false;
55 for (intptr_t i = 0; i < data_length_; i++) {
56 const uword before = data_[i];
57 const uword after = data_[i] | from->data_[i];
58 if (before != after) {
59 changed = true;
60 data_[i] = after;
61 }
62 }
63 return changed;
64}

◆ Clear()

void dart::BitVector::Clear ( )
inline

Definition at line 105 of file bit_vector.h.

105 {
106 for (intptr_t i = 0; i < data_length_; i++) {
107 data_[i] = 0;
108 }
109 }

◆ Contains()

bool dart::BitVector::Contains ( intptr_t  i) const
inline

Definition at line 91 of file bit_vector.h.

91 {
92 ASSERT(i >= 0 && i < length());
93 uword block = data_[i / kBitsPerWord];
94 return (block & (static_cast<uword>(1) << (i % kBitsPerWord))) != 0;
95 }

◆ CopyFrom()

void dart::BitVector::CopyFrom ( const BitVector other)
inline

Definition at line 54 of file bit_vector.h.

54 {
55 Clear();
56 AddAll(other);
57 }
bool AddAll(const BitVector *from)
Definition: bit_vector.cc:52

◆ Equals()

bool dart::BitVector::Equals ( const BitVector other) const

Definition at line 35 of file bit_vector.cc.

35 {
36 if (length_ != other.length_) return false;
37 intptr_t i = 0;
38 for (; i < data_length_ - 1; i++) {
39 if (data_[i] != other.data_[i]) return false;
40 }
41 if (i < data_length_) {
42 if (length_ % kBitsPerWord == 0) return data_[i] == other.data_[i];
43
44 // Don't compare bits beyond length_.
45 const intptr_t shift_size = kBitsPerWord - (length_ % kBitsPerWord);
46 const uword mask = static_cast<uword>(-1) >> shift_size;
47 if ((data_[i] & mask) != (other.data_[i] & mask)) return false;
48 }
49 return true;
50}

◆ Intersect()

void dart::BitVector::Intersect ( const BitVector other)

Definition at line 93 of file bit_vector.cc.

93 {
94 ASSERT(other->length() == length());
95 for (intptr_t i = 0; i < data_length_; i++) {
96 data_[i] = data_[i] & other->data_[i];
97 }
98}

◆ IsEmpty()

bool dart::BitVector::IsEmpty ( ) const

Definition at line 100 of file bit_vector.cc.

100 {
101 for (intptr_t i = 0; i < data_length_; i++) {
102 if (data_[i] != 0) {
103 return false;
104 }
105 }
106 return true;
107}

◆ KillAndAdd()

bool dart::BitVector::KillAndAdd ( BitVector kill,
BitVector gen 
)

Definition at line 80 of file bit_vector.cc.

80 {
81 ASSERT(data_length_ == kill->data_length_);
82 ASSERT(data_length_ == gen->data_length_);
83 bool changed = false;
84 for (intptr_t i = 0; i < data_length_; i++) {
85 const uword before = data_[i];
86 const uword after = data_[i] | (gen->data_[i] & ~kill->data_[i]);
87 if (before != after) changed = true;
88 data_[i] = after;
89 }
90 return changed;
91}
Definition: gen.py:1

◆ length()

intptr_t dart::BitVector::length ( ) const
inline

Definition at line 117 of file bit_vector.h.

117{ return length_; }

◆ Print()

void dart::BitVector::Print ( ) const

Definition at line 109 of file bit_vector.cc.

109 {
110 THR_Print("[");
111 for (intptr_t i = 0; i < length_; i++) {
112 THR_Print(Contains(i) ? "1" : "0");
113 }
114 THR_Print("]");
115}
bool Contains(intptr_t i) const
Definition: bit_vector.h:91
#define THR_Print(format,...)
Definition: log.h:20

◆ Remove()

void dart::BitVector::Remove ( intptr_t  i)
inline

Definition at line 68 of file bit_vector.h.

68 {
69 ASSERT(i >= 0 && i < length());
70 data_[i / kBitsPerWord] &= ~(static_cast<uword>(1) << (i % kBitsPerWord));
71 }

◆ RemoveAll()

bool dart::BitVector::RemoveAll ( const BitVector from)

Definition at line 66 of file bit_vector.cc.

66 {
67 ASSERT(data_length_ == from->data_length_);
68 bool changed = false;
69 for (intptr_t i = 0; i < data_length_; i++) {
70 const uword before = data_[i];
71 const uword after = data_[i] & ~from->data_[i];
72 if (before != after) {
73 changed = true;
74 data_[i] = after;
75 }
76 }
77 return changed;
78}

◆ Set()

void dart::BitVector::Set ( intptr_t  i,
bool  value 
)
inline

Definition at line 73 of file bit_vector.h.

73{ value ? Add(i) : Remove(i); }
void Add(intptr_t i)
Definition: bit_vector.h:63
void Remove(intptr_t i)
Definition: bit_vector.h:68
uint8_t value

◆ SetAll()

void dart::BitVector::SetAll ( )
inline

Definition at line 111 of file bit_vector.h.

111 {
112 for (intptr_t i = 0; i < data_length_; i++) {
113 data_[i] = static_cast<uword>(-1);
114 }
115 }

◆ SizeFor()

static intptr_t dart::BitVector::SizeFor ( intptr_t  length)
inlinestatic

Definition at line 59 of file bit_vector.h.

59 {
60 return 1 + ((length - 1) / kBitsPerWord);
61 }

◆ SubsetOf()

bool dart::BitVector::SubsetOf ( const BitVector other)
inline

Definition at line 97 of file bit_vector.h.

97 {
98 ASSERT(length_ == other.length_);
99 for (intptr_t i = 0; i < data_length_; ++i) {
100 if ((data_[i] & other.data_[i]) != data_[i]) return false;
101 }
102 return true;
103 }

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