blob: 34098fab019a67ceca9a664db1e94656fdb378fb (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
|
#include "orbsvcs/Notify/Bit_Vector.h"
TAO_BEGIN_VERSIONED_NAMESPACE_DECL
namespace TAO_Notify
{
Bit_Vector::Bit_Vector()
: size_(0)
, first_set_bit_(0)
, first_cleared_bit_(0)
{
}
Bit_Vector::~Bit_Vector()
{
}
bool
Bit_Vector::is_set(const size_t location) const
{
bool result = false;
if (location < this->size_)
{
result = (0 != (this->bitvec_[location >> BPW_LOG_2] & (1 << (location % BITS_PER_WORD))));
}
return result;
}
void
Bit_Vector::set_bit(const size_t location, bool set)
{
if (location >= this->size_)
{
if ((location >> BPW_LOG_2) >= (this->size_ >> BPW_LOG_2))
{
size_t need = (location >> BPW_LOG_2) - (this->size_ >> BPW_LOG_2);
this->bitvec_.resize(this->bitvec_.size() + need + 1, 0);
}
this->size_ = location + 1;
}
if (set)
{
this->bitvec_[location >> BPW_LOG_2] |= (1 << (location % BITS_PER_WORD));
}
else
{
this->bitvec_[location >> BPW_LOG_2] &= ~(1 << (location % BITS_PER_WORD));
}
this->evaluate_firsts(location, set);
}
size_t
Bit_Vector::find_first_bit(bool set) const
{
size_t result = 0;
if (set)
{
result = this->first_set_bit_;
}
else
{
result = this->first_cleared_bit_;
}
return result;
}
void
Bit_Vector::evaluate_firsts(const size_t location, bool set)
{
if (set)
{
if (this->first_cleared_bit_ == location)
{
this->first_cleared_bit_ = this->find_first_bit_of(location, false);
}
if (this->first_set_bit_ > location)
{
this->first_set_bit_ = location;
}
}
else if (!set)
{
if (this->first_set_bit_ == location)
{
this->first_set_bit_ = this->find_first_bit_of(location, true);
}
if (this->first_cleared_bit_ > location)
{
this->first_cleared_bit_ = location;
}
}
}
size_t
Bit_Vector::find_first_bit_of(const size_t location, bool set)
{
size_t newloc = 0;
size_t idx = 0;
for (idx = location; (newloc == 0) && (idx < this->size_ + 1); idx++)
{
if (is_set(idx) == set)
{
newloc = idx;
}
}
return newloc;
}
}
TAO_END_VERSIONED_NAMESPACE_DECL
|