-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathspecial.e
More file actions
980 lines (913 loc) · 25 KB
/
special.e
File metadata and controls
980 lines (913 loc) · 25 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
note
description: "[
Special objects: homogeneous sequences of values,
used to represent arrays and strings
]"
library: "Free implementation of ELKS library"
status: "See notice at end of class."
legal: "See notice at end of class."
date: "$Date$"
revision: "$Revision$"
external_alias: "[
`external_alias' note lists the pairs of aliasing occuring after
the execution of each external feature. Each pair is of form (v,w)
where `v' is an attribute and `w' may be an attribute, local variable,
an argument, or '+' (to denote `create'). Pairs are separated by '-'.
The pair (v,+) indicates `v' will be aliased to a fresh object of the
type of `v' (all previous aliases will be lost, e.g. create v). An empty
set of pairs '{}' indicates no aliasing will be performed.
`items' is a special (non-existing) attribute representing all positions
of the array after subsuming.
]"
frozen class
SPECIAL [T]
inherit
ABSTRACT_SPECIAL
redefine
debug_output
end
READABLE_INDEXABLE [T]
redefine
new_cursor
end
create
make_empty,
make_filled,
make_from_native_array
feature {NONE} -- Initialization
make_empty (n: INTEGER)
-- Create a special object for `n' entries.
note
external_alias: "{(items,+)}"
require
non_negative_argument: n >= 0
external
"built_in"
ensure
capacity_set: capacity = n
count_set: count = 0
end
make_filled (v: T; n: INTEGER)
-- Create a special object for `n' entries initialized with `v'.
note
external_alias: "{(items,+),(items, v)}"
require
non_negative_argument: n >= 0
do
make_empty (n)
fill_with (v, 0, n - 1)
ensure
capacity_set: capacity = n
count_set: count = n
filled: filled_with (v, 0, n - 1)
end
make_from_native_array (an_array: like native_array)
-- Create a special object from `an_array'.
note
external_alias: "{}"
require
is_dotnet: {PLATFORM}.is_dotnet
an_array_not_void: an_array /= Void
do
end
feature -- Access
item alias "[]" (i: INTEGER): T assign put
-- Item at `i'-th position.
-- (indices begin at 0)
note
external_alias: "{(Result,items)}"
external
"built_in"
end
at alias "@" (i: INTEGER): T
-- Item at `i'-th position.
-- (indices begin at 0)
note
external_alias: "{(Result,items)}"
require
valid_index: valid_index (i)
do
Result := item (i)
end
index_of (v: T; start_position: INTEGER): INTEGER
-- Index of first occurrence of item identical to `v'.
-- -1 if none.
-- (Use object equality for comparison.)
note
external_alias: "{}"
require
valid_start_position: start_position >= 0
local
nb: INTEGER
do
from
Result := start_position
nb := count
until
Result >= nb or else item (Result) ~ v
loop
Result := Result + 1
end
if Result >= nb then
Result := -1
end
ensure
found_or_not_found: Result = -1 or else (Result >= 0 and then Result < count)
end
item_address (i: INTEGER): POINTER
-- Address of element at position `i'.
-- Use only when interfacing with C externals when Current is guaranteed to not move in memory.
note
external_alias: "{}"
require
not_dotnet: not {PLATFORM}.is_dotnet
index_large_enough: i >= 0
index_small_enough: i < count
do
Result := base_address + i * element_size
ensure
element_address_not_null: Result /= default_pointer
end
base_address: POINTER
-- Address of element at position `0'.
-- Use only when interfacing with C externals when Current is guaranteed to not move in memory.
note
external_alias: "{}"
require
not_dotnet: not {PLATFORM}.is_dotnet
external
"built_in"
ensure
base_address_not_null: Result /= default_pointer
end
native_array: NATIVE_ARRAY [T]
-- Only for compatibility with .NET.
note
external_alias: "{(Result,+)}"
require
is_dotnet: {PLATFORM}.is_dotnet
do
create Result
end
to_array: ARRAY [T]
-- Build an array representation of Current from `1' to `count'.
do
create Result.make_from_special (Current)
ensure
to_array_attached: Result /= Void
to_array_lower_set: Result.lower = 1
to_array_upper_set: Result.upper = count
end
new_cursor: SPECIAL_ITERATION_CURSOR [T]
-- <Precursor>
do
create Result.make (Current)
end
feature -- Measurement
lower: INTEGER = 0
-- Minimum index of Current.
upper: INTEGER
-- Maximum index of Current.
note
external_alias: "{}"
do
Result := count - 1
end
count: INTEGER
-- Count of special area.
note
external_alias: "{}"
external
"built_in"
end
capacity: INTEGER
-- Capacity of special area.
note
external_alias: "{}"
external
"built_in"
end
feature -- Status report
filled_with (v: T; start_index, end_index: INTEGER): BOOLEAN
-- Are all items between index `start_index' and `end_index'
-- set to `v'?
-- (Use reference equality for comparison.)
note
external_alias: "{}"
require
start_index_non_negative: start_index >= 0
start_index_not_too_big: start_index <= end_index + 1
end_index_valid: end_index < count
local
i: INTEGER
do
from
Result := True
i := start_index
until
i > end_index or else not Result
loop
Result := item (i) = v
i := i + 1
end
end
same_items (other: like Current; source_index, destination_index, n: INTEGER): BOOLEAN
-- Are the `n' elements of `other' from `source_index' position the same as
-- the `n' elements of `Current' from `destination_index'?
-- (Use reference equality for comparison.)
note
external_alias: "{}"
require
other_not_void: other /= Void
source_index_non_negative: source_index >= 0
destination_index_non_negative: destination_index >= 0
n_non_negative: n >= 0
n_is_small_enough_for_source: source_index + n <= other.count
n_is_small_enough_for_destination: destination_index + n <= count
local
i, j, nb: INTEGER
do
Result := True
if other /= Current then
from
i := source_index
j := destination_index
nb := source_index + n
until
i = nb
loop
if other.item (i) /= item (j) then
Result := False
i := nb - 1
end
i := i + 1
j := j + 1
end
end
ensure
valid_on_empty_area: n = 0 implies Result
end
valid_index (i: INTEGER): BOOLEAN
-- Is `i' within the bounds of Current?
note
external_alias: "{}"
do
Result := 0 <= i and i < count
end
feature -- Element change
put (v: T; i: INTEGER)
-- Replace `i'-th item by `v'.
-- (Indices begin at 0.)
note
external_alias: "{(items,v)}"
require
index_large_enough: i >= 0
index_small_enough: i < count
external
"built_in"
ensure
inserted: item (i) = v
same_count: count = old count
same_capacity: capacity = old capacity
end
force (v: T; i: INTEGER)
-- If `i' is equal to `count' increase `count' by one and insert `v' at index `count',
-- otherwise replace `i'-th item by `v'.
-- (Indices begin at 0.)
note
external_alias: "{(items,v)}"
require
index_large_enough: i >= 0
index_small_enough: i <= count
not_full: i = count implies count < capacity
do
if i < count then
put (v, i)
else
extend (v)
end
ensure
count_updated: count = (i + 1).max (old count)
same_capacity: capacity = old capacity
inserted: item (i) = v
end
extend (v: T)
-- Add `v' at index `count'.
note
external_alias: "{(items,v)}"
require
count_small_enough: count < capacity
external
"built_in"
ensure
count_increased: count = old count + 1
same_capacity: capacity = old capacity
inserted: item (count - 1) = v
end
extend_filled (v: T)
-- Set items between `count' and `capacity - 1' with `v'.
note
external_alias: "{(items,v)}"
do
fill_with (v, count, capacity - 1)
ensure
same_capacity: capacity = old capacity
count_increased: count = capacity
filled: filled_with (v, old count, capacity - 1)
end
fill_with (v: T; start_index, end_index: INTEGER)
-- Set items between `start_index' and `end_index' with `v'.
note
external_alias: "{(items,v)}"
require
start_index_non_negative: start_index >= 0
start_index_in_bound: start_index <= count
start_index_not_too_big: start_index <= end_index + 1
end_index_valid: end_index < capacity
local
i, nb: INTEGER
l_count: like count
do
from
i := start_index
l_count := count.min (end_index + 1)
nb := l_count
until
i = nb
loop
put (v, i)
i := i + 1
end
from
i := l_count
nb := end_index + 1
until
i = nb
loop
extend (v)
i := i + 1
end
ensure
same_capacity: capacity = old capacity
count_definition: count = (old count).max (end_index + 1)
filled: filled_with (v, start_index, end_index)
end
fill_with_default (start_index, end_index: INTEGER)
-- Clear items between `start_index' and `end_index'.
note
external_alias: "{(items,{T}.default)}"
require
is_self_initializing: ({T}).has_default
start_index_non_negative: start_index >= 0
start_index_not_too_big: start_index <= end_index + 1
end_index_valid: end_index < count
do
fill_with (({T}).default, start_index, end_index)
ensure
filled: filled_with (({T}).default, start_index, end_index)
end
insert_data (other: SPECIAL [T]; source_index, destination_index, n: INTEGER)
-- Insert `n' elements of `other' from `source_index' position to Current at
-- `destination_index' and shift elements between `destination_index' and `count'
-- to the right. Other elements of Current remain unchanged.
note
external_alias: "{(items,other.items)}"
require
other_not_void: other /= Void
source_index_non_negative: source_index >= 0
destination_index_non_negative: destination_index >= 0
destination_index_in_bound: destination_index <= count
n_non_negative: n >= 0
n_is_small_enough_for_source: source_index + n <= other.count
n_is_small_enough_for_destination: count + n <= capacity
same_type: other.conforms_to (Current)
local
l_remaining_items, l_offset, l_nb_items_left: INTEGER
l_source_index, l_end_index, l_destination_index: INTEGER
do
l_remaining_items := count - destination_index
if l_remaining_items = 0 then
-- It is being added at the end of Current, therefore we can simply extend.
copy_data (other, source_index, destination_index, n)
elseif n <= l_remaining_items then
-- Simple case where we can perform a move of the existing items to the end
-- and then copy the elements of `other'.
move_data (destination_index, destination_index + n, l_remaining_items)
copy_data (other, source_index, destination_index, n)
else
-- Because we cannot have uninitialized items, we cannot move all the remaining items beyond count
-- instead we copy by chunks of `l_remaining_items'.
from
l_source_index := source_index
l_destination_index := destination_index
l_end_index := source_index + n
l_nb_items_left := n
l_offset := l_remaining_items
until
l_source_index >= l_end_index
loop
move_data (l_destination_index, l_destination_index + l_offset, l_remaining_items)
copy_data (other, l_source_index, l_destination_index, l_offset)
l_destination_index := l_destination_index + l_offset
l_source_index := l_source_index + l_offset
-- Compute how many more items we have to copy.
l_nb_items_left := l_nb_items_left - l_remaining_items
l_offset := l_offset.min (l_nb_items_left)
end
end
ensure
copied: same_items (other, source_index, destination_index, n)
count_updated: count = old count + n
end
copy_data (other: SPECIAL [T]; source_index, destination_index, n: INTEGER)
-- Copy `n' elements of `other' from `source_index' position to Current at
-- `destination_index'. Other elements of Current remain unchanged.
note
external_alias: "{(items,other.items)}"
require
other_not_void: other /= Void
source_index_non_negative: source_index >= 0
destination_index_non_negative: destination_index >= 0
destination_index_in_bound: destination_index <= count
n_non_negative: n >= 0
n_is_small_enough_for_source: source_index + n <= other.count
n_is_small_enough_for_destination: destination_index + n <= capacity
same_type: other.conforms_to (Current)
local
i, j, nb: INTEGER
do
if other = Current then
move_data (source_index, destination_index, n)
else
from
i := source_index
j := destination_index
nb := source_index + n
until
i = nb
loop
force (other.item (i), j)
i := i + 1
j := j + 1
end
end
ensure
copied: same_items (other, source_index, destination_index, n)
count_updated: count = (old count).max (destination_index + n)
end
move_data (source_index, destination_index, n: INTEGER)
-- Move `n' elements of Current from `source_start' position to `destination_index'.
-- Other elements remain unchanged.
note
external_alias: "{}"
require
source_index_non_negative: source_index >= 0
destination_index_non_negative: destination_index >= 0
destination_index_in_bound: destination_index <= count
n_non_negative: n >= 0
n_is_small_enough_for_source: source_index + n <= count
n_is_small_enough_for_destination: destination_index + n <= capacity
do
if source_index = destination_index then
elseif source_index > destination_index then
if destination_index + n < source_index then
non_overlapping_move (source_index, destination_index, n)
else
overlapping_move (source_index, destination_index, n)
end
else
if source_index + n < destination_index then
non_overlapping_move (source_index, destination_index, n)
else
overlapping_move (source_index, destination_index, n)
end
end
ensure
moved: same_items (old twin, source_index, destination_index, n)
count_updated: count = (old count).max (destination_index + n)
end
overlapping_move (source_index, destination_index, n: INTEGER)
-- Move `n' elements of Current from `source_start' position to `destination_index'.
-- Other elements remain unchanged.
note
external_alias: "{}"
require
source_index_non_negative: source_index >= 0
destination_index_non_negative: destination_index >= 0
destination_index_in_bound: destination_index <= count
n_non_negative: n >= 0
different_source_and_target: source_index /= destination_index
n_is_small_enough_for_source: source_index + n <= count
n_is_small_enough_for_destination: destination_index + n <= capacity
local
i, nb: INTEGER
l_offset: INTEGER
do
if source_index < destination_index then
-- We shift from left to right starting from the end
-- due to possible overlapping.
from
i := source_index + n - 1
nb := source_index - 1
l_offset := destination_index - source_index
if destination_index + n >= count then
-- Initialize elements above `count' to a dummy item.
fill_with (item (source_index), count, destination_index + n - 1)
end
check
l_offset_positive: l_offset > 0
end
until
i = nb
loop
put (item (i), i + l_offset)
i := i - 1
end
else
-- We shift from right to left.
from
i := source_index
nb := source_index + n
l_offset := source_index - destination_index
check
l_offset_positive: l_offset > 0
end
until
i = nb
loop
force (item (i), i - l_offset)
i := i + 1
end
end
ensure
moved: same_items (old twin, source_index, destination_index, n)
count_updated: count = (old count).max (destination_index + n)
end
non_overlapping_move (source_index, destination_index, n: INTEGER)
-- Move `n' elements of Current from `source_start' position to `destination_index'.
-- Other elements remain unchanged.
note
external_alias: "{}"
require
source_index_non_negative: source_index >= 0
destination_index_non_negative: destination_index >= 0
destination_index_in_bound: destination_index <= count
n_non_negative: n >= 0
different_source_and_target: source_index /= destination_index
non_overlapping:
(source_index < destination_index implies source_index + n < destination_index) or
(source_index > destination_index implies destination_index + n < source_index)
n_is_small_enough_for_source: source_index + n <= count
n_is_small_enough_for_destination: destination_index + n <= capacity
local
i, nb: INTEGER
l_offset: INTEGER
do
from
i := source_index
nb := source_index + n
l_offset := destination_index - source_index
until
i = nb
loop
force (item (i), i + l_offset)
i := i + 1
end
ensure
moved: same_items (Current, source_index, destination_index, n)
count_updated: count = (old count).max (destination_index + n)
end
feature -- Resizing
keep_head (n: INTEGER)
-- Keep the first `n' entries.
note
external_alias: "{}"
require
non_negative_argument: n >= 0
less_than_count: n <= count
do
set_count (n)
ensure
count_updated: count = n
kept: same_items (old twin, 0, 0, n)
end
keep_tail (n: INTEGER)
-- Keep the last `n' entries.
note
external_alias: "{}"
require
non_negative_argument: n >= 0
less_than_count: n <= count
do
overlapping_move (count - n, 0, n)
set_count (n)
ensure
count_updated: count = n
kept: same_items (old twin, n, 0, n)
end
remove_head (n: INTEGER)
-- Remove the first `n' entries.
note
external_alias: "{}"
require
non_negative_argument: n >= 0
less_than_count: n <= count
do
keep_tail (count - n)
ensure
count_updated: count = old count - n
kept: same_items (old twin, n, 0, count)
end
remove_tail (n: INTEGER)
-- Keep the first `count - n' entries.
note
external_alias: "{}"
require
non_negative_argument: n >= 0
less_than_count: n <= count
do
keep_head (count - n)
ensure
count_updated: count = old count - n
kept: same_items (old twin, 0, 0, count)
end
resized_area (n: INTEGER): like Current
-- A copy of Current with a count of `n'.
note
external_alias: "{(Result.items,items)}"
require
n_non_negative: n >= 0
do
create Result.make_empty (n)
Result.copy_data (Current, 0, 0, n.min (count))
ensure
Result_not_void: Result /= Void
Result_different_from_current: Result /= Current
new_count: Result.count = n.min (old count)
new_capacity: Result.capacity = n
preserved: Result.same_items (Current, 0, 0, n.min (old count))
end
resized_area_with_default (a_default_value: T; n: INTEGER): like Current
-- Create a copy of Current with a count of `n' where not yet initialized
-- entries are set to `a_default_value'.
note
external_alias: "{(Result.items,items)}"
require
n_non_negative: n >= 0
do
create Result.make_empty (n)
if n > count then
Result.copy_data (Current, 0, 0, count)
Result.fill_with (a_default_value, count, n - 1)
else
Result.copy_data (Current, 0, 0, n)
end
ensure
Result_not_void: Result /= Void
Result_different_from_current: Result /= Current
new_count: Result.count = n
new_capacity: Result.capacity = n
preserved: Result.same_items (Current, 0, 0, n.min (old count))
end
aliased_resized_area (n: INTEGER): like Current
-- Try to resize `Current' with a count of `n', if not
-- possible a new copy.
note
external_alias: "{(Result.items,items)}"
require
n_non_negative: n >= 0
external
"built_in"
ensure
Result_not_void: Result /= Void
new_count: Result.count = n.min (old count)
new_capacity: Result.capacity = n
preserved: Result.same_items (old twin, 0, 0, n.min (old count))
end
aliased_resized_area_with_default (a_default_value: T; n: INTEGER): like Current
-- Try to resize `Current' with a count of `n', if not
-- possible a new copy. Non yet initialized entries are set to `a_default_value'.
note
external_alias: "{(Result.items,items)}"
require
n_non_negative: n >= 0
do
Result := aliased_resized_area (n)
Result.fill_with (a_default_value, Result.count, n - 1)
ensure
Result_not_void: Result /= Void
new_count: Result.count = n
new_capacity: Result.capacity = n
preserved: Result.same_items (old twin, 0, 0, n.min (old count))
end
feature -- Removal
replace_all (v: T)
-- Replace all items with `v'.
note
external_alias: "{(items,+),(items,v)}"
local
i: INTEGER
do
from
i := count - 1
until
i < 0
loop
put (v, i)
i := i - 1
end
ensure
cleared: filled_with (v, 0, upper)
end
wipe_out
-- Reset count to zero.
note
external_alias: "{(items,+)}"
do
set_count (0)
ensure
same_capacity: capacity = old capacity
count_reset: count = 0
end
clear_all
-- Reset all items to default values.
note
external_alias: "{(items,+)}"
obsolete
"Because of the new precondition, it is recommended to use `fill_with' instead. [2017-05-31]"
require
has_default: ({T}).has_default
do
fill_with_default (0, upper)
ensure
same_capacity: capacity = old capacity
count_reset: count = old count
end
feature -- Iteration
do_all_in_bounds (action: PROCEDURE [T]; start_index, end_index: INTEGER)
-- Apply `action' to every item, from first to last.
-- Semantics not guaranteed if `action' changes the structure;
-- in such a case, apply iterator to clone of structure instead.
require
action_not_void: action /= Void
local
i, nb: INTEGER
do
from
i := start_index
nb := end_index
until
i > nb
loop
action.call ([item (i)])
i := i + 1
end
end
do_if_in_bounds (action: PROCEDURE [T]; test: FUNCTION [T, BOOLEAN]; start_index, end_index: INTEGER)
-- Apply `action' to every item that satisfies `test', from first to last.
-- Semantics not guaranteed if `action' or `test' changes the structure;
-- in such a case, apply iterator to clone of structure instead.
require
action_not_void: action /= Void
test_not_void: test /= Void
local
i, nb: INTEGER
do
from
i := start_index
nb := end_index
until
i > nb
loop
if test.item ([item (i)]) then
action.call ([item (i)])
end
i := i + 1
end
end
there_exists_in_bounds (test: FUNCTION [T, BOOLEAN]; start_index, end_index: INTEGER): BOOLEAN
-- Is `test' true for at least one item?
require
test_not_void: test /= Void
local
i, nb: INTEGER
do
from
i := start_index
nb := end_index
until
i > nb or Result
loop
Result := test.item ([item (i)])
i := i + 1
end
end
for_all_in_bounds (test: FUNCTION [T, BOOLEAN]; start_index, end_index: INTEGER): BOOLEAN
-- Is `test' true for all items?
require
test_not_void: test /= Void
local
i, nb: INTEGER
do
from
i := start_index
nb := end_index
Result := True
until
i > nb or not Result
loop
Result := test.item ([item (i)])
i := i + 1
end
end
do_all_with_index_in_bounds (action: PROCEDURE [T, INTEGER]; start_index, end_index: INTEGER)
-- Apply `action' to every item, from first to last.
-- `action' receives item and its index.
-- Semantics not guaranteed if `action' changes the structure;
-- in such a case, apply iterator to clone of structure instead.
require
action_not_void: action /= Void
local
i, j, nb: INTEGER
do
from
i := start_index
j := lower
nb := end_index
until
i > nb
loop
action.call ([item (i), j])
j := j + 1
i := i + 1
end
end
do_if_with_index_in_bounds (action: PROCEDURE [T, INTEGER]; test: FUNCTION [T, INTEGER, BOOLEAN]; start_index, end_index: INTEGER)
-- Apply `action' to every item that satisfies `test', from first to last.
-- `action' and `test' receive the item and its index.
-- Semantics not guaranteed if `action' or `test' changes the structure;
-- in such a case, apply iterator to clone of structure instead.
require
action_not_void: action /= Void
test_not_void: test /= Void
local
i, j, nb: INTEGER
do
from
i := start_index
j := lower
nb := end_index
until
i > nb
loop
if test.item ([item (i), j]) then
action.call ([item (i), j])
end
j := j + 1
i := i + 1
end
end
feature -- Output
debug_output: STRING
-- String that should be displayed in debugger to represent `Current'.
do
Result := Precursor
Result.append_string (", capacity=")
Result.append_integer (capacity)
end
feature {NONE} -- Implementation
element_size: INTEGER
-- Size of elements.
note
external_alias: "{}"
external
"built_in"
ensure
element_size_non_negative: Result >= 0
end
set_count (n: INTEGER)
-- Set `count' with `n'.
note
external_alias: "{}"
require
n_non_negative: n >= 0
valid_new_count: n <= count
external
"built_in"
ensure
count_set: count = n
capacity_preserved: capacity = old capacity
end
invariant
consistent_count: count = upper - lower + 1
note
copyright: "Copyright (c) 1984-2020, Eiffel Software and others"
license: "Eiffel Forum License v2 (see http://www.eiffel.com/licensing/forum.txt)"
source: "[
Eiffel Software
5949 Hollister Ave., Goleta, CA 93117 USA
Telephone 805-685-1006, Fax 805-685-6869
Website http://www.eiffel.com
Customer support http://support.eiffel.com
]"
end