/[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 91424 - (show annotations)
Tue Oct 26 18:39:32 2004 UTC (15 years, 2 months ago) by manus_eiffel
File size: 4193 byte(s)
Initial revision

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

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23