+
Point of view
All features
class FAST_ARRAY [E_]
Summary
General purpose resizable FAST_ARRAYs. The only difference with ARRAY is the fact that the lower bound is actually frozen to 0. The item access is likely to be more efficient as well as loop going from upper to lower just because lower is 0. Keep in mind that even if the lower is frozen to 0 it is really better to use the lower attribute, and not 0 directly, just because you may decide in the future to use another COLLECTION implementation.
Like ARRAY, the FAST_ARRAY implementation uses only one chunk of memory, the storage area which is a NATIVE_ARRAY. One must keep in mind that this internal storage area is always kept left align. Thus, you can expect good performances while using a FAST_ARRAY to modelize a stack behavior with add_last / last / remove_last. Conversely add_first and remove_first are likely to slow down your program if they are too often used. If the fact that lower is stuck to 0 do matter, also consider ARRAY. add_first and remove_first are O(count) commands for FAST_ARRAY.
Direct parents
Inherit list: ARRAYED_COLLECTION, COLLECTION
Insert list: NATIVE_ARRAY_COLLECTOR
Known children
Insert list: MACRO_COMMAND, STACK
Class invariant
Overview
Creation features
{ANY}
Features
{ANY}
Creation and modification:
{ANY}
Modification:
{ANY}
Implementation of deferred:
{ANY}
Garbage collector tuning (very low-level):
{}
  • mark_native_arrays
    For performance reasons, the unused area of storage is always left as it is when some elements are removed.
Implement manifest generic creation (very low-level):
{}
Accessing:
{ANY}
Writing:
{ANY}
Adding:
{ANY}
Removing:
{ANY}
Looking and Searching:
{ANY}
Looking and comparison:
{ANY}
Other features:
{ANY}
Implement manifest generic creation:
{}
{ANY}
Other features:
{ANY}
Agent-based features:
{ANY}
Printing:
{ANY}
{ANY}
{}
Agent-based features:
{ANY}
{}
Indexing:
{ANY}
Accessing:
{ANY}
{ARRAYED_COLLECTION, ARRAYED_COLLECTION_HANDLER}
{ANY}
Interfacing with C:
{ANY}
{ARRAYED_COLLECTION}
{}
lower: INTEGER_32
is 0
constant attribute
{ANY}
Frozen lower bound.
default_create
effective procedure
{ANY}
Create a new with empty FAST_ARRAY with capacity 32.
make (new_count: INTEGER_32)
effective procedure
{ANY}
Make array with range [0 .. new_count - 1].
When new_count = 0 the array is empty.
require
  • new_count >= 0
ensure
with_capacity (needed_capacity: INTEGER_32)
effective procedure
{ANY}
Create an empty array with at least needed_capacity.
require
  • needed_capacity >= 0
ensure
resize (new_count: INTEGER_32)
effective procedure
{ANY}
Resize the array.
When new_count is greater than count, new positions are initialized with appropriate default values.
require
  • new_count >= 0
ensure
is_empty: BOOLEAN
effective function
{ANY}
Is the hoard empty ?
See also count.
ensure
  • definition: Result = count = 0
item (i: INTEGER_32): E_
effective function
{ANY}
Item at the corresponding index i.
See also lower, upper, valid_index.
require
      • valid_index(i)
      • valid_index(i)
      • valid_index(i)
      • valid_index(i)
put (element: E_, i: INTEGER_32)
effective procedure
{ANY}
Make element the item at index i.
require
    • valid_index(i)
    • valid_index(i)
ensure
  • item(i) = element
  • count = old count
add_first (element: E_)
effective procedure
{ANY}
Add a new item in first position : count is increased by one and all other items are shifted right.
See also add_last, first, last, add.
ensure
  • first = element
  • count = 1 + old count
  • lower = old lower
  • upper = 1 + old upper
