diff options
author | Lorry Tar Creator <lorry-tar-importer@baserock.org> | 2014-08-05 19:32:57 +0000 |
---|---|---|
committer | <> | 2014-10-07 10:01:33 +0000 |
commit | 1c3648bf5b7d17fcd4fe9bc95802b16fd9eee304 (patch) | |
tree | 03de66686a262696ec2ac408e62250dc1f0c01aa /libs/dynamic_bitset | |
parent | 8c4528713d907ee2cfd3bfcbbad272c749867f84 (diff) | |
download | boost-tarball-1c3648bf5b7d17fcd4fe9bc95802b16fd9eee304.tar.gz |
Imported from /home/lorry/working-area/delta_boost-tarball/boost_1_56_0.tar.bz2.boost_1_56_0
Diffstat (limited to 'libs/dynamic_bitset')
-rw-r--r-- | libs/dynamic_bitset/bitset_test.hpp | 71 | ||||
-rw-r--r-- | libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp | 90 | ||||
-rw-r--r-- | libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp | 4 | ||||
-rw-r--r-- | libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp | 59 | ||||
-rw-r--r-- | libs/dynamic_bitset/dynamic_bitset.html | 89 | ||||
-rw-r--r-- | libs/dynamic_bitset/example/timing_tests.cpp | 15 |
6 files changed, 301 insertions, 27 deletions
diff --git a/libs/dynamic_bitset/bitset_test.hpp b/libs/dynamic_bitset/bitset_test.hpp index bca746eb2..ac47c04a6 100644 --- a/libs/dynamic_bitset/bitset_test.hpp +++ b/libs/dynamic_bitset/bitset_test.hpp @@ -1,6 +1,7 @@ // ----------------------------------------------------------- // Copyright (c) 2001 Jeremy Siek // Copyright (c) 2003-2006, 2008 Gennaro Prota +// Copyright (c) 2014 Ahmed Charles // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -129,7 +130,7 @@ struct bitset_test { // - any remaining bit positions are initialized to zero // - Bitset b(num_bits, num); + Bitset b(static_cast<typename Bitset::size_type>(num_bits), static_cast<unsigned long>(num)); // OK, we can now cast to size_type typedef typename Bitset::size_type size_type; @@ -267,11 +268,12 @@ struct bitset_test { } } - // assignment operator (absent from std::bitset) - static void assignment_operator(const Bitset& lhs, const Bitset& rhs) + // copy assignment operator (absent from std::bitset) + static void copy_assignment_operator(const Bitset& lhs, const Bitset& rhs) { Bitset b(lhs); b = rhs; + b = b; // self assignment check BOOST_CHECK(b == rhs); // Changes to the copy do not affect the original @@ -282,6 +284,32 @@ struct bitset_test { } } + static void max_size(const Bitset& b) + { + BOOST_CHECK(b.max_size() > 0); + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + + // move constructor (absent from std::bitset) + static void move_constructor(const Bitset& b) + { + Bitset copy(boost::move(b)); + BOOST_CHECK(b == copy); + } + + // move assignment operator (absent from std::bitset) + static void move_assignment_operator(const Bitset& lhs, const Bitset& rhs) + { + Bitset b(lhs); + Bitset c(rhs); + b = boost::move(c); + b = boost::move(b); // self assignment check + BOOST_CHECK(b == rhs); + } + +#endif // BOOST_NO_CXX11_RVALUE_REFERENCES + static void swap(const Bitset& lhs, const Bitset& rhs) { // bitsets must be swapped @@ -689,9 +717,21 @@ struct bitset_test { BOOST_CHECK(Bitset(b).set().count() == b.size()); } + static void all(const Bitset& b) + { + BOOST_CHECK(b.all() == (b.count() == b.size())); + bool result = true; + for(std::size_t i = 0; i < b.size(); ++i) + if(!b[i]) { + result = false; + break; + } + BOOST_CHECK(b.all() == result); + } + static void any(const Bitset& b) { - //BOOST_CHECK(b.any() == (b.count() > 0)); + BOOST_CHECK(b.any() == (b.count() != 0)); bool result = false; for(std::size_t i = 0; i < b.size(); ++i) if(b[i]) { @@ -925,6 +965,25 @@ struct bitset_test { } } + static void test_set_bit(const Bitset& b, std::size_t pos, bool value) + { + Bitset lhs(b); + std::size_t N = lhs.size(); + if (pos < N) { + Bitset prev(lhs); + // Stores a new value in the bit at position pos in lhs. + BOOST_CHECK(lhs.test_set(pos, value) == prev[pos]); + BOOST_CHECK(lhs[pos] == value); + + // All other values of lhs remain unchanged + for (std::size_t I = 0; I < N; ++I) + if (I != pos) + BOOST_CHECK(lhs[I] == prev[I]); + } else { + // Not in range, doesn't satisfy precondition. + } + } + static void operator_shift_left(const Bitset& lhs, std::size_t pos) { Bitset x(lhs); @@ -1048,7 +1107,7 @@ struct bitset_test { // This test require that os be an output _and_ input stream. // Of course dynamic_bitset's operator << doesn't require that. - size_type total_len = w <= 0 || (size_type)(w) < b.size()? b.size() : w; + size_type total_len = w <= 0 || static_cast<size_type>(w) < b.size()? b.size() : static_cast<size_type>(w); const string_type padding (total_len - b.size(), fill_char); string_type expected; boost::to_string(b, expected); @@ -1139,7 +1198,7 @@ struct bitset_test { // {digits} or part of them const typename Bitset::size_type max_digits = w > 0 && static_cast<typename Bitset::size_type>(w) < b.max_size() - ? w : b.max_size(); + ? static_cast<typename Bitset::size_type>(w) : b.max_size(); for( ; pos < len && (pos - after_spaces) < max_digits; ++pos) { if(!is_one_or_zero(is, str[pos])) diff --git a/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp b/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp index e6f9d78b4..31299d1ee 100644 --- a/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp +++ b/libs/dynamic_bitset/dyn_bitset_unit_tests1.cpp @@ -1,6 +1,10 @@ // ----------------------------------------------------------- // Copyright (c) 2001 Jeremy Siek // Copyright (c) 2003-2006 Gennaro Prota +// Copyright (c) 2014 Ahmed Charles +// +// Copyright (c) 2014 Glen Joseph Fernandes +// glenfe at live dot com // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -15,6 +19,28 @@ #include "boost/detail/workaround.hpp" +#if !defined(BOOST_NO_CXX11_ALLOCATOR) +#include <cstdlib> + +template<class T> +class minimal_allocator { +public: + typedef T value_type; + + T* allocate(std::size_t n) { + void* p = std::malloc(sizeof(T) * n); + if (!p) { + throw std::bad_alloc(); + } + return static_cast<T*>(p); + } + + void deallocate(T* p, std::size_t) { + std::free(p); + } +}; +#endif + #define BOOST_BITSET_TEST_COUNT(x) (sizeof(x)/sizeof(x[0])) @@ -117,9 +143,6 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) //===================================================================== // Test construction from unsigned long { - typedef typename bitset_type::size_type size_type; - - // NOTE: // // 1. keep this in sync with the numeric types supported @@ -240,29 +263,70 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) Tests::copy_constructor(b); } //===================================================================== - // Test assignment operator + // Test copy assignment operator + { + bitset_type a, b; + Tests::copy_assignment_operator(a, b); + } + { + bitset_type a(std::string("1")), b(std::string("0")); + Tests::copy_assignment_operator(a, b); + } + { + bitset_type a(long_string), b(long_string); + Tests::copy_assignment_operator(a, b); + } + { + bitset_type a; + bitset_type b(long_string); // b greater than a, a empty + Tests::copy_assignment_operator(a, b); + } + { + bitset_type a(std::string("0")); + bitset_type b(long_string); // b greater than a + Tests::copy_assignment_operator(a, b); + } + +#ifndef BOOST_NO_CXX11_RVALUE_REFERENCES + //===================================================================== + // Test move constructor + { + boost::dynamic_bitset<Block> b; + Tests::move_constructor(b); + } + { + boost::dynamic_bitset<Block> b(std::string("0")); + Tests::move_constructor(b); + } + { + boost::dynamic_bitset<Block> b(long_string); + Tests::move_constructor(b); + } + //===================================================================== + // Test move assignment operator { bitset_type a, b; - Tests::assignment_operator(a, b); + Tests::move_assignment_operator(a, b); } { bitset_type a(std::string("1")), b(std::string("0")); - Tests::assignment_operator(a, b); + Tests::move_assignment_operator(a, b); } { bitset_type a(long_string), b(long_string); - Tests::assignment_operator(a, b); + Tests::move_assignment_operator(a, b); } { bitset_type a; bitset_type b(long_string); // b greater than a, a empty - Tests::assignment_operator(a, b); + Tests::move_assignment_operator(a, b); } { bitset_type a(std::string("0")); bitset_type b(long_string); // b greater than a - Tests::assignment_operator(a, b); + Tests::move_assignment_operator(a, b); } +#endif // BOOST_NO_CXX11_RVALUE_REFERENCES //===================================================================== // Test swap { @@ -420,6 +484,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) bit_vec[i] = long_string[n - 1 - i] == '0' ? 0 : 1; Tests::operator_bracket(b, bit_vec); } +#if !defined(BOOST_NO_CXX11_ALLOCATOR) + { + typedef boost::dynamic_bitset<Block, + minimal_allocator<Block> > Bitset; + Bitset b; + bitset_test<Bitset>::max_size(b); + } +#endif } int diff --git a/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp b/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp index b2d781f90..457d762e4 100644 --- a/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp +++ b/libs/dynamic_bitset/dyn_bitset_unit_tests2.cpp @@ -1,6 +1,7 @@ // ----------------------------------------------------------- // Copyright (c) 2001 Jeremy Siek // Copyright (c) 2003-2006 Gennaro Prota +// Copyright (c) 2014 Ahmed Charles // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -194,14 +195,17 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) { // case pos >= b.size() boost::dynamic_bitset<Block> b; Tests::set_one(b, 0, true); + Tests::set_one(b, 0, false); } { // case pos < b.size() boost::dynamic_bitset<Block> b(std::string("0")); Tests::set_one(b, 0, true); + Tests::set_one(b, 0, false); } { // case pos == b.size() / 2 boost::dynamic_bitset<Block> b(long_string); Tests::set_one(b, long_string.size()/2, true); + Tests::set_one(b, long_string.size()/2, false); } //===================================================================== // Test b.reset() diff --git a/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp b/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp index 0792a2064..41e4c4ad4 100644 --- a/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp +++ b/libs/dynamic_bitset/dyn_bitset_unit_tests3.cpp @@ -1,6 +1,7 @@ // ----------------------------------------------------------- // Copyright (c) 2001 Jeremy Siek // Copyright (c) 2003-2006 Gennaro Prota +// Copyright (c) 2014 Ahmed Charles // // Distributed under the Boost Software License, Version 1.0. // (See accompanying file LICENSE_1_0.txt or copy at @@ -121,32 +122,73 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) Tests::size(b); } //===================================================================== + // Test b.all() + { + boost::dynamic_bitset<Block> b; + Tests::all(b); + Tests::all(~b); + Tests::all(b.set()); + Tests::all(b.reset()); + } + { + boost::dynamic_bitset<Block> b(std::string("0")); + Tests::all(b); + Tests::all(~b); + Tests::all(b.set()); + Tests::all(b.reset()); + } + { + boost::dynamic_bitset<Block> b(long_string); + Tests::all(b); + Tests::all(~b); + Tests::all(b.set()); + Tests::all(b.reset()); + } + //===================================================================== // Test b.any() { boost::dynamic_bitset<Block> b; Tests::any(b); + Tests::any(~b); + Tests::any(b.set()); + Tests::any(b.reset()); } { boost::dynamic_bitset<Block> b(std::string("0")); Tests::any(b); + Tests::any(~b); + Tests::any(b.set()); + Tests::any(b.reset()); } { boost::dynamic_bitset<Block> b(long_string); Tests::any(b); + Tests::any(~b); + Tests::any(b.set()); + Tests::any(b.reset()); } //===================================================================== // Test b.none() { boost::dynamic_bitset<Block> b; Tests::none(b); + Tests::none(~b); + Tests::none(b.set()); + Tests::none(b.reset()); } { boost::dynamic_bitset<Block> b(std::string("0")); Tests::none(b); + Tests::none(~b); + Tests::none(b.set()); + Tests::none(b.reset()); } { boost::dynamic_bitset<Block> b(long_string); Tests::none(b); + Tests::none(~b); + Tests::none(b.set()); + Tests::none(b.reset()); } //===================================================================== // Test a.is_subset_of(b) @@ -569,6 +611,23 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) Tests::test_bit(b, long_string.size()/2); } //===================================================================== + // Test b.test_set(pos) + { // case pos >= b.size() + boost::dynamic_bitset<Block> b; + Tests::test_set_bit(b, 0, true); + Tests::test_set_bit(b, 0, false); + } + { // case pos < b.size() + boost::dynamic_bitset<Block> b(std::string("0")); + Tests::test_set_bit(b, 0, true); + Tests::test_set_bit(b, 0, false); + } + { // case pos == b.size() / 2 + boost::dynamic_bitset<Block> b(long_string); + Tests::test_set_bit(b, long_string.size() / 2, true); + Tests::test_set_bit(b, long_string.size() / 2, false); + } + //===================================================================== // Test b << pos { // case pos == 0 std::size_t pos = 0; diff --git a/libs/dynamic_bitset/dynamic_bitset.html b/libs/dynamic_bitset/dynamic_bitset.html index cef2fe1cf..d03a5025d 100644 --- a/libs/dynamic_bitset/dynamic_bitset.html +++ b/libs/dynamic_bitset/dynamic_bitset.html @@ -6,6 +6,7 @@ <!-- Copyright (c) 2001 Jeremy Siek Copyright (c) 2003-2004, 2008 Gennaro Prota + Copyright (c) 2014 Ahmed Charles Distributed under the Boost Software License, Version 1.0. (See accompanying file LICENSE_1_0.txt or copy at @@ -163,11 +164,17 @@ public: <a href= "#cons5">dynamic_bitset</a>(const dynamic_bitset& b); + <a href= +"#move-cons">dynamic_bitset</a>(dynamic_bitset&& b); + void <a href="#swap">swap</a>(dynamic_bitset& b); dynamic_bitset& <a href= "#assign">operator=</a>(const dynamic_bitset& b); + dynamic_bitset& <a href= +"#move-assign">operator=</a>(dynamic_bitset&& b); + allocator_type <a href="#get_allocator">get_allocator()</a> const; void <a href= @@ -195,20 +202,22 @@ public: dynamic_bitset& <a href="#flip2">flip</a>(size_type n); dynamic_bitset& <a href="#flip1">flip</a>(); bool <a href="#test">test</a>(size_type n) const; + bool <a href="#test">test_set</a>(size_type n, bool val = true); + bool <a href="#all">all</a>() const; bool <a href="#any">any</a>() const; bool <a href="#none">none</a>() const; dynamic_bitset <a href="#op-not">operator~</a>() const; - size_type <a href="#count">count</a>() const; + size_type <a href="#count">count</a>() const noexcept; reference <a href="#bracket">operator[]</a>(size_type pos); bool <a href="#const-bracket">operator[]</a>(size_type pos) const; unsigned long <a href="#to_ulong">to_ulong</a>() const; - size_type <a href="#size">size</a>() const; - size_type <a href="#num_blocks">num_blocks</a>() const; - size_type <a href="#max_size">max_size</a>() const; - bool <a href="#empty">empty</a>() const; + size_type <a href="#size">size</a>() const noexcept; + size_type <a href="#num_blocks">num_blocks</a>() const noexcept; + size_type <a href="#max_size">max_size</a>() const noexcept; + bool <a href="#empty">empty</a>() const noexcept; bool <a href="#is_subset_of">is_subset_of</a>(const dynamic_bitset& a) const; bool <a href="#is_proper_subset_of">is_proper_subset_of</a>(const dynamic_bitset& a) const; @@ -623,6 +632,20 @@ allocator in <tt>x</tt>. <br /> <hr /> <pre> +<a id="move-cons">dynamic_bitset</a>(dynamic_bitset&& x) +</pre> + +<b>Effects:</b> Constructs a bitset that is the same as the bitset +<tt>x</tt>, while using the resources from <tt>x</tt>. The allocator +for this bitset is moved from the allocator in <tt>x</tt>. <br /> + <b>Postconditions:</b> For all <tt>i</tt> in the range +<tt>[0,x.size())</tt>, <tt>(*this)[i] == x[i]</tt>.<br /> + <b>Throws:</b> An allocation error if memory is exhausted +(<tt>std::bad_alloc</tt> if +<tt>Allocator=std::allocator</tt>). + +<hr /> +<pre> template <typename BlockInputIterator> explicit <a id= @@ -766,6 +789,20 @@ dynamic_bitset& <a id= <hr /> <pre> +dynamic_bitset& <a id= +"move-assign">operator=</a>(dynamic_bitset&& x) +</pre> + +<b>Effects:</b> This bitset becomes the same as the bitset +<tt>x</tt>, while using the resources from <tt>x</tt>.<br /> + <b>Postconditions:</b> For all <tt>i</tt> in the range +<tt>[0,x.size())</tt>, <tt>(*this)[i] == x[i]</tt>.<br /> + <b>Returns:</b> <tt>*this</tt>.<br /> + <b>Throws:</b> An allocation error if memory is exhausted +(<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>). + +<hr /> +<pre> allocator_type <a id="get_allocator">get_allocator()</a> const; </pre> <b>Returns:</b> A copy of the allocator object used to construct <tt>*this</tt>. @@ -1089,6 +1126,15 @@ set.<br /> <hr /> <pre> +bool <a id="all">all</a>() const +</pre> + +<b>Returns:</b> <tt>true</tt> if all bits in this bitset are set or +if <tt>size() == 0</tt>, and otherwise returns <tt>false</tt>.<br /> +<b>Throws:</b> nothing. + +<hr /> +<pre> bool <a id="any">any</a>() const </pre> @@ -1116,6 +1162,18 @@ bool <a id="test">test</a>(size_type n) const <hr /> <pre> +bool <a id="test">test_set</a>(size_type n, bool val = true) +</pre> + +<b>Precondition:</b> <tt>n < this->size()</tt>.<br /> + <b>Effects:</b> Sets bit <tt>n</tt> if <tt>val</tt> is +<tt>true</tt>, and clears bit <tt>n</tt> if <tt>val</tt> is +<tt>false</tt>. <br /> + <b>Returns:</b> <tt>true</tt> if the previous state of bit +<tt>n</tt> was set and <tt>false</tt> is bit <tt>n</tt> is 0. + +<hr /> +<pre> reference <a id="bracket">operator[]</a>(size_type n) </pre> @@ -1509,6 +1567,14 @@ exception guarantee. <hr /> <h3><a id="changes-from-previous-ver">Changes from previous version(s)</a></h3> +<h4><i>Changes in Boost 1.56.0</i></h4> +<ul> +<li>Support for C++11 move constructors.</li> +<li>Warning fixes on MSVC 2013.</li> +<li>Support for C++11 minimal allocators.</li> +<li>Add noexcept specifications.</li> +</ul> + <h4><i>Changes in Boost 1.37.0</i></h4> <ul> <li>The constructor from a block range implements a "do the right thing" @@ -1561,9 +1627,12 @@ applied to their corresponding <tt>dynamic_bitset</tt>s. </li> </ul> <i>General improvements</i> -<br /><br /> +<ul> +<li> Several optimizations to member and non-member functions and to the nested class <tt>reference</tt>. +</li> +</ul> <hr /> <h3><a id="see-also">See also</a></h3> @@ -1595,6 +1664,14 @@ href="mailto:cda@freshsources.com">cda@freshsources.com</a>)<br href="http://gennaro-prota.50webs.com/">Gennaro Prota</a> (name.surname yahoo.com)</td> </tr> +<tr> +<td>Copyright © 2014</td> +<td>Ahmed Charles (<a href="mailto:acharles@outlook.com">acharles@outlook.com</a>)</td> +</tr> +<tr> +<td>Copyright © 2014</td> +<td>Glen Fernandes (<a href="mailto:glenfe@live.com">glenfe@live.com</a>)</td> +</tr> </table> <br /> <div class="legalnotice"> diff --git a/libs/dynamic_bitset/example/timing_tests.cpp b/libs/dynamic_bitset/example/timing_tests.cpp index b4bb3a1ad..c31b45b32 100644 --- a/libs/dynamic_bitset/example/timing_tests.cpp +++ b/libs/dynamic_bitset/example/timing_tests.cpp @@ -23,6 +23,10 @@ // table in detail/dynamic_bitset.hpp and report any interesting // discovery on the list as well. +// You might also want to try both counting methods (by_bytes vs. +// by_blocks) to see if the one that is selected automatically is +// actually the fastest on your system. + // // // -----------------------------------------------------------------------// @@ -55,9 +59,9 @@ namespace { // see http://gcc.gnu.org/ml/gcc-bugs/1999-03n/msg00884.html // class boost_version { - const int m_major; - const int m_minor; - const int m_subminor; + int m_major; + int m_minor; + int m_subminor; public: boost_version(unsigned long v = BOOST_VERSION): @@ -91,11 +95,11 @@ template <typename T> void timing_test(T* = 0) // dummy parameter to workaround VC6 { - const unsigned long num = 100000; + const unsigned long num = 30 * 100000; // This variable is printed at the end of the test, - // to prevent the optimizer eliminating the call to + // to prevent the optimizer from removing the call to // count() in the loop below. typename boost::dynamic_bitset<T>::size_type dummy = 0; @@ -123,7 +127,6 @@ void timing_test(T* = 0) // dummy parameter to workaround VC6 int main() { - prologue(); timing_test<unsigned char>(); |