Skip to content

Commit 4416135

Browse files
committed
add InputIt support
1 parent 56e5f41 commit 4416135

2 files changed

Lines changed: 41 additions & 1 deletion

File tree

include/phasar/Utils/BitVectorSet.h

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ template <typename T> class BitVectorSet {
5252
}
5353
}
5454

55+
template <typename InputIt>
56+
BitVectorSet(InputIt First, InputIt Last) {
57+
while (First != Last) {
58+
insert(*First);
59+
++First;
60+
}
61+
}
62+
5563
~BitVectorSet() = default;
5664

5765
BitVectorSet<T> setUnion(const BitVectorSet<T> &Other) const {
@@ -148,6 +156,14 @@ template <typename T> class BitVectorSet {
148156
}
149157
}
150158

159+
template <typename InputIt>
160+
void insert(InputIt First, InputIt Last) {
161+
while (First != Last) {
162+
insert(*First);
163+
++First;
164+
}
165+
}
166+
151167
void erase(const T &Data) noexcept {
152168
auto Search = Position.left.find(Data);
153169
if (Search != Position.left.end()) {

unittests/Utils/BitVectorSetTest.cpp

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
#include <gtest/gtest.h>
22

33
#include <iostream>
4+
#include <set>
45
#include <utility>
56

67
#include <phasar/Utils/BitVectorSet.h>
@@ -18,6 +19,18 @@ TEST(BitVectorSet, ctor) {
1819
EXPECT_EQ(B.count(666), 0);
1920
}
2021

22+
TEST(BitVectorSet, ctorIter) {
23+
std::set<int> S({10, 20, 30, 40, 50});
24+
BitVectorSet<int> B(S.begin(), S.end());
25+
26+
EXPECT_EQ(B.count(10), 1);
27+
EXPECT_EQ(B.count(20), 1);
28+
EXPECT_EQ(B.count(30), 1);
29+
EXPECT_EQ(B.count(40), 1);
30+
EXPECT_EQ(B.count(50), 1);
31+
EXPECT_EQ(B.count(666), 0);
32+
}
33+
2134
TEST(BitVectorSet, copy) {
2235
BitVectorSet<int> B({10, 20, 30, 40, 50});
2336
BitVectorSet<int> C(B);
@@ -71,7 +84,7 @@ TEST(BitVectorSet, move) {
7184
EXPECT_EQ(C.count(42), 1);
7285
}
7386

74-
TEST(BitVectorSetTest, insert) {
87+
TEST(BitVectorSet, insert) {
7588
BitVectorSet<int> B;
7689
B.insert(1);
7790
B.insert(42);
@@ -83,6 +96,17 @@ TEST(BitVectorSetTest, insert) {
8396
EXPECT_EQ(B.count(666), 0);
8497
}
8598

99+
TEST(BitVectorSet, insertIter) {
100+
std::set<int> S = {1, 42, 13};
101+
BitVectorSet<int> B;
102+
B.insert(S.begin(), S.end());
103+
104+
EXPECT_EQ(B.count(1), 1);
105+
EXPECT_EQ(B.count(42), 1);
106+
EXPECT_EQ(B.count(13), 1);
107+
EXPECT_EQ(B.count(666), 0);
108+
}
109+
86110
TEST(BitVectorSet, insertBitVectorSet) {
87111
BitVectorSet<int> A({1, 2, 3, 4, 5, 6});
88112
BitVectorSet<int> B;

0 commit comments

Comments
 (0)