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