The first item is 0. The last is length-1
.
core :: Sequence :: defaultinit
core :: Sequence :: insert_all
Insert all elements at a given position, following elements are shifted.pthreads :: concurrent_collections $ Sequence :: CONCURRENT
Type of the concurrent variant of this collectioncore :: 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.
serialization :: Serializable :: core_serialize_to
Actual serialization ofself
to serializer
core :: Object :: defaultinit
core :: Sequence :: defaultinit
core :: SimpleCollection :: defaultinit
core :: Collection :: defaultinit
core :: SequenceRead :: defaultinit
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 :: 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
pthreads :: ConcurrentSequence
A concurrent variant to the standardSequence
ConcurrentList
Array
List
pthreads :: ReverseBlockingQueue
A collection whichis_empty
method blocks until it's empty
# Sequence are indexed collection.
# The first item is 0. The last is `length-1`.
interface Sequence[E]
super SequenceRead[E]
super SimpleCollection[E]
# Set the first item.
# Is equivalent with `self[0] = item`.
#
# var a = [1,2,3]
# a.first = 10
# assert a == [10,2,3]
fun first=(item: E)
do self[0] = item end
# Set the last item.
# Is equivalent with `self[length-1] = item`.
#
# var a = [1,2,3]
# a.last = 10
# assert a == [1,2,10]
#
# If the sequence is empty, `last=` is equivalent with `self[0]=` (thus with `first=`)
#
# var b = new Array[Int]
# b.last = 10
# assert b == [10]
fun last=(item: E)
do
var l = length
if l > 0 then
self[l-1] = item
else
self[0] = item
end
end
# A synonym of `push`
redef fun add(e) do push(e)
# Add an item after the last one.
#
# var a = [1,2,3]
# a.push(10)
# a.push(20)
# assert a == [1,2,3,10,20]
fun push(e: E) is abstract
# Add each item of `coll` after the last.
#
# var a = [1,2,3]
# a.append([7..9])
# assert a == [1,2,3,7,8,9]
#
# Alias of `add_all`
fun append(coll: Collection[E]) do add_all(coll)
# Remove the last item.
#
# var a = [1,2,3]
# assert a.pop == 3
# assert a.pop == 2
# assert a == [1]
#
# REQUIRE `not is_empty`
fun pop: E is abstract
# Add an item before the first one.
#
# var a = [1,2,3]
# a.unshift(10)
# a.unshift(20)
# assert a == [20,10,1,2,3]
fun unshift(e: E) is abstract
# Add all items of `coll` before the first one.
#
# var a = [1,2,3]
# a.prepend([7..9])
# assert a == [7,8,9,1,2,3]
#
# Alias of `insert_at(coll, 0)`
fun prepend(coll: Collection[E]) do insert_all(coll, 0)
# Remove the first item.
# The second item thus become the first.
#
# var a = [1,2,3]
# assert a.shift == 1
# assert a.shift == 2
# assert a == [3]
#
# REQUIRE `not is_empty`
fun shift: E is abstract
# Set the `item` at `index`.
#
# var a = [10,20,30]
# a[1] = 200
# assert a == [10,200,30]
#
# like with `[]`, index should be between `0` and `length-1`
# However, if `index==length`, `[]=` works like `push`.
#
# a[3] = 400
# assert a == [10,200,30,400]
#
# REQUIRE `index >= 0 and index <= length`
fun []=(index: Int, item: E) is abstract
# Set the index-th element but wrap
#
# Whereas `self[]=` requires the index to exists, the `modulo` accessor automatically
# wraps overbound and underbouds indexes.
#
# ~~~
# var a = [10,20,30]
# a.modulo(1) = 200
# a.modulo(3) = 100
# a.modulo(-1) = 300
# a.modulo(-10) = 301
# assert a == [100, 200, 301]
# ~~~
#
# REQUIRE `not_empty`
# ENSURE `self[modulo_index(index)] == value`
fun modulo=(index: Int, value: E) do self[modulo_index(index)] = value
# Insert an element at a given position, following elements are shifted.
#
# var a = [10, 20, 30, 40]
# a.insert(100, 2)
# assert a == [10, 20, 100, 30, 40]
#
# REQUIRE `index >= 0 and index <= length`
# ENSURE `self[index] == item`
fun insert(item: E, index: Int) is abstract
# Insert all elements at a given position, following elements are shifted.
#
# var a = [10, 20, 30, 40]
# a.insert_all([100..102], 2)
# assert a == [10, 20, 100, 101, 102, 30, 40]
#
# REQUIRE `index >= 0 and index <= length`
# ENSURE `self[index] == coll.first`
fun insert_all(coll: Collection[E], index: Int)
do
assert index >= 0 and index < length
if index == length then
add_all(coll)
end
for c in coll do
insert(c, index)
index += 1
end
end
# Remove the item at `index` and shift all following elements
#
# var a = [10,20,30]
# a.remove_at(1)
# assert a == [10,30]
#
# REQUIRE `index >= 0 and index < length`
fun remove_at(index: Int) is abstract
# Rotates the elements of self once to the left
#
# ~~~nit
# var a = [12, 23, 34, 45]
# a.rotate_left
# assert a == [23, 34, 45, 12]
# ~~~
fun rotate_left do
var fst = shift
push fst
end
# Rotates the elements of self once to the right
#
# ~~~nit
# var a = [12, 23, 34, 45]
# a.rotate_right
# assert a == [45, 12, 23, 34]
# ~~~
fun rotate_right do
var lst = pop
unshift lst
end
end
lib/core/collection/abstract_collection.nit:1072,1--1262,3
redef class Sequence[E]
# Return a LIFO proxy queue (stack) where `result.take` is `pop`.
#
# The point of such a proxy is to let the user choose the underling data structure
# behind the LIFO.
#
# ~~~
# var a = [1, 2, 3]
# var q = a.as_lifo
# assert q.take == 3
# assert q.take == 2
# q.add(4)
# q.add(5)
# assert q.take == 5
# assert a == [1, 4]
# ~~~
fun as_lifo: Queue[E] do return new LifoQueue[E](self)
# Return a FIFO proxy queue where `result.take` is `shift`.
#
# The point of such a proxy is to let the user choose the underling data structure
# behind the FIFO.
#
# Note that some `Sequence`, like `Array`, have an inefficient `shift` implementation,
# thus are not the best candidates to serve as a FIFO.
#
# ~~~
# var a = new List[Int].from([1,2,3])
# var q = a.as_fifo
# assert q.take == 1
# q.add(4)
# q.add(5)
# assert q.take == 2
# assert a == [3, 4, 5]
# ~~~
fun as_fifo: Queue[E] do return new FifoQueue[E](self)
end
lib/core/queue.nit:100,1--136,3
redef class Sequence[E]
redef type CONCURRENT: ConcurrentSequence[E]
end
lib/pthreads/concurrent_collections.nit:52,1--54,3