# priority_queue.hpp

Go to the documentation of this file.

    00001 // -*- C++ -*-
    00002
    00003 // Copyright (C) 2005, 2006 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 2, 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 // You should have received a copy of the GNU General Public License
    00017 // along with this library; see the file COPYING.  If not, write to
    00018 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
    00019 // MA 02111-1307, USA.
    00020
    00021 // As a special exception, you may use this file as part of a free
    00022 // software library without restriction.  Specifically, if other files
    00023 // instantiate templates or use macros or inline functions from this
    00024 // file, or you compile this file and link it with other files to
    00025 // produce an executable, this file does not by itself cause the
    00026 // resulting executable to be covered by the GNU General Public
    00027 // License.  This exception does not however invalidate any other
    00028 // reasons why the executable file might be covered by the GNU General
    00029 // Public License.
    00030
    00031 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
    00032
    00033 // Permission to use, copy, modify, sell, and distribute this software
    00034 // is hereby granted without fee, provided that the above copyright
    00035 // notice appears in all copies, and that both that copyright notice
    00036 // and this permission notice appear in supporting documentation. None
    00037 // of the above authors, nor IBM Haifa Research Laboratories, make any
    00038 // representation about the suitability of this software for any
    00039 // purpose. It is provided "as is" without express or implied
    00040 // warranty.
    00041
    00042 /**
    00043  * @file priority_queue.hpp
    00044  * Contains priority_queues.
    00045  */
    00046
    00047 #ifndef PB_DS_PRIORITY_QUEUE_HPP
    00048 #define PB_DS_PRIORITY_QUEUE_HPP
    00049
    00050 #include <ext/pb_ds/tag_and_trait.hpp>
    00051 #include <ext/pb_ds/detail/priority_queue_base_dispatch.hpp>
    00052 #include <ext/pb_ds/detail/standard_policies.hpp>
    00053
    00054 namespace pb_ds
    00055 {
    00056   // A priority queue.
    00057   template<typename Value_Type,
    00058        typename Cmp_Fn = std::less<Value_Type>,
    00059        typename Tag = pairing_heap_tag,
    00060        typename Allocator = std::allocator<char> >
    00061   class priority_queue
    00062     : public detail::priority_queue_base_dispatch<Value_Type,Cmp_Fn,Tag,Allocator>::type
    00063   {
    00064   private:
    00065     typedef typename detail::priority_queue_base_dispatch<Value_Type,Cmp_Fn,Tag,Allocator>::type base_type;
    00066
    00067   public:
    00068     typedef Value_Type                  value_type;
    00069     typedef Cmp_Fn                  cmp_fn;
    00070     typedef Tag                     container_category;
    00071     typedef Allocator                   allocator;
    00072     typedef typename allocator::size_type       size_type;
    00073     typedef typename allocator::difference_type     difference_type;
    00074
    00075     typedef typename allocator::template rebind<value_type>::other value_rebind;
    00076     typedef typename value_rebind::reference        reference;
    00077     typedef typename value_rebind::const_reference  const_reference;
    00078     typedef typename value_rebind::pointer      pointer;
    00079     typedef typename value_rebind::const_pointer    const_pointer;
    00080
    00081     typedef typename base_type::const_point_iterator const_point_iterator;
    00082     typedef typename base_type::point_iterator      point_iterator;
    00083     typedef typename base_type::const_iterator      const_iterator;
    00084     typedef typename base_type::iterator        iterator;
    00085
    00086     priority_queue() { }
    00087
    00088     // Constructor taking some policy objects. r_cmp_fn will be copied
    00089     // by the Cmp_Fn object of the container object.
    00090     priority_queue(const cmp_fn& r_cmp_fn) : base_type(r_cmp_fn) { }
    00091
    00092     // Constructor taking __iterators to a range of value_types. The
    00093     // value_types between first_it and last_it will be inserted into
    00094     // the container object.
    00095     template<typename It>
    00096     priority_queue(It first_it, It last_it)
    00097     { base_type::copy_from_range(first_it, last_it); }
    00098
    00099     // Constructor taking __iterators to a range of value_types and
    00100     // some policy objects The value_types between first_it and
    00101     // last_it will be inserted into the container object. r_cmp_fn
    00102     // will be copied by the cmp_fn object of the container object.
    00103     template<typename It>
    00104     priority_queue(It first_it, It last_it, const cmp_fn& r_cmp_fn)
    00105     : base_type(r_cmp_fn)
    00106     { base_type::copy_from_range(first_it, last_it); }
    00107
    00108     priority_queue(const priority_queue& other)
    00109     : base_type((const base_type& )other) { }
    00110
    00111     virtual
    00112     ~priority_queue() { }
    00113
    00114     priority_queue&
    00115     operator=(const priority_queue& other)
    00116     {
    00117       if (this !=& other)
    00118     {
    00119       priority_queue tmp(other);
    00120       swap(tmp);
    00121     }
    00122       return *this;
    00123     }
    00124
    00125     void
    00126     swap(priority_queue& other)
    00127     { base_type::swap(other); }
    00128   };
    00129 } // namespace pb_ds
    00130
    00131 #endif