]> git.ipfire.org Git - thirdparty/gcc.git/blame - libstdc++-v3/docs/html/ext/pb_assoc/list_updates.html
* typeck.c (build_modify_expr): Tidy diagnostic message.
[thirdparty/gcc.git] / libstdc++-v3 / docs / html / ext / pb_assoc / list_updates.html
CommitLineData
fd1e1726
BK
1<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
2<html>
3 <head>
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">
7 </head>
8
9<body bgcolor = "white">
10
11<h1>List-Update Containers</h1>
12
13<p>
14 This section describes policies for list updates. It is organized as follows:
15</p>
16
17<ol>
18 <li> The <a href = "#general">General Terms</a> Subsection describes general
19 terms.
20 </li>
21 <li> The <a href = "#imp_pb_assoc">Implementation in <tt>pb_assoc</tt></a>
22 Subsection describes the implementation of these concepts in <tt>pb_assoc</tt>.
23 </li>
24</ol>
25
26
27<h2><a name = "general">General Terms</a></h2>
28
29<p>
30 Associative containers use some attributes of the keys of which they store: tree-based
31containers use the ability to compare keys; hash-based containers use the ability to map
32keys into numbers.
33</p>
34
35<p>
36 In the (rare) case where keys can only be checked for equivalence, these
37types of containers cannot be used. In such a case, storing the entries in a list is a reasonable solution.
38Clearly, the order of the elements within the list affects performance; ideally, frequently accessed elements
39should be at the front of the list.
40</p>
41
42<p>
43 Many remarkable (online competitive
44[<a href = "references.html#motwani95random">motwani95random</a>])
45algorithms exist for reordering lists to reflect access prediction
46[<a href = "references.html#andrew04mtf">andrew04mtf</a>]. Some of these algorithms require storing
47metadata with each key, while others do not. Some of these algorithms require only the ability to
48move an element to the front of the list, while others require the ability to interchange an element and
49its predecessor.
50</p>
51
52<p>
53 For example, Figure
54<a href = "#lu">-A
55The counter algorithm
56</a>
57shows the counter algorithm. Each node contains both a key and a count metadata (shown in bold).
58When an element is accessed (<i>e.g.</i> 6)
59its count is incremented, as shown in
60Figure
61<a href = "#lu">
62The counter algorithm
63</a>-B.
64If the count reaches some predetermined value, say 10, as shown in
65Figure
66<a href = "#lu">
67The counter algorithm
68</a>-C,
69the count is set to 0
70and the node is moved to the front of the list, as in
71Figure
72<a href = "#lu">
73The counter algorithm
74</a>-D.
75
76
77</p>
78
79<h6 align = "center">
80<a name = "lu">
55e35fb7 81<img src = "lu_ops.jpg" width = "65%">
fd1e1726
BK
82</a>
83</h6>
84<h6 align = "center">
85The counter algorithm.
86</h6>
87
88
89
90<h2><a name = "imp_pb_assoc">Implementation in <tt>pb_assoc</tt></a></h2>
91
92<p>
93 The <tt>pb_assoc</tt> library allows instantiating lists with policies
94implementing any algorithm moving nodes to the front of the list (policies implementing
95algorithms interchanging nodes are currently unsupported).
96</p>
97
98<p>
99 Associative containers based on lists are parameterized by a <tt>Update_Policy</tt> parameter.
100This parameter defines the type of metadata each node contains, how to create the metadata, and how to
101decide, using this metadata, whether to move a node to the front of the list.
102 A list-based associative container object derives (publicly) from its update policy.
103</p>
104
105<p>
106 An instantiation of <tt>Update_Policy</tt> must define internally <tt>update_metadata</tt> as the metadata
107it requires. Internally, each node of the list contains, besides the usual key and data, an instance
108of <tt><b>typename</b> Update_Policy::update_metadata</tt>.
109</p>
110
111<p>
112 An instantiation of <tt>Update_Policy</tt> must define internally two operators:
113</p>
114<pre>
115update_metadata
116 <b>operator</b>()
117 ();
118
119<b>bool</b>
120 <b>operator</b>()
121 (update_metadata &);
122</pre>
123
124<p>
125 The first is called by the container object, when creating a new node, to create the node's metadata. The
126second is called by the container object, when a node is accessed (<i>e.g.</i>, when a find operation's key
127is equivalent to the key of the node), to determine whether to move the node to the front of the list.
128</p>
129
130<p>
131 Additionally, the library contains implementations of the move-to-front and counter policies. These
132are described in
133<a href="interface.html#policy_classes">Policy Classes</a>.
134</p>
135
136</body>
137
138</html>