+
Point of view
All features
expanded class NATIVE_ARRAY [E_]
Summary
This class gives access to the lowest level for arrays. As any low level array, you can get high performances with NATIVE_ARRAYs, but you loose most valid bounds checks (as you can do in plain C code for example).
Note: this class is the basic support for most of our high-level arrays-like classes: STRING, ARRAY, FAST_ARRAY as well as MUTABLE_BIG_INTEGER. Each class using some attribute of some NATIVE_ARRAY type needs an attribute named capacity with value set to the size of the actual NATIVE_ARRAY. Value has to be adjusted after each calloc/realloc/create_from.
Direct parents
Insert list: SAFE_EQUAL
Overview
Creation features
Features
Basic features:
{ANY}
{ANY}
Comparison:
{ANY}
Searching:
{ANY}
Removing:
{ANY}
Replacing:
{ANY}
  • replace_all (old_value: E_, new_value: E_, upper: INTEGER_32)
    Replace all occurrences of the element old_value by new_value using is_equal for comparison.
  • fast_replace_all (old_value: E_, new_value: E_, upper: INTEGER_32)
    Replace all occurrences of the element old_value by new_value using basic = for comparison.
Adding:
{ANY}
  • copy_at (at: INTEGER_32, src: NATIVE_ARRAY [E_], src_capacity: INTEGER_32)
    Copy range [0 .. src_capacity - 1] of src to range [at .. at + src_capacity - 1] of Current.
  • slice_copy (at: INTEGER_32, src: NATIVE_ARRAY [E_], src_min: INTEGER_32, src_max: INTEGER_32)
    Copy range [src_min .. src_max] of src to range [at .. at + src_max - src_min] of Current.
Other:
{ANY}
Interfacing with other languages:
{ANY}
Implement manifest generic creation.
{}
{ANY}
  • test (e1: E_, e2: E_): BOOLEAN
    In order to avoid run-time type errors, feature safe_equal calls is_equal only when e1 and e2 have exactly the same dynamic type.
  • safe_equal (e1: E_, e2: E_): BOOLEAN
    In order to avoid run-time type errors, feature safe_equal calls is_equal only when e1 and e2 have exactly the same dynamic type.
element_sizeof: INTEGER_32
{ANY}
The size in number of bytes for type E_.
calloc (nb_elements: INTEGER_32): NATIVE_ARRAY [E_]
{ANY}
Allocate a new array of nb_elements of type E_.
The new array is initialized with default values.
require
  • nb_elements > 0
ensure
item (index: INTEGER_32): E_
{ANY}
To read an item.
Assume that calloc is already done and that index is the range [0 .. nb_elements-1].
require
  • index >= 0
put (element: E_, index: INTEGER_32)
{ANY}
To write an item.
Assume that calloc is already done and that index is the range [0 .. nb_elements-1].
require
  • index >= 0
ensure
  • item(index) = element
realloc (old_nb_elts: INTEGER_32, new_nb_elts: INTEGER_32): NATIVE_ARRAY [E_]
effective function
{ANY}
Assume Current is a valid NATIVE_ARRAY in range [0 .. old_nb_elts-1].
Allocate a bigger new array in range [0 .. new_nb_elts-1]. Old range is copied in the new allocated array. New items are initialized with default values.
require ensure
memcmp (other: NATIVE_ARRAY [E_], capacity: INTEGER_32): BOOLEAN
effective function
{ANY}
True if all elements in range [0 .. capacity-1] are identical using is_equal.
Assume Current and other are big enough. See also fast_memcmp.
require
slice_memcmp (at: INTEGER_32, other: NATIVE_ARRAY [E_], other_lower: INTEGER_32, other_upper: INTEGER_32): BOOLEAN
effective function
{ANY}
True if all elements in range [0 .. other_upper - other_lower] are identical to the elements in range [other_lower .. other_upper] of other using is_equal.
Assume Current and other are big enough. See also slice_fast_memcmp.
require
  • at >= 0
  • other_lower >= 0
  • other_upper >= other_lower - 1
  • other_upper >= other_lower implies other.is_not_null
fast_memcmp (other: NATIVE_ARRAY [E_], capacity: INTEGER_32): BOOLEAN
effective function
{ANY}
Same jobs as memcmp but uses infix "=" instead of is_equal.
require
slice_fast_memcmp (at: INTEGER_32, other: NATIVE_ARRAY [E_], other_lower: INTEGER_32, other_upper: INTEGER_32): BOOLEAN
effective function
{ANY}
Same jobs as slice_memcmp but uses infix "=" instead of is_equal.
require
  • at >= 0
  • other_lower >= 0
  • other_upper >= other_lower - 1
  • other_upper >= other_lower implies other.is_not_null
