]>
git.ipfire.org Git - thirdparty/gcc.git/blob - libstdc++-v3/testsuite/ext/pb_ds/regression/priority_queues.cc
3 // Copyright (C) 2005-2018 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 3, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING3. If not see
18 // <http://www.gnu.org/licenses/>.
21 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
23 // Permission to use, copy, modify, sell, and distribute this software
24 // is hereby granted without fee, provided that the above copyright
25 // notice appears in all copies, and that both that copyright notice
26 // and this permission notice appear in supporting documentation. None
27 // of the above authors, nor IBM Haifa Research Laboratories, make any
28 // representation about the suitability of this software for any
29 // purpose. It is provided "as is" without express or implied
33 * This example shows how to use priority queues. It defines a
34 * function performing a sequence of operations on
35 * a generic container. It then calls this function with some containers.
38 #include <ext/pb_ds/priority_queue.hpp>
43 using namespace __gnu_pbds
;
44 using namespace __gnu_pbds
;
46 template<typename Cntnr
>
48 some_op_sequence(Cntnr
& r_c
)
51 assert(r_c
.size() == 0);
53 for (size_t i
= 0; i
< 10; ++i
)
56 cout
<< endl
<< "All values in the container:" << endl
;
57 for (typename
Cntnr::const_iterator it
= r_c
.begin(); it
!= r_c
.end();
62 assert(r_c
.size() == 10);
64 cout
<< "Popping all values: " << endl
;
68 cout
<< r_c
.top() << endl
;
74 assert(r_c
.size() == 0);
80 priority_queue_link_regression_test_0()
84 * Perform operations on a pairing-heap queue.
86 cout
<< "Pairing heap" << endl
;
87 __gnu_pbds::priority_queue
<int, less
<int>, pairing_heap_tag
> c
;
93 * Perform operations on a binomial-heap queue.
95 cout
<< "Binomial heap" << endl
;
96 __gnu_pbds::priority_queue
<int, less
<int>, binomial_heap_tag
> c
;
102 * Perform operations on a binomial-heap queue.
104 cout
<< "Redundant-counter binomial heap" << endl
;
105 __gnu_pbds::priority_queue
<int, less
<int>, rc_binomial_heap_tag
> c
;
111 * Perform operations on a binary-heap queue.
113 cout
<< "Binary heap" << endl
;
114 __gnu_pbds::priority_queue
<int, less
<int>, binary_heap_tag
> c
;
120 * Perform operations on a thin-heap queue.
122 cout
<< "Thin heap" << endl
;
123 __gnu_pbds::priority_queue
<int, less
<int>, thin_heap_tag
> c
;
130 priority_queue_link_regression_test_1()
134 * Perform operations on a pairing-heap queue.
136 cout
<< "Pairing heap" << endl
;
137 __gnu_pbds::priority_queue
<int, less
<int>, pairing_heap_tag
> c
;
143 * Perform operations on a binomial-heap queue.
145 cout
<< "Binomial heap" << endl
;
146 __gnu_pbds::priority_queue
<int, less
<int>, binomial_heap_tag
> c
;
152 * Perform operations on a binomial-heap queue.
154 cout
<< "Redundant-counter binomial heap" << endl
;
155 __gnu_pbds::priority_queue
<int, less
<int>, rc_binomial_heap_tag
> c
;
161 * Perform operations on a binomial-heap queue.
163 cout
<< "Binary heap" << endl
;
164 __gnu_pbds::priority_queue
<int, less
<int>, binary_heap_tag
> c
;
170 * Perform operations on a thin-heap queue.
172 cout
<< "Thin heap" << endl
;
173 __gnu_pbds::priority_queue
<int, less
<int>, thin_heap_tag
> c
;
181 priority_queue_link_regression_test_0();
182 priority_queue_link_regression_test_1();