Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[FEATURE] dynamic_bitset #1153

Merged
merged 19 commits into from
Aug 16, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1,849 changes: 1,849 additions & 0 deletions include/seqan3/range/container/dynamic_bitset.hpp

Large diffs are not rendered by default.

13 changes: 13 additions & 0 deletions test/snippet/range/container/dynamic_bitset_begin.cpp
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 test/snippet/range/container/dynamic_bitset_binary_and_member.cpp
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 test/snippet/range/container/dynamic_bitset_binary_or_member.cpp
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 test/snippet/range/container/dynamic_bitset_binary_xor_member.cpp
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 test/snippet/range/container/dynamic_bitset_construct_string.cpp
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 test/snippet/range/container/dynamic_bitset_construct_uint64_t.cpp
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
}
10 changes: 10 additions & 0 deletions test/snippet/range/container/dynamic_bitset_flip.cpp
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
}
10 changes: 10 additions & 0 deletions test/snippet/range/container/dynamic_bitset_flip_all.cpp
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
}
11 changes: 11 additions & 0 deletions test/snippet/range/container/dynamic_bitset_flip_pos.cpp
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
}
10 changes: 10 additions & 0 deletions test/snippet/range/container/dynamic_bitset_reset_all.cpp
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
}
11 changes: 11 additions & 0 deletions test/snippet/range/container/dynamic_bitset_reset_pos.cpp
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
}
14 changes: 14 additions & 0 deletions test/snippet/range/container/dynamic_bitset_resize.cpp
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
}
10 changes: 10 additions & 0 deletions test/snippet/range/container/dynamic_bitset_set_all.cpp
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
}
11 changes: 11 additions & 0 deletions test/snippet/range/container/dynamic_bitset_set_pos.cpp
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 test/snippet/range/container/dynamic_bitset_shift_left_copy.cpp
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 test/snippet/range/container/dynamic_bitset_shift_left_inplace.cpp
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 test/snippet/range/container/dynamic_bitset_shift_right_copy.cpp
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
}
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
}
13 changes: 13 additions & 0 deletions test/snippet/range/container/dynamic_bitset_subscript.cpp
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';
}
14 changes: 14 additions & 0 deletions test/snippet/range/container/dynamic_bitset_usage.cpp
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
}
1 change: 1 addition & 0 deletions test/unit/range/container/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ seqan3_test(container_of_container_test.cpp)
seqan3_test(container_test.cpp)
seqan3_test(debug_stream_container_of_container_test.cpp)
seqan3_test(debug_stream_container_test.cpp)
seqan3_test(dynamic_bitset_test.cpp)
seqan3_test(small_string_test.cpp)
seqan3_test(small_vector_test.cpp)
Loading