xref: /openbsd-src/gnu/gcc/libstdc++-v3/include/ext/pb_ds/priority_queue.hpp (revision 404b540a9034ac75a6199ad1a32d1bbc7a0d4210)
1*404b540aSrobert // -*- C++ -*-
2*404b540aSrobert 
3*404b540aSrobert // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
4*404b540aSrobert //
5*404b540aSrobert // This file is part of the GNU ISO C++ Library.  This library is free
6*404b540aSrobert // software; you can redistribute it and/or modify it under the terms
7*404b540aSrobert // of the GNU General Public License as published by the Free Software
8*404b540aSrobert // Foundation; either version 2, or (at your option) any later
9*404b540aSrobert // version.
10*404b540aSrobert 
11*404b540aSrobert // This library is distributed in the hope that it will be useful, but
12*404b540aSrobert // WITHOUT ANY WARRANTY; without even the implied warranty of
13*404b540aSrobert // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14*404b540aSrobert // General Public License for more details.
15*404b540aSrobert 
16*404b540aSrobert // You should have received a copy of the GNU General Public License
17*404b540aSrobert // along with this library; see the file COPYING.  If not, write to
18*404b540aSrobert // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19*404b540aSrobert // MA 02111-1307, USA.
20*404b540aSrobert 
21*404b540aSrobert // As a special exception, you may use this file as part of a free
22*404b540aSrobert // software library without restriction.  Specifically, if other files
23*404b540aSrobert // instantiate templates or use macros or inline functions from this
24*404b540aSrobert // file, or you compile this file and link it with other files to
25*404b540aSrobert // produce an executable, this file does not by itself cause the
26*404b540aSrobert // resulting executable to be covered by the GNU General Public
27*404b540aSrobert // License.  This exception does not however invalidate any other
28*404b540aSrobert // reasons why the executable file might be covered by the GNU General
29*404b540aSrobert // Public License.
30*404b540aSrobert 
31*404b540aSrobert // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32*404b540aSrobert 
33*404b540aSrobert // Permission to use, copy, modify, sell, and distribute this software
34*404b540aSrobert // is hereby granted without fee, provided that the above copyright
35*404b540aSrobert // notice appears in all copies, and that both that copyright notice
36*404b540aSrobert // and this permission notice appear in supporting documentation. None
37*404b540aSrobert // of the above authors, nor IBM Haifa Research Laboratories, make any
38*404b540aSrobert // representation about the suitability of this software for any
39*404b540aSrobert // purpose. It is provided "as is" without express or implied
40*404b540aSrobert // warranty.
41*404b540aSrobert 
42*404b540aSrobert /**
43*404b540aSrobert  * @file priority_queue.hpp
44*404b540aSrobert  * Contains priority_queues.
45*404b540aSrobert  */
46*404b540aSrobert 
47*404b540aSrobert #ifndef PB_DS_PRIORITY_QUEUE_HPP
48*404b540aSrobert #define PB_DS_PRIORITY_QUEUE_HPP
49*404b540aSrobert 
50*404b540aSrobert #include <ext/pb_ds/tag_and_trait.hpp>
51*404b540aSrobert #include <ext/pb_ds/detail/priority_queue_base_dispatch.hpp>
52*404b540aSrobert #include <ext/pb_ds/detail/standard_policies.hpp>
53*404b540aSrobert 
54*404b540aSrobert namespace pb_ds
55*404b540aSrobert {
56*404b540aSrobert   // A priority queue.
57*404b540aSrobert   template<typename Value_Type,
58*404b540aSrobert 	   typename Cmp_Fn = std::less<Value_Type>,
59*404b540aSrobert 	   typename Tag = pairing_heap_tag,
60*404b540aSrobert 	   typename Allocator = std::allocator<char> >
61*404b540aSrobert   class priority_queue
62*404b540aSrobert     : public detail::priority_queue_base_dispatch<Value_Type,Cmp_Fn,Tag,Allocator>::type
63*404b540aSrobert   {
64*404b540aSrobert   private:
65*404b540aSrobert     typedef typename detail::priority_queue_base_dispatch<Value_Type,Cmp_Fn,Tag,Allocator>::type base_type;
66*404b540aSrobert 
67*404b540aSrobert   public:
68*404b540aSrobert     typedef Value_Type 					value_type;
69*404b540aSrobert     typedef Cmp_Fn 					cmp_fn;
70*404b540aSrobert     typedef Tag 					container_category;
71*404b540aSrobert     typedef Allocator 					allocator;
72*404b540aSrobert     typedef typename allocator::size_type 		size_type;
73*404b540aSrobert     typedef typename allocator::difference_type 	difference_type;
74*404b540aSrobert 
75*404b540aSrobert     typedef typename allocator::template rebind<value_type>::other value_rebind;
76*404b540aSrobert     typedef typename value_rebind::reference 		reference;
77*404b540aSrobert     typedef typename value_rebind::const_reference 	const_reference;
78*404b540aSrobert     typedef typename value_rebind::pointer 	   	pointer;
79*404b540aSrobert     typedef typename value_rebind::const_pointer 	const_pointer;
80*404b540aSrobert 
81*404b540aSrobert     typedef typename base_type::const_point_iterator const_point_iterator;
82*404b540aSrobert     typedef typename base_type::point_iterator 		point_iterator;
83*404b540aSrobert     typedef typename base_type::const_iterator 		const_iterator;
84*404b540aSrobert     typedef typename base_type::iterator 		iterator;
85*404b540aSrobert 
priority_queue()86*404b540aSrobert     priority_queue() { }
87*404b540aSrobert 
88*404b540aSrobert     // Constructor taking some policy objects. r_cmp_fn will be copied
89*404b540aSrobert     // by the Cmp_Fn object of the container object.
priority_queue(const cmp_fn & r_cmp_fn)90*404b540aSrobert     priority_queue(const cmp_fn& r_cmp_fn) : base_type(r_cmp_fn) { }
91*404b540aSrobert 
92*404b540aSrobert     // Constructor taking __iterators to a range of value_types. The
93*404b540aSrobert     // value_types between first_it and last_it will be inserted into
94*404b540aSrobert     // the container object.
95*404b540aSrobert     template<typename It>
priority_queue(It first_it,It last_it)96*404b540aSrobert     priority_queue(It first_it, It last_it)
97*404b540aSrobert     { base_type::copy_from_range(first_it, last_it); }
98*404b540aSrobert 
99*404b540aSrobert     // Constructor taking __iterators to a range of value_types and
100*404b540aSrobert     // some policy objects The value_types between first_it and
101*404b540aSrobert     // last_it will be inserted into the container object. r_cmp_fn
102*404b540aSrobert     // will be copied by the cmp_fn object of the container object.
103*404b540aSrobert     template<typename It>
priority_queue(It first_it,It last_it,const cmp_fn & r_cmp_fn)104*404b540aSrobert     priority_queue(It first_it, It last_it, const cmp_fn& r_cmp_fn)
105*404b540aSrobert     : base_type(r_cmp_fn)
106*404b540aSrobert     { base_type::copy_from_range(first_it, last_it); }
107*404b540aSrobert 
priority_queue(const priority_queue & other)108*404b540aSrobert     priority_queue(const priority_queue& other)
109*404b540aSrobert     : base_type((const base_type& )other) { }
110*404b540aSrobert 
111*404b540aSrobert     virtual
~priority_queue()112*404b540aSrobert     ~priority_queue() { }
113*404b540aSrobert 
114*404b540aSrobert     priority_queue&
operator =(const priority_queue & other)115*404b540aSrobert     operator=(const priority_queue& other)
116*404b540aSrobert     {
117*404b540aSrobert       if (this !=& other)
118*404b540aSrobert 	{
119*404b540aSrobert 	  priority_queue tmp(other);
120*404b540aSrobert 	  swap(tmp);
121*404b540aSrobert 	}
122*404b540aSrobert       return *this;
123*404b540aSrobert     }
124*404b540aSrobert 
125*404b540aSrobert     void
swap(priority_queue & other)126*404b540aSrobert     swap(priority_queue& other)
127*404b540aSrobert     { base_type::swap(other); }
128*404b540aSrobert   };
129*404b540aSrobert } // namespace pb_ds
130*404b540aSrobert 
131*404b540aSrobert #endif
132