]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/libstdc++-v3/contrib/libstdc++-v3-4.3.3/include/ext/pb_ds/list_update_policy.hpp
update
[l4.git] / l4 / pkg / libstdc++-v3 / contrib / libstdc++-v3-4.3.3 / include / ext / pb_ds / list_update_policy.hpp
1 // -*- C++ -*-
2
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.
10
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.
15
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.
20
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.
30
31 // Copyright (C) 2004 Ami Tavory and Vladimir Dreizin, IBM-HRL.
32
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.
41
42 /**
43  * @file list_update_policy.hpp
44  * Contains policies for list update containers.
45  */
46
47 #ifndef PB_DS_LU_POLICY_HPP
48 #define PB_DS_LU_POLICY_HPP
49
50 #include <cstdlib>
51 #include <ext/pb_ds/detail/list_update_policy/counter_lu_metadata.hpp>
52
53 namespace __gnu_pbds
54 {
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   { };
59
60 #define PB_DS_CLASS_T_DEC template<typename Allocator>
61 #define PB_DS_CLASS_C_DEC move_to_front_lu_policy<Allocator>
62
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
67   {
68   public:
69     typedef Allocator allocator;
70       
71     // Metadata on which this functor operates.
72     typedef null_lu_metadata metadata_type;
73       
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;
77       
78     // Creates a metadata object.
79     metadata_type
80     operator()() const;
81       
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;
86       
87   private:
88     static null_lu_metadata s_metadata;
89   };
90   
91 #include <ext/pb_ds/detail/list_update_policy/mtf_lu_policy_imp.hpp>
92
93 #undef PB_DS_CLASS_T_DEC
94 #undef PB_DS_CLASS_C_DEC
95
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>
98
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>
104   {
105   public:
106     typedef Allocator allocator;
107
108     enum
109       {
110         max_count = Max_Count
111       };
112
113     typedef typename allocator::size_type size_type;
114
115     // Metadata on which this functor operates.
116     typedef detail::counter_lu_metadata<size_type> metadata_type;
117
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;
121
122     // Creates a metadata object.
123     metadata_type
124     operator()() const;
125
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;
130
131   private:
132     typedef detail::counter_lu_policy_base<typename Allocator::size_type> base_type;
133   };
134
135 #include <ext/pb_ds/detail/list_update_policy/counter_lu_policy_imp.hpp>
136
137 #undef PB_DS_CLASS_T_DEC
138 #undef PB_DS_CLASS_C_DEC
139
140 } // namespace __gnu_pbds
141
142 #endif