core :: AbstractArray :: defaultinit
core :: AbstractArray :: enlarge
Force the capacity to be at leastcap
.
core $ AbstractArray :: SELF
Type of this instance, automatically specialized in every classcore $ AbstractArray :: insert_all
Insert all elements at a given position, following elements are shifted.core $ AbstractArray :: remove_all
Remove all occurrences ofitem
core $ AbstractArray :: remove_at
Remove the item atindex
and shift all following elements
core :: Collection :: CONCURRENT
Type of the concurrent variant of this collectionserialization :: Serializable :: accept_json_serializer
Refinable service to customize the serialization of this class to JSONserialization :: Serializable :: accept_msgpack_attribute_counter
Hook to customize the behavior of theAttributeCounter
serialization :: Serializable :: accept_msgpack_serializer
Hook to customize the serialization of this class to MessagePackserialization :: Serializable :: add_to_bundle
Called by[]=
to dynamically choose the appropriate method according
core :: Object :: class_factory
Implementation used byget_class
to create the specific class.
core :: Collection :: combinations
Allr
-length combinations on self (in same order) without repeated elements.
core :: Collection :: combinations_with_replacement
Allr
-length combination on self (in same order) with repeated elements.
core :: AbstractArrayRead :: copy_to
Copy a portion ofself
to an other array.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: AbstractArrayRead :: defaultinit
core :: Object :: defaultinit
core :: Sequence :: defaultinit
core :: SimpleCollection :: defaultinit
core :: AbstractArray :: defaultinit
core :: Collection :: defaultinit
core :: SequenceRead :: defaultinit
core :: AbstractArray :: enlarge
Force the capacity to be at leastcap
.
serialization :: Serializable :: from_deserializer
Create an instance of this class from thedeserializer
core :: SequenceRead :: get_or_default
Try to get an element, returndefault
if the index
is invalid.
core :: SequenceRead :: get_or_null
Try to get an element, returnnull
if the index
is invalid.
core :: Collection :: has_all
Does the collection contain at least each element ofother
?
core :: Collection :: has_any
Does the collection contain at least one element ofother
?
core :: Collection :: has_exactly
Does the collection contain exactly all the elements ofother
?
core :: SequenceRead :: index_of_from
The index of the first occurrence ofitem
, starting from pos.
core :: Sequence :: insert_all
Insert all elements at a given position, following elements are shifted.core :: Object :: is_same_instance
Return true ifself
and other
are the same instance (i.e. same identity).
core :: Object :: is_same_serialized
Isself
the same as other
in a serialization context?
core :: Object :: is_same_type
Return true ifself
and other
have the same dynamic type.
core :: SequenceRead :: iterator_from
Gets a new Iterator starting at positionpos
core :: SequenceRead :: last_index_of
The index of the last occurrence ofitem
.
core :: SequenceRead :: last_index_of_from
The index of the last occurrence ofitem
starting from pos
and decrementing.
core :: AbstractArrayRead :: length=
core :: SequenceRead :: modulo_index
Returns the real index for a modulo index.serialization :: Serializable :: msgpack_extra_array_items
Hook to request a larger than usual metadata arraycore :: Object :: output_class_name
Display class name on stdout (debug only).core :: Collection :: permutations
Allr
-length permutations on self (all possible ordering) without repeated elements.
core :: Collection :: product
Cartesian product, overr
times self
.
core :: RemovableCollection :: remove
Remove an occurrence ofitem
core :: RemovableCollection :: remove_all
Remove all occurrences ofitem
core :: SequenceRead :: reverse_iterator
Gets an iterator starting at the end and going backwardscore :: SequenceRead :: reverse_iterator_from
Gets an iterator on the chars of self starting frompos
serialization :: Serializable :: serialize_msgpack
Serializeself
to MessagePack bytes
serialization :: Serializable :: serialize_to
Serializeself
to serializer
serialization :: Serializable :: serialize_to_json
Serializeself
to JSON
core :: Collection :: to_concurrent
Wrapsself
in a thread-safe collection
core :: Collection :: to_counter
Create and fill up a counter with the elements of `self.core :: Collection :: to_curlslist
Convert Collection[String] to CURLSListserialization :: Serializable :: to_pretty_json
Serializeself
to plain pretty JSON
core :: Collection :: to_shuffle
Return a new array made of elements in a random order.Serializer::serialize
# Resizable one dimension array of objects.
abstract class AbstractArray[E]
super AbstractArrayRead[E]
super Sequence[E]
# Force the capacity to be at least `cap`.
# The capacity of the array is an internal information.
# However, this method can be used to prepare a large amount of add
fun enlarge(cap: Int) is abstract
redef fun push(item) do add(item)
redef fun pop
do
assert not_empty: not is_empty
var r = last
_length -= 1
return r
end
redef fun shift
do
assert not_empty: not is_empty
var r = first
var l = length-1
copy_to(1, l, self, 0)
_length = l
return r
end
redef fun unshift(item)
do
var l = length
if l > 0 then
enlarge(l + 1)
copy_to(0, l, self, 1)
end
self[0] = item
end
redef fun insert(item, pos) do
enlarge(length + 1)
copy_to(pos, length-pos, self, pos + 1)
self[pos] = item
end
redef fun insert_all(coll, pos)
do
var l = coll.length
if l == 0 then return
enlarge(length + l)
_length += l
copy_to(pos, length-pos-l, self, pos + l)
for c in coll do
self[pos] = c
pos += 1
end
end
redef fun add(item) do self[length] = item
redef fun clear do _length = 0
redef fun remove(item) do remove_at(index_of(item))
redef fun remove_all(item)
do
var i = index_of(item)
while i >= 0 do
remove_at(i)
i = index_of_from(item, i)
end
end
redef fun remove_at(i)
do
var l = length
if i >= 0 and i < l then
var j = i + 1
while j < l do
self[j-1] = self[j]
j += 1
end
_length = l - 1
end
end
# Invert two elements in the array
#
# var a = [10, 20, 30, 40]
# a.swap_at(1, 3)
# assert a == [10, 40, 30, 20]
fun swap_at(a: Int,b: Int)
do
var e = self[a]
self[a] = self[b]
self[b] = e
end
end
lib/core/collection/array.nit:206,1--304,3
redef class AbstractArray[E]
# Reorder randomly the elements in self.
#
# ~~~
# var a = new Array[Int]
#
# a.shuffle
# assert a.is_empty
#
# a.add 1
# a.shuffle
# assert a == [1]
#
# a.add 2
# a.shuffle
# assert a == [1,2] or a == [2,1]
# ~~~
#
# ENSURE self.shuffle.has_exactly(old(self))
fun shuffle
do
for i in [0..length[ do
var j = i + (length-i).rand
var tmp = self[i]
self[i] = self[j]
self[j] = tmp
end
end
end
lib/core/math.nit:511,1--539,3