mirror of
https://github.com/boostorg/dynamic_bitset.git
synced 2026-01-23 05:32:09 +00:00
Compare commits
18 Commits
boost-1.32
...
boost-1.35
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
0cc2c1a773 | ||
|
|
61702fef06 | ||
|
|
6bf10f4ef0 | ||
|
|
0999a9b907 | ||
|
|
4ae778ba4a | ||
|
|
c9dcc1de64 | ||
|
|
cc9b262cb9 | ||
|
|
ba7ccc50ae | ||
|
|
3e03a8d947 | ||
|
|
a0d66fd920 | ||
|
|
3e3d36c571 | ||
|
|
3be249a20e | ||
|
|
5f1c39cb6c | ||
|
|
7c48bf04c2 | ||
|
|
5e260f4364 | ||
|
|
896a792bec | ||
|
|
39f11e7cc0 | ||
|
|
b18fc5cd99 |
21
Jamfile
21
Jamfile
@@ -1,21 +0,0 @@
|
||||
subproject libs/dynamic_bitset ;
|
||||
|
||||
unit-test dyn_bitset_unit_tests1
|
||||
: dyn_bitset_unit_tests1.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
unit-test dyn_bitset_unit_tests2
|
||||
: dyn_bitset_unit_tests2.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
unit-test dyn_bitset_unit_tests3
|
||||
: dyn_bitset_unit_tests3.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
unit-test dyn_bitset_unit_tests4
|
||||
: dyn_bitset_unit_tests4.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
@@ -1,3 +1,9 @@
|
||||
#
|
||||
# Copyright Vladimir Prus 2004
|
||||
#
|
||||
# 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)
|
||||
|
||||
test-suite dynamic_bitset :
|
||||
|
||||
|
||||
238
bitset_test.hpp
238
bitset_test.hpp
@@ -1,13 +1,14 @@
|
||||
// --------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2006.
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#ifndef BOOST_BITSET_TEST_HPP_GP_20040319
|
||||
#define BOOST_BITSET_TEST_HPP_GP_20040319
|
||||
@@ -18,13 +19,13 @@
|
||||
#endif
|
||||
|
||||
#include <vector>
|
||||
#include <fstream> // used for operator<< :( - gps
|
||||
#include <fstream> // used for operator<<
|
||||
#include <string> // for (basic_string and) getline()
|
||||
#include <algorithm> // for std::min
|
||||
#include <cassert>
|
||||
#include <assert.h> // <cassert> is sometimes macro-guarded :-(
|
||||
|
||||
#include "boost/limits.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/test/minimal.hpp"
|
||||
|
||||
|
||||
@@ -33,7 +34,9 @@ inline bool nth_bit(Block num, std::size_t n)
|
||||
{
|
||||
#ifdef __BORLANDC__
|
||||
// Borland deduces Block as a const qualified type,
|
||||
// and finds numeric_limits<Block> to be zero :(
|
||||
// and thus finds numeric_limits<Block> to be zero :(
|
||||
// (though not directly relevant here, see also
|
||||
// lib issue 559)
|
||||
int block_width = sizeof(Block) * CHAR_BIT;
|
||||
#else
|
||||
int block_width = std::numeric_limits<Block>::digits;
|
||||
@@ -77,20 +80,20 @@ bool is_white_space(const Stream & /*s*/, char c)
|
||||
}
|
||||
#else
|
||||
template <typename Stream, typename Ch>
|
||||
bool is_one_or_zero(const Stream& s, Ch c) // gps
|
||||
bool is_one_or_zero(const Stream& s, Ch c)
|
||||
{
|
||||
typedef typename Stream::traits_type Tr;
|
||||
const Ch zero = s.widen('0');
|
||||
const Ch one = s.widen('1');
|
||||
|
||||
return Tr::eq(c, one) || Tr::eq(c, zero) ;
|
||||
return Tr::eq(c, one) || Tr::eq(c, zero);
|
||||
}
|
||||
template <typename Stream, typename Ch>
|
||||
bool is_white_space(const Stream & s, Ch c)
|
||||
{
|
||||
// NOTE: the using directive is to satisfy Borland 5.6.4
|
||||
// with its own library (STLport), which chokes
|
||||
// on std::isspace(c, loc) - gps
|
||||
// with its own library (STLport), which doesn't
|
||||
// like std::isspace(c, loc)
|
||||
using namespace std;
|
||||
return isspace(c, s.getloc());
|
||||
}
|
||||
@@ -112,25 +115,29 @@ bool has_flags(const Stream& s, std::ios::iostate flags)
|
||||
template <typename Bitset>
|
||||
struct bitset_test {
|
||||
|
||||
static void from_unsigned_long(std::size_t N, unsigned long num)
|
||||
typedef typename Bitset::block_type Block;
|
||||
BOOST_STATIC_CONSTANT(int, bits_per_block = Bitset::bits_per_block);
|
||||
|
||||
|
||||
static void from_unsigned_long(std::size_t sz, unsigned long num)
|
||||
{
|
||||
// initializes the first M bit position to the cooresponding bit
|
||||
// values in val. M is the smaller of N and the width of unsigned
|
||||
// long
|
||||
// An object of size N = sz is constructed:
|
||||
// - the first M bit positions are initialized to the corresponding bit
|
||||
// values in num (M being the smaller of N and the width of unsigned
|
||||
// long)
|
||||
//
|
||||
// - if M < N remaining bit positions are initialized to zero
|
||||
|
||||
// missing from the std?
|
||||
// if M < N then the remaining bit positions are initialized to zero
|
||||
|
||||
Bitset b(N, num);
|
||||
BOOST_CHECK(b.size() == N);
|
||||
Bitset b(sz, num);
|
||||
BOOST_CHECK(b.size() == sz);
|
||||
|
||||
const std::size_t ulong_width = std::numeric_limits<unsigned long>::digits;
|
||||
std::size_t M = (std::min)(N, ulong_width);
|
||||
std::size_t I;
|
||||
for (I = 0; I < M; ++I)
|
||||
BOOST_CHECK(b[I] == nth_bit(num, I));
|
||||
for (; I < N; ++I)
|
||||
BOOST_CHECK(b[I] == 0);
|
||||
std::size_t m = (std::min)(sz, ulong_width);
|
||||
std::size_t i;
|
||||
for (i = 0; i < m; ++i)
|
||||
BOOST_CHECK(b.test(i) == nth_bit(num, i));
|
||||
for ( ; i < sz; ++i)
|
||||
BOOST_CHECK(b.test(i) == 0);
|
||||
}
|
||||
|
||||
// from string
|
||||
@@ -150,7 +157,7 @@ struct bitset_test {
|
||||
std::size_t num_bits = (std::size_t)(-1))
|
||||
{
|
||||
|
||||
std::size_t rlen = (std::min)(max_char, str.size() - pos); // [gps]
|
||||
std::size_t rlen = (std::min)(max_char, str.size() - pos);
|
||||
|
||||
// The resulting size N of the bitset is num_bits, if
|
||||
// that is different from the default arg, rlen otherwise.
|
||||
@@ -169,7 +176,7 @@ struct bitset_test {
|
||||
std::size_t m = (std::min)(num_bits, rlen);
|
||||
std::size_t j;
|
||||
for (j = 0; j < m; ++j)
|
||||
BOOST_CHECK(b[j] == (str[pos + m - 1 - j] == '1')); // [gps]
|
||||
BOOST_CHECK(b[j] == (str[pos + m - 1 - j] == '1'));
|
||||
// If M < N, remaining bit positions are zero
|
||||
for (; j < actual_size; ++j)
|
||||
BOOST_CHECK(b[j] == 0);
|
||||
@@ -177,9 +184,6 @@ struct bitset_test {
|
||||
|
||||
}
|
||||
|
||||
typedef typename Bitset::block_type Block;
|
||||
BOOST_STATIC_CONSTANT(int, bits_per_block = Bitset::bits_per_block);
|
||||
|
||||
static void to_block_range(const Bitset & b /*, BlockOutputIterator result*/)
|
||||
{
|
||||
typedef typename Bitset::size_type size_type;
|
||||
@@ -208,7 +212,7 @@ struct bitset_test {
|
||||
}
|
||||
}
|
||||
|
||||
// gps - TODO from_block_range (below) should be splitted
|
||||
// TODO from_block_range (below) should be splitted
|
||||
|
||||
// PRE: std::equal(first1, last1, first2) == true
|
||||
static void from_block_range(const std::vector<Block>& blocks)
|
||||
@@ -236,7 +240,7 @@ struct bitset_test {
|
||||
BOOST_CHECK(bset[bit] == nth_bit(blocks[b], i));
|
||||
}
|
||||
}
|
||||
BOOST_CHECK(n <= bset.num_blocks()); // gps - ok? ask on the list
|
||||
BOOST_CHECK(n <= bset.num_blocks());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,15 +276,17 @@ struct bitset_test {
|
||||
static void swap(const Bitset& lhs, const Bitset& rhs)
|
||||
{
|
||||
// bitsets must be swapped
|
||||
Bitset b1(lhs);
|
||||
Bitset b2(rhs);
|
||||
b1.swap(b2);
|
||||
Bitset copy1(lhs);
|
||||
Bitset copy2(rhs);
|
||||
copy1.swap(copy2);
|
||||
|
||||
BOOST_CHECK(b1 == rhs);
|
||||
BOOST_CHECK(b2 == lhs);
|
||||
BOOST_CHECK(copy1 == rhs);
|
||||
BOOST_CHECK(copy2 == lhs);
|
||||
|
||||
// references must be stable under a swap
|
||||
for(typename Bitset::size_type i = 0; i < b1.size(); ++i) {
|
||||
for(typename Bitset::size_type i = 0; i < lhs.size(); ++i) {
|
||||
Bitset b1(lhs);
|
||||
Bitset b2(rhs);
|
||||
typename Bitset::reference ref = b1[i];
|
||||
bool x = ref;
|
||||
if (i < b2.size())
|
||||
@@ -288,7 +294,8 @@ struct bitset_test {
|
||||
b1.swap(b2);
|
||||
BOOST_CHECK(b2[i] == x); // now it must be equal..
|
||||
b2.flip(i);
|
||||
BOOST_CHECK(ref == !x); // .. and ref must be into b2
|
||||
BOOST_CHECK(ref == b2[i]); // .. and ref must be into b2
|
||||
BOOST_CHECK(ref == !x);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -343,7 +350,7 @@ struct bitset_test {
|
||||
static void append_block(const Bitset& lhs)
|
||||
{
|
||||
Bitset b(lhs);
|
||||
Block value(128); // gps
|
||||
Block value(128);
|
||||
b.append(value);
|
||||
BOOST_CHECK(b.size() == lhs.size() + bits_per_block);
|
||||
for (typename Bitset::block_width_type i = 0; i < bits_per_block; ++i)
|
||||
@@ -615,29 +622,35 @@ struct bitset_test {
|
||||
// to_ulong()
|
||||
static void to_ulong(const Bitset& lhs)
|
||||
{
|
||||
std::size_t N = lhs.size();
|
||||
std::size_t n = std::numeric_limits<unsigned long>::digits;
|
||||
typedef unsigned long result_type;
|
||||
std::size_t n = std::numeric_limits<result_type>::digits;
|
||||
std::size_t sz = lhs.size();
|
||||
|
||||
bool will_overflow = false;
|
||||
for (std::size_t I = n; I < N; ++I)
|
||||
if (lhs[I] != 0)
|
||||
for (std::size_t i = n; i < sz; ++i) {
|
||||
if (lhs.test(i) != 0) {
|
||||
will_overflow = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (will_overflow) {
|
||||
try {
|
||||
(void)lhs.to_ulong();
|
||||
BOOST_CHECK(false); // It should have thrown an exception
|
||||
} catch (std::overflow_error) {
|
||||
} catch (std::overflow_error & ex) {
|
||||
// Good!
|
||||
BOOST_CHECK(!!ex.what());
|
||||
} catch (...) {
|
||||
BOOST_CHECK(false); // threw the wrong exception
|
||||
}
|
||||
} else {
|
||||
unsigned long num = lhs.to_ulong();
|
||||
// Make sure the number is right
|
||||
if (N == 0)
|
||||
result_type num = lhs.to_ulong();
|
||||
// Be sure the number is right
|
||||
if (sz == 0)
|
||||
BOOST_CHECK(num == 0);
|
||||
else {
|
||||
for (std::size_t I = 0; I < N; ++I)
|
||||
BOOST_CHECK(lhs[I] == (I < n ? nth_bit(num, I) : 0)); //G.P.S. bugfix
|
||||
for (std::size_t i = 0; i < sz; ++i)
|
||||
BOOST_CHECK(lhs[i] == (i < n ? nth_bit(num, i) : 0));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -645,29 +658,21 @@ struct bitset_test {
|
||||
// to_string()
|
||||
static void to_string(const Bitset& b)
|
||||
{
|
||||
// Construct a string object of the appropriate type and initializes
|
||||
// it to a string of length N characters. Each character is determined
|
||||
// by the value of its corresponding bit position in b. Character
|
||||
// position N - 1 corresponds to bit position zero. Sebsequent
|
||||
// decreasing character positions correspond to increasing bit
|
||||
// positions. Bit value zero becomes the charactet 0, bit value one
|
||||
// becomes the character 1.
|
||||
std::string str;
|
||||
boost::to_string(b, str);
|
||||
std::size_t N = b.size();
|
||||
BOOST_CHECK(str.size() == b.size());
|
||||
for (std::size_t I = 0; I < b.size(); ++I)
|
||||
BOOST_CHECK(b[I] == 0 ? (str[N - 1 - I] == '0') : (str[N - 1 - I] == '1'));
|
||||
for (std::size_t i = 0; i < b.size(); ++i)
|
||||
BOOST_CHECK(str[b.size() - 1 - i] ==(b.test(i)? '1':'0'));
|
||||
}
|
||||
|
||||
static void count(const Bitset& b)
|
||||
{
|
||||
std::size_t c = b.count();
|
||||
std::size_t c_real = 0;
|
||||
for (std::size_t I = 0; I < b.size(); ++I)
|
||||
if (b[I])
|
||||
++c_real;
|
||||
BOOST_CHECK(c == c_real);
|
||||
std::size_t actual = 0;
|
||||
for (std::size_t i = 0; i < b.size(); ++i)
|
||||
if (b[i])
|
||||
++actual;
|
||||
BOOST_CHECK(c == actual);
|
||||
}
|
||||
|
||||
static void size(const Bitset& b)
|
||||
@@ -677,47 +682,82 @@ struct bitset_test {
|
||||
|
||||
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]) {
|
||||
result = true;
|
||||
break;
|
||||
}
|
||||
BOOST_CHECK(b.any() == result);
|
||||
}
|
||||
|
||||
static void none(const Bitset& b)
|
||||
{
|
||||
bool result = true;
|
||||
for(std::size_t i = 0; i < b.size(); ++i) {
|
||||
if(b[i]) {
|
||||
result = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
BOOST_CHECK(b.none() == result);
|
||||
|
||||
// sanity
|
||||
BOOST_CHECK(b.none() == !b.any());
|
||||
BOOST_CHECK(b.none() == (b.count() == 0));
|
||||
}
|
||||
|
||||
static void subset(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a.is_subset_of(b)) {
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I])
|
||||
BOOST_CHECK(b[I]);
|
||||
} else {
|
||||
bool is_subset = true;
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I] && !b[I]) {
|
||||
BOOST_CHECK(a.size() == b.size()); // PRE
|
||||
|
||||
bool is_subset = true;
|
||||
if (b.size()) { // could use b.any() but let's be safe
|
||||
for(std::size_t i = 0; i < a.size(); ++i) {
|
||||
if(a.test(i) && !b.test(i)) {
|
||||
is_subset = false;
|
||||
break;
|
||||
}
|
||||
BOOST_CHECK(is_subset == false);
|
||||
}
|
||||
}
|
||||
else {
|
||||
// sanity
|
||||
BOOST_CHECK(a.count() == 0);
|
||||
BOOST_CHECK(a.any() == false);
|
||||
|
||||
//is_subset = (a.any() == false);
|
||||
}
|
||||
|
||||
BOOST_CHECK(a.is_subset_of(b) == is_subset);
|
||||
}
|
||||
|
||||
static void proper_subset(const Bitset& a, const Bitset& b)
|
||||
{
|
||||
if (a.is_proper_subset_of(b)) {
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I])
|
||||
BOOST_CHECK(b[I]);
|
||||
BOOST_CHECK(a.count() < b.count());
|
||||
} else {
|
||||
bool is_subset = true;
|
||||
for (std::size_t I = 0; I < a.size(); ++I)
|
||||
if (a[I] && !b[I]) {
|
||||
is_subset = false;
|
||||
break;
|
||||
// PRE: a.size() == b.size()
|
||||
BOOST_CHECK(a.size() == b.size());
|
||||
|
||||
bool is_proper = false;
|
||||
|
||||
if (b.size() != 0) {
|
||||
|
||||
// check it's a subset
|
||||
subset(a, b);
|
||||
|
||||
// is it proper?
|
||||
for (std::size_t i = 0; i < a.size(); ++i) {
|
||||
if (!a.test(i) && b.test(i)) {
|
||||
is_proper = true;
|
||||
// sanity
|
||||
BOOST_CHECK(a.count() < b.count());
|
||||
BOOST_CHECK(b.any());
|
||||
}
|
||||
BOOST_CHECK(is_subset == false || a.count() >= b.count());
|
||||
}
|
||||
}
|
||||
|
||||
BOOST_CHECK(a.is_proper_subset_of(b) == is_proper);
|
||||
if (is_proper)
|
||||
BOOST_CHECK(b.is_proper_subset_of(a) != is_proper);// antisymmetry
|
||||
}
|
||||
|
||||
static void intersects(const Bitset& a, const Bitset& b)
|
||||
@@ -730,7 +770,7 @@ struct bitset_test {
|
||||
have_intersection = true;
|
||||
|
||||
BOOST_CHECK(a.intersects(b) == have_intersection);
|
||||
// also check it is commutative
|
||||
// also check commutativity
|
||||
BOOST_CHECK(b.intersects(a) == have_intersection);
|
||||
}
|
||||
|
||||
@@ -981,14 +1021,14 @@ struct bitset_test {
|
||||
}
|
||||
#endif
|
||||
|
||||
BOOST_CHECK(did_throw || !stream_was_good || (s.width() == 0)); // gps
|
||||
BOOST_CHECK(did_throw || !stream_was_good || (s.width() == 0));
|
||||
|
||||
if (!stream_was_good) { // gps
|
||||
if (!stream_was_good) {
|
||||
BOOST_CHECK(s.good() == false);
|
||||
|
||||
// this should actually be oldstate == s.rdstate()
|
||||
// but some implementations add badbit in the
|
||||
// sentry constructor - gps
|
||||
// sentry constructor
|
||||
//
|
||||
BOOST_CHECK((oldstate & s.rdstate()) == oldstate);
|
||||
BOOST_CHECK(s.width() == w);
|
||||
@@ -1000,7 +1040,7 @@ struct bitset_test {
|
||||
// Of course dynamic_bitset's operator << doesn't require that.
|
||||
|
||||
size_type total_len = w <= 0 || (size_type)(w) < b.size()? b.size() : w;
|
||||
const string_type padding (total_len - b.size(), fill_char); // gps
|
||||
const string_type padding (total_len - b.size(), fill_char);
|
||||
string_type expected;
|
||||
boost::to_string(b, expected);
|
||||
if ((s.flags() & std::ios::adjustfield) != std::ios::left)
|
||||
@@ -1014,7 +1054,7 @@ struct bitset_test {
|
||||
s.close();
|
||||
corresponding_input_stream_type is(file_name);
|
||||
string_type contents;
|
||||
std::getline(is, contents, char_type()); // gps
|
||||
std::getline(is, contents, char_type());
|
||||
BOOST_CHECK(contents == expected);
|
||||
}
|
||||
}
|
||||
@@ -1045,7 +1085,7 @@ struct bitset_test {
|
||||
}
|
||||
catch(const std::ios::failure &) {
|
||||
did_throw = true;
|
||||
}// catch bad alloc?? - gps
|
||||
}
|
||||
|
||||
// postconditions
|
||||
BOOST_CHECK(except == is.exceptions()); // paranoid
|
||||
@@ -1101,7 +1141,7 @@ struct bitset_test {
|
||||
|
||||
// eofbit
|
||||
if((after_digits == len && max_digits > num_digits ))
|
||||
BOOST_CHECK(has_flags(is, std::ios::eofbit)); // gps
|
||||
BOOST_CHECK(has_flags(is, std::ios::eofbit));
|
||||
else
|
||||
BOOST_CHECK(!has_flags(is, std::ios::eofbit));
|
||||
|
||||
@@ -1144,16 +1184,16 @@ struct bitset_test {
|
||||
// bitset though there's nothing in the file to be extracted.
|
||||
// Note that the dynamic_bitset docs say a sentry object is
|
||||
// constructed and then converted to bool, thus we rely on
|
||||
// what the underlying library does. - gps
|
||||
// what the underlying library does.
|
||||
//
|
||||
#if !defined(BOOST_DINKUMWARE_STDLIB) || (BOOST_DINKUMWARE_STDLIB >= 306) // what about STLPORT? - gps
|
||||
#if !defined(BOOST_DINKUMWARE_STDLIB) || (BOOST_DINKUMWARE_STDLIB >= 306)
|
||||
BOOST_CHECK(b == a_copy);
|
||||
#else
|
||||
BOOST_CHECK(b.empty() == true);
|
||||
#endif
|
||||
}
|
||||
else {
|
||||
String sub = str.substr(after_spaces, num_digits); // gps
|
||||
String sub = str.substr(after_spaces, num_digits);
|
||||
BOOST_CHECK(b == Bitset(sub));
|
||||
}
|
||||
|
||||
@@ -1166,7 +1206,7 @@ struct bitset_test {
|
||||
// clear the stream to allow further reading then
|
||||
// retrieve any remaining chars with a single getline()
|
||||
is.exceptions(std::ios::goodbit);
|
||||
is.clear(); // gps
|
||||
is.clear();
|
||||
String remainder;
|
||||
std::getline(is, remainder, Ch());
|
||||
if(stream_was_good)
|
||||
|
||||
@@ -1,24 +1,29 @@
|
||||
// --------------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2006.
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/limits.hpp"
|
||||
#include "boost/config.hpp"
|
||||
|
||||
#include "boost/detail/workaround.hpp"
|
||||
|
||||
#define BOOST_BITSET_TEST_COUNT_OF(x) (sizeof(x)/sizeof(x[0]))
|
||||
|
||||
|
||||
// Codewarrior 8.3 for Win fails without this.
|
||||
// Thanks Howard Hinnant ;)
|
||||
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
|
||||
#pragma parse_func_templ off
|
||||
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
|
||||
# pragma parse_func_templ off
|
||||
#endif
|
||||
|
||||
|
||||
@@ -55,45 +60,32 @@ template <typename Block>
|
||||
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
{
|
||||
typedef boost::dynamic_bitset<Block> bitset_type;
|
||||
typedef bitset_test< bitset_type > Tests;
|
||||
typedef bitset_test<bitset_type> Tests;
|
||||
const int bits_per_block = bitset_type::bits_per_block;
|
||||
|
||||
const std::string long_string = get_long_string();
|
||||
const Block all_1s = static_cast<Block>(-1);
|
||||
|
||||
//=====================================================================
|
||||
// Test construction from unsigned long
|
||||
{
|
||||
const std::size_t ulong_width = std::numeric_limits<unsigned long>::digits;
|
||||
const unsigned long ulong_max =(std::numeric_limits<unsigned long>::max)();
|
||||
typedef unsigned long source_type;
|
||||
const std::size_t source_width = std::numeric_limits<source_type>::digits;
|
||||
const source_type source_max =(std::numeric_limits<source_type>::max)();
|
||||
|
||||
unsigned long numbers[] = { 0, 1, 40247, ulong_max >> 1, ulong_max };
|
||||
const std::size_t array_count = sizeof(numbers) / sizeof(numbers[0]);
|
||||
source_type numbers[] = { 0, 1, 40247, source_max >> 1, source_max };
|
||||
std::size_t sizes[] =
|
||||
{ 0, 7 * source_width / 10, source_width, 13 * source_width / 10,
|
||||
7 * bits_per_block / 10, bits_per_block, 13 * bits_per_block / 10,
|
||||
3 * bits_per_block };
|
||||
|
||||
for (std::size_t i = 0; i < array_count; ++i) {
|
||||
unsigned long number = numbers[i];
|
||||
std::size_t n = 0;
|
||||
Tests::from_unsigned_long(n, number);
|
||||
const std::size_t value_count = BOOST_BITSET_TEST_COUNT_OF(numbers);
|
||||
const std::size_t size_count = BOOST_BITSET_TEST_COUNT_OF(sizes);
|
||||
|
||||
n = std::size_t(0.7 * double(ulong_width));
|
||||
Tests::from_unsigned_long(n, number);
|
||||
|
||||
n = 1 * ulong_width;
|
||||
Tests::from_unsigned_long(n, number);
|
||||
|
||||
n = std::size_t(1.3 * double(ulong_width));
|
||||
Tests::from_unsigned_long(n, number);
|
||||
|
||||
n = std::size_t(0.7 * double(bits_per_block));
|
||||
Tests::from_unsigned_long(n, number);
|
||||
|
||||
n = 1 * bits_per_block;
|
||||
Tests::from_unsigned_long(n, number);
|
||||
|
||||
n = std::size_t(1.3 * double(bits_per_block));
|
||||
Tests::from_unsigned_long(n, number);
|
||||
|
||||
n = 3 * bits_per_block;
|
||||
Tests::from_unsigned_long(n, number);
|
||||
for (std::size_t v = 0; v < value_count; ++v) {
|
||||
for (std::size_t s = 0; s < size_count; ++s) {
|
||||
Tests::from_unsigned_long(sizes[s], numbers[v]);
|
||||
}
|
||||
}
|
||||
}
|
||||
//=====================================================================
|
||||
@@ -110,7 +102,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
// one hand I should have better tests. On the other one
|
||||
// I don't want tests for dynamic_bitset to cope with locales,
|
||||
// ctype::widen, etc. (but that's what you deserve when you
|
||||
// don't separate concerns at the library level) - gps
|
||||
// don't separate concerns at the library level)
|
||||
//
|
||||
run_string_tests<Tests>(
|
||||
std::wstring(L"11111000000111111111010101010101010101010111111"));
|
||||
@@ -123,8 +115,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
|
||||
}
|
||||
//=====================================================================
|
||||
// Test construction from a block range
|
||||
// [gps - this comment is erroneous]
|
||||
// test from_block_range
|
||||
{
|
||||
std::vector<Block> blocks;
|
||||
Tests::from_block_range(blocks);
|
||||
@@ -133,7 +124,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
std::vector<Block> blocks(3);
|
||||
blocks[0] = static_cast<Block>(0);
|
||||
blocks[1] = static_cast<Block>(1);
|
||||
blocks[2] = ~Block(0);
|
||||
blocks[2] = all_1s;
|
||||
Tests::from_block_range(blocks);
|
||||
}
|
||||
{
|
||||
@@ -305,7 +296,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
std::vector<Block> blocks(3);
|
||||
blocks[0] = static_cast<Block>(0);
|
||||
blocks[1] = static_cast<Block>(1);
|
||||
blocks[2] = ~Block(0);
|
||||
blocks[2] = all_1s;
|
||||
Tests::append_block_range(a, blocks);
|
||||
}
|
||||
{
|
||||
@@ -330,7 +321,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
std::vector<Block> blocks(3);
|
||||
blocks[0] = static_cast<Block>(0);
|
||||
blocks[1] = static_cast<Block>(1);
|
||||
blocks[2] = ~Block(0);
|
||||
blocks[2] = all_1s;
|
||||
Tests::append_block_range(a, blocks);
|
||||
}
|
||||
//=====================================================================
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
// --------------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2006.
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/config.hpp"
|
||||
|
||||
|
||||
|
||||
@@ -1,16 +1,18 @@
|
||||
// --------------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2006.
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// $Id$
|
||||
|
||||
|
||||
#include <assert.h>
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/limits.hpp"
|
||||
#include "boost/config.hpp"
|
||||
|
||||
@@ -18,7 +20,7 @@
|
||||
template <typename Block>
|
||||
void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
{
|
||||
// a bunch of typedefs to have handy later on
|
||||
// a bunch of typedefs which will be handy later on
|
||||
typedef boost::dynamic_bitset<Block> bitset_type;
|
||||
typedef bitset_test<bitset_type> Tests;
|
||||
// typedef typename bitset_type::size_type size_type; // unusable with Borland 5.5.1
|
||||
@@ -30,7 +32,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
// Test b.empty()
|
||||
{
|
||||
bitset_type b;
|
||||
Tests::empty(b); // gps
|
||||
Tests::empty(b);
|
||||
}
|
||||
{
|
||||
bitset_type b(1, 1ul);
|
||||
@@ -52,9 +54,13 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
Tests::to_ulong(b);
|
||||
}
|
||||
{
|
||||
Block all_ones = ~Block(0);
|
||||
boost::dynamic_bitset<Block> b(bitset_type::bits_per_block,
|
||||
static_cast<unsigned long>(all_ones));
|
||||
static_cast<unsigned long>(-1));
|
||||
Tests::to_ulong(b);
|
||||
}
|
||||
{
|
||||
std::string str(ul_width - 1, '1');
|
||||
boost::dynamic_bitset<Block> b(str);
|
||||
Tests::to_ulong(b);
|
||||
}
|
||||
{
|
||||
@@ -90,6 +96,14 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
boost::dynamic_bitset<Block> b(std::string("0"));
|
||||
Tests::count(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(std::string("1"));
|
||||
Tests::count(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(8, 255ul);
|
||||
Tests::count(b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> b(long_string);
|
||||
Tests::count(b);
|
||||
@@ -388,6 +402,10 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
boost::dynamic_bitset<Block> a(std::string("1")), b(std::string("1"));
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(std::string("10")), b(std::string("11"));
|
||||
Tests::operator_less_than(a, b);
|
||||
}
|
||||
{
|
||||
boost::dynamic_bitset<Block> a(long_string), b(long_string);
|
||||
Tests::operator_less_than(a, b);
|
||||
|
||||
@@ -1,18 +1,20 @@
|
||||
// --------------------------------------------------------
|
||||
// (C) Copyright Jeremy Siek 2001.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2006.
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#include <fstream>
|
||||
#include <string>
|
||||
#include <cstddef> // for std::size_t
|
||||
#include <cstddef> // for std::size_t
|
||||
#include <stdexcept> // for std::logic_error
|
||||
#include <cassert>
|
||||
#include <assert.h>
|
||||
|
||||
#include "boost/config.hpp"
|
||||
#if !defined (BOOST_NO_STRINGSTREAM)
|
||||
@@ -20,14 +22,14 @@
|
||||
#endif
|
||||
|
||||
#include "bitset_test.hpp"
|
||||
#include "boost/dynamic_bitset.hpp"
|
||||
#include "boost/dynamic_bitset/dynamic_bitset.hpp"
|
||||
#include "boost/detail/workaround.hpp"
|
||||
|
||||
|
||||
// Codewarrior 8.3 for Win fails without this.
|
||||
// Thanks Howard Hinnant ;)
|
||||
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
|
||||
#pragma parse_func_templ off
|
||||
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
|
||||
# pragma parse_func_templ off
|
||||
#endif
|
||||
|
||||
|
||||
@@ -42,9 +44,15 @@ std::wstring widen_string( const std::string & str,
|
||||
std::wstring result;
|
||||
const std::string::size_type len = str.length();
|
||||
if(len != 0) {
|
||||
|
||||
typedef std::ctype<wchar_t> ct_type;
|
||||
typedef std::wstring::traits_type tr_type;
|
||||
const ct_type & ct = BOOST_USE_FACET(ct_type, loc);
|
||||
|
||||
result.resize(len);
|
||||
BOOST_USE_FACET(std::ctype<wchar_t>, loc)
|
||||
.widen(&str[0], 1 + &str[len-1], &result[0]);
|
||||
for (std::size_t i = 0; i < len; ++i)
|
||||
tr_type::assign(result[i], ct.widen(str[i]));
|
||||
|
||||
}
|
||||
return result;
|
||||
}
|
||||
@@ -71,7 +79,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
std::ios::eofbit | std::ios::failbit
|
||||
};
|
||||
|
||||
std::string strings[] = {
|
||||
static std::string strings[] = {
|
||||
std::string(""),
|
||||
std::string("0"),
|
||||
std::string("1"),
|
||||
@@ -128,7 +136,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
|
||||
}
|
||||
{
|
||||
//NOTE: there are NO string stream tests - gps
|
||||
//NOTE: there are NO string stream tests
|
||||
}
|
||||
#if !defined (BOOST_DYNAMIC_BITSET_NO_WCHAR_T_TESTS)
|
||||
{
|
||||
@@ -163,7 +171,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
// a good "real life" test. Some characters, such as '\v' and '\f', are not
|
||||
// used exactly because they are the ones which will most likely give problems
|
||||
// on some systems (for instance '\f' could actually be written as a sequence
|
||||
// of new-lines, and we could never be able to read it back) [gps]
|
||||
// of new-lines, and we could never be able to read it back)
|
||||
//
|
||||
// Note how the bitset object is not initially empty. That helps checking
|
||||
// that it isn't erroneously clear()ed by operator>>.
|
||||
@@ -179,7 +187,7 @@ void run_test_cases( BOOST_EXPLICIT_TEMPLATE_TYPE(Block) )
|
||||
const std::string spaces = "\t\n "; //"\t\n\v\f ";
|
||||
|
||||
const std::string long_string = get_long_string();
|
||||
/*const*/ std::string strings[] = {
|
||||
/*const*/ static std::string strings[] = {
|
||||
// NOTE: "const" gives the usual problems with Borland
|
||||
// (in Tests::stream_extractor instantiation)
|
||||
|
||||
|
||||
@@ -46,20 +46,6 @@ align="middle" width="277" height="86">
|
||||
<br>
|
||||
</p>
|
||||
|
||||
<!-- BEGIN TODO -->
|
||||
TODO:
|
||||
<ul>
|
||||
<li> ask to Jeremy about reference::operator& and about
|
||||
making reference itself private</li>
|
||||
<li>check the whole synopsis against code changes </li>
|
||||
<li>document intersects() after we reach consensus</li>
|
||||
</ul>
|
||||
<br>
|
||||
Note:
|
||||
Other things to do are marked by "[gps]"
|
||||
<!-- END TODO -->
|
||||
|
||||
|
||||
<h1>dynamic_bitset<Block, Allocator></h1>
|
||||
|
||||
<h2>Contents</h2>
|
||||
@@ -145,7 +131,7 @@ public:
|
||||
typedef Block <a href="#block_type">block_type</a>;
|
||||
typedef Allocator <a href="#allocator_type">allocator_type</a>;
|
||||
typedef <i>implementation-defined</i> <a href="#size_type">size_type</a>;
|
||||
|
||||
|
||||
static const int <a href=
|
||||
"#bits_per_block">bits_per_block</a> = <i>implementation-defined</i>;
|
||||
static const size_type <a href=
|
||||
@@ -503,7 +489,7 @@ were chosen for this reason.</p>
|
||||
<p><tt>dynamic_bitset</tt> does not throw exceptions when a
|
||||
precondition is violated (as is done in <tt>std::bitset</tt>).
|
||||
Instead <tt>assert</tt> is used. See the guidelines for <a href=
|
||||
"../../more/error_handling.html">Error and Exception Handling</a>
|
||||
"http://www.boost.org/more/error_handling.html">Error and Exception Handling</a>
|
||||
for the explanation.</p>
|
||||
|
||||
<h3><a name="header-files">Header Files</a></h3>
|
||||
@@ -719,7 +705,7 @@ to <tt>std::numeric_limits<Block>::digits</tt>.
|
||||
<a name="npos">dynamic_bitset::npos</a>
|
||||
</pre>
|
||||
|
||||
The maximum value of <tt>size_type</tt>. [gps]
|
||||
The maximum value of <tt>size_type</tt>.
|
||||
|
||||
<hr>
|
||||
<h3><a name="constructors">Constructors</a></h3>
|
||||
@@ -954,7 +940,7 @@ void <a name=
|
||||
</pre>
|
||||
|
||||
<b>Effects:</b> This function provides the same end result as the
|
||||
following code, but is typically more efficient. [gps]
|
||||
following code, but is typically more efficient.
|
||||
|
||||
<pre>
|
||||
for (; first != last; ++first)
|
||||
@@ -1194,7 +1180,7 @@ object having the same type as <tt>*this</tt>. Note that if
|
||||
any <tt>dynamic_bitset</tt> operation causes <tt>size()</tt> to
|
||||
exceed <tt>max_size()</tt> then the <i>behavior is undefined</i>.
|
||||
<br><br>[The semantics of this function could change slightly
|
||||
when lib issue 197 will be closed - G.P.S.]<br>
|
||||
when lib issue 197 will be closed]<br>
|
||||
|
||||
<hr>
|
||||
<pre>
|
||||
@@ -1205,32 +1191,6 @@ bool <a name="empty">empty</a>() const;
|
||||
otherwise. <i>Note</i>: not to be confused with <tt>none()</tt>, that has
|
||||
different semantics.
|
||||
|
||||
<hr>
|
||||
<!-- ***************** To be removed - gps *************************
|
||||
<pre>
|
||||
void <a name="reserve">reserve</a>(size_type n);
|
||||
</pre>
|
||||
|
||||
<b>Precondition:</b> <tt>n <= this->max_size()</tt>.<br>
|
||||
<b>Effects:</b> informs the <tt>dynamic_bitset</tt> of a planned
|
||||
change in size(), so that reallocations can be managed accordingly.
|
||||
If before the call the dynamic_bitset's capacity is >= n then no
|
||||
reallocation happens and capacity remains unchanged. Otherwise
|
||||
storage is allocated and capacity becomes greater or equal to n.
|
||||
In any case, size() does not change.<br>
|
||||
<b>Throws:</b> An allocation error if <tt>n > capacity()</tt>
|
||||
and memory is exhausted (<tt>std::bad_alloc</tt> if <tt>
|
||||
Allocator=std::allocator</tt>).
|
||||
|
||||
<hr>
|
||||
<pre>
|
||||
size_type <a name="capacity">capacity()</a> const;
|
||||
</pre>
|
||||
|
||||
<b>Returns:</b> the total number of elements that <tt>*this</tt>
|
||||
can hold without requiring reallocation.<br>
|
||||
*************************************************************** -->
|
||||
|
||||
<hr>
|
||||
<pre>
|
||||
size_type <a name="count">count</a>() const
|
||||
@@ -1576,12 +1536,12 @@ precise specification, given in terms of "as if" rule: first, for each
|
||||
valid position i into the bitset <tt>b</tt> let's put:
|
||||
|
||||
<tt>character_of(b[i)]) = b[i]? os.widen('1') : os.widen('0');</tt>
|
||||
|
||||
|
||||
Let also <tt>s</tt> be a <tt>std::basic_string<Char, Traits></tt>
|
||||
object, having length <tt>b.size()</tt> and such as, for each <tt>i</tt>
|
||||
in <tt>[0, b.size())</tt>,
|
||||
|
||||
<tt>s[i] is character_of(b[i])</tt>
|
||||
<tt>s[i] is character_of(b[i])</tt>
|
||||
|
||||
Then, the output, the effects on <tt>os</tt> and the exception behavior
|
||||
is the same as outputting the object <tt>s</tt> to <tt>os</tt> (same
|
||||
@@ -1622,10 +1582,10 @@ were constructed by
|
||||
If <tt>bool(k)</tt> is true, it calls <tt>b.clear()</tt>
|
||||
then attempts to extract characters from <tt>is</tt>. For each character c
|
||||
that is a <i>bitset digit</i> the <i>corresponding bit value</i> is
|
||||
appended to the less significant end of <tt>b</tt> (appending may throw - gps ).
|
||||
appended to the less significant end of <tt>b</tt> (appending may throw).
|
||||
If <tt>is.width()</tt> is greater than zero and smaller than <tt>b.max_size()</tt>
|
||||
then the maximum number <tt>n</tt> of bits appended is <tt>is.width()</tt>;
|
||||
otherwise <tt>n</tt> = <tt>b.max_size()</tt>.
|
||||
otherwise <tt>n</tt> = <tt>b.max_size()</tt>.
|
||||
|
||||
Unless the extractor is exited via an exception, characters are extracted (and
|
||||
corresponding bits appended) until any of the following occurs:<br>
|
||||
@@ -1692,7 +1652,7 @@ it works correctly when setting exception masks on the stream.<br><br>
|
||||
<li>
|
||||
Several member functions (<tt>empty()</tt>, <tt>find_first()</tt>
|
||||
, <tt>find_next()</tt>, <tt>get_allocator()</tt>, <tt>intersects()</tt>
|
||||
, <tt>max_size()</tt>, <s><tt>reserve()</tt>, <tt>capacity()</tt></s>)
|
||||
, <tt>max_size()</tt> <!--, <tt>reserve()</tt>, <tt>capacity()</tt> -->)
|
||||
have been added.
|
||||
</li>
|
||||
<li>
|
||||
@@ -1714,7 +1674,7 @@ applied to their corresponding <tt>dynamic_bitset</tt>s.
|
||||
<i>General improvements</i>
|
||||
<br><br>
|
||||
Several optimizations to member and non-member functions and to the
|
||||
nested class <tt>reference</tt>.
|
||||
nested class <tt>reference</tt>.
|
||||
|
||||
<hr>
|
||||
<h3><a name="see-also">See also</a></h3>
|
||||
@@ -1742,7 +1702,7 @@ issues.</p>
|
||||
|
||||
<tr valign="top">
|
||||
<td nowrap>Copyright © 2001</td>
|
||||
<td><a href="../../people/jeremy_siek.htm">Jeremy Siek</a>,
|
||||
<td><a href="http://www.boost.org/people/jeremy_siek.htm">Jeremy Siek</a>,
|
||||
Indiana University (<a href=
|
||||
"mailto:jsiek@osl.iu.edu">jsiek@osl.iu.edu</a>)<br>
|
||||
<a href="http://freshsources.com">Chuck Allison</a>, Senior
|
||||
|
||||
@@ -1,20 +1,26 @@
|
||||
exe timing_tests
|
||||
: timing_tests.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
// (C) Copyright Gennaro Prota 2002
|
||||
//
|
||||
// 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)
|
||||
//
|
||||
// ----------------------------------------------------------
|
||||
//
|
||||
// $Id$
|
||||
|
||||
exe timing_tests
|
||||
: timing_tests.cpp
|
||||
;
|
||||
|
||||
exe example1
|
||||
: example1.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
exe example2
|
||||
: example2.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
exe example3
|
||||
: example3.cpp
|
||||
: <include>$(BOOST_ROOT)
|
||||
;
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@
|
||||
//
|
||||
//
|
||||
// -----------------------------------------------------------------------//
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#include "boost/config.hpp"
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// --------------------------------------------------
|
||||
//
|
||||
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2006.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -9,8 +9,9 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset for documentation.
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
|
||||
//
|
||||
// $Revision$ $Date$ - $Name$
|
||||
|
||||
#ifndef BOOST_DETAIL_DYNAMIC_BITSET_HPP
|
||||
#define BOOST_DETAIL_DYNAMIC_BITSET_HPP
|
||||
@@ -18,7 +19,6 @@
|
||||
#include <cstddef> // for std::size_t
|
||||
#include "boost/config.hpp"
|
||||
#include "boost/detail/workaround.hpp"
|
||||
//#include "boost/static_assert.hpp" // gps
|
||||
|
||||
|
||||
namespace boost {
|
||||
@@ -35,6 +35,14 @@ namespace boost {
|
||||
return static_cast<const unsigned char *>(static_cast<const void *>(p));
|
||||
}
|
||||
|
||||
template<typename T, int amount, int width /* = default */>
|
||||
struct shifter
|
||||
{
|
||||
static void left_shift(T & v) {
|
||||
amount >= width ? (v = 0)
|
||||
: (v >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(amount));
|
||||
}
|
||||
};
|
||||
|
||||
// ------- count function implementation --------------
|
||||
|
||||
|
||||
@@ -9,7 +9,9 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset for documentation.
|
||||
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
|
||||
//
|
||||
// $Revision$ $Date$ - $Name$
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_HPP
|
||||
#define BOOST_DYNAMIC_BITSET_HPP
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// --------------------------------------------------
|
||||
//
|
||||
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2006.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -9,8 +9,9 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset for documentation.
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
|
||||
//
|
||||
// $Revision$ $Date$ - $Name$
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_CONFIG_HPP_GP_20040424
|
||||
#define BOOST_DYNAMIC_BITSET_CONFIG_HPP_GP_20040424
|
||||
@@ -28,8 +29,8 @@
|
||||
#define BOOST_DYNAMIC_BITSET_GNUC_VERSION ( __GNUC__ * 100 * 100 \
|
||||
+ __GNUC_MINOR__ * 100)
|
||||
|
||||
// workaround for gcc bug c++/8419 - gps
|
||||
|
||||
// no-op function to workaround gcc bug c++/8419
|
||||
//
|
||||
namespace boost { namespace detail {
|
||||
template <typename T> T make_non_const(T t) { return t; }
|
||||
}}
|
||||
@@ -48,7 +49,7 @@ namespace boost { namespace detail {
|
||||
#define BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS
|
||||
#endif
|
||||
|
||||
// if we can't use friends then private members are exposed
|
||||
// if we can't use friends then we simply expose private members
|
||||
//
|
||||
#if defined(BOOST_DYNAMIC_BITSET_DONT_USE_FRIENDS)
|
||||
#define BOOST_DYNAMIC_BITSET_PRIVATE public
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
// --------------------------------------------------
|
||||
//
|
||||
// (C) Copyright Chuck Allison and Jeremy Siek 2001 - 2002.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2004.
|
||||
// (C) Copyright Gennaro Prota 2003 - 2006.
|
||||
//
|
||||
// Distributed under the Boost Software License, Version 1.0.
|
||||
// (See accompanying file LICENSE_1_0.txt or copy at
|
||||
@@ -9,24 +9,25 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset for documentation.
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
|
||||
//
|
||||
// $Revision$ $Date$ - $Name$
|
||||
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_DYNAMIC_BITSET_HPP
|
||||
#define BOOST_DYNAMIC_BITSET_DYNAMIC_BITSET_HPP
|
||||
|
||||
#include <cassert>
|
||||
#include <assert.h>
|
||||
#include <string>
|
||||
#include <stdexcept> // for std::overflow_error
|
||||
#include <algorithm> // for std::swap, std::min, std::copy, std::fill
|
||||
#include <stdexcept> // for std::overflow_error
|
||||
#include <algorithm> // for std::swap, min, copy, fill
|
||||
#include <vector>
|
||||
#include <climits> // for CHAR_BIT
|
||||
#include <climits> // for CHAR_BIT
|
||||
|
||||
#include "boost/dynamic_bitset/config.hpp"
|
||||
|
||||
#ifndef BOOST_NO_STD_LOCALE
|
||||
# include <locale> // G.P.S
|
||||
# include <locale>
|
||||
#endif
|
||||
|
||||
#if defined(BOOST_OLD_IOSTREAMS)
|
||||
@@ -68,7 +69,7 @@ public:
|
||||
typedef Block block_type;
|
||||
typedef Allocator allocator_type;
|
||||
typedef std::size_t size_type;
|
||||
typedef int block_width_type; // gps
|
||||
typedef int block_width_type;
|
||||
|
||||
BOOST_STATIC_CONSTANT(block_width_type, bits_per_block = (std::numeric_limits<Block>::digits));
|
||||
BOOST_STATIC_CONSTANT(size_type, npos = static_cast<size_type>(-1));
|
||||
@@ -77,7 +78,6 @@ public:
|
||||
public:
|
||||
|
||||
// A proxy class to simulate lvalues of bit type.
|
||||
// Shouldn't it be private? [gps]
|
||||
//
|
||||
class reference
|
||||
{
|
||||
@@ -87,7 +87,7 @@ public:
|
||||
// the one and only non-copy ctor
|
||||
reference(block_type & b, int pos)
|
||||
:m_block(b), m_mask(block_type(1) << pos)
|
||||
{}
|
||||
{ assert(pos >= 0 && pos < bits_per_block); }
|
||||
|
||||
void operator&(); // left undefined
|
||||
|
||||
@@ -129,16 +129,16 @@ public:
|
||||
const Allocator& alloc = Allocator());
|
||||
|
||||
|
||||
// The presence of this constructor is a concession to ease of
|
||||
// use, especially for the novice user. A conversion from string
|
||||
// is, in most cases, formatting, and should be done by the standard
|
||||
// formatting convention: operator>>.
|
||||
// WARNING: you should avoid using this constructor.
|
||||
//
|
||||
// A conversion from string is, in most cases, formatting,
|
||||
// and should be performed by using operator>>.
|
||||
//
|
||||
// NOTE:
|
||||
// Leave the parentheses around std::basic_string<CharT, Traits, Alloc>::npos.
|
||||
// g++ 3.2 requires them and probably the standard will - see core issue 325
|
||||
// NOTE 2:
|
||||
// split into two constructors because of bugs in MSVC 6.0sp5 with STLport
|
||||
// Leave the parentheses around std::basic_string<CharT, Traits, Alloc>::npos.
|
||||
// g++ 3.2 requires them and probably the standard will - see core issue 325
|
||||
// NOTE 2:
|
||||
// split into two constructors because of bugs in MSVC 6.0sp5 with STLport
|
||||
|
||||
template <typename CharT, typename Traits, typename Alloc>
|
||||
dynamic_bitset(const std::basic_string<CharT, Traits, Alloc>& s,
|
||||
@@ -150,7 +150,7 @@ public:
|
||||
:m_bits(alloc),
|
||||
m_num_bits(0)
|
||||
{
|
||||
init_from_string(s, pos, n, num_bits, alloc);
|
||||
init_from_string(s, pos, n, num_bits);
|
||||
}
|
||||
|
||||
template <typename CharT, typename Traits, typename Alloc>
|
||||
@@ -162,7 +162,7 @@ public:
|
||||
m_num_bits(0)
|
||||
{
|
||||
init_from_string(s, pos, (std::basic_string<CharT, Traits, Alloc>::npos),
|
||||
npos, Allocator());
|
||||
npos);
|
||||
}
|
||||
|
||||
// The first bit in *first is the least significant bit, and the
|
||||
@@ -264,10 +264,6 @@ public:
|
||||
size_type num_blocks() const;
|
||||
size_type max_size() const;
|
||||
bool empty() const;
|
||||
#if 0 // gps
|
||||
void reserve(size_type n);
|
||||
size_type capacity() const;
|
||||
#endif
|
||||
|
||||
bool is_subset_of(const dynamic_bitset& a) const;
|
||||
bool is_proper_subset_of(const dynamic_bitset& a) const;
|
||||
@@ -327,15 +323,14 @@ private:
|
||||
void init_from_string(const std::basic_string<CharT, Traits, Alloc>& s,
|
||||
typename std::basic_string<CharT, Traits, Alloc>::size_type pos,
|
||||
typename std::basic_string<CharT, Traits, Alloc>::size_type n,
|
||||
size_type num_bits,
|
||||
const Allocator& alloc)
|
||||
size_type num_bits)
|
||||
{
|
||||
assert(pos <= s.size());
|
||||
|
||||
typedef typename std::basic_string<CharT, Traits, Alloc> StrT;
|
||||
typedef typename StrT::traits_type Tr;
|
||||
|
||||
const typename StrT::size_type rlen = (std::min)(n, s.size() - pos); // gps
|
||||
const typename StrT::size_type rlen = (std::min)(n, s.size() - pos);
|
||||
const size_type sz = ( num_bits != npos? num_bits : rlen);
|
||||
m_bits.resize(calc_num_blocks(sz));
|
||||
m_num_bits = sz;
|
||||
@@ -344,7 +339,7 @@ private:
|
||||
BOOST_DYNAMIC_BITSET_CTYPE_FACET(CharT, fac, std::locale());
|
||||
const CharT one = BOOST_DYNAMIC_BITSET_WIDEN_CHAR(fac, '1');
|
||||
|
||||
const size_type m = num_bits < rlen ? num_bits : rlen; // [gps]
|
||||
const size_type m = num_bits < rlen ? num_bits : rlen;
|
||||
typename StrT::size_type i = 0;
|
||||
for( ; i < m; ++i) {
|
||||
|
||||
@@ -368,7 +363,7 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
|
||||
Block& m_highest_block();
|
||||
const Block& m_highest_block() const;
|
||||
|
||||
buffer_type m_bits; // [gps] to be renamed
|
||||
buffer_type m_bits;
|
||||
size_type m_num_bits;
|
||||
|
||||
|
||||
@@ -378,10 +373,11 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
|
||||
// helper for stream >>
|
||||
// Supplies to the lack of an efficient append at the less
|
||||
// significant end: bits are actually appended "at left" but
|
||||
// rearranged in the destructor. Everything works just as if
|
||||
// dynamic_bitset<> had an append_at_right() function (which
|
||||
// threw, in case, the same exceptions as push_back) except
|
||||
// that the function is actually called bit_appender::do_append().
|
||||
// rearranged in the destructor. From the perspective of
|
||||
// client code everything works *as if* dynamic_bitset<> had
|
||||
// an append_at_right() function (eventually throwing the same
|
||||
// exceptions as push_back) except that the function is in fact
|
||||
// called bit_appender::do_append().
|
||||
//
|
||||
dynamic_bitset & bs;
|
||||
size_type n;
|
||||
@@ -419,6 +415,28 @@ BOOST_DYNAMIC_BITSET_PRIVATE:
|
||||
|
||||
};
|
||||
|
||||
#if defined(__IBMCPP__) && BOOST_WORKAROUND(__IBMCPP__, BOOST_TESTED_AT(600))
|
||||
|
||||
// Workaround for IBM's AIX platform.
|
||||
// See http://comments.gmane.org/gmane.comp.lib.boost.user/15331
|
||||
//
|
||||
// NOTE:
|
||||
// The compiler is actually right, until core issue 454 will be settled:
|
||||
// http://www.open-std.org/JTC1/SC22/WG21/docs/cwg_active.html#454
|
||||
//
|
||||
// It's arguable whether we want to mark this with BOOST_WORKAROUND or not.
|
||||
|
||||
|
||||
template<typename Block, typename Allocator>
|
||||
dynamic_bitset<Block, Allocator>::block_width_type const
|
||||
dynamic_bitset<Block, Allocator>::bits_per_block;
|
||||
|
||||
template<typename Block, typename Allocator>
|
||||
dynamic_bitset<Block, Allocator>::block_width_type const
|
||||
dynamic_bitset<Block, Allocator>::ulong_width;
|
||||
|
||||
#endif
|
||||
|
||||
// Global Functions:
|
||||
|
||||
// comparison
|
||||
@@ -487,7 +505,7 @@ void swap(dynamic_bitset<Block, Allocator>& b1,
|
||||
|
||||
template <typename Block, typename Allocator, typename stringT>
|
||||
void
|
||||
to_string(const dynamic_bitset<Block, Allocator>& b, stringT & s); // gps
|
||||
to_string(const dynamic_bitset<Block, Allocator>& b, stringT & s);
|
||||
|
||||
template <typename Block, typename Allocator, typename BlockOutputIterator>
|
||||
void
|
||||
@@ -495,15 +513,13 @@ to_block_range(const dynamic_bitset<Block, Allocator>& b,
|
||||
BlockOutputIterator result);
|
||||
|
||||
|
||||
// gps - check docs with Jeremy
|
||||
//
|
||||
template <typename BlockIterator, typename B, typename A>
|
||||
inline void
|
||||
from_block_range(BlockIterator first, BlockIterator last,
|
||||
dynamic_bitset<B, A>& result)
|
||||
{
|
||||
// PRE: distance(first, last) <= numblocks()
|
||||
std::copy (first, last, result.m_bits.begin()); //[gps]
|
||||
std::copy (first, last, result.m_bits.begin());
|
||||
}
|
||||
|
||||
//=============================================================================
|
||||
@@ -527,26 +543,22 @@ dynamic_bitset(size_type num_bits, unsigned long value, const Allocator& alloc)
|
||||
m_num_bits(num_bits)
|
||||
{
|
||||
|
||||
if (num_bits == 0)
|
||||
return;
|
||||
|
||||
typedef unsigned long num_type;
|
||||
typedef boost::detail::shifter<num_type, bits_per_block, ulong_width> shifter;
|
||||
|
||||
// cut off all bits in value that have pos >= num_bits, if any
|
||||
//if (num_bits == 0)
|
||||
// return;
|
||||
|
||||
// zero out all bits at pos >= num_bits, if any;
|
||||
// note that: num_bits == 0 implies value == 0
|
||||
if (num_bits < static_cast<size_type>(ulong_width)) {
|
||||
const num_type mask = (num_type(1) << num_bits) - 1;
|
||||
value &= mask;
|
||||
}
|
||||
|
||||
if (bits_per_block >= ulong_width) {
|
||||
m_bits[0] = static_cast<block_type>(value);
|
||||
}
|
||||
else {
|
||||
for(size_type i = 0; value != 0; ++i) {
|
||||
|
||||
m_bits[i] = static_cast<block_type>(value);
|
||||
value >>= BOOST_DYNAMIC_BITSET_WRAP_CONSTANT(bits_per_block);
|
||||
}
|
||||
typename buffer_type::iterator it = m_bits.begin();
|
||||
for( ; value; shifter::left_shift(value), ++it) {
|
||||
*it = static_cast<block_type>(value);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -555,7 +567,7 @@ dynamic_bitset(size_type num_bits, unsigned long value, const Allocator& alloc)
|
||||
template <typename Block, typename Allocator>
|
||||
inline dynamic_bitset<Block, Allocator>::
|
||||
dynamic_bitset(const dynamic_bitset& b)
|
||||
: m_bits(b.m_bits), m_num_bits(b.m_num_bits) // [gps]
|
||||
: m_bits(b.m_bits), m_num_bits(b.m_num_bits)
|
||||
{
|
||||
|
||||
}
|
||||
@@ -579,15 +591,9 @@ template <typename Block, typename Allocator>
|
||||
dynamic_bitset<Block, Allocator>& dynamic_bitset<Block, Allocator>::
|
||||
operator=(const dynamic_bitset<Block, Allocator>& b)
|
||||
{
|
||||
#if 0 // gps
|
||||
dynamic_bitset<Block, Allocator> tmp(b);
|
||||
this->swap(tmp);
|
||||
return *this;
|
||||
#else
|
||||
m_bits = b.m_bits;
|
||||
m_num_bits = b.m_num_bits;
|
||||
return *this;
|
||||
#endif
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
@@ -611,34 +617,32 @@ resize(size_type num_bits, bool value) // strong guarantee
|
||||
const block_type v = value? ~Block(0) : Block(0);
|
||||
|
||||
if (required_blocks != old_num_blocks) {
|
||||
m_bits.resize(required_blocks, v); // s.g. (copy) [gps]
|
||||
m_bits.resize(required_blocks, v); // s.g. (copy)
|
||||
}
|
||||
|
||||
|
||||
// At this point:
|
||||
//
|
||||
// - if the buffer was shrunk, there's nothing to do, except
|
||||
// a call to m_zero_unused_bits()
|
||||
// - if the buffer was shrunk, we have nothing more to do,
|
||||
// except a call to m_zero_unused_bits()
|
||||
//
|
||||
// - if it it is enlarged, all the (used) bits in the new blocks have
|
||||
// the correct value, but we should also take care of the bits,
|
||||
// if any, that were 'unused bits' before enlarging: if value == true,
|
||||
// - if it was enlarged, all the (used) bits in the new blocks have
|
||||
// the correct value, but we have not yet touched those bits, if
|
||||
// any, that were 'unused bits' before enlarging: if value == true,
|
||||
// they must be set.
|
||||
|
||||
if (value && (num_bits > m_num_bits)) {
|
||||
|
||||
const size_type extra_bits = count_extra_bits(); // gps
|
||||
const size_type extra_bits = count_extra_bits();
|
||||
if (extra_bits) {
|
||||
assert(old_num_blocks >= 1 && old_num_blocks <= m_bits.size());
|
||||
|
||||
// Set them.
|
||||
m_bits[old_num_blocks - 1] |= (v << extra_bits); // gps
|
||||
m_bits[old_num_blocks - 1] |= (v << extra_bits);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
m_num_bits = num_bits;
|
||||
m_zero_unused_bits();
|
||||
|
||||
@@ -657,16 +661,15 @@ template <typename Block, typename Allocator>
|
||||
void dynamic_bitset<Block, Allocator>::
|
||||
push_back(bool bit)
|
||||
{
|
||||
resize(size() + 1);
|
||||
set(size() - 1, bit);
|
||||
const size_type sz = size();
|
||||
resize(sz + 1);
|
||||
set(sz, bit);
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
void dynamic_bitset<Block, Allocator>::
|
||||
append(Block value) // strong guarantee
|
||||
{
|
||||
// G.P.S. to be reviewed...
|
||||
|
||||
const block_width_type r = count_extra_bits();
|
||||
|
||||
if (r == 0) {
|
||||
@@ -766,10 +769,23 @@ dynamic_bitset<Block, Allocator>::operator<<=(size_type n)
|
||||
b[div] = b[0];
|
||||
}
|
||||
|
||||
// disable std::fill_n deprecated warning in MSVC++ 8.0 (warning C4996)
|
||||
// This will only work in MSVC++ 8.0 SP1, which brings up the warning
|
||||
// in the line of user code; otherwise, the warning will come up
|
||||
// in the line in the header itself, so if the user includes stdlib
|
||||
// headers before dynamic_bitset, he will still get the warning.
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
#pragma warning(push)
|
||||
#pragma warning(disable:4996)
|
||||
#endif
|
||||
|
||||
// zero out div blocks at the less significant end
|
||||
std::fill_n(b, div, static_cast<block_type>(0));
|
||||
|
||||
#if defined(_MSC_VER) && _MSC_VER >= 1400
|
||||
#pragma warning(pop)
|
||||
#endif
|
||||
|
||||
// zero out any 1 bit that flowed into the unused part
|
||||
m_zero_unused_bits(); // thanks to Lester Gong
|
||||
|
||||
@@ -853,13 +869,6 @@ template <typename Block, typename Allocator>
|
||||
dynamic_bitset<Block, Allocator>&
|
||||
dynamic_bitset<Block, Allocator>::set(size_type pos, bool val)
|
||||
{
|
||||
// [gps]
|
||||
//
|
||||
// Below we have no set(size_type) function to call when
|
||||
// value == true; instead of using a helper, I think
|
||||
// overloading set (rather than giving it a default bool
|
||||
// argument) would be more elegant.
|
||||
|
||||
assert(pos < m_num_bits);
|
||||
|
||||
if (val)
|
||||
@@ -884,14 +893,14 @@ dynamic_bitset<Block, Allocator>&
|
||||
dynamic_bitset<Block, Allocator>::reset(size_type pos)
|
||||
{
|
||||
assert(pos < m_num_bits);
|
||||
#if BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
|
||||
#if defined __MWERKS__ && BOOST_WORKAROUND(__MWERKS__, <= 0x3003) // 8.x
|
||||
// CodeWarrior 8 generates incorrect code when the &=~ is compiled,
|
||||
// use the |^ variation instead.. <grafik>
|
||||
m_bits[block_index(pos)] |= bit_mask(pos);
|
||||
m_bits[block_index(pos)] ^= bit_mask(pos);
|
||||
#else
|
||||
#else
|
||||
m_bits[block_index(pos)] &= ~bit_mask(pos);
|
||||
#endif
|
||||
#endif
|
||||
return *this;
|
||||
}
|
||||
|
||||
@@ -960,45 +969,6 @@ dynamic_bitset<Block, Allocator>::operator~() const
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
|
||||
The following is the straightforward implementation of count(), which
|
||||
we leave here in a comment for documentation purposes.
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
typename dynamic_bitset<Block, Allocator>::size_type
|
||||
dynamic_bitset<Block, Allocator>::count() const
|
||||
{
|
||||
size_type sum = 0;
|
||||
for (size_type i = 0; i != this->m_num_bits; ++i)
|
||||
if (test(i))
|
||||
++sum;
|
||||
return sum;
|
||||
}
|
||||
|
||||
The actual algorithm uses a lookup table.
|
||||
|
||||
|
||||
The basic idea of the method is to pick up X bits at a time
|
||||
from the internal array of blocks and consider those bits as
|
||||
the binary representation of a number N. Then, to use a table
|
||||
of 1<<X elements where table[N] is the number of '1' digits
|
||||
in the binary representation of N (i.e. in our X bits).
|
||||
|
||||
|
||||
In this implementation X is 8 (but can be easily changed: you
|
||||
just have to modify the definition of table_width and shrink/enlarge
|
||||
the table accordingly - it could be useful, for instance, to expand
|
||||
the table to 512 elements on an implementation with 9-bit bytes) and
|
||||
the internal array of blocks is seen, if possible, as an array of bytes.
|
||||
In practice the "reinterpretation" as array of bytes is possible if and
|
||||
only if X >= CHAR_BIT and Block has no padding bits (that would be counted
|
||||
together with the "real ones" if we saw the array as array of bytes).
|
||||
Otherwise we simply 'extract' X bits at a time from each Block.
|
||||
|
||||
*/
|
||||
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
typename dynamic_bitset<Block, Allocator>::size_type
|
||||
dynamic_bitset<Block, Allocator>::count() const
|
||||
@@ -1055,7 +1025,7 @@ void to_string_helper(const dynamic_bitset<B, A> & b, stringT & s,
|
||||
// making me (Gennaro) realize this important separation of
|
||||
// concerns issue, as well as many things about i18n.
|
||||
//
|
||||
template <typename Block, typename Allocator, typename stringT> // G.P.S.
|
||||
template <typename Block, typename Allocator, typename stringT>
|
||||
inline void
|
||||
to_string(const dynamic_bitset<Block, Allocator>& b, stringT& s)
|
||||
{
|
||||
@@ -1069,7 +1039,7 @@ to_string(const dynamic_bitset<Block, Allocator>& b, stringT& s)
|
||||
//
|
||||
template <typename B, typename A, typename stringT>
|
||||
inline void
|
||||
dump_to_string(const dynamic_bitset<B, A>& b, stringT& s) // G.P.S.
|
||||
dump_to_string(const dynamic_bitset<B, A>& b, stringT& s)
|
||||
{
|
||||
to_string_helper(b, s, true /* =dump_all*/);
|
||||
}
|
||||
@@ -1081,7 +1051,7 @@ to_block_range(const dynamic_bitset<Block, Allocator>& b,
|
||||
{
|
||||
// note how this copies *all* bits, including the
|
||||
// unused ones in the last block (which are zero)
|
||||
std::copy(b.m_bits.begin(), b.m_bits.end(), result); // [gps]
|
||||
std::copy(b.m_bits.begin(), b.m_bits.end(), result);
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
@@ -1098,26 +1068,30 @@ to_ulong() const
|
||||
throw std::overflow_error("boost::dynamic_bitset::to_ulong overflow");
|
||||
|
||||
|
||||
// Ok, from now on we can be sure there's no "on" bit beyond
|
||||
// the allowed positions
|
||||
// Ok, from now on we can be sure there's no "on" bit
|
||||
// beyond the "allowed" positions
|
||||
typedef unsigned long result_type;
|
||||
|
||||
if (bits_per_block >= ulong_width)
|
||||
return m_bits[0];
|
||||
/*
|
||||
if find_next() did its job correctly we don't need the if
|
||||
below, because all bits we care about are in the first block
|
||||
|
||||
if (bits_per_block >= ulong_width)
|
||||
return static_cast<result_type>(m_bits[0]);
|
||||
*/
|
||||
|
||||
size_type last_block = block_index((std::min)(m_num_bits-1, // gps
|
||||
(size_type)(ulong_width-1)));
|
||||
unsigned long result = 0;
|
||||
size_type last_block = block_index(
|
||||
(std::min)( m_num_bits, (size_type)ulong_width ) - 1 );
|
||||
result_type result = 0;
|
||||
for (size_type i = 0; i <= last_block; ++i) {
|
||||
|
||||
assert((size_type)bits_per_block * i < (size_type)ulong_width); // gps
|
||||
assert((size_type)bits_per_block * i < (size_type)ulong_width);
|
||||
|
||||
unsigned long piece = m_bits[i];
|
||||
result |= (piece << (bits_per_block * i));
|
||||
}
|
||||
|
||||
return result;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1162,31 +1136,6 @@ inline bool dynamic_bitset<Block, Allocator>::empty() const
|
||||
return size() == 0;
|
||||
}
|
||||
|
||||
#if 0 // gps
|
||||
template <typename Block, typename Allocator>
|
||||
inline void dynamic_bitset<Block, Allocator>::reserve(size_type n)
|
||||
{
|
||||
assert(n <= max_size()); // PRE - G.P.S.
|
||||
m_bits.reserve(calc_num_blocks(n));
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
typename dynamic_bitset<Block, Allocator>::size_type
|
||||
dynamic_bitset<Block, Allocator>::capacity() const
|
||||
{
|
||||
// capacity is m_bits.capacity() * bits_per_block
|
||||
// unless that one overflows
|
||||
const size_type m = static_cast<size_type>(-1);
|
||||
const size_type q = m / bits_per_block;
|
||||
|
||||
const size_type c = m_bits.capacity();
|
||||
|
||||
return c <= q ?
|
||||
c * bits_per_block :
|
||||
m;
|
||||
}
|
||||
#endif
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
bool dynamic_bitset<Block, Allocator>::
|
||||
is_subset_of(const dynamic_bitset<Block, Allocator>& a) const
|
||||
@@ -1203,13 +1152,17 @@ bool dynamic_bitset<Block, Allocator>::
|
||||
is_proper_subset_of(const dynamic_bitset<Block, Allocator>& a) const
|
||||
{
|
||||
assert(size() == a.size());
|
||||
assert(num_blocks() == a.num_blocks());
|
||||
|
||||
bool proper = false;
|
||||
for (size_type i = 0; i < num_blocks(); ++i) {
|
||||
Block bt = m_bits[i], ba = a.m_bits[i];
|
||||
const Block & bt = m_bits[i];
|
||||
const Block & ba = a.m_bits[i];
|
||||
|
||||
if (bt & ~ba)
|
||||
return false; // not a subset at all
|
||||
if (ba & ~bt)
|
||||
proper = true;
|
||||
if (bt & ~ba)
|
||||
return false;
|
||||
}
|
||||
return proper;
|
||||
}
|
||||
@@ -1294,7 +1247,7 @@ bool operator==(const dynamic_bitset<Block, Allocator>& a,
|
||||
const dynamic_bitset<Block, Allocator>& b)
|
||||
{
|
||||
return (a.m_num_bits == b.m_num_bits)
|
||||
&& (a.m_bits == b.m_bits); // [gps]
|
||||
&& (a.m_bits == b.m_bits);
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
@@ -1311,23 +1264,20 @@ bool operator<(const dynamic_bitset<Block, Allocator>& a,
|
||||
assert(a.size() == b.size());
|
||||
typedef typename dynamic_bitset<Block, Allocator>::size_type size_type;
|
||||
|
||||
if (a.size() == 0)
|
||||
return false;
|
||||
//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.
|
||||
|
||||
// Compare a block at a time
|
||||
for (size_type i = a.num_blocks() - 1; i > 0; --i)
|
||||
//
|
||||
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;
|
||||
|
||||
if (a.m_bits[0] < b.m_bits[0])
|
||||
return true;
|
||||
else
|
||||
return false;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
template <typename Block, typename Allocator>
|
||||
@@ -1369,7 +1319,7 @@ operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b)
|
||||
const ios::iostate ok = ios::goodbit;
|
||||
ios::iostate err = ok;
|
||||
|
||||
if (os.opfx()) { // gps
|
||||
if (os.opfx()) {
|
||||
|
||||
//try
|
||||
typedef typename dynamic_bitset<Block, Alloc>::size_type bitsetsize_type;
|
||||
@@ -1377,7 +1327,7 @@ operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b)
|
||||
const bitsetsize_type sz = b.size();
|
||||
std::streambuf * buf = os.rdbuf();
|
||||
size_t npad = os.width() <= 0 // careful: os.width() is signed (and can be < 0)
|
||||
|| (bitsetsize_type) os.width() <= sz? 0 : os.width() - sz; //- gps
|
||||
|| (bitsetsize_type) os.width() <= sz? 0 : os.width() - sz;
|
||||
|
||||
const char fill_char = os.fill();
|
||||
const ios::fmtflags adjustfield = os.flags() & ios::adjustfield;
|
||||
@@ -1386,16 +1336,16 @@ operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b)
|
||||
if (adjustfield != ios::left) {
|
||||
for (; 0 < npad; --npad)
|
||||
if (fill_char != buf->sputc(fill_char)) {
|
||||
err |= ios::failbit; // gps
|
||||
err |= ios::failbit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ok) {
|
||||
// output the bitset
|
||||
for (bitsetsize_type i = b.size(); 0 < i; --i) {// G.P.S.
|
||||
for (bitsetsize_type i = b.size(); 0 < i; --i) {
|
||||
const char dig = b.test(i-1)? '1' : '0';
|
||||
if (EOF == buf->sputc(dig)) { // ok?? gps
|
||||
if (EOF == buf->sputc(dig)) {
|
||||
err |= ios::failbit;
|
||||
break;
|
||||
}
|
||||
@@ -1418,7 +1368,7 @@ operator<<(std::ostream& os, const dynamic_bitset<Block, Alloc>& b)
|
||||
} // if opfx
|
||||
|
||||
if(err != ok)
|
||||
os.setstate(err); // assume this does NOT throw - gps
|
||||
os.setstate(err); // assume this does NOT throw
|
||||
return os;
|
||||
|
||||
}
|
||||
@@ -1445,11 +1395,11 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
|
||||
try {
|
||||
|
||||
typedef typename dynamic_bitset<Block, Alloc>::size_type bitsetsize_type;
|
||||
typedef basic_streambuf<Ch, Tr> buffer_type; // G.P.S.
|
||||
typedef basic_streambuf<Ch, Tr> buffer_type;
|
||||
|
||||
buffer_type * buf = os.rdbuf();
|
||||
size_t npad = os.width() <= 0 // careful: os.width() is signed (and can be < 0)
|
||||
|| (bitsetsize_type) os.width() <= b.size()? 0 : os.width() - b.size(); //- G.P.S.
|
||||
|| (bitsetsize_type) os.width() <= b.size()? 0 : os.width() - b.size();
|
||||
|
||||
const Ch fill_char = os.fill();
|
||||
const ios_base::fmtflags adjustfield = os.flags() & ios_base::adjustfield;
|
||||
@@ -1458,14 +1408,14 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
|
||||
if (adjustfield != ios_base::left) {
|
||||
for (; 0 < npad; --npad)
|
||||
if (Tr::eq_int_type(Tr::eof(), buf->sputc(fill_char))) {
|
||||
err |= ios_base::failbit; // G.P.S.
|
||||
err |= ios_base::failbit;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (err == ok) {
|
||||
// output the bitset
|
||||
for (bitsetsize_type i = b.size(); 0 < i; --i) {// G.P.S.
|
||||
for (bitsetsize_type i = b.size(); 0 < i; --i) {
|
||||
typename buffer_type::int_type
|
||||
ret = buf->sputc(b.test(i-1)? one : zero);
|
||||
if (Tr::eq_int_type(Tr::eof(), ret)) {
|
||||
@@ -1507,8 +1457,8 @@ operator<<(std::basic_ostream<Ch, Tr>& os,
|
||||
|
||||
#ifdef BOOST_OLD_IOSTREAMS
|
||||
|
||||
// gps - A sentry-like class that calls isfx in its
|
||||
// destructor. Necessary because bit_appender::do_append may throw.
|
||||
// A sentry-like class that calls isfx in its destructor.
|
||||
// "Necessary" because bit_appender::do_append may throw.
|
||||
class pseudo_sentry {
|
||||
std::istream & m_r;
|
||||
const bool m_ok;
|
||||
@@ -1532,21 +1482,21 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
|
||||
typedef dynamic_bitset<Block, Alloc> bitset_type;
|
||||
typedef typename bitset_type::size_type size_type;
|
||||
|
||||
std::ios::iostate err = std::ios::goodbit; // gps
|
||||
std::ios::iostate err = std::ios::goodbit;
|
||||
pseudo_sentry cerberos(is); // skips whitespaces
|
||||
if(cerberos) {
|
||||
|
||||
b.clear();
|
||||
|
||||
const std::streamsize w = is.width();
|
||||
const size_type limit = w > 0 && static_cast<size_type>(w) < b.max_size()// gps
|
||||
const size_type limit = w > 0 && static_cast<size_type>(w) < b.max_size()
|
||||
? w : b.max_size();
|
||||
typename bitset_type::bit_appender appender(b);
|
||||
std::streambuf * buf = is.rdbuf();
|
||||
for(int c = buf->sgetc(); appender.get_count() < limit; c = buf->snextc() ) {
|
||||
|
||||
if (c == EOF) {
|
||||
err |= std::ios::eofbit; // G.P.S.
|
||||
err |= std::ios::eofbit;
|
||||
break;
|
||||
}
|
||||
else if (char(c) != '0' && char(c) != '1')
|
||||
@@ -1554,7 +1504,6 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
|
||||
|
||||
else {
|
||||
try {
|
||||
//throw std::bad_alloc(); // gps
|
||||
appender.do_append(char(c) == '1');
|
||||
}
|
||||
catch(...) {
|
||||
@@ -1566,10 +1515,10 @@ operator>>(std::istream& is, dynamic_bitset<Block, Alloc>& b)
|
||||
} // for
|
||||
}
|
||||
|
||||
is.width(0); // gps
|
||||
is.width(0);
|
||||
if (b.size() == 0)
|
||||
err |= std::ios::failbit;
|
||||
if (err != std::ios::goodbit) // gps
|
||||
if (err != std::ios::goodbit)
|
||||
is.setstate (err); // may throw
|
||||
|
||||
return is;
|
||||
@@ -1588,10 +1537,10 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
|
||||
typedef typename bitset_type::size_type size_type;
|
||||
|
||||
const streamsize w = is.width();
|
||||
const size_type limit = 0 < w && static_cast<size_type>(w) < b.max_size()? // gps
|
||||
const size_type limit = 0 < w && static_cast<size_type>(w) < b.max_size()?
|
||||
w : b.max_size();
|
||||
|
||||
ios_base::iostate err = ios_base::goodbit; // gps
|
||||
ios_base::iostate err = ios_base::goodbit;
|
||||
typename basic_istream<Ch, Tr>::sentry cerberos(is); // skips whitespaces
|
||||
if(cerberos) {
|
||||
|
||||
@@ -1604,11 +1553,11 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
|
||||
try {
|
||||
typename bitset_type::bit_appender appender(b);
|
||||
basic_streambuf <Ch, Tr> * buf = is.rdbuf();
|
||||
typename Tr::int_type c = buf->sgetc(); // G.P.S.
|
||||
typename Tr::int_type c = buf->sgetc();
|
||||
for( ; appender.get_count() < limit; c = buf->snextc() ) {
|
||||
|
||||
if (Tr::eq_int_type(Tr::eof(), c)) {
|
||||
err |= ios_base::eofbit; // G.P.S.
|
||||
err |= ios_base::eofbit;
|
||||
break;
|
||||
}
|
||||
else {
|
||||
@@ -1629,7 +1578,7 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
|
||||
//
|
||||
// bits_stored bits have been extracted and stored, and
|
||||
// either no further character is extractable or we can't
|
||||
// append to the underlying vector (out of memory) gps
|
||||
// append to the underlying vector (out of memory)
|
||||
|
||||
bool rethrow = false; // see std 27.6.1.1/4
|
||||
try { is.setstate(ios_base::badbit); }
|
||||
@@ -1641,10 +1590,10 @@ operator>>(std::basic_istream<Ch, Tr>& is, dynamic_bitset<Block, Alloc>& b)
|
||||
}
|
||||
}
|
||||
|
||||
is.width(0); // gps
|
||||
is.width(0);
|
||||
if (b.size() == 0 /*|| !cerberos*/)
|
||||
err |= ios_base::failbit;
|
||||
if (err != ios_base::goodbit) // gps
|
||||
if (err != ios_base::goodbit)
|
||||
is.setstate (err); // may throw
|
||||
|
||||
return is;
|
||||
@@ -1702,7 +1651,7 @@ inline void
|
||||
swap(dynamic_bitset<Block, Allocator>& left,
|
||||
dynamic_bitset<Block, Allocator>& right) // no throw
|
||||
{
|
||||
left.swap(right); // gps
|
||||
left.swap(right);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -9,8 +9,9 @@
|
||||
//
|
||||
// -----------------------------------------------------------
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset for documentation.
|
||||
|
||||
// See http://www.boost.org/libs/dynamic_bitset/ for documentation.
|
||||
//
|
||||
// $Revision$ $Date$ - $Name$
|
||||
|
||||
#ifndef BOOST_DYNAMIC_BITSET_FWD_HPP
|
||||
#define BOOST_DYNAMIC_BITSET_FWD_HPP
|
||||
|
||||
@@ -10,11 +10,13 @@
|
||||
// http://www.boost.org/LICENSE_1_0.txt)
|
||||
//
|
||||
// ------------------------------------------------------
|
||||
//
|
||||
// $Id$
|
||||
|
||||
#ifndef BOOST_LOWEST_BIT_HPP_GP_20030301
|
||||
#define BOOST_LOWEST_BIT_HPP_GP_20030301
|
||||
|
||||
#include <cassert>
|
||||
#include <assert.h>
|
||||
#include "boost/pending/integer_log2.hpp"
|
||||
|
||||
|
||||
|
||||
10
index.html
10
index.html
@@ -1,9 +1,15 @@
|
||||
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="refresh" content="0; URL=dynamic_bitset.html">
|
||||
<meta http-equiv=refresh content="0; URL=dynamic_bitset.html">
|
||||
<title>Automatic redirection</title>
|
||||
</head>
|
||||
<body>
|
||||
Automatic redirection failed, please go to
|
||||
<a href="dynamic_bitset.html">dynamic_bitset.html</a>.
|
||||
<a href="dynamic_bitset.html">dynamic_bitset.html</a>. <hr>
|
||||
<p>© Copyright Beman Dawes, 2001</p>
|
||||
<p>Distributed under the Boost Software License, Version 1.0. (See accompanying
|
||||
file <a href="../../LICENSE_1_0.txt">LICENSE_1_0.txt</a> or copy
|
||||
at <a href="http://www.boost.org/LICENSE_1_0.txt">www.boost.org/LICENSE_1_0.txt</a>)</p>
|
||||
</body>
|
||||
</html>
|
||||
Reference in New Issue
Block a user