Install gcc-4.4.0-tdm-1-core-2.tar.gz
[msysgit.git] / mingw / lib / gcc / mingw32 / 4.3.3 / include / c++ / ext / pb_ds / list_update_policy.hpp
blob5a63a3e16dc6ff05238a029c104fd43593f9f7b3
1 // -*- C++ -*-
3 // Copyright (C) 2005, 2006, 2007 Free Software Foundation, Inc.
4 //
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
9 // version.
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
29 // Public License.
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
40 // warranty.
42 /**
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 <cstdlib>
51 #include <ext/pb_ds/detail/list_update_policy/counter_lu_metadata.hpp>
53 namespace __gnu_pbds
55 // A null type that means that each link in a list-based container
56 // does not actually need metadata.
57 struct null_lu_metadata
58 { };
60 #define PB_DS_CLASS_T_DEC template<typename Allocator>
61 #define PB_DS_CLASS_C_DEC move_to_front_lu_policy<Allocator>
63 // A list-update policy that unconditionally moves elements to the
64 // front of the list.
65 template<typename Allocator = std::allocator<char> >
66 class move_to_front_lu_policy
68 public:
69 typedef Allocator allocator;
71 // Metadata on which this functor operates.
72 typedef null_lu_metadata metadata_type;
74 // Reference to metadata on which this functor operates.
75 typedef typename allocator::template rebind<metadata_type>::other metadata_rebind;
76 typedef typename metadata_rebind::reference metadata_reference;
78 // Creates a metadata object.
79 metadata_type
80 operator()() const;
82 // Decides whether a metadata object should be moved to the front
83 // of the list.
84 inline bool
85 operator()(metadata_reference r_metadata) const;
87 private:
88 static null_lu_metadata s_metadata;
91 #include <ext/pb_ds/detail/list_update_policy/mtf_lu_policy_imp.hpp>
93 #undef PB_DS_CLASS_T_DEC
94 #undef PB_DS_CLASS_C_DEC
96 #define PB_DS_CLASS_T_DEC template<size_t Max_Count, class Allocator>
97 #define PB_DS_CLASS_C_DEC counter_lu_policy<Max_Count, Allocator>
99 // A list-update policy that moves elements to the front of the list
100 // based on the counter algorithm.
101 template<size_t Max_Count = 5, typename Allocator = std::allocator<char> >
102 class counter_lu_policy
103 : private detail::counter_lu_policy_base<typename Allocator::size_type>
105 public:
106 typedef Allocator allocator;
108 enum
110 max_count = Max_Count
113 typedef typename allocator::size_type size_type;
115 // Metadata on which this functor operates.
116 typedef detail::counter_lu_metadata<size_type> metadata_type;
118 // Reference to metadata on which this functor operates.
119 typedef typename Allocator::template rebind<metadata_type>::other metadata_rebind;
120 typedef typename metadata_rebind::reference metadata_reference;
122 // Creates a metadata object.
123 metadata_type
124 operator()() const;
126 // Decides whether a metadata object should be moved to the front
127 // of the list.
128 bool
129 operator()(metadata_reference r_metadata) const;
131 private:
132 typedef detail::counter_lu_policy_base<typename Allocator::size_type> base_type;
135 #include <ext/pb_ds/detail/list_update_policy/counter_lu_policy_imp.hpp>
137 #undef PB_DS_CLASS_T_DEC
138 #undef PB_DS_CLASS_C_DEC
140 } // namespace __gnu_pbds
142 #endif