From f60a5c4a863b36451a4ab2634aa888f97c4d71e3 Mon Sep 17 00:00:00 2001 From: Adrian Kuta Date: Sun, 7 Jun 2026 23:30:48 +0200 Subject: [PATCH] Release 4.1.0: structural mutations, query algorithms, customizable prettyString, immutable module --- CHANGELOG.md | 5 ++++- README.md | 29 +++++++++++++++++++++++------ build.gradle.kts | 2 +- 3 files changed, 28 insertions(+), 8 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 87b2e1c..77874e6 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,8 @@ All notable changes to this project are documented here. The format is based on ## [Unreleased] +## [4.1.0] - 2026-06-07 + ### Added - Structural mutation helpers on `TreeNode`: `insertChild`, `removeChildAt`, `replaceChild`, `moveChild`, `addChildren`, and `sortChildren`. @@ -89,7 +91,8 @@ A breaking release that cleans up the core API and enforces an explicit public s ## [3.1.3] - iOS targets and Maven Central (Sonatype Central Portal) publishing. -[Unreleased]: https://github.com/AdrianKuta/Tree-Data-Structure/compare/v4.0.0...HEAD +[Unreleased]: https://github.com/AdrianKuta/Tree-Data-Structure/compare/v4.1.0...HEAD +[4.1.0]: https://github.com/AdrianKuta/Tree-Data-Structure/compare/v4.0.0...v4.1.0 [4.0.0]: https://github.com/AdrianKuta/Tree-Data-Structure/compare/v3.4.0...v4.0.0 [3.4.0]: https://github.com/AdrianKuta/Tree-Data-Structure/compare/v3.1.5...v3.4.0 [3.1.5]: https://github.com/AdrianKuta/Tree-Data-Structure/compare/v3.1.3...v3.1.5 diff --git a/README.md b/README.md index bdbc272..73c2fb5 100644 --- a/README.md +++ b/README.md @@ -30,14 +30,14 @@ Gradle (Kotlin DSL): ```kotlin // commonMain for KMP projects, or any sourceSet/module where you need it dependencies { - implementation("com.github.adriankuta:tree-structure:4.0.0") // latest version is on the badge above + implementation("com.github.adriankuta:tree-structure:4.1.0") // latest version is on the badge above } ``` Gradle (Groovy): ```groovy dependencies { - implementation "com.github.adriankuta:tree-structure:4.0.0" + implementation "com.github.adriankuta:tree-structure:4.1.0" } ``` @@ -46,7 +46,7 @@ Maven: com.github.adriankuta tree-structure - 4.0.0 + 4.1.0 ``` @@ -160,7 +160,7 @@ that depends on the core. `@Serializable` directly. Convert to and from the acyclic `TreeNodeDto` instead. ```kotlin -implementation("com.github.adriankuta:tree-structure-serialization:4.0.0") +implementation("com.github.adriankuta:tree-structure-serialization:4.1.0") ``` ```kotlin val json = Json.encodeToString(root.toDto()) @@ -172,7 +172,7 @@ val restored = Json.decodeFromString>(json).toTreeNode() Traverse a tree as a cold `Flow`, which is handy inside coroutine and `ViewModel` pipelines. ```kotlin -implementation("com.github.adriankuta:tree-structure-coroutines:4.0.0") +implementation("com.github.adriankuta:tree-structure-coroutines:4.1.0") ``` ```kotlin root.preOrderFlow().collect { println(it.value) } @@ -185,7 +185,7 @@ A `LazyTree` composable for Compose Multiplatform (JVM/desktop, iOS, Wasm). Only are composed, and you decide how each node looks: ```kotlin -implementation("com.github.adriankuta:tree-structure-compose:4.0.0") +implementation("com.github.adriankuta:tree-structure-compose:4.1.0") ``` ```kotlin LazyTree(root) { node, depth, expanded, toggle -> @@ -196,6 +196,23 @@ LazyTree(root) { node, depth, expanded, toggle -> } ``` +### Immutable (`tree-structure-immutable`) + +A persistent `ImmutableTreeNode` with structural sharing. Every operation (`addChild`, +`removeChild`, `mapValues`) returns a **new** root and leaves the original untouched; unchanged +subtrees are reused, so updates are cheap and old roots stay valid. Backed by +`kotlinx.collections.immutable`. + +```kotlin +implementation("com.github.adriankuta:tree-structure-immutable:4.1.0") +``` +```kotlin +val root = ImmutableTreeNode("World").addChild(ImmutableTreeNode("Europe")) +val bigger = root.addChild(ImmutableTreeNode("Asia")) // root is unchanged; bigger is a new tree + +bigger.preOrder().forEach { println(it.value) } // pre/post/level-order, nodeCount(), height() +``` + ## Notes `TreeNode` is mutable and not thread-safe. Add your own synchronization if you share a tree across diff --git a/build.gradle.kts b/build.gradle.kts index db0806f..18e36ee 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -11,7 +11,7 @@ plugins { val PUBLISH_GROUP_ID = "com.github.adriankuta" val PUBLISH_ARTIFACT_ID = "tree-structure" // base artifact; KMP will add -jvm, -ios*, etc. -val PUBLISH_VERSION = "4.0.0" +val PUBLISH_VERSION = "4.1.0" val snapshot: String? by project