diff options
Diffstat (limited to 'boost/dynamic_bitset/dynamic_bitset.hpp')
-rw-r--r-- | boost/dynamic_bitset/dynamic_bitset.hpp | 104 |
1 files changed, 90 insertions, 14 deletions
diff --git a/boost/dynamic_bitset/dynamic_bitset.hpp b/boost/dynamic_bitset/dynamic_bitset.hpp index 05798b5262..c1ae8b15f1 100644 --- a/boost/dynamic_bitset/dynamic_bitset.hpp +++ b/boost/dynamic_bitset/dynamic_bitset.hpp @@ -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 ) @@ -328,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, @@ -1420,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]) + if (!bsize) + { + return false; + } + else if (!asize) + { return true; - else if (a.m_bits[i] > b.m_bits[i]) + } + 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; - } - 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> |