deep_memcmp (other: NATIVE_ARRAY [E_], capacity: INTEGER_32): BOOLEAN
effective function
{ANY}
Same jobs as memcmp but uses is_deep_equal instead of is_equal.
require
slice_deep_memcmp (at: INTEGER_32, other: NATIVE_ARRAY [E_], other_lower: INTEGER_32, other_upper: INTEGER_32): BOOLEAN
effective function
{ANY}
Same jobs as slice_memcmp but uses is_deep_equal instead of is_equal.
require
  • at >= 0
  • other_lower >= 0
  • other_upper >= other_lower - 1
  • other_upper >= other_lower implies other.is_not_null
first_index_of (element: E_, upper: INTEGER_32): INTEGER_32
effective function
{ANY}
Using is_equal for comparison, gives the index of the first occurrence of element at or after 0.
Answer upper + 1 when the search fail. See also fast_index_of, reverse_index_of.
require
  • upper >= 0
ensure
  • Result.in_range(0, upper + 1)
  • Result <= upper implies safe_equal(element, item(Result))
index_of (element: E_, start_index: INTEGER_32, upper: 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.
Answer upper + 1 when the search fail. See also fast_index_of, reverse_index_of.
require
  • start_index >= 0
  • start_index <= upper
ensure
  • Result.in_range(start_index, upper + 1)
  • Result <= upper implies safe_equal(element, item(Result))
reverse_index_of (element: E_, upper: INTEGER_32): INTEGER_32
effective function
{ANY}
Using is_equal for comparison, gives the index of the first occurrence of element at or before upper.
Search is done in reverse direction, which means from upper down to the 0. Answer -1 when the search fail. See also fast_reverse_index_of, index_of.
require
  • upper >= -1
ensure
  • Result.in_range(-1, upper)
  • Result > 0 implies safe_equal(element, item(Result))
fast_index_of (element: E_, start_index: INTEGER_32, upper: 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 the search fail. See also index_of, reverse_index_of.
require
  • start_index >= 0
  • start_index <= upper + 1
ensure
  • Result.in_range(start_index, upper + 1)
  • Result <= upper implies element = item(Result)
fast_reverse_index_of (element: E_, upper: INTEGER_32): INTEGER_32
effective function
{ANY}
Using basic = for comparison, gives the index of the first occurrence of element at or before upper.
Search is done in reverse direction, which means from upper down to the 0. Answer -1 when the search fail. See also reverse_index_of, index_of.
require
  • upper >= -1
ensure
  • Result.in_range(-1, upper)
  • Result > 0 implies element = item(Result)
fast_first_index_of (element: E_, upper: INTEGER_32): INTEGER_32
effective function
{ANY}
Using basic = for comparison, gives the index of the first occurrence of element at or after 0.
Answer upper + 1 when the search fail. See also fast_index_of, reverse_index_of.
require
  • upper >= 0
ensure
  • Result.in_range(0, upper + 1)
  • Result <= upper implies element = item(Result)
has (element: E_, upper: INTEGER_32): BOOLEAN
effective function
{ANY}
Look for element using is_equal for comparison.
Also consider fast_has to choose the most appropriate.
require
  • upper >= -1
slice_has (element: E_, lower: INTEGER_32, upper: INTEGER_32): BOOLEAN
effective function
{ANY}
Look for element using is_equal for comparison.
Also consider slice_fast_has to choose the most appropriate.
require
  • lower >= 0
  • upper >= lower - 1
fast_has (element: E_, upper: INTEGER_32): BOOLEAN
effective function
{ANY}
Look for element using basic = for comparison.
Also consider has to choose the most appropriate.
require
  • upper >= -1
slice_fast_has (element: E_, lower: INTEGER_32, upper: INTEGER_32): BOOLEAN
effective function
{ANY}
Look for element using is_equal for comparison.
Also consider slice_fast_has to choose the most appropriate.
require
  • lower >= 0
  • upper >= lower - 1
remove_first (upper: INTEGER_32)
effective procedure
{ANY}
Assume upper is a valid index.
Move range [1 .. upper] by 1 position left.
require
  • upper >= 0
remove (index: INTEGER_32, upper: INTEGER_32)
effective procedure
{ANY}
Assume upper is a valid index.
Move range [index + 1 .. upper] by 1 position left.
require
  • index >= 0
  • index <= upper
replace_all (old_value: E_, new_value: E_, upper: INTEGER_32)
effective procedure
{ANY}
Replace all occurrences of the element old_value by new_value using is_equal for comparison.
See also fast_replace_all to choose the appropriate one.
require
  • upper >= -1
fast_replace_all (old_value: E_, new_value: E_, upper: INTEGER_32)
effective procedure
{ANY}
Replace all occurrences of the element old_value by new_value using basic = for comparison.
See also replace_all to choose the appropriate one.
require
  • upper >= -1
copy_at (at: INTEGER_32, src: NATIVE_ARRAY [E_], src_capacity: INTEGER_32)
effective procedure
{ANY}
Copy range [0 .. src_capacity - 1] of src to range [at .. at + src_capacity - 1] of Current.
No subscript checking.
require
  • at >= 0
  • src_capacity >= 0
slice_copy (at: INTEGER_32, src: NATIVE_ARRAY [E_], src_min: INTEGER_32, src_max: INTEGER_32)
{ANY}
Copy range [src_min .. src_max] of src to range [at .. at + src_max - src_min] of Current.
No subscript checking.
require
  • at >= 0
  • src_max >= src_min - 1
  • useful_work: src /= Current or at /= src_min
set_all_with (v: E_, upper: INTEGER_32)
effective procedure
{ANY}
Set all elements in range [0 .. upper] with value v.
require
  • upper >= -1
set_slice_with (v: E_, lower: INTEGER_32, upper: INTEGER_32)
effective procedure
{ANY}
Set all elements in range [lower .. upper] with value v.
require
  • lower >= 0
  • upper >= lower - 1
clear_all (upper: INTEGER_32)
effective procedure
{ANY}
Set all elements in range [0 .. upper] with the default value.
require
  • upper >= -1
ensure
clear (lower: INTEGER_32, upper: INTEGER_32)
effective procedure
{ANY}
Set all elements in range [lower .. upper] with the default value.
require
  • lower >= 0
  • upper >= lower - 1
copy_from (model: NATIVE_ARRAY [E_], upper: INTEGER_32)
effective procedure
{ANY}
Assume upper is a valid index both in Current and model.
require
  • upper >= -1
copy_slice_from (model: NATIVE_ARRAY [E_], lower: INTEGER_32, upper: INTEGER_32)
effective procedure
{ANY}
Assume upper is a valid index both in Current and model.
require
  • lower >= 0
  • upper >= lower - 1
  • useful_work: model /= Current or else lower > 0
deep_twin_from (capacity: INTEGER_32): NATIVE_ARRAY [E_]
effective function
{ANY}
To implement deep_twin.
Allocate a new array of capacity initialized with deep_twin. Assume capacity is valid both in Current and model.
require
  • capacity >= 0
move (lower: INTEGER_32, upper: INTEGER_32, offset: INTEGER_32)
effective procedure
{ANY}
Move range [lower .. upper] by offset positions.
Freed positions are not initialized to default values.
require
  • lower >= 0
  • upper >= lower
  • lower + offset >= 0
occurrences (element: E_, upper: INTEGER_32): INTEGER_32
effective function
{ANY}
Number of occurrences of element in range [0 .. upper] using is_equal for comparison.
See also fast_occurrences to chose the appropriate one.
require
  • upper >= -1
slice_occurrences (element: E_, lower: INTEGER_32, upper: INTEGER_32): INTEGER_32
effective function
{ANY}
Number of occurrences of element in range [lower .. upper] using is_equal for comparison.
See also slice_fast_occurrences to chose the appropriate one.
require
  • lower >= 0
  • upper >= lower - 1
fast_occurrences (element: E_, upper: INTEGER_32): INTEGER_32
effective function
{ANY}
Number of occurrences of element in range [0 .. upper] using basic "=" for comparison.
See also occurrences to chose the appropriate one.
require
  • upper >= -1
slice_fast_occurrences (element: E_, lower: INTEGER_32, upper: INTEGER_32): INTEGER_32
effective function
{ANY}
Number of occurrences of element in range [lower .. upper] using basic "=" for comparison.
See also slice_occurrences to chose the appropriate one.
require
  • lower >= 0
  • upper >= lower - 1
all_default (upper: INTEGER_32): BOOLEAN
effective function
{ANY}
Do all items in range [0 .. upper] have their type's default value?
Note: for non Void items, the test is performed with the is_default predicate.
require
  • upper >= -1
slice_default (lower: INTEGER_32, upper: INTEGER_32): BOOLEAN
effective function
{ANY}
Do all items in range [lower .. upper] have their type's default value?
Note: for non Void items, the test is performed with the is_default predicate.
require
  • lower >= 0
  • upper >= lower - 1
to_external: POINTER
effective function
{ANY}
Gives access to the C pointer on the area of storage.
from_pointer (pointer: POINTER): NATIVE_ARRAY [E_]
{ANY}
Convert pointer into Current type.
is_not_null: BOOLEAN
effective function
{ANY}
is_null: BOOLEAN
effective function
{ANY}
manifest_make (needed_capacity: INTEGER_32)
effective procedure
{}
Manifest creation (see also calloc and realloc for creation).
manifest_put (index: INTEGER_32, element: E_)
effective procedure
{}
manifest_semicolon_check: BOOLEAN
is False
constant attribute
{}
test (e1: E_, e2: E_): BOOLEAN
effective function
{ANY}
In order to avoid run-time type errors, feature safe_equal calls is_equal only when e1 and e2 have exactly the same dynamic type.
safe_equal (e1: E_, e2: E_): BOOLEAN
effective function
{ANY}
In order to avoid run-time type errors, feature safe_equal calls is_equal only when e1 and e2 have exactly the same dynamic type.