add_last (element: E_)
effective procedure
{ANY}
Add a new item at the end : count is increased by one.
See also add_first, last, first, add.
ensure
  • last = element
  • count = 1 + old count
  • lower = old lower
  • upper = 1 + old upper
count: INTEGER_32
effective function
{ANY}
Number of available items in the hoard.
See also is_empty
ensure
  • Result >= 0
clear_count
effective procedure
{ANY}
Discard all items (is_empty is True after that call).
If possible, the actual implementation supposed to keep its internal storage area in order to refill Current in an efficient way.
See also clear_count_and_capacity.
ensure
clear_count_and_capacity
effective procedure
{ANY}
Discard all items (is_empty is True after that call).
If possible, the actual implementation supposed to release its internal storage area for this memory to be used by other objects.
See also clear_count.
ensure
copy (other: FAST_ARRAY [E_])
effective procedure
{ANY}
Copy other onto Current.
require
    • not immutable
    • same_dynamic_type(other)
      • not immutable
      • same_dynamic_type(other)
        • not immutable
        • same_dynamic_type(other)
        • not immutable
        • same_dynamic_type(other)
ensure
  • is_equal(other)
set_all_with (v: E_)
effective procedure
{ANY}
Set all items with value v.
See also set_slice_with.
ensure
  • count = old count
from_collection (model: TRAVERSABLE[E_])
effective procedure
{ANY}
Initialize the current object with the contents of model.
require
    • model /= Void
    • useful_work: model /= Current
    • model /= Void
    • useful_work: model /= Current
ensure
  • count = model.count
fast_is_equal (other: FAST_ARRAY [E_]): BOOLEAN
effective function
{ANY}
Do both collections have the same lower, upper, and items?
The basic = is used for comparison of items.
See also is_equal, same_items.
ensure
  • Result implies lower = other.lower and upper = other.upper
is_equal (other: FAST_ARRAY [E_]): BOOLEAN
effective function
{ANY}
Do both collections have the same lower, upper, and items?
Feature is_equal is used for comparison of items.
See also fast_is_equal, same_items.
require
    • other /= Void
      • other /= Void
        • other /= Void
        • other /= Void
ensure
  • commutative: generating_type = other.generating_type implies Result = other.is_equal(Current)
  • Result implies lower = other.lower and upper = other.upper
all_default: BOOLEAN
effective function
{ANY}
Do all items have their type's default value?
Note: for non Void items, the test is performed with the is_default predicate.
See also clear_all.
occurrences (element: E_): INTEGER_32
effective function
{ANY}
Number of occurrences of element using is_equal for comparison.
ensure
  • Result >= 0
fast_occurrences (element: E_): INTEGER_32
effective function
{ANY}
Number of occurrences of element using basic = for comparison.
See also occurrences, index_of.
ensure
  • Result >= 0
first_index_of (element: E_): INTEGER_32
effective function
{ANY}
Give the index of the first occurrence of element using is_equal for comparison.
Answer upper + 1 when element is not inside.
See also fast_first_index_of, index_of, last_index_of, reverse_index_of.
ensure
  • definition: Result = index_of(element, lower)
index_of (element: E_, start_index: INTEGER_32): INTEGER_32
effective function
{ANY}
Using is_equal for comparison, gives the index of the first occurrence of element at or after start_index.
Return upper + 1 if the search for element failed.
See also fast_index_of, reverse_index_of, first_index_of.
ensure
  • Result.in_range(start_index, upper + 1)
  • valid_index(Result) implies (create {SAFE_EQUAL}).test(element, item(Result))
reverse_index_of (element: E_, start_index: INTEGER_32): INTEGER_32
effective function
{ANY}
Using is_equal for comparison, gives the index of the first occurrence of element at or before start_index.
Search is done in reverse direction, which means from the start_index down to the lower index . Answer lower -1 when the search fail.
See also fast_reverse_index_of, last_index_of, index_of.
require
    • valid_index(start_index)
    • valid_index(start_index)
