libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005, 2006, 2009, 2010 Free Software Foundation, Inc. 00004 // 00005 // This file is part of the GNU ISO C++ Library. This library is free 00006 // software; you can redistribute it and/or modify it under the terms 00007 // of the GNU General Public License as published by the Free Software 00008 // Foundation; either version 3, or (at your option) any later 00009 // version. 00010 00011 // This library is distributed in the hope that it will be useful, but 00012 // WITHOUT ANY WARRANTY; without even the implied warranty of 00013 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00014 // General Public License for more details. 00015 00016 // Under Section 7 of GPL version 3, you are granted additional 00017 // permissions described in the GCC Runtime Library Exception, version 00018 // 3.1, as published by the Free Software Foundation. 00019 00020 // You should have received a copy of the GNU General Public License and 00021 // a copy of the GCC Runtime Library Exception along with this program; 00022 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see 00023 // <http://www.gnu.org/licenses/>. 00024 00025 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL. 00026 00027 // Permission to use, copy, modify, sell, and distribute this software 00028 // is hereby granted without fee, provided that the above copyright 00029 // notice appears in all copies, and that both that copyright notice 00030 // and this permission notice appear in supporting documentation. None 00031 // of the above authors, nor IBM Haifa Research Laboratories, make any 00032 // representation about the suitability of this software for any 00033 // purpose. It is provided "as is" without express or implied 00034 // warranty. 00035 00036 /** 00037 * @file priority_queue.hpp 00038 * Contains priority_queues. 00039 */ 00040 00041 #ifndef PB_DS_PRIORITY_QUEUE_HPP 00042 #define PB_DS_PRIORITY_QUEUE_HPP 00043 00044 #include <bits/c++config.h> 00045 #include <ext/pb_ds/tag_and_trait.hpp> 00046 #include <ext/pb_ds/detail/priority_queue_base_dispatch.hpp> 00047 #include <ext/pb_ds/detail/standard_policies.hpp> 00048 00049 namespace __gnu_pbds 00050 { 00051 // A priority queue. 00052 template<typename Value_Type, 00053 typename Cmp_Fn = std::less<Value_Type>, 00054 typename Tag = pairing_heap_tag, 00055 typename Allocator = std::allocator<char> > 00056 class priority_queue 00057 : public detail::priority_queue_base_dispatch<Value_Type, 00058 Cmp_Fn,Tag,Allocator>::type 00059 { 00060 private: 00061 typedef typename 00062 detail::priority_queue_base_dispatch<Value_Type, Cmp_Fn, 00063 Tag, Allocator>::type base_type; 00064 00065 public: 00066 typedef Value_Type value_type; 00067 typedef Cmp_Fn cmp_fn; 00068 typedef Tag container_category; 00069 typedef Allocator allocator_type; 00070 typedef typename allocator_type::size_type size_type; 00071 typedef typename allocator_type::difference_type difference_type; 00072 00073 typedef typename allocator_type::template rebind<value_type>::other value_rebind; 00074 typedef typename value_rebind::reference reference; 00075 typedef typename value_rebind::const_reference const_reference; 00076 typedef typename value_rebind::pointer pointer; 00077 typedef typename value_rebind::const_pointer const_pointer; 00078 00079 typedef typename base_type::const_point_iterator const_point_iterator; 00080 typedef typename base_type::point_iterator point_iterator; 00081 typedef typename base_type::const_iterator const_iterator; 00082 typedef typename base_type::iterator iterator; 00083 00084 priority_queue() { } 00085 00086 // Constructor taking some policy objects. r_cmp_fn will be copied 00087 // by the Cmp_Fn object of the container object. 00088 priority_queue(const cmp_fn& r_cmp_fn) : base_type(r_cmp_fn) { } 00089 00090 // Constructor taking __iterators to a range of value_types. The 00091 // value_types between first_it and last_it will be inserted into 00092 // the container object. 00093 template<typename It> 00094 priority_queue(It first_it, It last_it) 00095 { base_type::copy_from_range(first_it, last_it); } 00096 00097 // Constructor taking __iterators to a range of value_types and 00098 // some policy objects The value_types between first_it and 00099 // last_it will be inserted into the container object. r_cmp_fn 00100 // will be copied by the cmp_fn object of the container object. 00101 template<typename It> 00102 priority_queue(It first_it, It last_it, const cmp_fn& r_cmp_fn) 00103 : base_type(r_cmp_fn) 00104 { base_type::copy_from_range(first_it, last_it); } 00105 00106 priority_queue(const priority_queue& other) 00107 : base_type((const base_type& )other) { } 00108 00109 virtual 00110 ~priority_queue() { } 00111 00112 priority_queue& 00113 operator=(const priority_queue& other) 00114 { 00115 if (this != &other) 00116 { 00117 priority_queue tmp(other); 00118 swap(tmp); 00119 } 00120 return *this; 00121 } 00122 00123 void 00124 swap(priority_queue& other) 00125 { base_type::swap(other); } 00126 }; 00127 } // namespace __gnu_pbds 00128 00129 #endif