libstdc++
|
00001 // -*- C++ -*- 00002 00003 // Copyright (C) 2005, 2006, 2007, 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 list_update_policy.hpp 00038 * Contains policies for list update containers. 00039 */ 00040 00041 #ifndef PB_DS_LU_POLICY_HPP 00042 #define PB_DS_LU_POLICY_HPP 00043 00044 #include <cstdlib> 00045 #include <ext/pb_ds/detail/list_update_policy/counter_lu_metadata.hpp> 00046 00047 namespace __gnu_pbds 00048 { 00049 // A null type that means that each link in a list-based container 00050 // does not actually need metadata. 00051 struct null_lu_metadata 00052 { }; 00053 00054 #define PB_DS_CLASS_T_DEC template<typename Allocator> 00055 #define PB_DS_CLASS_C_DEC move_to_front_lu_policy<Allocator> 00056 00057 // A list-update policy that unconditionally moves elements to the 00058 // front of the list. 00059 template<typename Allocator = std::allocator<char> > 00060 class move_to_front_lu_policy 00061 { 00062 public: 00063 typedef Allocator allocator_type; 00064 00065 // Metadata on which this functor operates. 00066 typedef null_lu_metadata metadata_type; 00067 00068 // Reference to metadata on which this functor operates. 00069 typedef typename allocator_type::template rebind<metadata_type>::other metadata_rebind; 00070 typedef typename metadata_rebind::reference metadata_reference; 00071 00072 // Creates a metadata object. 00073 metadata_type 00074 operator()() const; 00075 00076 // Decides whether a metadata object should be moved to the front 00077 // of the list. 00078 inline bool 00079 operator()(metadata_reference r_metadata) const; 00080 00081 private: 00082 static null_lu_metadata s_metadata; 00083 }; 00084 00085 #include <ext/pb_ds/detail/list_update_policy/mtf_lu_policy_imp.hpp> 00086 00087 #undef PB_DS_CLASS_T_DEC 00088 #undef PB_DS_CLASS_C_DEC 00089 00090 #define PB_DS_CLASS_T_DEC template<size_t Max_Count, class Allocator> 00091 #define PB_DS_CLASS_C_DEC counter_lu_policy<Max_Count, Allocator> 00092 00093 // A list-update policy that moves elements to the front of the list 00094 // based on the counter algorithm. 00095 template<size_t Max_Count = 5, typename Allocator = std::allocator<char> > 00096 class counter_lu_policy 00097 : private detail::counter_lu_policy_base<typename Allocator::size_type> 00098 { 00099 public: 00100 typedef Allocator allocator_type; 00101 00102 enum 00103 { 00104 max_count = Max_Count 00105 }; 00106 00107 typedef typename allocator_type::size_type size_type; 00108 00109 // Metadata on which this functor operates. 00110 typedef detail::counter_lu_metadata<size_type> metadata_type; 00111 00112 // Reference to metadata on which this functor operates. 00113 typedef typename Allocator::template rebind<metadata_type>::other metadata_rebind; 00114 typedef typename metadata_rebind::reference metadata_reference; 00115 00116 // Creates a metadata object. 00117 metadata_type 00118 operator()() const; 00119 00120 // Decides whether a metadata object should be moved to the front 00121 // of the list. 00122 bool 00123 operator()(metadata_reference r_metadata) const; 00124 00125 private: 00126 typedef detail::counter_lu_policy_base<typename Allocator::size_type> base_type; 00127 }; 00128 00129 #include <ext/pb_ds/detail/list_update_policy/counter_lu_policy_imp.hpp> 00130 00131 #undef PB_DS_CLASS_T_DEC 00132 #undef PB_DS_CLASS_C_DEC 00133 00134 } // namespace __gnu_pbds 00135 00136 #endif