ensure
  • Result.in_range(lower - 1, start_index)
  • valid_index(Result) implies item(Result).is_equal(element)
fast_first_index_of (element: E_): INTEGER_32
effective function
{ANY}
Give the index of the first occurrence of element using basic = for comparison.
Answer upper + 1 when element is not inside.
See also first_index_of, last_index_of, fast_last_index_of.
ensure
  • definition: Result = fast_index_of(element, lower)
fast_index_of (element: E_, start_index: INTEGER_32): INTEGER_32
effective function
{ANY}
Using basic = for comparison, gives the index of the first occurrence of element at or after start_index.
Answer upper + 1 when element when the search fail.
See also index_of, fast_reverse_index_of, fast_first_index_of.
ensure
  • Result.in_range(start_index, upper + 1)
  • valid_index(Result) implies element = item(Result)
fast_reverse_index_of (element: E_, start_index: INTEGER_32): INTEGER_32
effective function
{ANY}
Using basic = comparison, gives the index of the first occurrence of element at or before start_index.
Search is done in reverse direction, which means from the start_index down to the lower index . Answer lower -1 when the search fail.
See also reverse_index_of, fast_index_of, fast_last_index_of.
require
    • valid_index(start_index)
    • valid_index(start_index)
ensure
  • Result.in_range(lower - 1, start_index)
  • valid_index(Result) implies item(Result) = element
subarray (min: INTEGER_32, max: INTEGER_32): FAST_ARRAY [E_]
effective function
{ANY}
New collection consisting of items at indexes in [min .. max].
Result has the same dynamic type as Current. See also slice.
require
  • lower <= min
  • max <= upper
  • min <= max + 1
ensure
  • same_dynamic_type(Result)
  • Result.count = max - min + 1
  • Result.lower = min or Result.lower = 0
slice (min: INTEGER_32, max: INTEGER_32): FAST_ARRAY [E_]
effective function
{ANY}
New collection consisting of items at indexes in [min..max].
Result has the same dynamic type as Current. The lower index of the Result is the same as lower.
See also from_collection, move, replace_all.
require
    • lower <= min
    • max <= upper
    • min <= max + 1
    • lower <= min
    • max <= upper
    • min <= max + 1
ensure
  • same_dynamic_type(Result)
  • Result.count = max - min + 1
  • Result.lower = lower
force (element: E_, index: INTEGER_32)
effective procedure
{ANY}
Make element the item at index, enlarging the collection if necessary (new bounds except index are initialized with default values).
See also put, item, swap.
require
    • index >= lower
    • index >= lower
ensure
  • upper = index.max(old upper)
  • item(index) = element
remove_first
effective procedure
{ANY}
Remove the first element of the collection.
require
    • not is_empty
    • not is_empty
ensure
  • lower = old lower
  • count = old count - 1
  • lower = old lower + 1 xor upper = old upper - 1
remove_head (n: INTEGER_32)
effective procedure
{ANY}
Remove the n elements of the collection.
require
    • n > 0 and n <= count
    • n > 0 and n <= count
ensure
  • count = old count - n
  • lower = old lower + n xor upper = old upper - n
remove (index: INTEGER_32)
effective procedure
{ANY}
Remove the item at position index.
Followings items are shifted left by one position.
See also remove_first, remove_head, remove_tail, remove_last.
require
    • valid_index(index)
    • valid_index(index)
ensure
  • count = old count - 1
  • upper = old upper - 1
new_iterator: ITERATOR[E_]
effective function
{ANY}
ensure
  • Result /= Void
  • Result.generation = generation
mark_native_arrays
effective procedure
{}
For performance reasons, the unused area of storage is always left as it is when some elements are removed.
No time is lost to clean the released area with a Void or a 0 value. (Look for example the remove_last implementation.) Thus, the unused area of storage may contains references of actually unreachable objects. The following mark_native_arrays actually replace the default behavior (the call is automatic) in order to mark only reachable objects.
manifest_make (needed_capacity: INTEGER_32)
effective procedure
{}
Manifest creation of a FAST_ARRAY[E_].
require
  • needed_capacity > 0
