The first element is 0 and the last is length-1
If index is invalid, the program aborts
var a = [10,20,30]
assert a[0] == 10
assert a[1] == 20
assert a[2] == 30
REQUIRE index >= 0 and index < length
# Return the index-th element of the sequence.
# The first element is 0 and the last is `length-1`
# If index is invalid, the program aborts
#
# var a = [10,20,30]
# assert a[0] == 10
# assert a[1] == 20
# assert a[2] == 30
#
# REQUIRE `index >= 0 and index < length`
fun [](index: Int): E is abstract
lib/core/collection/abstract_collection.nit:852,2--862,34
redef fun [](i) do
assert i >= 0 and i < target._byte_length
var flps = _cache_start
if i >= flps and i <= _cache_end then
return _cache.bytes[i - flps]
end
var lf = get_leaf_at(i)
return lf.bytes[i - _cache_start]
end
lib/core/text/ropes.nit:670,2--678,4
redef fun [](index)
do
# Check that the index (+ _first_byte) is not larger than last_byte
# In other terms, if the index is valid
var target = _target
assert index >= 0 and index < target._byte_length
var ind = index + target._first_byte
return target._items[ind]
end
lib/core/text/flat.nit:843,2--851,4
redef fun [](i) in "Java" `{ return self[(int)i]; `}
lib/java/collections.nit:56,2--53
redef fun [](i) in "Java" `{ return (short)self[(int)i]; `}
lib/java/collections.nit:70,2--60
redef fun [](i) in "Java" `{ return self[(int)i]; `}
lib/java/collections.nit:84,2--53
redef fun [](i) in "Java" `{ return (double)self[(int)i]; `}
lib/java/collections.nit:101,2--61
redef fun [](i) in "Java" `{ return self[(int)i]; `}
lib/java/collections.nit:115,2--53
redef fun [](i) in "Java" `{ return self[(int)i]; `}
lib/java/collections.nit:143,2--53
redef fun [](i) in "Java" `{ return (byte)self[(int)i]; `}
lib/java/collections.nit:157,2--59
redef fun [](i) in "Java" `{ return (char)self[(int)i]; `}
lib/java/collections.nit:171,2--59
redef fun [](index)
do
var node = node_at(index)
index = index_within_node + node.head_index
return node.items[index]
end
lib/more_collections/more_collections.nit:413,2--418,4