LisaacTM Platform

ARRAY


General purpose resizable ARRAYs .
General purpose resizable ARRAYs as they are define in the Eiffel language definition. The `lower' bound can be any arbitrary value, even a negative one.


This 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 an 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 always stuck to 0 is not a problem for you, also consider FAST_ARRAY to get better performances.
Inherit/Insert Summary
parent_arrayed_collection
parent_arrayed No developed.
parent_collection No developed.
 
Constructor Summary
create to
Prepare the array to hold values for indexes in range [min_index .. max_index]. Set all values to default. When max_index = min_index - 1, the array is_empty.
create_with_capacity lower
Create an empty array with capacity initialized at least to needed_capacity and lower set to low.
 
Slot Summary
lower
Lower index bound.
Creation and Modification:
Minimum index.
See also upper, valid_index, item.
make to
Prepare the array to hold values for indexes in range [min_index .. max_index]. Set all values to default. When max_index = min_index - 1, the array is_empty.
with_capacity lower
Create an empty array with capacity initialized at least to needed_capacity and lower set to low.
ensure_capacity and_bounds to
Extend needed capacity and bouds if necessary
storage
Internal access to storage location.
element_sizeof
The size in number of bytes for type E. The size in number of bytes for type E.
capacity
Internal storage capacity in number of item.
upper
Upper index bound. Maximum index.
See also lower, valid_index, item.
set_upper
set_count
to_native_array_uinteger_8
add_last_buffer from to
get_buffer_from_byte size_bytes
 
Modification:
resize to
Resize to bounds min_index and max_index. Do not lose any item whose index is in both [lower .. upper] and [min_index .. max_index]. New positions if any are initialized with the appropriate default value.
reindex
Change indexing to take in account the expected new_lower index. The upper index is translated accordingly.
 
Implementation of deferred:
subarray to
Return the subarray between min to max
is_empty
Is Self empty ? Is collection empty ?
See also count.
count
Size of current Number of available indices.
See also is_empty, lower, upper.
item
Item at the corresponding index i.
put to
Make element the item at index i.
force to
Make element the item at index i, reindexing array if necessary.
copy
Copy other into Self Reinitialize by copying all the items of other.
set_all_with
Set all element with v Set all items with value v.
remove_first
Remove the first element
remove_head
Remove the n firsts element
remove
Remove the nth element Remove the item at position index. Followings items are shifted left by one position.
clear
Clear the array
add_first
Add a new item in first position : count is increased by one and all other items are shifted right.
add_last
Add a new item at the end : count is increased by one.
from_collection
Initialize the current object with the contents of model Initialize the current object with the contents of model.
all_default
Do all items have their type's default value? Note: for non NULL items, the test is performed with the is_default predicate.
occurrences
Number of occurrences of element using equal for comparison.
fast_occurrences
Number of occurrences of element using basic = for comparison.
first_index_of
Give the index of the first occurrence of element using == for comparison. Answer upper + 1 when element is not inside.
index_of start
Using is_equal 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.
reverse_index_of start
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.
fast_index_of start
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.
fast_reverse_index_of start
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.
Infix '=='
Do both collections have the same lower, upper, and items? The basic = is used for comparison of items.
is_equal_map
Do both collections have the same lower, upper, and items? Feature == is used for comparison of items.
slice to
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.
first
The very first item.
See also last, item.
second
last
The last item.
See also first, item.
add to
Add a new element at rank index : count is increased by one and range [index .. upper] is shifted right by one position.
remove_last
Remove the last item.
remove_tail
Remove the last n item(s).
replace_all with
Replace all occurrences of the element old_value by new_value using equal for comparison.
fast_replace_all with
Replace all occurrences of the element old_value by new_value using operator = for comparison.
reverse
Reverse the order of the elements.
 
Interfacing with C:
to_external
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.
to_native_array
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.
 

Inherit/Insert Detail

parent_arrayed_collection

.../base/collection/array.li line #23

Section:
Inherit

Profile:
+ SelfSELFparent_arrayed_collection :Expanded  ARRAYED_COLLECTIONV)

parent_arrayed

.../base/collection/low_level/arrayed_collection.li line #12

Section:
Inherit

Profile:
- SelfSELFparent_arrayed : ARRAYED

parent_collection

.../base/collection/low_level/arrayed_collection.li line #14

Section:
Inherit

Profile:
- SelfSELFparent_collection : COLLECTIONV)

Constructor Detail

create to

.../base/collection/array.li line #33

Section:
Public

Profile:
- SelfSELFcreate   min_index : INTEGER  to   max_index : INTEGERSELF

Description:
Prepare the array to hold values for indexes in range [min_index .. max_index]. Set all values to default. When max_index = min_index - 1, the array is_empty.

create_with_capacity lower

.../base/collection/array.li line #64

Section:
Public

Profile:
- SelfSELFcreate_with_capacity   needed_capacity : INTEGER  lower   low : INTEGERSELF

Description:
Create an empty array with capacity initialized at least to needed_capacity and lower set to low.

Detail slot

lower

.../base/collection/array.li line #27

Section:
Public

Profile:
+ SelfSELFlower : INTEGER

Description:
Lower index bound.
Creation and Modification:
Minimum index.
See also upper, valid_index, item.

make to

.../base/collection/array.li line #44

Section:
Public

Profile:
- SelfSELFmake   min_index : INTEGER  to   max_index : INTEGER

Description:
Prepare the array to hold values for indexes in range [min_index .. max_index]. Set all values to default. When max_index = min_index - 1, the array is_empty.

Require:
min_index inferior or equal to max_index + 1

Ensure:
lower is equal to min_index

Ensure:
upper is equal to max_index

Ensure:
all values are in default

with_capacity lower

.../base/collection/array.li line #74

Section:
Public

Profile:
- SelfSELFwith_capacity   needed_capacity : INTEGER  lower   low : INTEGER

Description:
Create an empty array with capacity initialized at least to needed_capacity and lower set to low.

ensure_capacity and_bounds to

.../base/collection/array.li line #91

Section:
Public

Profile:
- SelfSELFensure_capacity   needed_capacity : INTEGER  and_bounds   low : INTEGER  to   up : INTEGER

Description:
Extend needed capacity and bouds if necessary

Require:
up superior or equal to low - 1

storage

.../base/collection/low_level/arrayed_collection.li line #18

Section:
Public

Profile:
+ SelfSELFstorage : NATIVE_ARRAYV)

Description:
Internal access to storage location.

element_sizeof

.../base/collection/low_level/arrayed_collection.li line #23

Section:
Public

Profile:
- SelfSELFelement_sizeof : INTEGER

Description:
The size in number of bytes for type E. The size in number of bytes for type E.

capacity

.../base/collection/low_level/arrayed_collection.li line #35

Section:
Public

Profile:
+ SelfSELFcapacity : INTEGER

Description:
Internal storage capacity in number of item.

upper

.../base/collection/low_level/arrayed_collection.li line #38

Section:
Public

Profile:
+ SelfSELFupper : INTEGER

Description:
Upper index bound. Maximum index.
See also lower, valid_index, item.

set_upper

.../base/collection/low_level/arrayed_collection.li line #151

Section:
Public

Profile:
- SelfSELFset_upper   new_upper : INTEGER

set_count

.../base/collection/low_level/arrayed_collection.li line #167

Section:
Public

Profile:
- SelfSELFset_count   new_count : INTEGER

to_native_array_uinteger_8

.../base/collection/low_level/arrayed_collection.li line #172

Section:
Public

Profile:
- SelfSELFto_native_array_uinteger_8 : NATIVE_ARRAYUINTEGER_8)

add_last_buffer from to

.../base/collection/low_level/arrayed_collection.li line #177

Section:
Public

Profile:
- SelfSELFadd_last_buffer   buf : FAST_ARRAYUINTEGER_8)  from   beg : INTEGER  to   end : INTEGER

get_buffer_from_byte size_bytes

.../base/collection/low_level/arrayed_collection.li line #200

Section:
Public

Profile:
- SelfSELFget_buffer_from_byte   i : INTEGER  size_bytes   s : INTEGERFAST_ARRAYUINTEGER_8)

Modification:

resize to

.../base/collection/array.li line #117

Section:
Public

Profile:
- SelfSELFresize   min_index : INTEGER  to   max_index : INTEGER

Description:
Resize to bounds min_index and max_index. Do not lose any item whose index is in both [lower .. upper] and [min_index .. max_index]. New positions if any are initialized with the appropriate default value.

Require:
min_index inferior or equal to max_index + 1

Ensure:
lower is equal to min_index

Ensure:
upper is equal to max_index

reindex

.../base/collection/array.li line #173

Section:
Public

Profile:
- SelfSELFreindex   new_lower : INTEGER

Description:
Change indexing to take in account the expected new_lower index. The upper index is translated accordingly.

Ensure:
lower is equal to new_lower

Ensure:
count is equal to count before

Implementation of deferred:

subarray to

.../base/collection/array.li line #193

Section:
Public

Profile:
- SelfSELFsubarray   min : INTEGER  to   max : INTEGERSELF

Description:
Return the subarray between min to max

Ensure:
Result.lower is equal to min before New collection consisting of items at indexes in [min .. max]. Result has the same dynamic type as Current. See also slice.

is_empty

.../base/collection/array.li line #206

Section:
Public

Profile:
- SelfSELFis_empty : BOOLEAN

Description:
Is Self empty ? Is collection empty ?
See also count.

count

.../base/collection/array.li line #210

Section:
Public

Profile:
- SelfSELFcount : INTEGER

Description:
Size of current Number of available indices.
See also is_empty, lower, upper.

item

.../base/collection/array.li line #214

Section:
Public

Profile:
- SelfSELFitem   i : INTEGERV

Description:
Item at the corresponding index i.

See:
lower, upper, valid_index, put, swap Item at the corresponding index i.

See:
lower, upper, valid_index, put, swap

put to

.../base/collection/array.li line #222

Section:
Public

Profile:
- SelfSELFput   element : V  to   i : INTEGER

Description:
Make element the item at index i.

See:
lower, upper, valid_index, item, swap, force. Make element the item at index i.

See:
lower, upper, valid_index, item, swap, force.

force to

.../base/collection/array.li line #229

Section:
Public

Profile:
- SelfSELFforce   element : V  to   index : INTEGER

Description:
Make element the item at index i, reindexing array if necessary.

See:
lower, upper, valid_index, item, swap, force. Make element the item at index, enlarging the collection if necessary (new bounds except index are initialized with default values).

See:
put, item, swap.

copy

.../base/collection/array.li line #251

Section:
Public

Profile:
- SelfSELFcopy   other : SELF

Description:
Copy other into Self Reinitialize by copying all the items of other.

set_all_with

.../base/collection/array.li line #267

Section:
Public

Profile:
- SelfSELFset_all_with   v : V

Description:
Set all element with v Set all items with value v.

See:
set_slice_with.

remove_first

.../base/collection/array.li line #273

Section:
Public

Profile:
- SelfSELFremove_first 

Description:
Remove the first element

Ensure:
upper has same value before and after Remove the first element of the collection.

See:
remove_last, remove, remove_head.

remove_head

.../base/collection/array.li line #284

Section:
Public

Profile:
- SelfSELFremove_head   n : INTEGER

Description:
Remove the n firsts element

Ensure:
upper has same value before and after Remove the n elements of the collection.

See:
remove_tail, remove, remove_first.

remove

.../base/collection/array.li line #295

Section:
Public

Profile:
- SelfSELFremove   index : INTEGER

Description:
Remove the nth element Remove the item at position index. Followings items are shifted left by one position.

See:
remove_first, remove_head, remove_tail, remove_last.

clear

.../base/collection/array.li line #303

Section:
Public

Profile:
- SelfSELFclear 

Description:
Clear the array

Ensure:
capacity has same value before and after Discard all items in order to make it is_empty.

See:
clear_all.

add_first

.../base/collection/array.li line #313

Section:
Public

Profile:
- SelfSELFadd_first   element : V

Description:
Add a new item in first position : count is increased by one and all other items are shifted right.

See:
add_last, first, last, add. Add a new item in first position : count is increased by one and all other items are shifted right.

See:
add_last, first, last, add.

add_last

.../base/collection/array.li line #328

Section:
Public

Profile:
- SelfSELFadd_last   element : V

Description:
Add a new item at the end : count is increased by one.

See:
add_first, last, first, add. Add a new item at the end : count is increased by one.

See:
add_first, last, first, add.

from_collection

.../base/collection/array.li line #349

Section:
Public

Profile:
- SelfSELFfrom_collection   model : COLLECTIONV)

Description:
Initialize the current object with the contents of model Initialize the current object with the contents of model.

all_default

.../base/collection/array.li line #363

Section:
Public

Profile:
- SelfSELFall_default : BOOLEAN

Description:
Do all items have their type's default value? Note: for non NULL items, the test is performed with the is_default predicate.

See:
clear_all.

occurrences

.../base/collection/array.li line #368

Section:
Public

Profile:
- SelfSELFoccurrences   element : VINTEGER

Description:
Number of occurrences of element using equal for comparison.

See:
fast_occurrences, index_of.

fast_occurrences

.../base/collection/array.li line #373

Section:
Public

Profile:
- SelfSELFfast_occurrences   element : VINTEGER

Description:
Number of occurrences of element using basic = for comparison.

See:
occurrences, index_of.

first_index_of

.../base/collection/array.li line #378

Section:
Public

Profile:
- SelfSELFfirst_index_of   element : VINTEGER

Description:
Give the index of the first occurrence of element using == for comparison. Answer upper + 1 when element is not inside.

Parameter:
element : element to search.

Require:
element not null.

Ensure:
Very good fonction

See:
fast_first_index_of, index_of start, last_index_of, reverse_index_of.

Description en francais:
Donne l'index de la premiere occurence de element en utilisant == pour la comparaison. Renvoi upper + 1 lorsque element est absent.

Necessite:
element pas null.

Voir:
fast_first_index_of, index_of, last_index_of, reverse_index_of.

index_of start

.../base/collection/array.li line #388

Section:
Public

Profile:
- SelfSELFindex_of   element : V  start   start_index : INTEGERINTEGER

Description:
Using is_equal 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:
fast_index_of, reverse_index_of, first_index_of.

reverse_index_of start

.../base/collection/array.li line #399

Section:
Public

Profile:
- SelfSELFreverse_index_of   element : V  start   start_index : INTEGERINTEGER

Description:
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:
fast_reverse_index_of, last_index_of, index_of.

fast_index_of start

.../base/collection/array.li line #409

Section:
Public

Profile:
- SelfSELFfast_index_of   element : V  start   start_index : INTEGERINTEGER

Description:
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:
index_of, fast_reverse_index_of, fast_first_index_of.

fast_reverse_index_of start

.../base/collection/array.li line #420

Section:
Public

Profile:
- SelfSELFfast_reverse_index_of   element : V  start   start_index : INTEGERINTEGER

Description:
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:
reverse_index_of, fast_index_of, fast_last_index_of.

Infix '=='

.../base/collection/array.li line #431

Section:
Public

Profile:
- SelfSELF== ' Right 60  other : SELFBOOLEAN

Description:
Do both collections have the same lower, upper, and items? The basic = is used for comparison of items.

See:
is_equal_map, same_items.

is_equal_map

.../base/collection/array.li line #442

Section:
Public

Profile:
- SelfSELFis_equal_map   other : SELFBOOLEAN

Description:
Do both collections have the same lower, upper, and items? Feature == is used for comparison of items.

See:
==, same_items.

slice to

.../base/collection/array.li line #453

Section:
Public

Profile:
- SelfSELFslice   min : INTEGER  to   max : INTEGERSELF

Description:
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:
from_collection, move, replace_all.

Require:
lower inferior or equal to min

Require:
max inferior or equal to upper

Require:
min inferior or equal to max + 1

Ensure:
Self is same dynamic type of Result

Ensure:
Result size is equal to max - min + 1

Ensure:
Result first element index is same as Self first element index

first

.../base/collection/low_level/arrayed_collection.li line #64

Section:
Public

Profile:
- SelfSELFfirst : V

Description:
The very first item.
See also last, item.

second

.../base/collection/low_level/arrayed_collection.li line #66

Section:
Public

Profile:
- SelfSELFsecond : V

last

.../base/collection/low_level/arrayed_collection.li line #68

Section:
Public

Profile:
- SelfSELFlast : V

Description:
The last item.
See also first, item.

add to

.../base/collection/low_level/arrayed_collection.li line #70

Section:
Public

Profile:
- SelfSELFadd   element : V  to   index : INTEGER

Description:
Add a new element at rank index : count is increased by one and range [index .. upper] is shifted right by one position.

See:
add_first, add_last, append_collection.

remove_last

.../base/collection/low_level/arrayed_collection.li line #81

Section:
Public

Profile:
- SelfSELFremove_last 

Description:
Remove the last item.

See:
remove_first, remove, remove_tail.

remove_tail

.../base/collection/low_level/arrayed_collection.li line #86

Section:
Public

Profile:
- SelfSELFremove_tail   n : INTEGER

Description:
Remove the last n item(s).

See:
remove_head, remove, remove_last.

replace_all with

.../base/collection/low_level/arrayed_collection.li line #91

Section:
Public

Profile:
- SelfSELFreplace_all   old_value : V  with   new_value : V

Description:
Replace all occurrences of the element old_value by new_value using equal for comparison.

See:
fast_replace_all, move.

fast_replace_all with

.../base/collection/low_level/arrayed_collection.li line #96

Section:
Public

Profile:
- SelfSELFfast_replace_all   old_value : V  with   new_value : V

Description:
Replace all occurrences of the element old_value by new_value using operator = for comparison.

See:
replace_all, move.

reverse

.../base/collection/low_level/arrayed_collection.li line #101

Section:
Public

Profile:
- SelfSELFreverse 

Description:
Reverse the order of the elements.

Interfacing with C:

to_external

.../base/collection/low_level/arrayed_collection.li line #117

Section:
Public

Profile:
- SelfSELFto_external : POINTER

Description:
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.

to_native_array

.../base/collection/low_level/arrayed_collection.li line #133

Section:
Public

Profile:
- SelfSELFto_native_array : NATIVE_ARRAYV)

Description:
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.