mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-24 18:02:09 +00:00
Compare commits
22 Commits
boost-1.59
...
boost-1.67
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
4f54d83981 | ||
|
|
4cac68e762 | ||
|
|
d3eb4faf0c | ||
|
|
3f3662d39d | ||
|
|
184d1ba7ad | ||
|
|
5b39db5ba0 | ||
|
|
f4e49ff56f | ||
|
|
0c8640efb8 | ||
|
|
0ead484c37 | ||
|
|
6cafa21c6d | ||
|
|
dbfce8e174 | ||
|
|
684b6117dd | ||
|
|
572e9d78ff | ||
|
|
e49b08a289 | ||
|
|
d644c83b13 | ||
|
|
a50768c085 | ||
|
|
91895380c6 | ||
|
|
7259281f5b | ||
|
|
92af4f52e9 | ||
|
|
d86f4ebddb | ||
|
|
340822f979 | ||
|
|
1c5e30fe49 |
3
Jamfile
Normal file
3
Jamfile
Normal file
@@ -0,0 +1,3 @@
|
||||
# Empty Jamfile because the super project still expects one to appear here.
|
||||
# Can be deleted once 'status/Jamfile.v2' has been updated in the super
|
||||
# project.
|
||||
1
doc/readme
Normal file
1
doc/readme
Normal file
@@ -0,0 +1 @@
|
||||
The documentation for the dynamic_bitset library is the top-level index.html file.
|
||||
@@ -7,6 +7,7 @@
|
||||
Copyright (c) 2001 Jeremy Siek
|
||||
Copyright (c) 2003-2004, 2008 Gennaro Prota
|
||||
Copyright (c) 2014 Ahmed Charles
|
||||
Copyright (c) 2014 Riccardo Marcangelo
|
||||
|
||||
Distributed under the Boost Software License, Version 1.0.
|
||||
(See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -219,6 +220,9 @@ public:
|
||||
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;
|
||||
size_type <a href="#capacity">capacity</a>() const noexcept;
|
||||
void <a href="#reserve">reserve</a>(size_type num_bits);
|
||||
void <a href="#shrink_to_fit">shrink_to_fit</a>();
|
||||
|
||||
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;
|
||||
@@ -843,7 +847,7 @@ void <a id="pop_back">pop_back</a>();
|
||||
<b>Precondition:</b> <tt>!this->empty()</tt>.<br />
|
||||
<b>Effects:</b> Decreases the size of the bitset by one.<br />
|
||||
<b>Throws:</b> nothing.
|
||||
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
void <a id="push_back">push_back</a>(bool value);
|
||||
@@ -1125,6 +1129,40 @@ bool <a id="empty">empty</a>() const;
|
||||
otherwise. <i>Note</i>: not to be confused with <tt>none()</tt>, that has
|
||||
different semantics.
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
size_type <a id="capacity">capacity</a>() const;
|
||||
</pre>
|
||||
|
||||
<b>Returns:</b> The total number of elements that <tt>*this</tt> can hold without requiring
|
||||
reallocation.<br />
|
||||
<b>Throws:</b> nothing.
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
void <a id="reserve">reserve</a>(size_type num_bits);
|
||||
</pre>
|
||||
|
||||
<b>Effects:</b> A directive that informs the bitset of a planned change in size, so that it can
|
||||
manage the storage allocation accordingly. After reserve(), capacity() is greater or equal to the
|
||||
argument of reserve() if reallocation happens; and equal to the previous value of capacity() otherwise.
|
||||
Reallocation happens at this point if and only if the current capacity is less than the argument of
|
||||
reserve(). <br />
|
||||
<i>Note:</i> It does not change the size() of the bitset.<br />
|
||||
<b>Postcondtitions:</b> <tt>this->capacity() >= num_bits</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>
|
||||
void <a id="shrink_to_fit">shrink_to_fit</a>();
|
||||
</pre>
|
||||
|
||||
<b>Effects:</b> shrink_to_fit() is a request to reduce memory use by removing unused capacity.<br />
|
||||
<i>Note:</i> It does not change the size() of the bitset.<br />
|
||||
<b>Throws:</b> An allocation error if memory is exhausted
|
||||
(<tt>std::bad_alloc</tt> if <tt>Allocator=std::allocator</tt>).
|
||||
|
||||
<hr />
|
||||
<pre>
|
||||
size_type <a id="count">count</a>() const
|
||||
@@ -1682,6 +1720,10 @@ href="mailto:cda@freshsources.com">cda@freshsources.com</a>)<br
|
||||
<td>Copyright © 2014</td>
|
||||
<td>Glen Fernandes (<a href="mailto:glenfe@live.com">glenfe@live.com</a>)</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td>Copyright © 2014</td>
|
||||
<td>Riccardo Marcangelo (<a href="mailto:ricky.65@outlook.com">ricky.65@outlook.com</a>)</td>
|
||||
</tr>
|
||||
</table>
|
||||
<br />
|
||||
<div class="legalnotice">
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2002 Gennaro Prota
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
# -----------------------------------------------------------
|
||||
# Copyright (c) 2002 Gennaro Prota
|
||||
#
|
||||
# Distributed under the Boost Software License, Version 1.0.
|
||||
# (See accompanying file LICENSE_1_0.txt or copy at
|
||||
# http://www.boost.org/LICENSE_1_0.txt)
|
||||
#
|
||||
# -----------------------------------------------------------
|
||||
|
||||
exe timing_tests
|
||||
: timing_tests.cpp
|
||||
;
|
||||
|
||||
@@ -86,7 +86,7 @@ public:
|
||||
|
||||
|
||||
// the one and only non-copy ctor
|
||||
reference(block_type & b, block_type pos)
|
||||
reference(block_type & b, block_width_type pos)
|
||||
:m_block(b),
|
||||
m_mask( (assert(pos < bits_per_block),
|
||||
block_type(1) << pos )
|
||||
@@ -305,6 +305,9 @@ public:
|
||||
size_type num_blocks() const BOOST_NOEXCEPT;
|
||||
size_type max_size() const BOOST_NOEXCEPT;
|
||||
bool empty() const BOOST_NOEXCEPT;
|
||||
size_type capacity() const BOOST_NOEXCEPT;
|
||||
void reserve(size_type num_bits);
|
||||
void shrink_to_fit();
|
||||
|
||||
bool is_subset_of(const dynamic_bitset& a) const;
|
||||
bool is_proper_subset_of(const dynamic_bitset& a) const;
|
||||
@@ -325,6 +328,10 @@ public:
|
||||
friend bool operator<(const dynamic_bitset<B, A>& a,
|
||||
const dynamic_bitset<B, A>& b);
|
||||
|
||||
template <typename B, typename A>
|
||||
friend bool oplessthan(const dynamic_bitset<B, A>& a,
|
||||
const dynamic_bitset<B, A>& b);
|
||||
|
||||
|
||||
template <typename B, typename A, typename BlockOutputIterator>
|
||||
friend void to_block_range(const dynamic_bitset<B, A>& b,
|
||||
@@ -345,6 +352,10 @@ public:
|
||||
|
||||
#endif
|
||||
|
||||
public:
|
||||
// forward declaration for optional zero-copy serialization support
|
||||
class serialize_impl;
|
||||
friend class serialize_impl;
|
||||
|
||||
private:
|
||||
BOOST_STATIC_CONSTANT(block_width_type, ulong_width = std::numeric_limits<unsigned long>::digits);
|
||||
@@ -750,15 +761,15 @@ push_back(bool bit)
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
void dynamic_bitset<Block, Allocator>::
|
||||
pop_back()
|
||||
pop_back()
|
||||
{
|
||||
const size_type old_num_blocks = num_blocks();
|
||||
const size_type required_blocks = calc_num_blocks(m_num_bits - 1);
|
||||
|
||||
|
||||
if (required_blocks != old_num_blocks) {
|
||||
m_bits.pop_back();
|
||||
m_bits.pop_back();
|
||||
}
|
||||
|
||||
|
||||
--m_num_bits;
|
||||
m_zero_unused_bits();
|
||||
}
|
||||
@@ -966,7 +977,7 @@ template <typename Block, typename Allocator>
|
||||
dynamic_bitset<Block, Allocator>&
|
||||
dynamic_bitset<Block, Allocator>::set()
|
||||
{
|
||||
std::fill(m_bits.begin(), m_bits.end(), ~Block(0));
|
||||
std::fill(m_bits.begin(), m_bits.end(), static_cast<Block>(~0));
|
||||
m_zero_unused_bits();
|
||||
return *this;
|
||||
}
|
||||
@@ -1045,7 +1056,7 @@ bool dynamic_bitset<Block, Allocator>::all() const
|
||||
}
|
||||
|
||||
const block_width_type extra_bits = count_extra_bits();
|
||||
block_type const all_ones = ~static_cast<Block>(0);
|
||||
block_type const all_ones = static_cast<Block>(~0);
|
||||
|
||||
if (extra_bits == 0) {
|
||||
for (size_type i = 0, e = num_blocks(); i < e; ++i) {
|
||||
@@ -1059,7 +1070,7 @@ bool dynamic_bitset<Block, Allocator>::all() const
|
||||
return false;
|
||||
}
|
||||
}
|
||||
block_type const mask = ~(~static_cast<Block>(0) << extra_bits);
|
||||
const block_type mask = (block_type(1) << extra_bits) - 1;
|
||||
if (m_highest_block() != mask) {
|
||||
return false;
|
||||
}
|
||||
@@ -1267,6 +1278,27 @@ inline bool dynamic_bitset<Block, Allocator>::empty() const BOOST_NOEXCEPT
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
inline typename dynamic_bitset<Block, Allocator>::size_type
|
||||
dynamic_bitset<Block, Allocator>::capacity() const BOOST_NOEXCEPT
|
||||
{
|
||||
return m_bits.capacity() * bits_per_block;
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
inline void dynamic_bitset<Block, Allocator>::reserve(size_type num_bits)
|
||||
{
|
||||
m_bits.reserve(calc_num_blocks(num_bits));
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
void dynamic_bitset<Block, Allocator>::shrink_to_fit()
|
||||
{
|
||||
if (m_bits.size() < m_bits.capacity()) {
|
||||
buffer_type(m_bits).swap(m_bits);
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
bool dynamic_bitset<Block, Allocator>::
|
||||
is_subset_of(const dynamic_bitset<Block, Allocator>& a) const
|
||||
@@ -1392,23 +1424,95 @@ template <typename Block, typename Allocator>
|
||||
bool operator<(const dynamic_bitset<Block, Allocator>& a,
|
||||
const dynamic_bitset<Block, Allocator>& b)
|
||||
{
|
||||
assert(a.size() == b.size());
|
||||
typedef typename dynamic_bitset<Block, Allocator>::size_type size_type;
|
||||
// assert(a.size() == b.size());
|
||||
|
||||
//if (a.size() == 0)
|
||||
// return false;
|
||||
typedef BOOST_DEDUCED_TYPENAME dynamic_bitset<Block, Allocator>::size_type size_type;
|
||||
|
||||
size_type asize(a.size());
|
||||
size_type bsize(b.size());
|
||||
|
||||
// Since we are storing the most significant bit
|
||||
// at pos == size() - 1, we need to do the comparisons in reverse.
|
||||
//
|
||||
for (size_type ii = a.num_blocks(); ii > 0; --ii) {
|
||||
size_type i = ii-1;
|
||||
if (a.m_bits[i] < b.m_bits[i])
|
||||
return true;
|
||||
else if (a.m_bits[i] > b.m_bits[i])
|
||||
if (!bsize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else if (!asize)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else if (asize == bsize)
|
||||
{
|
||||
for (size_type ii = a.num_blocks(); ii > 0; --ii)
|
||||
{
|
||||
size_type i = ii-1;
|
||||
if (a.m_bits[i] < b.m_bits[i])
|
||||
return true;
|
||||
else if (a.m_bits[i] > b.m_bits[i])
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
size_type leqsize(std::min BOOST_PREVENT_MACRO_SUBSTITUTION(asize,bsize));
|
||||
|
||||
for (size_type ii = 0; ii < leqsize; ++ii,--asize,--bsize)
|
||||
{
|
||||
size_type i = asize-1;
|
||||
size_type j = bsize-1;
|
||||
if (a[i] < b[j])
|
||||
return true;
|
||||
else if (a[i] > b[j])
|
||||
return false;
|
||||
}
|
||||
return (a.size() < b.size());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
bool oplessthan(const dynamic_bitset<Block, Allocator>& a,
|
||||
const dynamic_bitset<Block, Allocator>& b)
|
||||
{
|
||||
// assert(a.size() == b.size());
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME dynamic_bitset<Block, Allocator>::size_type size_type;
|
||||
|
||||
size_type asize(a.num_blocks());
|
||||
size_type bsize(b.num_blocks());
|
||||
assert(asize == 3);
|
||||
assert(bsize == 4);
|
||||
|
||||
if (!bsize)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else if (!asize)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
|
||||
size_type leqsize(std::min BOOST_PREVENT_MACRO_SUBSTITUTION(asize,bsize));
|
||||
assert(leqsize == 3);
|
||||
|
||||
//if (a.size() == 0)
|
||||
// return false;
|
||||
|
||||
// Since we are storing the most significant bit
|
||||
// at pos == size() - 1, we need to do the comparisons in reverse.
|
||||
//
|
||||
for (size_type ii = 0; ii < leqsize; ++ii,--asize,--bsize)
|
||||
{
|
||||
size_type i = asize-1;
|
||||
size_type j = bsize-1;
|
||||
if (a.m_bits[i] < b.m_bits[j])
|
||||
return true;
|
||||
else if (a.m_bits[i] > b.m_bits[j])
|
||||
return false;
|
||||
}
|
||||
return (a.num_blocks() < b.num_blocks());
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
@@ -1836,8 +1940,7 @@ inline void dynamic_bitset<Block, Allocator>::m_zero_unused_bits()
|
||||
const block_width_type extra_bits = count_extra_bits();
|
||||
|
||||
if (extra_bits != 0)
|
||||
m_highest_block() &= ~(~static_cast<Block>(0) << extra_bits);
|
||||
|
||||
m_highest_block() &= (Block(1) << extra_bits) - 1;
|
||||
}
|
||||
|
||||
// check class invariants
|
||||
@@ -1846,7 +1949,7 @@ bool dynamic_bitset<Block, Allocator>::m_check_invariants() const
|
||||
{
|
||||
const block_width_type extra_bits = count_extra_bits();
|
||||
if (extra_bits > 0) {
|
||||
block_type const mask = (~static_cast<Block>(0) << extra_bits);
|
||||
const block_type mask = block_type(~0) << extra_bits;
|
||||
if ((m_highest_block() & mask) != 0)
|
||||
return false;
|
||||
}
|
||||
|
||||
46
include/boost/dynamic_bitset/serialization.hpp
Normal file
46
include/boost/dynamic_bitset/serialization.hpp
Normal file
@@ -0,0 +1,46 @@
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// Copyright (c) 2015 Seth Heeren
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
|
||||
#define BOOST_DYNAMIC_BITSET_SERIALIZATION_HPP
|
||||
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include <boost/serialization/vector.hpp>
|
||||
|
||||
namespace boost {
|
||||
|
||||
// implementation for optional zero-copy serialization support
|
||||
template <typename Block, typename Allocator>
|
||||
class dynamic_bitset<Block, Allocator>::serialize_impl
|
||||
{
|
||||
public:
|
||||
template <typename Ar>
|
||||
static void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned) {
|
||||
ar & serialization::make_nvp("m_num_bits", bs.m_num_bits)
|
||||
& serialization::make_nvp("m_bits", bs.m_bits);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
// ADL hook to Boost Serialization library
|
||||
namespace boost {
|
||||
namespace serialization {
|
||||
|
||||
template <typename Ar, typename Block, typename Allocator>
|
||||
void serialize(Ar& ar, dynamic_bitset<Block, Allocator>& bs, unsigned version) {
|
||||
dynamic_bitset<Block, Allocator>::serialize_impl::serialize(ar, bs, version);
|
||||
}
|
||||
|
||||
} // namespace serialization
|
||||
} // namespace boost
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
#define BOOST_LOWEST_BIT_HPP_GP_20030301
|
||||
|
||||
#include <assert.h>
|
||||
#include "boost/pending/integer_log2.hpp"
|
||||
#include "boost/integer/integer_log2.hpp"
|
||||
|
||||
|
||||
namespace boost {
|
||||
|
||||
@@ -11,4 +11,6 @@ test-suite dynamic_bitset :
|
||||
[ run dyn_bitset_unit_tests2.cpp ]
|
||||
[ run dyn_bitset_unit_tests3.cpp ]
|
||||
[ run dyn_bitset_unit_tests4.cpp ]
|
||||
;
|
||||
[ run dyn_bitset_unit_tests5.cpp /boost/serialization//boost_serialization
|
||||
: : : <define>_SCL_SECURE_NO_WARNINGS=1 ]
|
||||
;
|
||||
@@ -2,7 +2,7 @@
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006, 2008 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
// Copyright (c) 2014 Riccardo Marcangelo
|
||||
// Copyright (c) 2014 Riccardo Marcangelo
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -28,7 +28,6 @@
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/test/minimal.hpp"
|
||||
|
||||
|
||||
template <typename Block>
|
||||
inline bool nth_bit(Block num, std::size_t n)
|
||||
{
|
||||
@@ -732,6 +731,67 @@ struct bitset_test {
|
||||
BOOST_CHECK(Bitset(b).set().count() == b.size());
|
||||
}
|
||||
|
||||
static void capacity_test_one(const Bitset& lhs)
|
||||
{
|
||||
//empty bitset
|
||||
Bitset b(lhs);
|
||||
BOOST_CHECK(b.capacity() == 0);
|
||||
}
|
||||
|
||||
static void capacity_test_two(const Bitset& lhs)
|
||||
{
|
||||
//bitset constructed with size "100"
|
||||
Bitset b(lhs);
|
||||
BOOST_CHECK(b.capacity() >= 100);
|
||||
b.resize(200);
|
||||
BOOST_CHECK(b.capacity() >= 200);
|
||||
}
|
||||
|
||||
static void reserve_test_one(const Bitset& lhs)
|
||||
{
|
||||
//empty bitset
|
||||
Bitset b(lhs);
|
||||
b.reserve(16);
|
||||
BOOST_CHECK(b.capacity() >= 16);
|
||||
}
|
||||
|
||||
static void reserve_test_two(const Bitset& lhs)
|
||||
{
|
||||
//bitset constructed with size "100"
|
||||
Bitset b(lhs);
|
||||
BOOST_CHECK(b.capacity() >= 100);
|
||||
b.reserve(60);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
BOOST_CHECK(b.capacity() >= 100);
|
||||
b.reserve(160);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
BOOST_CHECK(b.capacity() >= 160);
|
||||
}
|
||||
|
||||
static void shrink_to_fit_test_one(const Bitset& lhs)
|
||||
{
|
||||
//empty bitset
|
||||
Bitset b(lhs);
|
||||
b.shrink_to_fit();
|
||||
BOOST_CHECK(b.size() == 0);
|
||||
BOOST_CHECK(b.capacity() == 0);
|
||||
}
|
||||
|
||||
static void shrink_to_fit_test_two(const Bitset& lhs)
|
||||
{
|
||||
//bitset constructed with size "100"
|
||||
Bitset b(lhs);
|
||||
b.shrink_to_fit();
|
||||
BOOST_CHECK(b.capacity() >= 100);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
b.reserve(200);
|
||||
BOOST_CHECK(b.capacity() >= 200);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
b.shrink_to_fit();
|
||||
BOOST_CHECK(b.capacity() < 200);
|
||||
BOOST_CHECK(b.size() == 100);
|
||||
}
|
||||
|
||||
static void all(const Bitset& b)
|
||||
{
|
||||
BOOST_CHECK(b.all() == (b.count() == b.size()));
|
||||
@@ -897,23 +957,41 @@ struct bitset_test {
|
||||
|
||||
static bool less_than(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
// Compare from most significant to least.
|
||||
// Careful, don't send unsigned int into negative territory!
|
||||
if (a.size() == 0)
|
||||
return false;
|
||||
|
||||
std::size_t I;
|
||||
for (I = a.size() - 1; I > 0; --I)
|
||||
if (a[I] < b[I])
|
||||
return true;
|
||||
else if (a[I] > b[I])
|
||||
|
||||
typedef BOOST_DEDUCED_TYPENAME Bitset::size_type size_type;
|
||||
|
||||
size_type asize(a.size());
|
||||
size_type bsize(b.size());
|
||||
|
||||
if (!bsize)
|
||||
{
|
||||
return false;
|
||||
// if (a[I] = b[I]) skip to next
|
||||
|
||||
if (a[0] < b[0])
|
||||
return true;
|
||||
}
|
||||
else if (!asize)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
return false;
|
||||
{
|
||||
|
||||
// Compare from most significant to least.
|
||||
|
||||
size_type leqsize(std::min BOOST_PREVENT_MACRO_SUBSTITUTION(asize,bsize));
|
||||
size_type I;
|
||||
for (I = 0; I < leqsize; ++I,--asize,--bsize)
|
||||
{
|
||||
|
||||
size_type i = asize-1;
|
||||
size_type j = bsize-1;
|
||||
|
||||
if (a[i] < b[j])
|
||||
return true;
|
||||
else if (a[i] > b[j])
|
||||
return false;
|
||||
// if (a[i] = b[j]) skip to next
|
||||
}
|
||||
return (a.size() < b.size());
|
||||
}
|
||||
}
|
||||
|
||||
static typename Bitset::size_type next_bit_on(const Bitset& b, typename Bitset::size_type prev)
|
||||
@@ -2,6 +2,7 @@
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006 Gennaro Prota
|
||||
// Copyright (c) 2014 Ahmed Charles
|
||||
// Copyright (c) 2014 Riccardo Marcangelo
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -15,7 +16,6 @@
|
||||
#include "boost/limits.hpp"
|
||||
#include "boost/config.hpp"
|
||||
|
||||
|
||||
template <typename Block>
|
||||
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
{
|
||||
@@ -122,6 +122,36 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
Tests::size(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.capacity()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::capacity_test_one(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(100);
|
||||
Tests::capacity_test_two(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.reserve()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::reserve_test_one(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(100);
|
||||
Tests::reserve_test_two(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.shrink_to_fit()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
Tests::shrink_to_fit_test_one(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(100);
|
||||
Tests::shrink_to_fit_test_two(b);
|
||||
}
|
||||
//=====================================================================
|
||||
// Test b.all()
|
||||
{
|
||||
boost::dynamic_bitset<Block> b;
|
||||
@@ -446,6 +476,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("11"));
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("101")), b(std::string("11"));
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("111"));
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::operator_less_than(a, b);
|
||||
@@ -460,7 +498,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
b[long_string.size()/2].flip();
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
// check for consistency with ulong behaviour
|
||||
// check for consistency with ulong behaviour when the sizes are equal
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(3, 5ul);
|
||||
assert(a < b);
|
||||
@@ -473,6 +511,31 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
boost::dynamic_bitset<Block> a(3, 5ul), b(3, 4ul);
|
||||
assert(!(a < b));
|
||||
}
|
||||
// when the sizes are not equal lexicographic compare does not necessarily correspond to ulong behavior
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(4, 4ul), b(3, 5ul);
|
||||
assert(a < b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(4, 5ul);
|
||||
assert(!(a < b));
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(4, 4ul), b(3, 4ul);
|
||||
assert(a < b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 4ul), b(4, 4ul);
|
||||
assert(!(a < b));
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(4, 5ul), b(3, 4ul);
|
||||
assert(a < b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(3, 5ul), b(4, 4ul);
|
||||
assert(!(a < b));
|
||||
}
|
||||
//=====================================================================
|
||||
// Test operator<=
|
||||
{
|
||||
@@ -735,6 +798,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
int
|
||||
test_main(int, char*[])
|
||||
{
|
||||
@@ -176,11 +176,11 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
|
||||
|
||||
std::ios::iostate masks[] = {
|
||||
std::ios::goodbit,
|
||||
std::ios::eofbit,
|
||||
std::ios::failbit,
|
||||
std::ios::eofbit | std::ios::failbit
|
||||
};
|
||||
std::ios::goodbit,
|
||||
std::ios::eofbit,
|
||||
std::ios::failbit,
|
||||
std::ios::eofbit | std::ios::failbit
|
||||
};
|
||||
|
||||
const std::string spaces = "\t\n "; //"\t\n\v\f ";
|
||||
|
||||
111
test/dyn_bitset_unit_tests5.cpp
Normal file
111
test/dyn_bitset_unit_tests5.cpp
Normal file
@@ -0,0 +1,111 @@
|
||||
// -----------------------------------------------------------
|
||||
// Copyright (c) 2001 Jeremy Siek
|
||||
// Copyright (c) 2003-2006 Gennaro Prota
|
||||
//
|
||||
// Copyright (c) 2015 Seth Heeren
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#if !defined (BOOST_NO_STRINGSTREAM)
|
||||
# include <sstream>
|
||||
#endif
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/dynamic_bitset/serialization.hpp"
|
||||
#include "boost/detail/workaround.hpp"
|
||||
|
||||
|
||||
// Codewarrior 8.3 for Win fails without this.
|
||||
// Thanks Howard Hinnant ;)
|
||||
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
|
||||
# pragma parse_func_templ off
|
||||
#endif
|
||||
|
||||
|
||||
#if defined BOOST_NO_STD_WSTRING || defined BOOST_NO_STD_LOCALE
|
||||
# define BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS
|
||||
#endif
|
||||
|
||||
#include <boost/archive/binary_oarchive.hpp>
|
||||
#include <boost/archive/binary_iarchive.hpp>
|
||||
#include <boost/archive/xml_oarchive.hpp>
|
||||
#include <boost/archive/xml_iarchive.hpp>
|
||||
#include <sstream>
|
||||
|
||||
namespace {
|
||||
template <typename Block>
|
||||
struct SerializableType {
|
||||
boost::dynamic_bitset<Block> x;
|
||||
|
||||
private:
|
||||
friend class boost::serialization::access;
|
||||
template <class Archive> void serialize(Archive &ar, const unsigned int) {
|
||||
ar & BOOST_SERIALIZATION_NVP(x);
|
||||
}
|
||||
};
|
||||
|
||||
template <typename Block, typename IArchive, typename OArchive>
|
||||
void test_serialization( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
{
|
||||
SerializableType<Block> a;
|
||||
|
||||
for (int i=0; i<128; ++i)
|
||||
a.x.resize(11*i, i%2);
|
||||
|
||||
#if !defined (BOOST_NO_STRINGSTREAM)
|
||||
std::stringstream ss;
|
||||
|
||||
// test serialization
|
||||
{
|
||||
OArchive oa(ss);
|
||||
oa << BOOST_SERIALIZATION_NVP(a);
|
||||
}
|
||||
|
||||
// test de-serialization
|
||||
{
|
||||
IArchive ia(ss);
|
||||
SerializableType<Block> b;
|
||||
ia >> BOOST_SERIALIZATION_NVP(b);
|
||||
|
||||
assert(a.x == b.x);
|
||||
}
|
||||
#else
|
||||
# error "TODO implement file-based test path?"
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename Block>
|
||||
void test_binary_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
|
||||
test_serialization<Block, boost::archive::binary_iarchive, boost::archive::binary_oarchive>();
|
||||
}
|
||||
|
||||
template <typename Block>
|
||||
void test_xml_archive( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) ) {
|
||||
test_serialization<Block, boost::archive::xml_iarchive, boost::archive::xml_oarchive>();
|
||||
}
|
||||
}
|
||||
|
||||
template <typename Block>
|
||||
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
{
|
||||
test_binary_archive<Block>();
|
||||
test_xml_archive<Block>();
|
||||
}
|
||||
|
||||
int test_main(int, char*[])
|
||||
{
|
||||
run_test_cases<unsigned char>();
|
||||
run_test_cases<unsigned short>();
|
||||
run_test_cases<unsigned int>();
|
||||
run_test_cases<unsigned long>();
|
||||
# ifdef BOOST_HAS_LONG_LONG
|
||||
run_test_cases< ::boost::ulong_long_type>();
|
||||
# endif
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user