Scoop API

scoop:scoop.std:0.1.0

src/collections/priority_queue_iteration.scoop

Selected production source · src/collections/priority_queue_iteration.scoop

1package scoop.collections
3import scoop.comparisons.Comparator
4import scoop.comparisons.naturalOrder
6/**
7 * Creates a min-priority queue from the supplied elements using the selected ordering.
8 */
9public 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 result
15/**
16 * Creates a min-priority queue from the supplied elements using the selected ordering.
17 */
18public fun <T : Compare<T>> priorityQueueOf(vararg elements: T): PriorityQueue<T> =
19 priorityQueueOf<T>(naturalOrder<T>(), *elements)
21internal class HeapIterator<T> internal constructor(
22 private val source: PriorityQueue<T>, private val structure: ModificationCounter
23) : Iterator<T> {
24 private val stamp: RevisionStamp = structure.snapshot()
25 private var index: Long = 0L
26 private var exhausted: Boolean = false
28 public override fun next(): T? {
29 if (exhausted) return None
30 structure.check(stamp)
31 if (index == source.size) { exhausted = true; return None }
32 val value = source.elementAt(index)
33 index += 1L
34 return Some(value)
35 }