]>
Commit | Line | Data |
---|---|---|
7c673cae FG |
1 | //======================================================================= |
2 | // Copyright 1997, 1998, 1999, 2000 University of Notre Dame. | |
3 | // Authors: Andrew Lumsdaine, Lie-Quan Lee, Jeremy G. Siek | |
4 | // | |
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 | //======================================================================= | |
92f5a8d4 | 9 | |
7c673cae FG |
10 | #include <boost/config.hpp> |
11 | #include <vector> | |
12 | #include <iostream> | |
13 | ||
14 | #include <stdlib.h> | |
15 | #include <boost/pending/bucket_sorter.hpp> | |
16 | ||
7c673cae FG |
17 | int main() { |
18 | using namespace std; | |
19 | using boost::bucket_sorter; | |
92f5a8d4 | 20 | |
7c673cae FG |
21 | const std::size_t N = 10; |
22 | ||
23 | vector<std::size_t> bucket(N); | |
24 | for (std::size_t i=0; i<N; i++) { | |
25 | bucket[i] = rand() % N; | |
26 | cout.width(6); | |
92f5a8d4 | 27 | cout << "Number " << i << " is in bucket " << bucket[i] << endl; |
7c673cae FG |
28 | } |
29 | ||
92f5a8d4 TL |
30 | typedef boost::identity_property_map ID; |
31 | typedef bucket_sorter<std::size_t, int, | |
7c673cae FG |
32 | vector<std::size_t>::iterator, ID> BS; |
33 | BS my_bucket_sorter(N, N, bucket.begin()); | |
34 | ||
35 | for (std::size_t ii=0; ii<N; ii++) | |
36 | my_bucket_sorter.push(ii); | |
92f5a8d4 | 37 | |
7c673cae FG |
38 | std::size_t j; |
39 | for (j=0; j<N; j++) { | |
40 | cout << "The bucket " << j; | |
41 | if ( ! my_bucket_sorter[j].empty() ) { | |
42 | cout << " has number "; | |
43 | do { | |
44 | int v = my_bucket_sorter[j].top(); | |
45 | my_bucket_sorter[j].pop(); | |
46 | cout << v << " "; | |
47 | } while ( ! my_bucket_sorter[j].empty() ); | |
48 | cout << endl; | |
49 | } else { | |
92f5a8d4 | 50 | cout << " has no number associated with it." << endl; |
7c673cae FG |
51 | } |
52 | } | |
53 | ||
54 | for (std::size_t k=0; k<N; k++) | |
55 | my_bucket_sorter.push(k); | |
56 | ||
57 | my_bucket_sorter.remove(5); | |
58 | my_bucket_sorter.remove(7); | |
59 | ||
92f5a8d4 | 60 | cout << "After removing numbers 5 and 7, check correctness again." << endl; |
7c673cae FG |
61 | |
62 | for (j=0; j<N; j++) { | |
63 | cout << "The bucket " << j; | |
64 | if ( ! my_bucket_sorter[j].empty() ) { | |
65 | cout << " has number "; | |
66 | do { | |
67 | int v = my_bucket_sorter[j].top(); | |
68 | my_bucket_sorter[j].pop(); | |
69 | cout << v << " "; | |
70 | } while ( ! my_bucket_sorter[j].empty() ); | |
71 | cout << endl; | |
72 | } else { | |
92f5a8d4 | 73 | cout << " has no number associated with it." << endl; |
7c673cae FG |
74 | } |
75 | } | |
76 | ||
77 | std::size_t iii; | |
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); | |
85 | } | |
86 | } | |
87 | ||
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); | |
94 | } | |
95 | } | |
96 | ||
97 | return 0; | |
98 | } |