From 4e270bd62b4e443f26110806babeffaa334b5829 Mon Sep 17 00:00:00 2001 From: David Einstein Date: Tue, 22 Jan 2019 14:25:42 -0500 Subject: [PATCH] Fix bucket_sorter example. Bug #151 Changed ID toidentity_property_map. Added concept check to bucket_sorter.hpp. Fixed minor grammar nits. --- example/Jamfile.v2 | 2 +- example/bucket_sorter.cpp | 27 ++++++------------ include/boost/pending/bucket_sorter.hpp | 37 +++++++++++++------------ 3 files changed, 29 insertions(+), 37 deletions(-) diff --git a/example/Jamfile.v2 b/example/Jamfile.v2 index 23444d71..21284f9d 100644 --- a/example/Jamfile.v2 +++ b/example/Jamfile.v2 @@ -26,7 +26,7 @@ exe boost_web_graph : boost_web_graph.cpp ; exe boykov_kolmogorov-eg : boykov_kolmogorov-eg.cpp ; exe bron_kerbosch_clique_number : bron_kerbosch_clique_number.cpp ; exe bron_kerbosch_print_cliques : bron_kerbosch_print_cliques.cpp ; -#exe bucket_sorter : bucket_sorter.cpp ; +exe bucket_sorter : bucket_sorter.cpp ; exe canonical_ordering : canonical_ordering.cpp ; # exe cc-internet : cc-internet.cpp ../build//boost_graph ; exe city_visitor : city_visitor.cpp ; diff --git a/example/bucket_sorter.cpp b/example/bucket_sorter.cpp index 0b5ca055..3f8c6587 100644 --- a/example/bucket_sorter.cpp +++ b/example/bucket_sorter.cpp @@ -13,38 +13,27 @@ #include #include -template -struct trivial_id { - std::size_t operator[](Integral i) { - return i; - } - std::size_t operator[](Integral i) const { - return i; - } -}; - - int main() { using namespace std; using boost::bucket_sorter; - + const std::size_t N = 10; vector bucket(N); for (std::size_t i=0; i ID; - typedef bucket_sorter::iterator, ID> BS; BS my_bucket_sorter(N, N, bucket.begin()); for (std::size_t ii=0; ii #include #include +#include +#include namespace boost { - template class bucket_sorter { + BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept )); public: typedef BucketType bucket_type; typedef ValueType value_type; typedef typename std::vector::size_type size_type; - - bucket_sorter(size_type _length, bucket_type _max_bucket, - const Bucket& _bucket = Bucket(), - const ValueIndexMap& _id = ValueIndexMap()) + + bucket_sorter(size_type _length, bucket_type _max_bucket, + const Bucket& _bucket = Bucket(), + const ValueIndexMap& _id = ValueIndexMap()) : head(_max_bucket, invalid_value()), - next(_length, invalid_value()), + next(_length, invalid_value()), prev(_length, invalid_value()), id_to_value(_length), bucket(_bucket), id(_id) { } - + void remove(const value_type& x) { const size_type i = get(id, x); const size_type& next_node = next[i]; const size_type& prev_node = prev[i]; - - //check if i is the end of the bucket list + + //check if i is the end of the bucket list if ( next_node != invalid_value() ) - prev[next_node] = prev_node; + prev[next_node] = prev_node; //check if i is the begin of the bucket list if ( prev_node != invalid_value() ) next[prev_node] = next_node; @@ -58,21 +61,21 @@ namespace boost { id_to_value[get(id, x)] = x; (*this)[bucket[x]].push(x); } - + void update(const value_type& x) { remove(x); (*this)[bucket[x]].push(x); } - // private: + // private: // with KCC, the nested stack class is having access problems // despite the friend decl. static size_type invalid_value() { return (std::numeric_limits::max)(); } - + typedef typename std::vector::iterator Iter; typedef typename std::vector::iterator IndexValueMap; - + public: friend class stack; @@ -86,7 +89,7 @@ namespace boost { // constructor of the ValueIndexMap is not required if not used. stack(bucket_type _bucket_id, Iter h, Iter n, Iter p, IndexValueMap v) : bucket_id(_bucket_id), head(h), next(n), prev(p), value(v) {} - + void push(const value_type& x) { const size_type new_head = get(id, x); const size_type current = head[bucket_id]; @@ -114,7 +117,7 @@ namespace boost { IndexValueMap value; ValueIndexMap id; }; - + stack operator[](const bucket_type& i) { assert(i < head.size()); return stack(i, head.begin(), next.begin(), prev.begin(), @@ -128,7 +131,7 @@ namespace boost { Bucket bucket; ValueIndexMap id; }; - + } #endif