manifest_put (index: INTEGER_32, element: E_)
effective procedure
{}
require
    • index >= 0
    • index >= 0
infix "@" (i: INTEGER_32): E_
frozen
effective function
{ANY}
The infix notation which is actually just a synonym for item.
See also item.
require ensure
  • definition: Result = item(i)
swap (i1: INTEGER_32, i2: INTEGER_32)
effective procedure
{ANY}
Swap item at index i1 with item at index i2.
See also item, put.
require ensure
set_slice_with (v: ANY, lower_index: INTEGER_32, upper_index: INTEGER_32)
effective procedure
{ANY}
Set all items in range [lower_index .. upper_index] with v.
See also set_all_with.
require ensure
clear_all
effective procedure
{ANY}
Set every item to its default value.
The count is not affected.
See also clear, all_default.
ensure
add (element: ANY, index: INTEGER_32)
deferred procedure
{ANY}
Add a new element at rank index : count is increased by one and range [index .. upper] is shifted right by one position.
require ensure
append_collection (other: COLLECTION[E_])
effective procedure
{ANY}
Append other to Current.
This feature is obsolete: Use `append_traversable' instead.
append_traversable (other: TRAVERSABLE[E_])
effective procedure
{ANY}
Append other to Current.
See also add_last, add_first, add.
require
  • other /= Void
ensure
remove_last
deferred procedure
{ANY}
Remove the last item.
require ensure
remove_tail (n: INTEGER_32)
deferred procedure
{ANY}
Remove the last n item(s).
require ensure
has (x: ANY): BOOLEAN
effective function
{ANY}
Look for x using is_equal for comparison.
ensure
  • definition: Result = valid_index(first_index_of(x))
fast_has (x: ANY): BOOLEAN
effective function
{ANY}
Look for x using basic = for comparison.
See also has, fast_index_of, index_of.
ensure
  • definition: Result = valid_index(fast_first_index_of(x))
last_index_of (element: ANY): INTEGER_32
effective function
{ANY}
Using is_equal for comparison, gives the index of the last occurrence of element at or before upper.
Search is done in reverse direction, which means from the upper down to the lower index . Answer lower -1 when the search fail.
See also fast_last_index_of, reverse_index_of, index_of.
ensure
  • definition: Result = reverse_index_of(element, upper)
fast_last_index_of (element: ANY): INTEGER_32
effective function
{ANY}
Using basic = for comparison, gives the index of the last occurrence of element at or before upper.
Search is done in reverse direction, which means from the upper down to the lower index . Answer lower -1 when the search fail.
See also fast_reverse_index_of, last_index_of.
ensure
  • definition: Result = fast_reverse_index_of(element, upper)
is_equal_map (other: FAST_ARRAY [E_]): BOOLEAN
effective function
{ANY}
Do both collections have the same lower, upper, and items?
This feature is obsolete: Use `is_equal' instead.
same_items (other: COLLECTION[E_]): BOOLEAN
effective function
{ANY}
Do both collections have the same items?
The basic = is used for comparison of items and indices are not considered (for example this routine may yield True with Current indexed in range [1..2] and other indexed in range [2..3]).
See also is_equal, fast_is_equal.
require
  • other /= Void
