1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
4 <title>List Updates</title>
5 <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
6 <meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
9 <body bgcolor = "white">
11 <h1>List-Update Containers</h1>
15 This section describes list-based containers. It is organized as follows.
19 <li> <a href = "#overview">Overview</a> is an overview.</li>
20 <li> <a href = "#list_updates">List Updates</a> describes updating lists
21 as elements are accessed.</li>
25 <h2><a name = "overview">Overview</a></h2>
28 Associative containers typically use some attributes of the keys of which they store: tree-based
29 containers use the ability to compare keys; hash-based containers use the ability to map
34 In some cases it is better to avoid this:
39 Hash-based and tree-based containers typically require additional memory
43 Hash-based and tree-based containers require extra information
44 about keys: hash-based containers need hash functors, tree-based containers need
45 comparison functors. In some (rare) cases, a key might be encapsulated to the extent that it is not possible to supply these functors.
50 In such cases, storing the entries in a unique-key list is a reasonable solution.
51 This uses the minimal amount of memory, and requires only an equivalence functor.
52 Clearly, the order of the elements within the list affects performance; ideally, frequently accessed elements
53 should be at the front of the list.
57 Many remarkable (online competitive
58 [<a href = "references.html#motwani95random">motwani95random</a>])
59 algorithms exist for reordering lists to reflect access prediction
60 [<a href = "references.html#andrew04mtf">andrew04mtf</a>].
65 <a href = "#lu_cd">List-update containers</a>
66 shows the container-hierarchy; the list-based container is circled.
71 <img src = "lu_cd.jpg" width = "70%" alt = "no image">
75 List-update containers.
80 The list-based container has the following declaration:
87 <b>class</b> Eq_Fn = std::equal_to<Key>,
88 <b>class</b> Update_Policy =
89 <a href = "move_to_front_lu_policy.html">move_to_front_lu_policy<></a>,
90 <b>class</b> Allocator =
91 std::allocator<<b>char</b>> >
92 <b>class</b> <a href = "lu_assoc_cntnr.html">lu_assoc_cntnr</a>;
97 The parameters have the following meaning:
100 <li> <tt>Key</tt> is the key type.
102 <li> <tt>Data</tt> is the data-policy, and is explained in
103 <a href = "ms_gen.html#ds_policy">Mapping-Semantics Genericity::Data Types as a Policy</a>.
105 <li> <tt>Eq_Fn</tt> is a key equivalence functor.</li>
106 <li> <tt>Update_Policy</tt> is a policy updating
107 positions in the list based on access patterns. It is described in
108 the following subsection.
110 <li> <tt>Allocator</tt> is (surprisingly) an allocator type.
118 <h2><a name = "list_updates">List Updates</a></h2>
121 This subsection describes list-update policies. It is organized as follows.
125 <li> <a href = "#general">General Terms</a> describes general
128 <li> <a href = "#imp_pb_assoc">Implementation in <tt>pb_assoc</tt></a>
129 describes the implementation of these concepts in <tt>pb_assoc</tt>.
136 <h3><a name = "general">General Terms</a></h3>
142 The counter algorithm
144 shows the counter algorithm. Each node contains both a key and a count metadata (shown in bold).
145 When an element is accessed (<i>e.g.</i> 6)
146 its count is incremented, as shown in
149 The counter algorithm
151 If the count reaches some predetermined value, say 10, as shown in
154 The counter algorithm
156 the count is set to 0
157 and the node is moved to the front of the list, as in
160 The counter algorithm
166 <h6 align = "center">
168 <img src = "lu_ops.jpg" width = "65%">
171 <h6 align = "center">
172 The counter algorithm.
177 <h3><a name = "imp_pb_assoc">Implementation in <tt>pb_assoc</tt></a></h3>
180 The <tt>pb_assoc</tt> library allows instantiating lists with policies
181 implementing any algorithm moving nodes to the front of the list (policies implementing
182 algorithms interchanging nodes are currently unsupported).
186 Associative containers based on lists are parameterized by a <tt>Update_Policy</tt> parameter.
187 This parameter defines the type of metadata each node contains, how to create the metadata, and how to
188 decide, using this metadata, whether to move a node to the front of the list.
189 A list-based associative container object derives (publicly) from its update policy.
193 An instantiation of <tt>Update_Policy</tt> must define internally <tt>update_metadata</tt> as the metadata
194 it requires. Internally, each node of the list contains, besides the usual key and data, an instance
195 of <tt><b>typename</b> Update_Policy::update_metadata</tt>.
199 An instantiation of <tt>Update_Policy</tt> must define internally two operators:
212 The first is called by the container object, when creating a new node, to create the node's metadata. The
213 second is called by the container object, when a node is accessed (<i>e.g.</i>, when a find operation's key
214 is equivalent to the key of the node), to determine whether to move the node to the front of the list.
218 Additionally, the library contains implementations of the move-to-front and counter policies. These
220 <a href="interface.html#policy_classes">Policy Classes</a>.