Scoop API

scoop:scoop.std:0.1.0

src/collections/tree_iterator.scoop

Selected production source · src/collections/tree_iterator.scoop

1package scoop.collections
3internal class TreeIterator<K, V> internal constructor(
4 private val tree: BTree<K, V>,
5 private val structure: ModificationCounter
6) : 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 = 0L
10 private var exhausted: Boolean = false
12 public override fun next(): Map.Entry<K, V>? {
13 if (exhausted) return None
14 structure.check(stamp)
15 if (current == None) {
16 exhausted = true
17 return None
18 }
19 val node = current!!
20 val entry = node.entry(index)
21 val next = tree.successor(node, index)
22 current = next.node
23 index = next.index
24 return Some(entry)
25 }