3 // Copyright (C) 2005, 2006, 2007, 2009, 2010, 2011
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/lu_counter_metadata.hpp>
48 #include <ext/pb_ds/tag_and_trait.hpp>
53 * A list-update policy that unconditionally moves elements to the
54 * front of the list. A null type means that each link in a
55 * list-based container does not actually need metadata.
57 template<typename _Alloc = std::allocator<char> >
58 class lu_move_to_front_policy
61 typedef _Alloc allocator_type;
63 /// Metadata on which this functor operates.
64 typedef null_type metadata_type;
67 typedef typename _Alloc::template rebind<metadata_type> __rebind_m;
70 /// Reference to metadata on which this functor operates.
71 typedef typename __rebind_m::other::reference metadata_reference;
73 /// Creates a metadata object.
76 { return s_metadata; }
78 /// Decides whether a metadata object should be moved to the front
81 operator()(metadata_reference r_metadata) const
85 static null_type s_metadata;
89 * A list-update policy that moves elements to the front of the
90 * list based on the counter algorithm.
92 template<std::size_t Max_Count = 5, typename _Alloc = std::allocator<char> >
93 class lu_counter_policy
94 : private detail::lu_counter_policy_base<typename _Alloc::size_type>
97 typedef _Alloc allocator_type;
98 typedef typename allocator_type::size_type size_type;
102 /// When some element is accessed this number of times, it
103 /// will be moved to the front of the list.
104 max_count = Max_Count
107 /// Metadata on which this functor operates.
108 typedef detail::lu_counter_metadata<size_type> metadata_type;
111 typedef detail::lu_counter_policy_base<size_type> base_type;
112 typedef typename _Alloc::template rebind<metadata_type> __rebind_m;
115 /// Reference to metadata on which this functor operates.
116 typedef typename __rebind_m::other::reference metadata_reference;
118 /// Creates a metadata object.
121 { return base_type::operator()(max_count); }
123 /// Decides whether a metadata object should be moved to the front
126 operator()(metadata_reference r_data) const
127 { return base_type::operator()(r_data, max_count); }
129 } // namespace __gnu_pbds