-
Notifications
You must be signed in to change notification settings - Fork 81
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1153 from eseiler/feature/constexpr_bitset
[FEATURE] dynamic_bitset
- Loading branch information
Showing
23 changed files
with
2,906 additions
and
0 deletions.
There are no files selected for viewing
1,849 changes: 1,849 additions & 0 deletions
1,849
include/seqan3/range/container/dynamic_bitset.hpp
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{0b1011'1000'1111}; | ||
|
||
// begin() refers to the rightmost position. | ||
for (auto it = t1.begin(); it != t1.end(); ++it) | ||
seqan3::debug_stream << *it; // 1111'0001'1101 | ||
|
||
seqan3::debug_stream << '\n'; | ||
} |
11 changes: 11 additions & 0 deletions
11
test/snippet/range/container/dynamic_bitset_binary_and_member.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
seqan3::dynamic_bitset const t2{0b1011'1000}; | ||
|
||
t1 &= t2; | ||
seqan3::debug_stream << t1 << '\n'; // 1000'1000 | ||
} |
11 changes: 11 additions & 0 deletions
11
test/snippet/range/container/dynamic_bitset_binary_or_member.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
seqan3::dynamic_bitset const t2{0b1011'1000}; | ||
|
||
t1 |= t2; | ||
seqan3::debug_stream << t1 << '\n'; // 1011'1100 | ||
} |
11 changes: 11 additions & 0 deletions
11
test/snippet/range/container/dynamic_bitset_binary_xor_member.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
seqan3::dynamic_bitset const t2{0b1011'1000}; | ||
|
||
t1 ^= t2; | ||
seqan3::debug_stream << t1 << '\n'; // 0011'0100 | ||
} |
11 changes: 11 additions & 0 deletions
11
test/snippet/range/container/dynamic_bitset_construct_string.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"101110001111"}; // Use character literal. | ||
seqan3::dynamic_bitset t2{"000010001111"}; // Leading zeros are kept. | ||
|
||
seqan3::debug_stream << t1 << '\n'; // 1011'1000'1111 | ||
seqan3::debug_stream << t2 << '\n'; // 0000'1000'1111 | ||
} |
13 changes: 13 additions & 0 deletions
13
test/snippet/range/container/dynamic_bitset_construct_uint64_t.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{0b1011'1000'1111}; // Use binary literal. | ||
seqan3::dynamic_bitset t2{0b0000'1000'1111}; // Leading zeros are stripped. | ||
seqan3::dynamic_bitset t3{832}; // Use a number. | ||
|
||
seqan3::debug_stream << t1 << '\n'; // 1011'1000'1111 | ||
seqan3::debug_stream << t2 << '\n'; // 1000'1111 | ||
seqan3::debug_stream << t3 << '\n'; // 1101'0000'00 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset const t1{"10001100"}; | ||
seqan3::dynamic_bitset t2 = ~t1; | ||
|
||
seqan3::debug_stream << t2 << '\n'; // 0111'0011 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
|
||
t1.flip(); | ||
seqan3::debug_stream << t1 << '\n'; // 0111'0011 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
|
||
t1.flip(0); | ||
t1.flip(3); | ||
seqan3::debug_stream << t1 << '\n'; // 1000'0101 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
|
||
t1.reset(); | ||
seqan3::debug_stream << t1 << '\n'; // 0000'0000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
|
||
t1.reset(2); | ||
t1.reset(3); | ||
seqan3::debug_stream << t1 << '\n'; // 1000'0000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"1100"}; | ||
|
||
t1.resize(8); // Enlarge to 8. | ||
seqan3::debug_stream << t1 << '\n'; // 0000'1100 | ||
t1.resize(5); // Shrink to 5, last three bits (5, 6, 7) are set to false. | ||
seqan3::debug_stream << t1 << '\n'; // 0110'0 | ||
t1.resize(10, true); // Enlarge to 10 and set new bits to true. | ||
seqan3::debug_stream << t1 << '\n'; // 1111'1011'00 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
|
||
t1.set(); | ||
seqan3::debug_stream << t1 << '\n'; // 1111'1111 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
|
||
t1.set(0); | ||
t1.set(2, false); | ||
seqan3::debug_stream << t1 << '\n'; // 1000'1001 | ||
} |
10 changes: 10 additions & 0 deletions
10
test/snippet/range/container/dynamic_bitset_shift_left_copy.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset const t1{"10001100"}; | ||
|
||
seqan3::dynamic_bitset t2 = t1 << 3; | ||
seqan3::debug_stream << t2 << '\n'; // 0110'0000 | ||
} |
10 changes: 10 additions & 0 deletions
10
test/snippet/range/container/dynamic_bitset_shift_left_inplace.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
|
||
t1 <<= 3; | ||
seqan3::debug_stream << t1 << '\n'; // 0110'0000 | ||
} |
10 changes: 10 additions & 0 deletions
10
test/snippet/range/container/dynamic_bitset_shift_right_copy.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset const t1{"10001100"}; | ||
|
||
seqan3::dynamic_bitset t2 = t1 >> 3; | ||
seqan3::debug_stream << t2 << '\n'; // 0001'0001 | ||
} |
10 changes: 10 additions & 0 deletions
10
test/snippet/range/container/dynamic_bitset_shift_right_inplace.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; | ||
|
||
t1 >>= 3; | ||
seqan3::debug_stream << t1 << '\n'; // 0001'0001 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{0b1011'1000'1111}; | ||
|
||
// Positions are 0-based and start at the rightmost bit. | ||
for (size_t i = 0; i < t1.size(); ++i) | ||
seqan3::debug_stream << t1[i]; // 1111'0001'1101 | ||
|
||
seqan3::debug_stream << '\n'; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
#include <seqan3/core/debug_stream.hpp> | ||
#include <seqan3/range/container/dynamic_bitset.hpp> | ||
|
||
int main() | ||
{ | ||
seqan3::dynamic_bitset t1{"10001100"}; // Construct from string. | ||
seqan3::dynamic_bitset const t2{0b1011'1000}; // Construct from binary literal or integer. | ||
|
||
seqan3::debug_stream << t1 << '\n'; // Debug printing inserts separators: 1000'1100 | ||
std::cout << t2 << '\n'; // Standard printing does not: 10111000 | ||
|
||
t1 &= t2; // Assign t1 the result of a binary AND of t1 and t2. | ||
seqan3::debug_stream << t1 << '\n'; // 1000'1000 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.