Skip to content

Commit 462bd32

Browse files
authored
Merge pull request #22 from bugparty/codex/rename-bitvector-class-to-bitvector
Rename bitvector class to BitVector
2 parents 87b17e0 + f7ee3b5 commit 462bd32

File tree

5 files changed

+44
-44
lines changed

5 files changed

+44
-44
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ The following table shows benchmark times from the latest CI run. Each test was
3636
`incrementUntilZero` scans the bit vector starting at the given position until it reaches the first zero bit. The position is updated in place:
3737

3838
```cpp
39-
bitvector<> bv(1024, true);
39+
BitVector<> bv(1024, true);
4040
bv.set_bit(1023, false); // ensure there is a zero bit
4141
size_t pos = 0;
4242
bv.incrementUntilZero(pos);

bitvector.hpp

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ namespace bowen
141141
}
142142
};
143143
template<typename Allocator = std::allocator<BitType>>
144-
class bitvector
144+
class BitVector
145145
{
146146
private:
147147
BitType* m_data;
@@ -170,24 +170,24 @@ namespace bowen
170170
typedef size_t size_type;
171171
typedef BitReference<Allocator> reference;
172172

173-
bitvector()
173+
BitVector()
174174
: m_data(nullptr), m_size(0), m_capacity(0) {}
175175

176-
explicit bitvector(size_t n, bool value = false)
176+
explicit BitVector(size_t n, bool value = false)
177177
: m_size(n), m_capacity(num_words(n))
178178
{
179179
allocate_memory(m_capacity);
180180
std::memset(m_data, value ? ~0 : 0, m_capacity * sizeof(BitType));
181181
}
182182

183-
bitvector(const bitvector& other)
183+
BitVector(const BitVector& other)
184184
: m_size(other.m_size), m_capacity(other.m_capacity)
185185
{
186186
allocate_memory(m_capacity);
187187
std::copy(other.m_data, other.m_data + m_capacity, m_data);
188188
}
189189

190-
bitvector& operator=(const bitvector& other)
190+
BitVector& operator=(const BitVector& other)
191191
{
192192
if (this != &other)
193193
{
@@ -201,7 +201,7 @@ namespace bowen
201201
return *this;
202202
}
203203

204-
~bitvector()
204+
~BitVector()
205205
{
206206
deallocate_memory();
207207
}
@@ -211,7 +211,7 @@ namespace bowen
211211
#ifndef BITVECTOR_NO_BOUND_CHECK
212212
if (pos >= m_size){
213213
std::stringstream ss;
214-
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
214+
ss << "BitVector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
215215
throw std::out_of_range(ss.str());
216216
}
217217
#endif
@@ -226,7 +226,7 @@ namespace bowen
226226
#ifndef BITVECTOR_NO_BOUND_CHECK
227227
if (pos >= m_size){
228228
std::stringstream ss;
229-
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
229+
ss << "BitVector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
230230
throw std::out_of_range(ss.str());
231231
}
232232
#endif
@@ -238,7 +238,7 @@ namespace bowen
238238
#ifndef BITVECTOR_NO_BOUND_CHECK
239239
if (pos >= m_size){
240240
std::stringstream ss;
241-
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
241+
ss << "BitVector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
242242
throw std::out_of_range(ss.str());
243243
}
244244
#endif
@@ -325,7 +325,7 @@ namespace bowen
325325
#ifndef BITVECTOR_NO_BOUND_CHECK
326326
if (pos >= m_size){
327327
std::stringstream ss;
328-
ss << "bitvector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
328+
ss << "BitVector index out of range" << "pos: "<< pos << " size: " << m_size << std::endl;
329329
throw std::out_of_range(ss.str());
330330
return;
331331
}

bitvector_benchmark.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,12 @@
66
#define BITVECTOR_BENCHMARK_MIN_TIME 0.2
77
#endif
88

9-
using bowen::bitvector;
9+
using bowen::BitVector;
1010

1111
static void BM_Bowen_Set(benchmark::State& state) {
1212
size_t n = state.range(0);
1313
for (auto _ : state) {
14-
bitvector<> bv(n);
14+
BitVector<> bv(n);
1515
for (size_t i=0;i<n;++i) {
1616
bv[i] = static_cast<bool>(i & 1);
1717
}
@@ -33,7 +33,7 @@ static void BM_Std_Set(benchmark::State& state) {
3333
static void BM_Bowen_PushBack(benchmark::State& state) {
3434
size_t n = state.range(0);
3535
for (auto _ : state) {
36-
bitvector<> bv;
36+
BitVector<> bv;
3737
bv.reserve(n);
3838
for (size_t i=0;i<n;++i) {
3939
bv.push_back(static_cast<bool>(i & 1));
@@ -56,7 +56,7 @@ static void BM_Std_PushBack(benchmark::State& state) {
5656

5757
static void BM_Bowen_Access(benchmark::State& state) {
5858
size_t n = state.range(0);
59-
bitvector<> bv(n);
59+
BitVector<> bv(n);
6060
for (size_t i=0;i<n;++i) bv[i] = static_cast<bool>(i & 1);
6161
for (auto _ : state) {
6262
size_t sum=0;
@@ -79,7 +79,7 @@ static void BM_Std_Access(benchmark::State& state) {
7979
static void BM_Bowen_SetBit(benchmark::State& state) {
8080
size_t n = state.range(0);
8181
for (auto _ : state) {
82-
bitvector<> bv(n);
82+
BitVector<> bv(n);
8383
for (size_t i=0;i<n;++i) {
8484
bv.set_bit(i, static_cast<bool>(i & 1));
8585
}
@@ -101,7 +101,7 @@ static void BM_Std_SetBit(benchmark::State& state) {
101101
static void BM_Bowen_SetBitTrueUnsafe(benchmark::State& state) {
102102
size_t n = state.range(0);
103103
for (auto _ : state) {
104-
bitvector<> bv(n);
104+
BitVector<> bv(n);
105105
for (size_t i=0;i<n;++i) {
106106
bv.set_bit_true_unsafe(i);
107107
}
@@ -124,7 +124,7 @@ static void BM_Std_SetBitTrueUnsafe(benchmark::State& state) {
124124
static void BM_Bowen_SetBitTrue6(benchmark::State& state) {
125125
size_t n = state.range(0);
126126
for (auto _ : state) {
127-
bitvector<> bv(n);
127+
BitVector<> bv(n);
128128
for (size_t pos=0; pos+5 < n; pos+=6) {
129129
bv.set_bit_true_6(pos, 1);
130130
}
@@ -148,7 +148,7 @@ static void BM_Std_SetBitTrue6(benchmark::State& state) {
148148
static void BM_Bowen_QSetBitTrue6V2(benchmark::State& state) {
149149
size_t n = state.range(0);
150150
for (auto _ : state) {
151-
bitvector<> bv(n);
151+
BitVector<> bv(n);
152152
bv.qset_bit_true_6_v2(0, 1, n);
153153
benchmark::ClobberMemory();
154154
}
@@ -167,7 +167,7 @@ static void BM_Std_QSetBitTrue6(benchmark::State& state) {
167167

168168
static void BM_Bowen_IncrementUntilZero(benchmark::State& state) {
169169
size_t n = state.range(0);
170-
bitvector<> bv(n, true);
170+
BitVector<> bv(n, true);
171171
bv.set_bit(n-1, false);
172172
for (auto _ : state) {
173173
size_t pos = 0;

bitvector_test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include <gtest/gtest.h>
33

44
TEST(BitvectorTest, PushBackBasic) {
5-
bowen::bitvector<> bv;
5+
bowen::BitVector<> bv;
66
EXPECT_TRUE(bv.empty());
77

88
bv.push_back(false);
@@ -17,7 +17,7 @@ TEST(BitvectorTest, PushBackBasic) {
1717

1818
TEST(BitvectorTest, IncrementUntilZero) {
1919
const size_t N = 20;
20-
bowen::bitvector<> bv(N);
20+
bowen::BitVector<> bv(N);
2121

2222
// Set bits 5 through 7 to 1
2323
for (size_t i = 5; i <= 7; ++i) {
@@ -30,7 +30,7 @@ TEST(BitvectorTest, IncrementUntilZero) {
3030
}
3131

3232
TEST(BitvectorTest, ConstructWithValue) {
33-
bowen::bitvector<> bv(10, true);
33+
bowen::BitVector<> bv(10, true);
3434
ASSERT_EQ(bv.size(), 10u);
3535
for (size_t i = 0; i < bv.size(); ++i) {
3636
EXPECT_TRUE(bv[i]);
@@ -39,18 +39,18 @@ TEST(BitvectorTest, ConstructWithValue) {
3939

4040
#ifndef BITVECTOR_NO_BOUND_CHECK
4141
TEST(BitvectorTest, OutOfRangeThrows) {
42-
bowen::bitvector<> bv(5);
42+
bowen::BitVector<> bv(5);
4343
EXPECT_THROW(bv[5], std::out_of_range);
4444
EXPECT_THROW(bv.set_bit(5, true), std::out_of_range);
4545
}
4646
#endif
4747

4848
TEST(BitvectorTest, CopyAndAssignment) {
49-
bowen::bitvector<> bv1;
49+
bowen::BitVector<> bv1;
5050
bv1.push_back(false);
5151
bv1.push_back(true);
5252

53-
bowen::bitvector<> bv2(bv1);
53+
bowen::BitVector<> bv2(bv1);
5454
ASSERT_EQ(bv2.size(), bv1.size());
5555
EXPECT_FALSE(bv2[0]);
5656
EXPECT_TRUE(bv2[1]);
@@ -59,15 +59,15 @@ TEST(BitvectorTest, CopyAndAssignment) {
5959
EXPECT_TRUE(bv1[0]);
6060
EXPECT_FALSE(bv2[0]);
6161

62-
bowen::bitvector<> bv3;
62+
bowen::BitVector<> bv3;
6363
bv3 = bv1;
6464
ASSERT_EQ(bv3.size(), bv1.size());
6565
EXPECT_TRUE(bv3[0]);
6666
EXPECT_TRUE(bv3[1]);
6767
}
6868

6969
TEST(BitvectorTest, AssignResizesAndSets) {
70-
bowen::bitvector<> bv;
70+
bowen::BitVector<> bv;
7171
bv.assign(12, true);
7272
ASSERT_EQ(bv.size(), 12u);
7373
for (size_t i = 0; i < bv.size(); ++i)
@@ -80,7 +80,7 @@ TEST(BitvectorTest, AssignResizesAndSets) {
8080
}
8181

8282
TEST(BitvectorTest, IteratorTraversal) {
83-
bowen::bitvector<> bv;
83+
bowen::BitVector<> bv;
8484
bv.push_back(true);
8585
bv.push_back(false);
8686
bv.push_back(true);

main.cpp

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,13 @@ void benchmarkStdVectorBool(){
5050
std::cout << "[std::vector<bool>] True count: " << true_count << std::endl;
5151
}
5252

53-
// Benchmarks the performance of bowen::bitvector for setting, assigning, accessing, and traversing elements.
53+
// Benchmarks the performance of bowen::BitVector for setting, assigning, accessing, and traversing elements.
5454
void benchmarkBowenBitvector(){
5555

56-
std::cout << "Benchmarking bowen::bitvector..." << std::endl;
56+
std::cout << "Benchmarking bowen::BitVector..." << std::endl;
5757

5858
// Define a bitvector
59-
bowen::bitvector bool_vector(SIZE);
59+
bowen::BitVector bool_vector(SIZE);
6060

6161
// Time setting each element
6262
auto start_set = std::chrono::high_resolution_clock::now();
@@ -65,15 +65,15 @@ void benchmarkBowenBitvector(){
6565
}
6666
auto end_set = std::chrono::high_resolution_clock::now();
6767
auto duration_set = std::chrono::duration_cast<std::chrono::milliseconds>(end_set - start_set);
68-
std::cout << "[bowen::bitvector] Setting all elements took " << duration_set.count() << " milliseconds." << std::endl;
68+
std::cout << "[bowen::BitVector] Setting all elements took " << duration_set.count() << " milliseconds." << std::endl;
6969

7070
// Time setting each element using assign
7171
auto start_assign = std::chrono::high_resolution_clock::now();
72-
bowen::bitvector vector2;
72+
bowen::BitVector vector2;
7373
vector2.assign(SIZE, 1);
7474
auto end_assign = std::chrono::high_resolution_clock::now();
7575
auto duration_assign = std::chrono::duration_cast<std::chrono::milliseconds>(end_assign - start_assign);
76-
std::cout << "[bowen::bitvector] Assigning all elements took " << duration_assign.count() << " milliseconds." << std::endl;
76+
std::cout << "[bowen::BitVector] Assigning all elements took " << duration_assign.count() << " milliseconds." << std::endl;
7777

7878
// Time accessing each element
7979
size_t true_count = 0;
@@ -85,7 +85,7 @@ void benchmarkBowenBitvector(){
8585
}
8686
auto end_access = std::chrono::high_resolution_clock::now();
8787
auto duration_access = std::chrono::duration_cast<std::chrono::milliseconds>(end_access - start_access);
88-
std::cout << "[bowen::bitvector] Accessing all elements took " << duration_access.count() << " milliseconds." << std::endl;
88+
std::cout << "[bowen::BitVector] Accessing all elements took " << duration_access.count() << " milliseconds." << std::endl;
8989

9090
// Time traversing the entire vector
9191
auto start_traverse = std::chrono::high_resolution_clock::now();
@@ -96,16 +96,16 @@ void benchmarkBowenBitvector(){
9696
}
9797
auto end_traverse = std::chrono::high_resolution_clock::now();
9898
auto duration_traverse = std::chrono::duration_cast<std::chrono::milliseconds>(end_traverse - start_traverse);
99-
std::cout << "[bowen::bitvector] Traversing all elements took " << duration_traverse.count() << " milliseconds." << std::endl;
99+
std::cout << "[bowen::BitVector] Traversing all elements took " << duration_traverse.count() << " milliseconds." << std::endl;
100100

101-
std::cout << "[bowen::bitvector] True count: " << true_count << std::endl;
101+
std::cout << "[bowen::BitVector] True count: " << true_count << std::endl;
102102
}
103103

104-
// Compares the behavior of bowen::bitvector against std::vector<bool> for basic operations.
104+
// Compares the behavior of bowen::BitVector against std::vector<bool> for basic operations.
105105
void testBitvectorAgainstStdVectorBool(){
106106

107107
// Define a bitvector and a vector<bool>
108-
bowen::bitvector bool_vector1(SIZE);
108+
bowen::BitVector bool_vector1(SIZE);
109109
std::vector<bool> bool_vector2(SIZE);
110110
// Time setting each element
111111
auto start_set = std::chrono::high_resolution_clock::now();
@@ -134,14 +134,14 @@ void testBitvectorAgainstStdVectorBool(){
134134

135135
}
136136

137-
// Tests the incrementUntilZero method of bowen::bitvector.
137+
// Tests the incrementUntilZero method of bowen::BitVector.
138138
// This method is expected to increment a counter starting from a given position
139139
// as long as it encounters '1's in the bitvector, stopping at the first '0' or the end of the vector.
140140
void testBitvectorIncrementUntilZero(){
141141
constexpr size_t SIZE = 128*10; // Size of the bitvector
142142

143143
// Define a bitvector
144-
bowen::bitvector bool_vector1(SIZE);
144+
bowen::BitVector bool_vector1(SIZE);
145145
// Time setting some elements to true
146146
int start = rand()%(SIZE-2);
147147
int correct_count=start;
@@ -165,7 +165,7 @@ void testBitvectorIncrementUntilZero(){
165165

166166
void calculateSpeedup(double std_time, double bowen_time) {
167167
double speedup = std_time / bowen_time;
168-
std::cout << "Speedup (std::vector<bool> vs bowen::bitvector): " << speedup << "x" << std::endl;
168+
std::cout << "Speedup (std::vector<bool> vs bowen::BitVector): " << speedup << "x" << std::endl;
169169
}
170170

171171
int main() {
@@ -175,7 +175,7 @@ int main() {
175175
auto end_std = std::chrono::high_resolution_clock::now();
176176
double std_time = std::chrono::duration_cast<std::chrono::milliseconds>(end_std - start_std).count();
177177

178-
// Benchmark bowen::bitvector
178+
// Benchmark bowen::BitVector
179179
auto start_bowen = std::chrono::high_resolution_clock::now();
180180
benchmarkBowenBitvector();
181181
auto end_bowen = std::chrono::high_resolution_clock::now();

0 commit comments

Comments
 (0)