Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,10 @@ tasks.test {
}
kotlin {
jvmToolchain(23)
compilerOptions {
allWarningsAsErrors.set(true)
freeCompilerArgs.add("-Xreturn-value-checker=full")
}
}

tasks.withType<org.jetbrains.dokka.gradle.DokkaTask>().configureEach {
Expand Down
1 change: 1 addition & 0 deletions src/main/kotlin/kodvent/collections/MapExtensions.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ public fun <T> MutableMap<T, Int>.increment(key: T) {
* @sample samples.IncrementAndDecrementSamples.decrementBasicUsage
* @sample samples.IncrementAndDecrementSamples.decrementInventoryManagement
*/
@IgnorableReturnValue
public fun <T> MutableMap<T, Int>.decrement(key: T): Boolean {
val count = this[key] ?: return false
if (count > 1) {
Expand Down
5 changes: 4 additions & 1 deletion src/main/kotlin/kodvent/datastructures/DisjointSetUnion.kt
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public class DisjointSetUnion(size: Int) {
* @sample samples.DisjointSetUnionSamples.basicUsage
* @sample samples.DisjointSetUnionSamples.detectingCycles
*/
@IgnorableReturnValue
public fun union(x: Int, y: Int): Boolean {
val rootX = find(x)
val rootY = find(y)
Expand Down Expand Up @@ -159,7 +160,9 @@ public class DisjointSetUnion(size: Int) {
throw IndexOutOfBoundsException("Element ($x) is out of disjoint set bounds: [0, ${parent.size})")
}

parent.indices.forEach { find(it) }
for (i in parent.indices) {
parent[i] = find(i)
}

val oldRoot = parent[x]
val elementsInSet = parent.indices.filter { parent[it] == oldRoot }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -494,8 +494,9 @@ class DisjointSetUnionTest {
dsu.union(5, 6)

// Trigger path compression by finding a deep element
dsu.find(6)
dsu.find(0)
val root6BeforeIsolate = dsu.find(6)
val root0BeforeIsolate = dsu.find(0)
assertEquals(root6BeforeIsolate, root0BeforeIsolate, "All elements should share the same root before isolate(3)")

// Now isolate element 3
dsu.isolate(3)
Expand Down