scoop:scoop.std:0.1.0
src/collections/priority_queue_iteration.scoop
Selected production source · src/collections/priority_queue_iteration.scoop
1
package scoop.collections3
import scoop.comparisons.Comparator4
import scoop.comparisons.naturalOrder6
/**7
* Creates a min-priority queue from the supplied elements using the selected ordering.8
*/9
public fun <T> priorityQueueOf(comparator: Comparator<T>, vararg elements: T): PriorityQueue<T> {10
val result = PriorityQueue<T>(comparator)11
for (element in elements) result.add(element)12
return result13
}15
/**16
* Creates a min-priority queue from the supplied elements using the selected ordering.17
*/18
public fun <T : Compare<T>> priorityQueueOf(vararg elements: T): PriorityQueue<T> =19
priorityQueueOf<T>(naturalOrder<T>(), *elements)21
internal class HeapIterator<T> internal constructor(22
private val source: PriorityQueue<T>, private val structure: ModificationCounter23
) : Iterator<T> {24
private val stamp: RevisionStamp = structure.snapshot()25
private var index: Long = 0L26
private var exhausted: Boolean = false28
public override fun next(): T? {29
if (exhausted) return None30
structure.check(stamp)31
if (index == source.size) { exhausted = true; return None }32
val value = source.elementAt(index)33
index += 1L34
return Some(value)35
}36
}