]>
git.proxmox.com Git - ceph.git/blob - ceph/src/boost/libs/graph/example/bucket_sorter.cpp
1 //=======================================================================
2 // Copyright 1997, 1998, 1999, 2000 University of Notre Dame.
3 // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek
5 // Distributed under the Boost Software License, Version 1.0. (See
6 // accompanying file LICENSE_1_0.txt or copy at
7 // http://www.boost.org/LICENSE_1_0.txt)
8 //=======================================================================
10 #include <boost/config.hpp>
15 #include <boost/pending/bucket_sorter.hpp>
19 using boost::bucket_sorter
;
21 const std::size_t N
= 10;
23 vector
<std::size_t> bucket(N
);
24 for (std::size_t i
=0; i
<N
; i
++) {
25 bucket
[i
] = rand() % N
;
27 cout
<< "Number " << i
<< " is in bucket " << bucket
[i
] << endl
;
30 typedef boost::identity_property_map ID
;
31 typedef bucket_sorter
<std::size_t, int,
32 vector
<std::size_t>::iterator
, ID
> BS
;
33 BS
my_bucket_sorter(N
, N
, bucket
.begin());
35 for (std::size_t ii
=0; ii
<N
; ii
++)
36 my_bucket_sorter
.push(ii
);
40 cout
<< "The bucket " << j
;
41 if ( ! my_bucket_sorter
[j
].empty() ) {
42 cout
<< " has number ";
44 int v
= my_bucket_sorter
[j
].top();
45 my_bucket_sorter
[j
].pop();
47 } while ( ! my_bucket_sorter
[j
].empty() );
50 cout
<< " has no number associated with it." << endl
;
54 for (std::size_t k
=0; k
<N
; k
++)
55 my_bucket_sorter
.push(k
);
57 my_bucket_sorter
.remove(5);
58 my_bucket_sorter
.remove(7);
60 cout
<< "After removing numbers 5 and 7, check correctness again." << endl
;
63 cout
<< "The bucket " << j
;
64 if ( ! my_bucket_sorter
[j
].empty() ) {
65 cout
<< " has number ";
67 int v
= my_bucket_sorter
[j
].top();
68 my_bucket_sorter
[j
].pop();
70 } while ( ! my_bucket_sorter
[j
].empty() );
73 cout
<< " has no number associated with it." << endl
;
78 for (iii
=0; iii
<N
; iii
++) {
79 std::size_t current
= rand() % N
;
80 if ( ! my_bucket_sorter
[current
].empty() ) {
81 int v
= my_bucket_sorter
[current
].top();
82 my_bucket_sorter
[current
].pop();
83 bucket
[v
] = rand() % N
;
84 my_bucket_sorter
.push(v
);
88 for (iii
=0; iii
<N
; iii
++) {
89 std::size_t current
= rand() % N
;
90 if ( ! my_bucket_sorter
[current
].empty() ) {
91 int v
= my_bucket_sorter
[current
].top();
92 bucket
[v
] = rand() % N
;
93 my_bucket_sorter
.update(v
);