3 // Copyright (C) 2005, 2006 Free Software Foundation, Inc.
5 // This file is part of the GNU ISO C++ Library. This library is free
6 // software; you can redistribute it and/or modify it under the terms
7 // of the GNU General Public License as published by the Free Software
8 // Foundation; either version 2, or (at your option) any later
11 // This library is distributed in the hope that it will be useful, but
12 // WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 // General Public License for more details.
16 // You should have received a copy of the GNU General Public License
17 // along with this library; see the file COPYING. If not, write to
18 // the Free Software Foundation, 59 Temple Place - Suite 330, Boston,
19 // MA 02111-1307, USA.
21 // As a special exception, you may use this file as part of a free
22 // software library without restriction. Specifically, if other files
23 // instantiate templates or use macros or inline functions from this
24 // file, or you compile this file and link it with other files to
25 // produce an executable, this file does not by itself cause the
26 // resulting executable to be covered by the GNU General Public
27 // License. This exception does not however invalidate any other
28 // reasons why the executable file might be covered by the GNU General
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
33 // Permission to use, copy, modify, sell, and distribute this software
34 // is hereby granted without fee, provided that the above copyright
35 // notice appears in all copies, and that both that copyright notice
36 // and this permission notice appear in supporting documentation. None
37 // of the above authors, nor IBM Haifa Research Laboratories, make any
38 // representation about the suitability of this software for any
39 // purpose. It is provided "as is" without express or implied
43 * @file list_update_policy.hpp
44 * Contains policies for list update containers.
47 #ifndef PB_DS_LU_POLICY_HPP
48 #define PB_DS_LU_POLICY_HPP
50 #include <ext/pb_ds/detail/list_update_policy/counter_lu_metadata.hpp>
54 // A null type that means that each link in a list-based container
55 // does not actually need metadata.
56 struct null_lu_metadata
59 #define PB_DS_CLASS_T_DEC template<typename Allocator>
60 #define PB_DS_CLASS_C_DEC move_to_front_lu_policy<Allocator>
62 // A list-update policy that unconditionally moves elements to the
64 template<typename Allocator = std::allocator<char> >
65 class move_to_front_lu_policy
68 typedef Allocator allocator;
70 // Metadata on which this functor operates.
71 typedef null_lu_metadata metadata_type;
73 // Reference to metadata on which this functor operates.
74 typedef typename allocator::template rebind<metadata_type>::other metadata_rebind;
75 typedef typename metadata_rebind::reference metadata_reference;
77 // Creates a metadata object.
81 // Decides whether a metadata object should be moved to the front
84 operator()(metadata_reference r_metadata) const;
87 static null_lu_metadata s_metadata;
90 #include <ext/pb_ds/detail/list_update_policy/mtf_lu_policy_imp.hpp>
92 #undef PB_DS_CLASS_T_DEC
93 #undef PB_DS_CLASS_C_DEC
95 #define PB_DS_CLASS_T_DEC template<size_t Max_Count, class Allocator>
96 #define PB_DS_CLASS_C_DEC counter_lu_policy<Max_Count, Allocator>
98 // A list-update policy that moves elements to the front of the list
99 // based on the counter algorithm.
100 template<size_t Max_Count = 5, typename Allocator = std::allocator<char> >
101 class counter_lu_policy
102 : private detail::counter_lu_policy_base<typename Allocator::size_type>
105 typedef Allocator allocator;
109 max_count = Max_Count
112 typedef typename allocator::size_type size_type;
114 // Metadata on which this functor operates.
115 typedef detail::counter_lu_metadata<size_type> metadata_type;
117 // Reference to metadata on which this functor operates.
118 typedef typename Allocator::template rebind<metadata_type>::other metadata_rebind;
119 typedef typename metadata_rebind::reference metadata_reference;
121 // Creates a metadata object.
125 // Decides whether a metadata object should be moved to the front
128 operator()(metadata_reference r_metadata) const;
131 typedef detail::counter_lu_policy_base<typename Allocator::size_type> base_type;
134 #include <ext/pb_ds/detail/list_update_policy/counter_lu_policy_imp.hpp>
136 #undef PB_DS_CLASS_T_DEC
137 #undef PB_DS_CLASS_C_DEC