scoop:scoop.std:0.1.0
src/collections/sorted_set_factories.scoop
Selected production source · src/collections/sorted_set_factories.scoop
1
package scoop.collections3
import scoop.comparisons.Comparator4
import scoop.comparisons.naturalOrder6
internal class SortedSetSnapshot<T> internal constructor(7
private val elements: SortedSet<T>8
) : SortedSet<T> by elements10
/**11
* Creates an ordered set using the supplied or natural comparator.12
*/13
public fun <T> sortedSetOf(comparator: Comparator<T>, vararg elements: T): TreeSet<T> {14
val result = TreeSet<T>(comparator)15
for (element in elements) result.add(element)16
return result17
}19
/**20
* Creates an ordered set using the supplied or natural comparator.21
*/22
public fun <T : Compare<T>> sortedSetOf(vararg elements: T): TreeSet<T> =23
sortedSetOf<T>(naturalOrder<T>(), *elements)25
/**26
* Copies elements into a read-only ordered set using the selected ordering.27
*/28
public fun <T> Iterable<T>.toSortedSet(comparator: Comparator<T>): SortedSet<T> {29
val result = TreeSet<T>(comparator)30
for (element in this) result.add(element)31
return SortedSetSnapshot<T>(result)32
}34
/**35
* Copies elements into a read-only ordered set using the selected ordering.36
*/37
public fun <T : Compare<T>> Iterable<T>.toSortedSet(): SortedSet<T> = toSortedSet<T>(naturalOrder<T>())