# another product.
# This module handle double linked lists
-package list
+module list
import abstract_collection
return nb
end
- redef fun has_key(index) do return get_node(index) != null
+ # Return a list of elements between 'from' and 'to'.
+ fun slice(from: Int, to: Int): List[E] do
+ assert from >= 0 and from < length
+ assert to >= 0 and to < length and from <= to
+ var list = new List[E]
+ while from <= to do
+ list.add(self[from])
+ from += 1
+ end
+ return list
+ end
# Add elements
_head = node
end
- # Append `l' to `self' but clear `l'.
+ # Append `l` to `self` but clear `l`.
##
# O(1)
fun link(l: List[E])
# Build an empty list.
init do end
- # Build a list filled with the items of `coll'.
+ # Build a list filled with the items of `coll`.
init from(coll: Collection[E]) do append(coll)
# The first node of the list
# The last node of the list
var _tail: nullable ListNode[E]
- # Get the `i'th node. get `null' otherwise.
+ # Get the `i`th node. get `null` otherwise.
private fun get_node(i: Int): nullable ListNode[E]
do
var n = _head
return n
end
- # get the first node that contains e after 'after', null otherwise
+ # get the first node that contains `e` after 'after', null otherwise
private fun search_node_after(e: E, after: nullable ListNode[E]): nullable ListNode[E]
do
var n = after
_index += 1
end
- # Build a new iterator from `node'.
+ # Build a new iterator for `list`.
private init(list: List[E])
do
_list = list