From 05a39a12d38f34e1e436cb50bbe74cad9f71d68f Mon Sep 17 00:00:00 2001 From: Eric Eilebrecht Date: Thu, 16 May 2024 07:27:48 -0700 Subject: [PATCH] Update comments --- .../kotlin/com/certora/collect/TreapSet.kt | 26 ++++++++++++++++--- 1 file changed, 22 insertions(+), 4 deletions(-) diff --git a/collect/src/main/kotlin/com/certora/collect/TreapSet.kt b/collect/src/main/kotlin/com/certora/collect/TreapSet.kt index f09913d..14e719a 100644 --- a/collect/src/main/kotlin/com/certora/collect/TreapSet.kt +++ b/collect/src/main/kotlin/com/certora/collect/TreapSet.kt @@ -26,8 +26,9 @@ public sealed interface TreapSet : PersistentSet { override fun builder(): Builder<@UnsafeVariance T> = TreapSetBuilder(this) /** - Checks if this set contains any of the given [elements]. This is equivalent to, but more efficient than, - `this.intersect(elements).isNotEmpty()`. + Checks if this set contains any of the given [elements]. + + This is equivalent to, but more efficient than, `this.intersect(elements).isNotEmpty()`. */ public fun containsAny(elements: Iterable<@UnsafeVariance T>): Boolean @@ -43,17 +44,34 @@ public sealed interface TreapSet : PersistentSet { /** If this set contains an element that compares equal to the specified [element], returns that element instance. + This is useful for implementing intern tables, for example. */ public fun findEqual(element: @UnsafeVariance T): T? /** - Calls [action] for each element in the set. This traverses the treap without allocating temporary storage, - which may be more efficient than [forEach]. + Calls [action] for each element in the set. + + This traverses the treap without allocating temporary storage, which may be more efficient than [forEach]. */ public fun forEachElement(action: (element: T) -> Unit): Unit + /** + Calls [map] for each element in the set, and then reduces the results with [reduce]. + + This traverses the treap without allocating temporary storage, which may be more efficient than using the [map] + and [reduce] functions. + */ public fun mapReduce(map: (T) -> R, reduce: (R, R) -> R): R? + + /** + Calls [map] for each element in the set, and then reduces the results with [reduce]. + + Operations are performed in parallel for sets larger than (approximately) 2^parallelThresholdLog2. + + This traverses the treap without allocating temporary storage, which may be more efficient than using the [map] + and [reduce] functions. + */ public fun parallelMapReduce(map: (T) -> R, reduce: (R, R) -> R, parallelThresholdLog2: Int = 5): R? }