]>
Commit | Line | Data |
---|---|---|
4569a895 AT |
1 | // -*- C++ -*- |
2 | ||
a5544970 | 3 | // Copyright (C) 2005-2019 Free Software Foundation, Inc. |
4569a895 AT |
4 | // |
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 | |
748086b7 | 8 | // Foundation; either version 3, or (at your option) any later |
4569a895 AT |
9 | // version. |
10 | ||
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. | |
15 | ||
748086b7 JJ |
16 | // Under Section 7 of GPL version 3, you are granted additional |
17 | // permissions described in the GCC Runtime Library Exception, version | |
18 | // 3.1, as published by the Free Software Foundation. | |
4569a895 | 19 | |
748086b7 JJ |
20 | // You should have received a copy of the GNU General Public License and |
21 | // a copy of the GCC Runtime Library Exception along with this program; | |
22 | // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see | |
23 | // <http://www.gnu.org/licenses/>. | |
4569a895 AT |
24 | |
25 | // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. | |
26 | ||
27 | // Permission to use, copy, modify, sell, and distribute this software | |
28 | // is hereby granted without fee, provided that the above copyright | |
29 | // notice appears in all copies, and that both that copyright notice | |
30 | // and this permission notice appear in supporting documentation. None | |
31 | // of the above authors, nor IBM Haifa Research Laboratories, make any | |
32 | // representation about the suitability of this software for any | |
33 | // purpose. It is provided "as is" without express or implied | |
34 | // warranty. | |
35 | ||
36 | /** | |
37 | * @file priority_queue.hpp | |
38 | * Contains priority_queues. | |
39 | */ | |
40 | ||
41 | #ifndef PB_DS_PRIORITY_QUEUE_HPP | |
42 | #define PB_DS_PRIORITY_QUEUE_HPP | |
43 | ||
8fc81078 | 44 | #include <bits/c++config.h> |
4569a895 AT |
45 | #include <ext/pb_ds/tag_and_trait.hpp> |
46 | #include <ext/pb_ds/detail/priority_queue_base_dispatch.hpp> | |
47 | #include <ext/pb_ds/detail/standard_policies.hpp> | |
48 | ||
5e11f978 | 49 | namespace __gnu_pbds |
4569a895 | 50 | { |
a345e45d | 51 | /** |
d8dd52a9 | 52 | * @defgroup heap-based Heap-Based |
30a96b3b BK |
53 | * @ingroup containers-pbds |
54 | * @{ | |
a345e45d | 55 | */ |
30a96b3b BK |
56 | |
57 | /** | |
58 | * @defgroup heap-detail Base and Policy Classes | |
59 | * @ingroup heap-based | |
60 | */ | |
61 | ||
62 | /** | |
63 | * A priority queue composed of one specific heap policy. | |
64 | * | |
65 | * @tparam _Tv Value type. | |
66 | * @tparam Cmp_Fn Comparison functor. | |
67 | * @tparam Tag Instantiating data structure type, | |
68 | * see container_tag. | |
69 | * @tparam _Alloc Allocator type. | |
70 | * | |
71 | * Base is dispatched at compile time via Tag, from the following | |
72 | * choices: binary_heap_tag, binomial_heap_tag, pairing_heap_tag, | |
73 | * rc_binomial_heap_tag, thin_heap_tag | |
74 | * | |
75 | * Base choices are: detail::binary_heap, detail::binomial_heap, | |
76 | * detail::pairing_heap, detail::rc_binomial_heap, | |
77 | * detail::thin_heap. | |
78 | */ | |
79 | template<typename _Tv, | |
a345e45d | 80 | typename Cmp_Fn = std::less<_Tv>, |
4569a895 | 81 | typename Tag = pairing_heap_tag, |
a345e45d BK |
82 | typename _Alloc = std::allocator<char> > |
83 | class priority_queue | |
84 | : public detail::container_base_dispatch<_Tv, Cmp_Fn, _Alloc, Tag>::type | |
4569a895 | 85 | { |
4569a895 | 86 | public: |
a345e45d | 87 | typedef _Tv value_type; |
4569a895 AT |
88 | typedef Cmp_Fn cmp_fn; |
89 | typedef Tag container_category; | |
a345e45d | 90 | typedef _Alloc allocator_type; |
b67758fe BK |
91 | typedef typename allocator_type::size_type size_type; |
92 | typedef typename allocator_type::difference_type difference_type; | |
4569a895 | 93 | |
a345e45d BK |
94 | private: |
95 | typedef typename detail::container_base_dispatch<_Tv, Cmp_Fn, _Alloc, | |
96 | Tag>::type | |
97 | base_type; | |
98 | typedef typename _Alloc::template rebind<_Tv> __rebind_v; | |
99 | typedef typename __rebind_v::other __rebind_va; | |
100 | ||
101 | public: | |
102 | typedef typename __rebind_va::reference reference; | |
103 | typedef typename __rebind_va::const_reference const_reference; | |
104 | typedef typename __rebind_va::pointer pointer; | |
105 | typedef typename __rebind_va::const_pointer const_pointer; | |
4569a895 | 106 | |
4569a895 | 107 | typedef typename base_type::point_iterator point_iterator; |
a345e45d | 108 | typedef typename base_type::point_const_iterator point_const_iterator; |
4569a895 | 109 | typedef typename base_type::iterator iterator; |
a345e45d | 110 | typedef typename base_type::const_iterator const_iterator; |
4569a895 AT |
111 | |
112 | priority_queue() { } | |
113 | ||
30a96b3b BK |
114 | /// Constructor taking some policy objects. r_cmp_fn will be |
115 | /// copied by the Cmp_Fn object of the container object. | |
4569a895 AT |
116 | priority_queue(const cmp_fn& r_cmp_fn) : base_type(r_cmp_fn) { } |
117 | ||
30a96b3b BK |
118 | /// Constructor taking __iterators to a range of value_types. The |
119 | /// value_types between first_it and last_it will be inserted into | |
120 | /// the container object. | |
4569a895 AT |
121 | template<typename It> |
122 | priority_queue(It first_it, It last_it) | |
123 | { base_type::copy_from_range(first_it, last_it); } | |
124 | ||
30a96b3b BK |
125 | /// Constructor taking __iterators to a range of value_types and |
126 | /// some policy objects The value_types between first_it and | |
127 | /// last_it will be inserted into the container object. r_cmp_fn | |
128 | /// will be copied by the cmp_fn object of the container object. | |
4569a895 AT |
129 | template<typename It> |
130 | priority_queue(It first_it, It last_it, const cmp_fn& r_cmp_fn) | |
131 | : base_type(r_cmp_fn) | |
132 | { base_type::copy_from_range(first_it, last_it); } | |
133 | ||
134 | priority_queue(const priority_queue& other) | |
135 | : base_type((const base_type& )other) { } | |
136 | ||
137 | virtual | |
138 | ~priority_queue() { } | |
139 | ||
a345e45d | 140 | priority_queue& |
4569a895 AT |
141 | operator=(const priority_queue& other) |
142 | { | |
2e3f9c21 | 143 | if (this != &other) |
4569a895 AT |
144 | { |
145 | priority_queue tmp(other); | |
146 | swap(tmp); | |
147 | } | |
148 | return *this; | |
149 | } | |
150 | ||
151 | void | |
152 | swap(priority_queue& other) | |
153 | { base_type::swap(other); } | |
154 | }; | |
5e11f978 | 155 | } // namespace __gnu_pbds |
30a96b3b | 156 | //@} heap-based |
a345e45d | 157 | #endif |