ensure
replace_all (old_value: ANY, new_value: ANY)
deferred procedure
{ANY}
Replace all occurrences of the element old_value by new_value using is_equal for comparison.
See also fast_replace_all, move.
ensure
fast_replace_all (old_value: ANY, new_value: ANY)
deferred procedure
{ANY}
Replace all occurrences of the element old_value by new_value using basic = for comparison.
See also replace_all, move.
ensure
move (lower_index: INTEGER_32, upper_index: INTEGER_32, distance: INTEGER_32)
effective procedure
{ANY}
Move range lower_index ..
upper_index by distance positions. Negative distance moves towards lower indices. Free places get default values.
See also slice, replace_all.
require ensure
reverse
deferred procedure
{ANY}
Reverse the order of the elements.
ensure
manifest_semicolon_check: BOOLEAN
is False
constant attribute
{}
enumerate: ENUMERATE[E_]
effective function
{ANY}
get_new_iterator: ITERATOR[E_]
frozen
effective function
{ANY}
This feature is obsolete: Use `new_iterator' instead. This historical SmartEiffel feature is badly named.
for_each (action: PROCEDURE[TUPLE[TUPLE 1[E_]]])
effective procedure
{ANY}
Apply action to every item of Current.
See also for_all, exists, aggregate.
require
  • action /= Void
for_all (test: FUNCTION[TUPLE[TUPLE 1[E_]]]): BOOLEAN
effective function
{ANY}
Do all items satisfy test?
See also for_each, exists, aggregate.
require
  • test /= Void
exists (test: FUNCTION[TUPLE[TUPLE 1[E_]]]): BOOLEAN
effective function
{ANY}
Does at least one item satisfy test?
See also for_each, for_all, aggregate.
require
  • test /= Void
aggregate (action: FUNCTION[TUPLE[TUPLE 2[E_, E_], E_]], initial: E_): E_
effective function
{ANY}
Aggregate all the elements starting from the initial value.
See also for_each, for_all, exists.
require
  • action /= Void
out_in_tagged_out_memory
effective procedure
{ANY}
Append terse printable representation of current object in tagged_out_memory.
require
  • locked: tagged_out_locked
ensure
  • still_locked: tagged_out_locked
  • not_cleared: tagged_out_memory.count >= old tagged_out_memory.count
  • append_only: old tagged_out_memory.twin.is_equal(tagged_out_memory.substring(1, old tagged_out_memory.count))
generation: INTEGER_32
writable attribute
{ANY}
next_generation
effective procedure
{}
ensure
do_all (action: ROUTINE[TUPLE[TUPLE 1[E_]]])
frozen
effective procedure
{ANY}
Apply action to every item of Current.
This feature is obsolete: Use `for_each` instead. This feature is not secure because it accepts a FUNCTION, the result of which is lost.
_inline_agent1 (a: ROUTINE[TUPLE[TUPLE 1[E_]]], e: E_)
frozen
effective procedure
{}
upper: INTEGER_32
deferred function
{ANY}
Maximum index.
See also lower, valid_index, item.
valid_index (i: INTEGER_32): BOOLEAN
effective function
{ANY}
True when i is valid (i.e., inside actual bounds).
See also lower, upper, item.
ensure
first: E_
deferred function
{ANY}
The very first item.
See also last, item.
require ensure
last: E_
deferred function
{ANY}
The last item.
See also first, item.
require ensure
storage: NATIVE_ARRAY[E_]
writable attribute
Internal access to storage location.
from_external (a_storage: POINTER, a_capacity: INTEGER_32)
effective procedure
require
  • a_capacity > 0 implies a_storage.is_not_null
ensure
capacity: INTEGER_32
writable attribute
{ANY}
Internal storage capacity in number of item.
to_external: POINTER
effective function
{ANY}
Gives C access into the internal storage of the ARRAY.
Result is pointing the element at index lower.
NOTE: do not free/realloc the Result. Resizing of the array
      can makes this pointer invalid.
require ensure
  • Result.is_not_null
set_upper (new_upper: INTEGER_32)
effective procedure
mark_item (native_array: NATIVE_ARRAY[E_], index: INTEGER_32)
{}
To be used _only_ inside the definition of mark_native_arrays.
Forces the garbage collector to continue the marking process on the index-th element of the native_array. The element at index can be Void or not Void (the Void-ness test performed inside the mark_item itself).