priority_queue.hpp

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 
00003 // Copyright (C) 2005, 2006, 2009 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 <ext/pb_ds/tag_and_trait.hpp>
00045 #include <ext/pb_ds/detail/priority_queue_base_dispatch.hpp>
00046 #include <ext/pb_ds/detail/standard_policies.hpp>
00047 
00048 namespace __gnu_pbds
00049 {
00050   // A priority queue.
00051   template<typename Value_Type, 
00052        typename Cmp_Fn = std::less<Value_Type>,
00053        typename Tag = pairing_heap_tag,
00054        typename Allocator = std::allocator<char> >
00055   class priority_queue 
00056   : public detail::priority_queue_base_dispatch<Value_Type,Cmp_Fn,Tag,Allocator>::type
00057   {
00058   private:
00059     typedef typename detail::priority_queue_base_dispatch<Value_Type,Cmp_Fn,Tag,Allocator>::type base_type;
00060 
00061   public:
00062     typedef Value_Type                  value_type;
00063     typedef Cmp_Fn                  cmp_fn;
00064     typedef Tag                     container_category;
00065     typedef Allocator                   allocator_type;
00066     typedef typename allocator_type::size_type      size_type;
00067     typedef typename allocator_type::difference_type    difference_type;
00068 
00069     typedef typename allocator_type::template rebind<value_type>::other value_rebind;
00070     typedef typename value_rebind::reference        reference;
00071     typedef typename value_rebind::const_reference  const_reference;
00072     typedef typename value_rebind::pointer      pointer;
00073     typedef typename value_rebind::const_pointer    const_pointer;
00074 
00075     typedef typename base_type::const_point_iterator const_point_iterator;
00076     typedef typename base_type::point_iterator      point_iterator;
00077     typedef typename base_type::const_iterator      const_iterator;
00078     typedef typename base_type::iterator        iterator;
00079 
00080     priority_queue() { }
00081 
00082     // Constructor taking some policy objects. r_cmp_fn will be copied
00083     // by the Cmp_Fn object of the container object.
00084     priority_queue(const cmp_fn& r_cmp_fn) : base_type(r_cmp_fn) { }
00085 
00086     // Constructor taking __iterators to a range of value_types. The
00087     // value_types between first_it and last_it will be inserted into
00088     // the container object.
00089     template<typename It>
00090     priority_queue(It first_it, It last_it)
00091     { base_type::copy_from_range(first_it, last_it); }
00092 
00093     // Constructor taking __iterators to a range of value_types and
00094     // some policy objects The value_types between first_it and
00095     // last_it will be inserted into the container object. r_cmp_fn
00096     // will be copied by the cmp_fn object of the container object.
00097     template<typename It>
00098     priority_queue(It first_it, It last_it, const cmp_fn& r_cmp_fn)
00099     : base_type(r_cmp_fn)
00100     { base_type::copy_from_range(first_it, last_it); }
00101 
00102     priority_queue(const priority_queue& other)
00103     : base_type((const base_type& )other) { }
00104 
00105     virtual
00106     ~priority_queue() { }
00107 
00108     priority_queue& 
00109     operator=(const priority_queue& other)
00110     {
00111       if (this != &other)
00112     {
00113       priority_queue tmp(other);
00114       swap(tmp);
00115     }
00116       return *this;
00117     }
00118 
00119     void
00120     swap(priority_queue& other)
00121     { base_type::swap(other); }
00122   };
00123 } // namespace __gnu_pbds
00124 
00125 #endif 

Generated on Thu Jul 23 21:16:13 2009 for libstdc++ by  doxygen 1.5.8