1 
manus 
65296 
indexing 
2 



3 


description: 
4 


"Structures whose items may be accessed sequentially, oneway"; 
5 



6 


status: "See notice at end of class"; 
7 


names: sequential, traversing; 
8 


access: membership; 
9 


contents: generic; 
10 


date: "$Date$"; 
11 


revision: "$Revision$" 
12 



13 


deferred class LINEAR [G] inherit 
14 



15 


TRAVERSABLE [G] 
16 



17 


feature  Access 
18 



19 


has (v: like item): BOOLEAN is 
20 


 Does structure include an occurrence of `v'? 
21 


 (Reference or object equality, 
22 


 based on `object_comparison'.) 
23 


do 
24 


start; 
25 


if not off then 
26 


search (v) 
27 


end; 
28 


Result := not exhausted 
29 


end; 
30 



31 


index_of (v: like item; i: INTEGER): INTEGER is 
32 


 Index of `i'th occurrence of `v'. 
33 


 0 if none. 
34 


 (Reference or object equality, 
35 


 based on `object_comparison'.) 
36 


require 
37 


positive_occurrences: i > 0 
38 


local 
39 


occur, pos: INTEGER 
40 


do 
41 


if object_comparison and v /= Void then 
42 


from 
43 


start 
44 


pos := 1 
45 


until 
46 


off or (occur = i) 
47 


loop 
48 


if item /= Void and then v.is_equal (item) then 
49 


occur := occur + 1 
50 


end 
51 


forth 
52 


pos := pos + 1 
53 


end 
54 


else 
55 


from 
56 


start 
57 


pos := 1 
58 


until 
59 


off or (occur = i) 
60 


loop 
61 


if item = v then 
62 


occur := occur + 1 
63 


end 
64 


forth 
65 


pos := pos + 1 
66 


end 
67 


end 
68 


if occur = i then 
69 


Result := pos  1 
70 


end 
71 


ensure 
72 


non_negative_result: Result >= 0 
73 


end 
74 



75 


search (v: like item) is 
76 


 Move to first position (at or after current 
77 


 position) where `item' and `v' are equal. 
78 


 (Reference or object equality, 
79 


 based on `object_comparison'.) 
80 


 If no such position ensure that `exhausted' will be true. 
81 


do 
82 


if object_comparison and v /= Void then 
83 


from 
84 


until 
85 


exhausted or else (item /= Void and then v.is_equal (item)) 
86 


loop 
87 


forth 
88 


end 
89 


else 
90 


from 
91 


until 
92 


exhausted or else v = item 
93 


loop 
94 


forth 
95 


end 
96 


end 
97 


ensure 
98 


object_found: (not exhausted and object_comparison) 
99 


implies equal (v, item) 
100 


item_found: (not exhausted and not object_comparison) 
101 


implies v = item 
102 


end 
103 



104 


index: INTEGER is 
105 


 Index of current position 
106 


deferred 
107 


end; 
108 



109 


occurrences (v: G): INTEGER is 
110 


 Number of times `v' appears. 
111 


 (Reference or object equality, 
112 


 based on `object_comparison'.) 
113 


do 
114 


from 
115 


start; 
116 


search (v) 
117 


until 
118 


exhausted 
119 


loop 
120 


Result := Result + 1; 
121 


forth; 
122 


search (v) 
123 


end; 
124 


end; 
125 



126 


feature  Status report 
127 



128 


exhausted: BOOLEAN is 
129 


 Has structure been completely explored? 
130 


do 
131 


Result := off 
132 


ensure 
133 


exhausted_when_off: off implies Result 
134 


end; 
135 



136 


after: BOOLEAN is 
137 


 Is there no valid position to the right of current one? 
138 


deferred 
139 


end; 
140 



141 


off: BOOLEAN is 
142 


 Is there no current item? 
143 


do 
144 


Result := is_empty or after 
145 


end; 
146 



147 


feature  Cursor movement 
148 



149 


finish is 
150 


 Move to last position. 
151 


deferred 
152 


end; 
153 



154 


forth is 
155 


 Move to next position; if no next position, 
156 


 ensure that `exhausted' will be true. 
157 


require 
158 


not_after: not after 
159 


deferred 
160 


ensure 
161 


 moved_forth_before_end: (not after) implies index = old index + 1 
162 


end; 
163 



164 


feature  Conversion 
165 



166 


linear_representation: LINEAR [G] is 
167 


 Representation as a linear structure 
168 


do 
169 


Result := Current 
170 


end; 
171 



172 


invariant 
173 



174 


after_constraint: after implies off 
175 



176 


end  class LINEAR 
177 



178 



179 


 
180 


 EiffelBase: Library of reusable components for Eiffel. 
181 


 Copyright (c) 19932006 University of Southern California and contributors. 
182 


 For ISE customers the original versions are an ISE product 
183 


 covered by the ISE Eiffel license and support agreements. 
184 


 EiffelBase may now be used by anyone as FREE SOFTWARE to 
185 


 develop any product, publicdomain or commercial, without 
186 


 payment to ISE, under the terms of the ISE Free Eiffel Library 
187 


 License (IFELL) at http://eiffel.com/products/base/license.html. 
188 


 
189 


 Interactive Software Engineering Inc. 
190 


 ISE Building, 2nd floor 
191 


 270 Storke Road, Goleta, CA 93117 USA 
192 


 Telephone 8056851006, Fax 8056856869 
193 


 Electronic mail <info@eiffel.com> 
194 


 Customer support email <support@eiffel.com> 
195 


 For latest info see awardwinning pages: http://eiffel.com 
196 


 
197 


