3 // Copyright (C) 2005, 2006, 2007, 2009, 2010
4 // Free Software Foundation, Inc.
6 // This file is part of the GNU ISO C++ Library. This library is free
7 // software; you can redistribute it and/or modify it under the terms
8 // of the GNU General Public License as published by the Free Software
9 // Foundation; either version 3, or (at your option) any later
12 // This library is distributed in the hope that it will be useful, but
13 // WITHOUT ANY WARRANTY; without even the implied warranty of
14 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 // General Public License for more details.
17 // Under Section 7 of GPL version 3, you are granted additional
18 // permissions described in the GCC Runtime Library Exception, version
19 // 3.1, as published by the Free Software Foundation.
21 // You should have received a copy of the GNU General Public License and
22 // a copy of the GCC Runtime Library Exception along with this program;
23 // see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 // <http://www.gnu.org/licenses/>.
26 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
28 // Permission to use, copy, modify, sell, and distribute this software
29 // is hereby granted without fee, provided that the above copyright
30 // notice appears in all copies, and that both that copyright notice
31 // and this permission notice appear in supporting documentation. None
32 // of the above authors, nor IBM Haifa Research Laboratories, make any
33 // representation about the suitability of this software for any
34 // purpose. It is provided "as is" without express or implied
38 * @file list_update_policy.hpp
39 * Contains policies for list update containers.
42 #ifndef PB_DS_LU_POLICY_HPP
43 #define PB_DS_LU_POLICY_HPP
45 #include <bits/c++config.h>
47 #include <ext/pb_ds/detail/list_update_policy/counter_lu_metadata.hpp>
51 // A null type that means that each link in a list-based container
52 // does not actually need metadata.
53 struct null_lu_metadata
56 #define PB_DS_CLASS_T_DEC template<typename Allocator>
57 #define PB_DS_CLASS_C_DEC move_to_front_lu_policy<Allocator>
59 // A list-update policy that unconditionally moves elements to the
61 template<typename Allocator = std::allocator<char> >
62 class move_to_front_lu_policy
65 typedef Allocator allocator_type;
67 // Metadata on which this functor operates.
68 typedef null_lu_metadata metadata_type;
70 // Reference to metadata on which this functor operates.
71 typedef typename allocator_type::template rebind<metadata_type>::other metadata_rebind;
72 typedef typename metadata_rebind::reference metadata_reference;
74 // Creates a metadata object.
78 // Decides whether a metadata object should be moved to the front
81 operator()(metadata_reference r_metadata) const;
84 static null_lu_metadata s_metadata;
87 #include <ext/pb_ds/detail/list_update_policy/mtf_lu_policy_imp.hpp>
89 #undef PB_DS_CLASS_T_DEC
90 #undef PB_DS_CLASS_C_DEC
92 #define PB_DS_CLASS_T_DEC template<std::size_t Max_Count, class Allocator>
93 #define PB_DS_CLASS_C_DEC counter_lu_policy<Max_Count, Allocator>
95 // A list-update policy that moves elements to the front of the list
96 // based on the counter algorithm.
97 template<std::size_t Max_Count = 5,
98 typename Allocator = std::allocator<char> >
99 class counter_lu_policy
100 : private detail::counter_lu_policy_base<typename Allocator::size_type>
103 typedef Allocator allocator_type;
107 max_count = Max_Count
110 typedef typename allocator_type::size_type size_type;
112 // Metadata on which this functor operates.
113 typedef detail::counter_lu_metadata<size_type> metadata_type;
115 // Reference to metadata on which this functor operates.
116 typedef typename Allocator::template rebind<metadata_type>::other metadata_rebind;
117 typedef typename metadata_rebind::reference metadata_reference;
119 // Creates a metadata object.
123 // Decides whether a metadata object should be moved to the front
126 operator()(metadata_reference r_metadata) const;
129 typedef detail::counter_lu_policy_base<typename Allocator::size_type> base_type;
132 #include <ext/pb_ds/detail/list_update_policy/counter_lu_policy_imp.hpp>
134 #undef PB_DS_CLASS_T_DEC
135 #undef PB_DS_CLASS_C_DEC
137 } // namespace __gnu_pbds