/[eiffelstudio]/FreeELKS/trunk/library/structures/dispenser/bounded_stack.e
ViewVC logotype

Contents of /FreeELKS/trunk/library/structures/dispenser/bounded_stack.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 91477 - (show annotations)
Sun Jan 14 09:47:13 2007 UTC (13 years ago) by ericb
File size: 3779 byte(s)
Synchronized with ISE 6.0.65740
1 indexing
2
3 description:
4 "Stacks with a bounded physical size, implemented by arrays"
5 legal: "See notice at end of class."
6
7 status: "See notice at end of class."
8 names: dispenser, array;
9 representation: array;
10 access: fixed, lifo, membership;
11 size: fixed;
12 contents: generic;
13 date: "$Date$"
14 revision: "$Revision$"
15
16 class BOUNDED_STACK [G] inherit
17
18 STACK [G]
19 redefine
20 replace, item,
21 linear_representation
22 end
23
24 BOUNDED [G]
25 undefine
26 copy, is_equal
27 end
28
29 create
30
31 make
32
33 feature -- Initialization
34
35 make (n: INTEGER) is
36 -- Create a stack for at most `n' items.
37 require
38 non_negative_argument: n >= 0
39 do
40 create fl.make (0, n)
41 ensure
42 stack_allocated: capacity = n
43 empty_stack: count = 0
44 end
45
46 feature -- Access
47
48 item: G is
49 -- Last item pushed (i.e. top)
50 require else
51 not_empty: count > 0
52 do
53 Result := fl.item (count)
54 end
55
56 item_for_iteration: G is
57 -- Element at current iteration position
58 require
59 not_off: not off
60 do
61 Result := fl.item (index)
62 end
63
64 feature -- Measurement
65
66 count: INTEGER
67
68 capacity: INTEGER is
69 do
70 Result := fl.count - 1
71 end
72
73 occurrences (v: G): INTEGER is
74 do
75 if object_comparison then
76 fl.compare_objects
77 else
78 fl.compare_references
79 end
80 Result := fl.occurrences (v)
81 end
82
83 feature -- Element change
84
85 extend, force, put (v: like item) is
86 -- Push `v' on top.
87 do
88 count := count + 1
89 fl.put (v, count)
90 end
91
92 replace (v: like item) is
93 -- Replace top item by `v'.
94 do
95 fl.put (v, count)
96 end
97 feature -- Access
98
99 has (v: G): BOOLEAN is
100 -- Does `v' appear in stack?
101 -- (Reference or object equality,
102 -- based on `object_comparison'.)
103 do
104 if object_comparison then
105 fl.compare_objects
106 else
107 fl.compare_references
108 end
109 Result := fl.has (v)
110 end
111
112 feature -- Removal
113
114 remove is
115 -- Remove top item.
116 require else
117 not_empty: count /= 0
118 local
119 default_value: like item
120 do
121 fl.put (default_value, count)
122 count := count - 1
123 end
124
125 wipe_out is
126 -- Remove all items.
127 do
128 fl.clear_all
129 count := 0
130 end
131
132 feature -- Status report
133
134 extendible: BOOLEAN is
135 do
136 Result := not full
137 ensure then
138 Result = not full
139 end
140
141 resizable: BOOLEAN is True
142
143 prunable: BOOLEAN is True
144
145 feature -- Conversion
146
147 linear_representation: ARRAYED_LIST [G] is
148 -- Representation as a linear structure
149 -- (in the reverse order of original insertion)
150 local
151 i: INTEGER
152 do
153 from
154 create Result.make (count)
155 i := count
156 until
157 i < 0
158 loop
159 Result.extend (fl.item (i))
160 i := i - 1
161 end
162 end
163
164 feature -- Iteration
165
166 start is
167 -- Move to first position.
168 -- (No effect if empty)
169 do
170 if not is_empty then
171 index := count
172 end
173 end
174
175 finish is
176 -- Move to last position.
177 -- (No effect if empty)
178 do
179 if not is_empty then
180 index := 1
181 end
182 end
183
184 forth is
185 -- Move to next position.
186 do
187 index := index - 1
188 end
189
190 off: BOOLEAN is
191 -- Is there no current item?
192 do
193 Result := (index < 1) or else (index > count)
194 end
195
196 feature {NONE} -- Implementation
197
198 fl: ARRAY [G]
199 -- Storage
200
201 index: INTEGER
202 -- Current place in stack.
203
204 feature {NONE} -- Inapplicable
205
206 prune (v: G) is
207 do
208 end
209
210 invariant
211
212 count_small_enough: count <= capacity
213 extendible_definition: extendible = not full
214
215 indexing
216 library: "EiffelBase: Library of reusable components for Eiffel."
217 copyright: "Copyright (c) 1984-2006, Eiffel Software and others"
218 license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
219 source: "[
220 Eiffel Software
221 356 Storke Road, Goleta, CA 93117 USA
222 Telephone 805-685-1006, Fax 805-685-6869
223 Website http://www.eiffel.com
224 Customer support http://support.eiffel.com
225 ]"
226
227
228
229
230
231
232
233 end -- class BOUNDED_STACK
234
235
236

Properties

Name Value
svn:eol-style native
svn:keywords Author Date Id Revision

  ViewVC Help
Powered by ViewVC 1.1.23