// (C) Copyright 2008-2009 SDML (www.sdml.info) // // Use, modification and distribution is subject to 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 Andrew Sutton 2007 // // Use, modification and distribution are subject to 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_SETS_DYNAMIC_BITSET_HPP #define BOOST_SETS_DYNMAIC_BITSET_HPP // Boost.Range is part of the generic interface to the library. #include #include #include #include namespace boost { namespace sets { // Return the size (cardinality) of the set. Note that this is not the // same as the bitset's size, but rather the number of on bits in the // bitset. template inline bool size(const dynamic_bitset& s) { return s.count(); } // For bitsets, ths means that there are no elements set. Unfortunately, // this is linear (bit still really, really fast). template inline bool empty(const dynamic_bitset& s) { return s.none(); } // Return true if the bitset contains the elment x. This is true iff the // bit x is on. template inline bool contains(const dynamic_bitset& s, std::size_t x) { return s.test(x); } // Return true if the bitset s contains the elements in the bitset t. This // is true if the intersection (binary and) of the two bitsets is equal to // the second (t). This is a near-constant operation (linear in sizeof // the bitset's block type). template inline bool contains(const dynamic_bitset& s, const dynamic_bitset& t) { return (s & t) == t; } // Turn on the bit at the given location. template inline std::pair, bool> add(dynamic_bitset& s, std::size_t x) { bool b = s.test(x); s.set(x); return std::make_pair(bitset_iterator(s, x), b); } // Remove the element by turning off the bit at the given location. template void remove(dynamic_bitset& s, std::size_t x) { s.reset(x); } // Remove the referenced element by turning off the bit at the given // location. template void remove(dynamic_bitset& s, bitset_iterator i) { s.reset(*i); } // Clear the bitset by setting all bits to 0. template void clear(dynamic_bitset& s) { s.reset(); } } /* namespace sets */ } /* namespace boost */ #include #include #include #endif