mirror of
https://github.com/boostorg/graph.git
synced 2025-05-11 05:14:01 +00:00
Merge branch 'bucket_sorter' of https://github.com/deinst/graph into develop
Fixed Conflicts: example/Jamfile.v2
This commit is contained in:
commit
e694fc7e9e
@ -30,6 +30,7 @@ run boost_web_graph.cpp : $(TEST_DIR)/boost_web.dat ;
|
|||||||
exe boykov_kolmogorov-eg : boykov_kolmogorov-eg.cpp ;
|
exe boykov_kolmogorov-eg : boykov_kolmogorov-eg.cpp ;
|
||||||
exe bron_kerbosch_clique_number : bron_kerbosch_clique_number.cpp ;
|
exe bron_kerbosch_clique_number : bron_kerbosch_clique_number.cpp ;
|
||||||
exe bron_kerbosch_print_cliques : bron_kerbosch_print_cliques.cpp ;
|
exe bron_kerbosch_print_cliques : bron_kerbosch_print_cliques.cpp ;
|
||||||
|
run bucket_sorter.cpp ;
|
||||||
run canonical_ordering.cpp ;
|
run canonical_ordering.cpp ;
|
||||||
run city_visitor.cpp ;
|
run city_visitor.cpp ;
|
||||||
exe closeness_centrality : closeness_centrality.cpp ;
|
exe closeness_centrality : closeness_centrality.cpp ;
|
||||||
@ -223,7 +224,3 @@ explicit girth ;
|
|||||||
# This one dereferences a null-iterator:
|
# This one dereferences a null-iterator:
|
||||||
#
|
#
|
||||||
# run ordered_out_edges.cpp ;
|
# run ordered_out_edges.cpp ;
|
||||||
#
|
|
||||||
# does not compile:
|
|
||||||
#
|
|
||||||
# run bucket_sorter.cpp ;
|
|
||||||
|
@ -24,38 +24,27 @@
|
|||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <boost/pending/bucket_sorter.hpp>
|
#include <boost/pending/bucket_sorter.hpp>
|
||||||
|
|
||||||
template <class Integral>
|
|
||||||
struct trivial_id {
|
|
||||||
std::size_t operator[](Integral i) {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
std::size_t operator[](Integral i) const {
|
|
||||||
return i;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using boost::bucket_sorter;
|
using boost::bucket_sorter;
|
||||||
|
|
||||||
const std::size_t N = 10;
|
const std::size_t N = 10;
|
||||||
|
|
||||||
vector<std::size_t> bucket(N);
|
vector<std::size_t> bucket(N);
|
||||||
for (std::size_t i=0; i<N; i++) {
|
for (std::size_t i=0; i<N; i++) {
|
||||||
bucket[i] = rand() % N;
|
bucket[i] = rand() % N;
|
||||||
cout.width(6);
|
cout.width(6);
|
||||||
cout << "Number " << i << " has its bucket " << bucket[i] << endl;
|
cout << "Number " << i << " is in bucket " << bucket[i] << endl;
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef trivial_id<int> ID;
|
typedef boost::identity_property_map ID;
|
||||||
typedef bucket_sorter<std::size_t, int,
|
typedef bucket_sorter<std::size_t, int,
|
||||||
vector<std::size_t>::iterator, ID> BS;
|
vector<std::size_t>::iterator, ID> BS;
|
||||||
BS my_bucket_sorter(N, N, bucket.begin());
|
BS my_bucket_sorter(N, N, bucket.begin());
|
||||||
|
|
||||||
for (std::size_t ii=0; ii<N; ii++)
|
for (std::size_t ii=0; ii<N; ii++)
|
||||||
my_bucket_sorter.push(ii);
|
my_bucket_sorter.push(ii);
|
||||||
|
|
||||||
std::size_t j;
|
std::size_t j;
|
||||||
for (j=0; j<N; j++) {
|
for (j=0; j<N; j++) {
|
||||||
cout << "The bucket " << j;
|
cout << "The bucket " << j;
|
||||||
@ -68,7 +57,7 @@ int main() {
|
|||||||
} while ( ! my_bucket_sorter[j].empty() );
|
} while ( ! my_bucket_sorter[j].empty() );
|
||||||
cout << endl;
|
cout << endl;
|
||||||
} else {
|
} else {
|
||||||
cout << " has no number associated with." << endl;
|
cout << " has no number associated with it." << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,7 +67,7 @@ int main() {
|
|||||||
my_bucket_sorter.remove(5);
|
my_bucket_sorter.remove(5);
|
||||||
my_bucket_sorter.remove(7);
|
my_bucket_sorter.remove(7);
|
||||||
|
|
||||||
cout << "Afer remove number 5 and 7, check correctness again." << endl;
|
cout << "After removing numbers 5 and 7, check correctness again." << endl;
|
||||||
|
|
||||||
for (j=0; j<N; j++) {
|
for (j=0; j<N; j++) {
|
||||||
cout << "The bucket " << j;
|
cout << "The bucket " << j;
|
||||||
@ -91,7 +80,7 @@ int main() {
|
|||||||
} while ( ! my_bucket_sorter[j].empty() );
|
} while ( ! my_bucket_sorter[j].empty() );
|
||||||
cout << endl;
|
cout << endl;
|
||||||
} else {
|
} else {
|
||||||
cout << " has no number associated with." << endl;
|
cout << " has no number associated with it." << endl;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -19,34 +19,37 @@
|
|||||||
#include <vector>
|
#include <vector>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <boost/limits.hpp>
|
#include <boost/limits.hpp>
|
||||||
|
#include <boost/concept/assert.hpp>
|
||||||
|
#include <boost/property_map/property_map.hpp>
|
||||||
|
|
||||||
namespace boost {
|
namespace boost {
|
||||||
|
|
||||||
template <class BucketType, class ValueType, class Bucket,
|
template <class BucketType, class ValueType, class Bucket,
|
||||||
class ValueIndexMap>
|
class ValueIndexMap>
|
||||||
class bucket_sorter {
|
class bucket_sorter {
|
||||||
|
BOOST_CONCEPT_ASSERT(( ReadablePropertyMapConcept<ValueIndexMap, ValueType> ));
|
||||||
public:
|
public:
|
||||||
typedef BucketType bucket_type;
|
typedef BucketType bucket_type;
|
||||||
typedef ValueType value_type;
|
typedef ValueType value_type;
|
||||||
typedef typename std::vector<value_type>::size_type size_type;
|
typedef typename std::vector<value_type>::size_type size_type;
|
||||||
|
|
||||||
bucket_sorter(size_type _length, bucket_type _max_bucket,
|
bucket_sorter(size_type _length, bucket_type _max_bucket,
|
||||||
const Bucket& _bucket = Bucket(),
|
const Bucket& _bucket = Bucket(),
|
||||||
const ValueIndexMap& _id = ValueIndexMap())
|
const ValueIndexMap& _id = ValueIndexMap())
|
||||||
: head(_max_bucket, invalid_value()),
|
: head(_max_bucket, invalid_value()),
|
||||||
next(_length, invalid_value()),
|
next(_length, invalid_value()),
|
||||||
prev(_length, invalid_value()),
|
prev(_length, invalid_value()),
|
||||||
id_to_value(_length),
|
id_to_value(_length),
|
||||||
bucket(_bucket), id(_id) { }
|
bucket(_bucket), id(_id) { }
|
||||||
|
|
||||||
void remove(const value_type& x) {
|
void remove(const value_type& x) {
|
||||||
const size_type i = get(id, x);
|
const size_type i = get(id, x);
|
||||||
const size_type& next_node = next[i];
|
const size_type& next_node = next[i];
|
||||||
const size_type& prev_node = prev[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() )
|
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
|
//check if i is the begin of the bucket list
|
||||||
if ( prev_node != invalid_value() )
|
if ( prev_node != invalid_value() )
|
||||||
next[prev_node] = next_node;
|
next[prev_node] = next_node;
|
||||||
@ -58,21 +61,21 @@ namespace boost {
|
|||||||
id_to_value[get(id, x)] = x;
|
id_to_value[get(id, x)] = x;
|
||||||
(*this)[bucket[x]].push(x);
|
(*this)[bucket[x]].push(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
void update(const value_type& x) {
|
void update(const value_type& x) {
|
||||||
remove(x);
|
remove(x);
|
||||||
(*this)[bucket[x]].push(x);
|
(*this)[bucket[x]].push(x);
|
||||||
}
|
}
|
||||||
// private:
|
// private:
|
||||||
// with KCC, the nested stack class is having access problems
|
// with KCC, the nested stack class is having access problems
|
||||||
// despite the friend decl.
|
// despite the friend decl.
|
||||||
static size_type invalid_value() {
|
static size_type invalid_value() {
|
||||||
return (std::numeric_limits<size_type>::max)();
|
return (std::numeric_limits<size_type>::max)();
|
||||||
}
|
}
|
||||||
|
|
||||||
typedef typename std::vector<size_type>::iterator Iter;
|
typedef typename std::vector<size_type>::iterator Iter;
|
||||||
typedef typename std::vector<value_type>::iterator IndexValueMap;
|
typedef typename std::vector<value_type>::iterator IndexValueMap;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
friend class stack;
|
friend class stack;
|
||||||
|
|
||||||
@ -86,7 +89,7 @@ namespace boost {
|
|||||||
// constructor of the ValueIndexMap is not required if not used.
|
// constructor of the ValueIndexMap is not required if not used.
|
||||||
stack(bucket_type _bucket_id, Iter h, Iter n, Iter p, IndexValueMap v)
|
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) {}
|
: bucket_id(_bucket_id), head(h), next(n), prev(p), value(v) {}
|
||||||
|
|
||||||
void push(const value_type& x) {
|
void push(const value_type& x) {
|
||||||
const size_type new_head = get(id, x);
|
const size_type new_head = get(id, x);
|
||||||
const size_type current = head[bucket_id];
|
const size_type current = head[bucket_id];
|
||||||
@ -114,7 +117,7 @@ namespace boost {
|
|||||||
IndexValueMap value;
|
IndexValueMap value;
|
||||||
ValueIndexMap id;
|
ValueIndexMap id;
|
||||||
};
|
};
|
||||||
|
|
||||||
stack operator[](const bucket_type& i) {
|
stack operator[](const bucket_type& i) {
|
||||||
assert(i < head.size());
|
assert(i < head.size());
|
||||||
return stack(i, head.begin(), next.begin(), prev.begin(),
|
return stack(i, head.begin(), next.begin(), prev.begin(),
|
||||||
@ -128,7 +131,7 @@ namespace boost {
|
|||||||
Bucket bucket;
|
Bucket bucket;
|
||||||
ValueIndexMap id;
|
ValueIndexMap id;
|
||||||
};
|
};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
x
Reference in New Issue
Block a user