1 | <HTML> |
---|
2 | <!-- |
---|
3 | -- Copyright (c) Jeremy Siek 2000 |
---|
4 | -- |
---|
5 | -- Permission to use, copy, modify, distribute and sell this software |
---|
6 | -- and its documentation for any purpose is hereby granted without fee, |
---|
7 | -- provided that the above copyright notice appears in all copies and |
---|
8 | -- that both that copyright notice and this permission notice appear |
---|
9 | -- in supporting documentation. Silicon Graphics makes no |
---|
10 | -- representations about the suitability of this software for any |
---|
11 | -- purpose. It is provided "as is" without express or implied warranty. |
---|
12 | --> |
---|
13 | <Head> |
---|
14 | <Title>Buffer</Title> |
---|
15 | </HEAD> |
---|
16 | <BODY BGCOLOR="#ffffff" LINK="#0000ee" TEXT="#000000" VLINK="#551a8b" |
---|
17 | ALINK="#ff0000"> |
---|
18 | <IMG SRC="../../../boost.png" |
---|
19 | ALT="C++ Boost" width="277" height="86"> |
---|
20 | |
---|
21 | <BR Clear> |
---|
22 | |
---|
23 | <h3>Buffer Concept</h3> |
---|
24 | |
---|
25 | A Buffer is something in which items can be put and removed. |
---|
26 | The Buffer <i>concept</i> has very few requirements. It does |
---|
27 | not require any particular ordering of how the items are stored or in |
---|
28 | what order they will appear when removed, however, there is typically |
---|
29 | some sort of ordering policy. |
---|
30 | |
---|
31 | <h3>Notation</h3> |
---|
32 | |
---|
33 | <table> |
---|
34 | <tr> <td> <tt>B</tt> </td> <td> is a type that models Buffer. </td></tr> |
---|
35 | <tr> <td> <tt>T</tt> </td> <td> is the value type of <tt>B</tt>. </td></tr> |
---|
36 | <tr> <td> <tt>t</tt> </td> <td> is an object of type <tt>T</tt>. </td></tr> |
---|
37 | </table> |
---|
38 | |
---|
39 | |
---|
40 | <h3>Members</h3> |
---|
41 | |
---|
42 | For a type to model the Buffer concept it must have the following members. |
---|
43 | |
---|
44 | <p> |
---|
45 | |
---|
46 | <table border="1"> |
---|
47 | |
---|
48 | <tr> <td><b>Member</b></td> <td><b>Description</b></td> </tr> |
---|
49 | |
---|
50 | <tr> <td> <tt>value_type</tt> </td> |
---|
51 | <td> The type of object stored in the Buffer. The value type |
---|
52 | must be <A href="http://www.sgi.com/tech/stl/Assignable.html">Assignable</a>.</td> |
---|
53 | </tr> |
---|
54 | |
---|
55 | <tr> <td> <tt>size_type</tt> </td> |
---|
56 | <td> An unsigned integral type for representing the number of |
---|
57 | objects in the Buffer.</td> |
---|
58 | </tr> |
---|
59 | |
---|
60 | <tr> <td> <tt>void push(const T& t)</tt> </td> |
---|
61 | <td> Inserts <tt>t</tt> into the Buffer. <tt>size()</tt> will be |
---|
62 | incremented by one.</td> |
---|
63 | </tr> |
---|
64 | |
---|
65 | <tr> <td> <tt>void pop()</tt> </td> |
---|
66 | <td> Removes an object from the Buffer. <tt>size()</tt> will be |
---|
67 | decremented by one. Precondition: <tt>empty()</tt> |
---|
68 | is <tt>false</tt>. </td> |
---|
69 | </tr> |
---|
70 | |
---|
71 | <tr> <td> <tt>T& top()</tt> </td> |
---|
72 | <td> Returns a mutable reference to some object in the Buffer. |
---|
73 | Precondition: <tt>empty()</tt> is <tt>false</tt>.</td> |
---|
74 | </tr> |
---|
75 | |
---|
76 | <tr> <td> <tt>const T& top() const</tt> </td> |
---|
77 | <td> Returns a const reference to some object in the Buffer. |
---|
78 | Precondition: <tt>empty()</tt> is <tt>false</tt>.</td> |
---|
79 | </tr> |
---|
80 | |
---|
81 | <tr> <td> <tt>size_type size() const</tt> </td> |
---|
82 | <td> Returns the number of objects in the Buffer. |
---|
83 | Invariant: <tt>size() >= 0</tt>. </td> |
---|
84 | </tr> |
---|
85 | |
---|
86 | <tr> <td> <tt>bool empty() const</tt> </td> |
---|
87 | <td> Equivalent to <tt>b.size() == 0</tt>.</td> |
---|
88 | </tr> |
---|
89 | |
---|
90 | </table> |
---|
91 | |
---|
92 | <h3>Complexity Guarantees</h3> |
---|
93 | |
---|
94 | <UL> |
---|
95 | |
---|
96 | <LI> <tt>push()</tt>, <tt>pop()</tt>, and <tt>size()</tt> must be at |
---|
97 | most linear time complexity in the size of the Generalized Queue. |
---|
98 | |
---|
99 | <LI> <tt>top()</tt> and <tt>empty()</tt> must be amortized constant time. |
---|
100 | |
---|
101 | </UL> |
---|
102 | |
---|
103 | <h3>Models</h3> |
---|
104 | |
---|
105 | <UL> |
---|
106 | <LI><a href="http://www.sgi.com/tech/stl/stack.html"><tt>std::stack</tt></a> |
---|
107 | <LI><a href="../../../boost/pending/mutable_queue.hpp"><tt>boost::mutable_queue</tt></a> |
---|
108 | </UL> |
---|
109 | |
---|
110 | <p> |
---|
111 | |
---|
112 | <br> |
---|
113 | <HR> |
---|
114 | <TABLE> |
---|
115 | <TR valign=top> |
---|
116 | <TD nowrap>Copyright © 2000-2001</TD><TD> |
---|
117 | <A HREF="../../../people/jeremy_siek.htm">Jeremy Siek</A>, Indiana University and C++ Library & Compiler Group/SGI (<A HREF="mailto:jsiek@engr.sgi.com">jsiek@engr.sgi.com</A>) |
---|
118 | </TD></TR></TABLE> |
---|
119 | |
---|
120 | </BODY> |
---|
121 | </HTML> |
---|
122 | |
---|