nitlanguage
/
nit.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge: GitHub API: handles comments
[nit.git]
/
lib
/
standard
/
collection
/
list.nit
diff --git
a/lib/standard/collection/list.nit
b/lib/standard/collection/list.nit
index
0c5ce5f
..
66ef4af
100644
(file)
--- a/
lib/standard/collection/list.nit
+++ b/
lib/standard/collection/list.nit
@@
-18,7
+18,9
@@
import abstract_collection
# Double linked lists.
class List[E]
super Sequence[E]
# Double linked lists.
class List[E]
super Sequence[E]
+
# Access
# Access
+
redef fun [](index) do return get_node(index).item
redef fun []=(index, item) do get_node(index).item = item
redef fun [](index) do return get_node(index).item
redef fun []=(index, item) do get_node(index).item = item
@@
-137,7
+139,7
@@
class List[E]
end
# Append `l` to `self` but clear `l`.
end
# Append `l` to `self` but clear `l`.
- ##
+ #
# O(1)
fun link(l: List[E])
do
# O(1)
fun link(l: List[E])
do
@@
-210,10
+212,10
@@
class List[E]
init from(coll: Collection[E]) do append(coll)
# The first node of the list
init from(coll: Collection[E]) do append(coll)
# The first node of the list
- var _head: nullable ListNode[E]
+ private var head: nullable ListNode[E] = null
# The last node of the list
# The last node of the list
- var _tail: nullable ListNode[E]
+ private var tail: nullable ListNode[E] = null
# Get the `i`th node. get `null` otherwise.
private fun get_node(i: Int): nullable ListNode[E]
# Get the `i`th node. get `null` otherwise.
private fun get_node(i: Int): nullable ListNode[E]
@@
-276,6
+278,7
@@
class ListIterator[E]
super IndexedIterator[E]
redef fun item do return _node.item
super IndexedIterator[E]
redef fun item do return _node.item
+ # Set item `e` at self `index`.
fun item=(e: E) do _node.item = e
redef fun is_ok do return not _node == null
fun item=(e: E) do _node.item = e
redef fun is_ok do return not _node == null
@@
-287,21
+290,19
@@
class ListIterator[E]
end
# Build a new iterator for `list`.
end
# Build a new iterator for `list`.
- private init(list: List[E])
+ init
do
do
- _list = list
- _node = list._head
- _index = 0
+ _node = _list._head
end
# The current list
end
# The current list
- var _list: List[E]
+ private var list: List[E]
# The current node of the list
# The current node of the list
- var _node: nullable ListNode[E]
+ private var node: nullable ListNode[E] = null
# The index of the current node
# The index of the current node
- redef readable var _index: Int
+ redef var index = 0
# Remove the current item
fun delete
# Remove the current item
fun delete
@@
-325,9
+326,9
@@
private class ListReverseIterator[E]
_index -= 1
end
_index -= 1
end
- private init(list: List[E])
+ init
do
do
- _list = list
+ var list = _list
_node = list._tail
_index = list.length
end
_node = list._tail
_index = list.length
end
@@
-336,14
+337,10
@@
end
# Linked nodes that constitute a linked list.
private class ListNode[E]
super Container[E]
# Linked nodes that constitute a linked list.
private class ListNode[E]
super Container[E]
- init(i: E)
- do
- item = i
- end
# The next node.
# The next node.
- readable writable var _next: nullable ListNode[E]
+ var next: nullable ListNode[E] = null
# The previous node.
# The previous node.
- readable writable var _prev: nullable ListNode[E]
+ var prev: nullable ListNode[E] = null
end
end