redef fun iterator do return new ContainerIterator[E](self)
- # Create a new instance with a given initial value.
- init(e: E) do item = e
-
# The stored item
var item: E is writable
end
redef fun next do is_ok = false
- init(c: Container[E]) do _container = c
-
redef var is_ok: Bool = true
private var container: Container[E]
end
private var iter: Iterator[Couple[K,V]]
-
- init(i: Iterator[Couple[K,V]]) do _iter = i
end
# Some tools ###################################################################
# The second element of the couple.
var second: S is writable
-
- # Create a new instance with a first and a second object.
- init(f: F, s: S)
- do
- first = f
- second = s
- end
end
redef fun next do _index += 1
- init(a: AbstractArrayRead[E])
- do
- _array = a
- _index = 0
- end
-
redef var index = 0
private var array: AbstractArrayRead[E]
redef fun next do _index -= 1
- init(a: AbstractArrayRead[E])
+ init
do
- _array = a
- _index = a.length - 1
+ _index = _array.length - 1
end
end
redef fun item: E do return _iter.item
- init(iter: ArrayIterator[E]) do _iter = iter
-
private var iter: ArrayIterator[E]
end
private var prev_item: nullable N = null
private var prev_in_bucklet: nullable N = null
private var next_in_bucklet: nullable N = null
- init(k: K)
- do
- _key = k
- end
end
# A map implemented with a hash table.
super HashNode[K]
redef type N: HashMapNode[K, V]
private var value: V
-
- init(k: K, v: V)
- do
- super(k)
- _value = v
- end
end
class HashMapIterator[K: Object, V]
private var map: HashMap[K, V]
# The current node
- private var node: nullable HashMapNode[K, V]
+ private var node: nullable HashMapNode[K, V] = null
- init(map: HashMap[K, V])
+ init
do
_map = map
- _node = map._first_item
+ _node = _map._first_item
end
end
private class HashSetNode[E: Object]
super HashNode[E]
redef type N: HashSetNode[E]
-
- init(e: E)
- do
- _key = e
- end
end
private class HashSetIterator[E: Object]
private var set: HashSet[E]
# The position in the internal map storage
- private var node: nullable HashSetNode[E]
+ private var node: nullable HashSetNode[E] = null
- init(set: HashSet[E])
+ init
do
- _set = set
- _node = set._first_item
+ _node = _set._first_item
end
end
end
# Build a new iterator for `list`.
- private init(list: List[E])
+ init
do
- _list = list
- _node = list._head
- _index = 0
+ _node = _list._head
end
# The current list
private var list: List[E]
# The current node of the list
- private var node: nullable ListNode[E]
+ private var node: nullable ListNode[E] = null
# The index of the current node
- redef var index
+ redef var index = 0
# Remove the current item
fun delete
_index -= 1
end
- private init(list: List[E])
+ init
do
- _list = list
+ var list = _list
_node = list._tail
_index = list.length
end
# Linked nodes that constitute a linked list.
private class ListNode[E]
super Container[E]
- init(i: E)
- do
- item = i
- end
# The next node.
- var next: nullable ListNode[E]
+ var next: nullable ListNode[E] = null
# The previous node.
- var prev: nullable ListNode[E]
+ var prev: nullable ListNode[E] = null
end
# Iterator on ranges.
super Iterator[E]
private var range: Range[E]
- redef var item
+ redef var item is noinit
redef fun is_ok do return _item < _range.after
redef fun next do _item = _item.successor(1)
- init(r: Range[E])
+ init
do
- _range = r
- _item = r.first
+ _item = _range.first
end
end
end
end
- private init do end
- private init without_file do end
end
# File output stream
self.path = path
_is_writable = true
end
-
- private init do end
- private init without_file do end
end
###############################################################################
class Stdin
super IFStream
- private init do
+ init do
_file = new NativeFile.native_stdin
path = "/dev/stdin"
prepare_buffer(1)
class Stdout
super OFStream
- private init do
+ init do
_file = new NativeFile.native_stdout
path = "/dev/stdout"
_is_writable = true
class Stderr
super OFStream
- private init do
+ init do
_file = new NativeFile.native_stderr
path = "/dev/stderr"
_is_writable = true
init(default_comparator)
end
- init(comparator: Comparator) do self.comparator = comparator
-
redef fun is_empty do return items.is_empty
redef fun length do return items.length
redef fun iterator do return items.iterator
private var target: SELFTYPE
- private init(tgt: SELFTYPE)
- do
- target = tgt
- end
-
redef fun is_empty do return target.is_empty
redef fun length do return target.length
var tgt: nullable FlatText
- init(tgt: FlatText) do self.tgt = tgt
-
redef fun item do
assert is_ok
return tgt.as(not null)
end
end
- # Compile a new motif
- init(motif: String)
+ init
do
- _motif = motif
_length = _motif.length
_gs = new Array[Int].with_capacity(_length)
- _bc_table = new ArrayMap[Char, Int]
compute_gs
compute_bc
end
private var motif: String
# length of the motif
- private var length: Int
+ private var length: Int is noinit
private fun bc(e: Char): Int
do
end
# good shifts
- private var gs: Array[Int]
+ private var gs: Array[Int] is noinit
# bad characters
- private var bc_table: Map[Char, Int]
+ private var bc_table = new ArrayMap[Char, Int]
private fun compute_bc
do
# The contents of the matching part
redef fun to_s do return string.substring(from,length)
- # Matches `len` characters of `s` from `f`.
- init(s: String, f: Int, len: Int)
+ init
do
- assert positive_length: len >= 0
- assert valid_from: f >= 0
- assert valid_after: f + len <= s.length
- string = s
- from = f
- length = len
+ assert positive_length: length >= 0
+ assert valid_from: from >= 0
+ assert valid_after: from + length <= string.length
end
end