scoop:scoop.std:0.1.0
src/collections/tree_iterator.scoop
Selected production source · src/collections/tree_iterator.scoop
1
package scoop.collections3
internal class TreeIterator<K, V> internal constructor(4
private val tree: BTree<K, V>,5
private val structure: ModificationCounter6
) : Iterator<Map.Entry<K, V>> {7
private val stamp: RevisionStamp = structure.snapshot()8
private var current: BTreeNode<K, V>? = tree.first(tree.root)9
private var index: Long = 0L10
private var exhausted: Boolean = false12
public override fun next(): Map.Entry<K, V>? {13
if (exhausted) return None14
structure.check(stamp)15
if (current == None) {16
exhausted = true17
return None18
}19
val node = current!!20
val entry = node.entry(index)21
val next = tree.successor(node, index)22
current = next.node23
index = next.index24
return Some(entry)25
}26
}