/[eiffelstudio]/trunk/eweasel/tests/incr071/dynamic_chain.e
ViewVC logotype

Contents of /trunk/eweasel/tests/incr071/dynamic_chain.e

Parent Directory Parent Directory | Revision Log Revision Log


Revision 65297 - (show annotations)
Thu Nov 30 20:22:33 2006 UTC (13 years, 2 months ago) by manus
File size: 5210 byte(s)
Moved from trunk/Src/eweasel to trunk/eweasel so that a simple checkout of the source code is not penalized by the lenghty process of checking out all the tests of eweasel.
1 indexing
2
3 description:
4 "Dynamically modifiable chains";
5
6 status: "See notice at end of class";
7 names: dynamic_chain, sequence;
8 access: index, cursor, membership;
9 contents: generic;
10 date: "$Date$";
11 revision: "$Revision$"
12
13 deferred class DYNAMIC_CHAIN [G] inherit
14
15 CHAIN [G]
16 export
17 {ANY} remove, prune_all, prune
18 undefine
19 remove, prune_all, prune
20 end;
21
22 UNBOUNDED [G]
23
24 feature -- Status report
25
26 extendible: BOOLEAN is True;
27 -- May new items be added? (Answer: yes.)
28
29 prunable: BOOLEAN is
30 -- May items be removed? (Answer: yes.)
31 do
32 Result := True
33 end;
34
35 feature -- Element change
36
37 put_front (v: like item) is
38 -- Add `v' at beginning.
39 -- Do not move cursor.
40 deferred
41 ensure
42 new_count: count = old count + 1;
43 item_inserted: first = v
44 end;
45
46 put_left (v: like item) is
47 -- Add `v' to the left of cursor position.
48 -- Do not move cursor.
49 require
50 extendible: extendible;
51 not_before: not before
52 deferred
53 ensure
54 new_count: count = old count + 1;
55 new_index: index = old index + 1
56 end;
57
58 put_right (v: like item) is
59 -- Add `v' to the right of cursor position.
60 -- Do not move cursor.
61 require
62 extendible: extendible;
63 not_after: not after
64 deferred
65 ensure
66 new_count: count = old count + 1;
67 same_index: index = old index
68 end;
69
70 merge_left (other: like Current) is
71 -- Merge `other' into current structure before cursor
72 -- position. Do not move cursor. Empty `other'.
73 require
74 extendible: extendible;
75 not_off: not before;
76 other_exists: other /= Void
77 deferred
78 ensure
79 new_count: count = old count + old other.count;
80 new_index: index = old index + old other.count;
81 other_is_empty: other.is_empty
82 end;
83
84 merge_right (other: like Current) is
85 -- Merge `other' into current structure after cursor
86 -- position. Do not move cursor. Empty `other'.
87 require
88 extendible: extendible;
89 not_off: not after;
90 other_exists: other /= Void
91 deferred
92 ensure
93 new_count: count = old count + old other.count;
94 same_index: index = old index;
95 other_is_empty: other.is_empty
96 end;
97
98 feature -- Removal
99
100 prune (v: like item) is
101 -- Remove first occurrence of `v', if any,
102 -- after cursor position.
103 -- If found, move cursor to right neighbor;
104 -- if not, make structure `exhausted'.
105 do
106 search (v);
107 if not exhausted then
108 remove
109 end
110 end;
111
112 remove_left is
113 -- Remove item to the left of cursor position.
114 -- Do not move cursor.
115 require
116 left_exists: index > 1
117 deferred
118 ensure
119 new_count: count = old count - 1;
120 new_index: index = old index - 1
121 end;
122
123 remove_right is
124 -- Remove item to the right of cursor position.
125 -- Do not move cursor.
126 require
127 right_exists: index < count
128 deferred
129 ensure
130 new_count: count = old count - 1;
131 same_index: index = old index
132 end;
133
134 prune_all (v: like item) is
135 -- Remove all occurrences of `v'.
136 -- (Reference or object equality,
137 -- based on `object_comparison'.)
138 -- Leave structure `exhausted'.
139 do
140 from
141 start;
142 search (v)
143 until
144 exhausted
145 loop
146 remove;
147 search (v)
148 end
149 ensure then
150 is_exhausted: exhausted
151 end;
152
153 wipe_out is
154 -- Remove all items.
155 do
156 from
157 start
158 until
159 is_empty
160 loop
161 remove
162 end
163 end;
164
165 feature -- Duplication
166
167 duplicate (n: INTEGER): like Current is
168 -- Copy of sub-chain beginning at current position
169 -- and having min (`n', `from_here') items,
170 -- where `from_here' is the number of items
171 -- at or to the right of current position.
172 local
173 pos: CURSOR;
174 counter: INTEGER
175 do
176 from
177 Result := new_chain;
178 if object_comparison then
179 Result.compare_objects
180 end
181 pos := cursor
182 until
183 (counter = n) or else exhausted
184 loop
185 Result.extend (item);
186 forth;
187 counter := counter + 1
188 end;
189 go_to (pos)
190 end;
191
192 feature {DYNAMIC_CHAIN} -- Implementation
193
194 new_chain: like Current is
195 -- A newly created instance of the same type.
196 -- This feature may be redefined in descendants so as to
197 -- produce an adequately allocated and initialized object.
198 deferred
199 ensure
200 result_exists: Result /= Void
201 end;
202
203 invariant
204
205 extendible: extendible
206
207 end -- class DYNAMIC_CHAIN
208
209
210 --|----------------------------------------------------------------
211 --| EiffelBase: Library of reusable components for Eiffel.
212 --| Copyright (c) 1993-2006 University of Southern California and contributors.
213 --| For ISE customers the original versions are an ISE product
214 --| covered by the ISE Eiffel license and support agreements.
215 --| EiffelBase may now be used by anyone as FREE SOFTWARE to
216 --| develop any product, public-domain or commercial, without
217 --| payment to ISE, under the terms of the ISE Free Eiffel Library
218 --| License (IFELL) at http://eiffel.com/products/base/license.html.
219 --|
220 --| Interactive Software Engineering Inc.
221 --| ISE Building, 2nd floor
222 --| 270 Storke Road, Goleta, CA 93117 USA
223 --| Telephone 805-685-1006, Fax 805-685-6869
224 --| Electronic mail <info@eiffel.com>
225 --| Customer support e-mail <support@eiffel.com>
226 --| For latest info see award-winning pages: http://eiffel.com
227 --|----------------------------------------------------------------
228

Properties

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

  ViewVC Help
Powered by ViewVC 1.1.23