mirror of
https://github.com/boostorg/graph.git
synced 2026-01-30 20:02:12 +00:00
new files, and changes to bitset
[SVN r9589]
This commit is contained in:
@@ -23,6 +23,7 @@
|
||||
#include <algorithm>
|
||||
#include <string>
|
||||
#include <boost/pending/ct_if.hpp>
|
||||
#include <boost/graph/detail/bitset_adaptor.hpp>
|
||||
|
||||
// This provides versions of std::bitset with both static and dynamic size.
|
||||
|
||||
@@ -57,6 +58,8 @@ namespace boost {
|
||||
//=========================================================================
|
||||
template <class WordTraits, class SizeType, class Derived>
|
||||
class bitset_base
|
||||
: public bitset_adaptor< SizeType,
|
||||
bitset_base<WordTraits, SizeType, Derived> >
|
||||
{
|
||||
// private:
|
||||
public:
|
||||
@@ -314,6 +317,12 @@ namespace boost {
|
||||
return static_cast<Derived&>(*this);
|
||||
}
|
||||
|
||||
// this wasn't working, why?
|
||||
int compare_3way(const Derived& x) const {
|
||||
return std::lexicographical_compare_3way
|
||||
(data(), data() + num_words(), x.data(), x.data() + x.num_words());
|
||||
}
|
||||
|
||||
// less-than compare
|
||||
bool operator<(const Derived& x) const {
|
||||
return std::lexicographical_compare
|
||||
@@ -380,6 +389,14 @@ namespace boost {
|
||||
return result;
|
||||
}
|
||||
|
||||
template <class W, class S, class D>
|
||||
inline int compare_3way(const bitset_base<W,S,D>& x,
|
||||
const bitset_base<W,S,D>& y) {
|
||||
return std::lexicographical_compare_3way
|
||||
(x.data(), x.data() + x.num_words(),
|
||||
y.data(), y.data() + y.num_words());
|
||||
}
|
||||
|
||||
|
||||
template <class W, class S, class D>
|
||||
std::istream&
|
||||
@@ -468,7 +485,7 @@ namespace boost {
|
||||
(const basic_string<CharT,Traits,Alloc>& s,
|
||||
std::size_t pos = 0,
|
||||
std::size_t n = size_t(basic_string<CharT,Traits,Alloc>::npos),
|
||||
const Allocator& alloc = Allocator())
|
||||
const Allocator& alloc = Allocator())
|
||||
: m_data(alloc.allocate((n + word_size - 1) / word_size)),
|
||||
m_size(n), m_num_words((n + word_size - 1) / word_size),
|
||||
m_alloc(alloc)
|
||||
@@ -480,8 +497,8 @@ namespace boost {
|
||||
template <typename InputIterator>
|
||||
explicit dyn_size_bitset
|
||||
(InputIterator first, InputIterator last,
|
||||
size_type n, // size of the set's "universe"
|
||||
const Allocator& alloc = Allocator())
|
||||
size_type n, // size of the set's "universe"
|
||||
const Allocator& alloc = Allocator())
|
||||
: m_data(alloc.allocate((n + word_size - 1) / word_size)),
|
||||
m_size(N), m_num_words((n + word_size - 1) / word_size),
|
||||
m_alloc(alloc)
|
||||
|
||||
81
include/boost/graph/detail/bitset_adaptor.hpp
Normal file
81
include/boost/graph/detail/bitset_adaptor.hpp
Normal file
@@ -0,0 +1,81 @@
|
||||
#ifndef BOOST_BITSET_ADAPTOR_HPP
|
||||
#define BOOST_BITSET_ADAPTOR_HPP
|
||||
|
||||
template <class T, class Derived>
|
||||
struct bitset_adaptor {
|
||||
Derived& derived() { return static_cast<Derived&>(*this); }
|
||||
const Derived& derived() const {
|
||||
return static_cast<const Derived&>(*this);
|
||||
}
|
||||
};
|
||||
|
||||
template <class T, class D, class V>
|
||||
bool set_contains(const bitset_adaptor<T,D>& s, const V& x) {
|
||||
return s.derived().test(x);
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
bool set_equal(const bitset_adaptor<T,D>& x,
|
||||
const bitset_adaptor<T,D>& y) {
|
||||
return x.derived() == y.derived();
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
int set_lex_order(const bitset_adaptor<T,D>& x,
|
||||
const bitset_adaptor<T,D>& y) {
|
||||
return compare_3way(x.derived(), y.derived());
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
void set_clear(bitset_adaptor<T,D>& x) {
|
||||
x.derived().reset();
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
bool set_empty(const bitset_adaptor<T,D>& x) {
|
||||
return x.derived().none();
|
||||
}
|
||||
|
||||
template <class T, class D, class V>
|
||||
void set_insert(bitset_adaptor<T,D>& x, const V& a) {
|
||||
x.derived().set(a);
|
||||
}
|
||||
|
||||
template <class T, class D, class V>
|
||||
void set_remove(bitset_adaptor<T,D>& x, const V& a) {
|
||||
x.derived().set(a, false);
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
void set_intersect(const bitset_adaptor<T,D>& x,
|
||||
const bitset_adaptor<T,D>& y,
|
||||
bitset_adaptor<T,D>& z)
|
||||
{
|
||||
z.derived() = x.derived() & y.derived();
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
void set_union(const bitset_adaptor<T,D>& x,
|
||||
const bitset_adaptor<T,D>& y,
|
||||
bitset_adaptor<T,D>& z)
|
||||
{
|
||||
z.derived() = x.derived() | y.derived();
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
void set_difference(const bitset_adaptor<T,D>& x,
|
||||
const bitset_adaptor<T,D>& y,
|
||||
bitset_adaptor<T,D>& z)
|
||||
{
|
||||
z.derived() = x.derived() - y.derived();
|
||||
}
|
||||
|
||||
template <class T, class D>
|
||||
void set_compliment(const bitset_adaptor<T,D>& x,
|
||||
bitset_adaptor<T,D>& z)
|
||||
{
|
||||
z.derived() = x.derived();
|
||||
z.derived().flip();
|
||||
}
|
||||
|
||||
#endif // BOOST_BITSET_ADAPTOR_HPP
|
||||
103
include/boost/graph/detail/set_adaptor.hpp
Normal file
103
include/boost/graph/detail/set_adaptor.hpp
Normal file
@@ -0,0 +1,103 @@
|
||||
#ifndef BOOST_SET_ADAPTOR_HPP
|
||||
#define BOOST_SET_ADAPTOR_HPP
|
||||
|
||||
#include <set>
|
||||
|
||||
template <class K, class C, class A, class T>
|
||||
bool set_contains(const std::set<K,C,A>& s, const T& x) {
|
||||
return s.find(x) != s.end();
|
||||
}
|
||||
|
||||
template <class K, class C, class A>
|
||||
bool set_equal(const std::set<K,C,A>& x,
|
||||
const std::set<K,C,A>& y)
|
||||
{
|
||||
return x == y;
|
||||
}
|
||||
|
||||
// Not the same as lexicographical_compare_3way applied to std::set.
|
||||
// this is equivalent semantically to bitset::operator<()
|
||||
template <class K, class C, class A>
|
||||
int set_lex_order(const std::set<K,C,A>& x,
|
||||
const std::set<K,C,A>& y)
|
||||
{
|
||||
typename std::set<K,C,A>::iterator
|
||||
xi = x.begin(), yi = y.begin(), xend = x.end(), yend = y.end();
|
||||
for (; xi != xend && yi != yend; ++xi, ++yi) {
|
||||
if (*xi < *yi)
|
||||
return 1;
|
||||
else if (*yi < *xi)
|
||||
return -1;
|
||||
}
|
||||
if (xi == xend)
|
||||
return (yi == yend) ? 0 : -1;
|
||||
else
|
||||
return 1;
|
||||
}
|
||||
|
||||
template <class K, class C, class A>
|
||||
void set_clear(std::set<K,C,A>& x) {
|
||||
x.clear();
|
||||
}
|
||||
|
||||
template <class K, class C, class A>
|
||||
bool set_empty(const std::set<K,C,A>& x) {
|
||||
return x.empty();
|
||||
}
|
||||
|
||||
template <class K, class C, class A, class T>
|
||||
void set_insert(std::set<K,C,A>& x, const T& a) {
|
||||
x.insert(a);
|
||||
}
|
||||
|
||||
template <class K, class C, class A, class T>
|
||||
void set_remove(std::set<K,C,A>& x, const T& a) {
|
||||
x.remove(a);
|
||||
}
|
||||
|
||||
template <class K, class C, class A>
|
||||
void set_intersect(const std::set<K,C,A>& x,
|
||||
const std::set<K,C,A>& y,
|
||||
std::set<K,C,A>& z)
|
||||
{
|
||||
z.clear();
|
||||
std::set_intersection(x.begin(), x.end(),
|
||||
y.begin(), y.end(),
|
||||
std::inserter(z));
|
||||
}
|
||||
|
||||
template <class K, class C, class A>
|
||||
void set_union(const std::set<K,C,A>& x,
|
||||
const std::set<K,C,A>& y,
|
||||
std::set<K,C,A>& z)
|
||||
{
|
||||
z.clear();
|
||||
std::set_union(x.begin(), x.end(),
|
||||
y.begin(), y.end(),
|
||||
std::inserter(z));
|
||||
}
|
||||
|
||||
template <class K, class C, class A>
|
||||
void set_difference(const std::set<K,C,A>& x,
|
||||
const std::set<K,C,A>& y,
|
||||
std::set<K,C,A>& z)
|
||||
{
|
||||
z.clear();
|
||||
std::set_difference(x.begin(), x.end(),
|
||||
y.begin(), y.end(),
|
||||
std::inserter(z));
|
||||
}
|
||||
|
||||
// Shit, can't implement this without knowing the size of the
|
||||
// universe.
|
||||
template <class K, class C, class A>
|
||||
void set_compliment(const std::set<K,C,A>& x,
|
||||
std::set<K,C,A>& z)
|
||||
{
|
||||
z.clear();
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
#endif // BOOST_SET_ADAPTOR_HPP
|
||||
Reference in New Issue
Block a user