
Ordered B-tree map and set implementing Rust std semantics, preserving upstream behavior and tests; offers stable-order iteration, efficient B-tree operations, and parity-oriented translation.
This is a Kotlin Multiplatform port of Rust's std::collections::BTreeMap
and BTreeSet, translated from the Rust standard library implementation in
rust-lang/rust.
The upstream Rust repository is the main source repository for the Rust compiler, standard library, and documentation. This package focuses only on the standard-library B-tree collections and keeps their public behavior, tests, and documentation as the behavioral oracle for the Kotlin API.
The original implementation belongs to the Rust Project and its contributors:
rust-lang/rust
library/alloc/src/collections/btree
BTreeMap docs: std::collections::BTreeMap
BTreeSet docs: std::collections::BTreeSet
btree-kotlin is downstream translation work. The collection design, edge-case
behavior, examples, and much of the test corpus come from the Rust standard
library. Thank you to the Rust Project contributors and maintainers for the
careful B-tree implementation this port is built from.
BTreeMap<K, V> is an ordered map. Keys are stored by their natural
Comparable<K> order, iteration visits entries in ascending key order, and
lookup/update/removal follow the B-tree behavior of the upstream Rust
collection.
BTreeSet<T> is an ordered set implemented on top of the same B-tree map
machinery. Its iteration order is ascending item order, and its set operations
track the Rust standard library semantics where those operations have Kotlin
equivalents.
As in Rust, keys or set items should not change their ordering while they are stored in a collection. Kotlin cannot model Rust's exact ownership and allocator APIs, so this port keeps the observable collection behavior while adapting the memory-management pieces to Kotlin Multiplatform.
dependencies {
implementation("io.github.kotlinmania:btree-kotlin:0.2.1")
}import io.github.kotlinmania.btree.BTreeMap
import io.github.kotlinmania.btree.BTreeSet
val reviews = BTreeMap<String, String>()
reviews.insert("Office Space", "Deals with real issues in the workplace.")
reviews.insert("Pulp Fiction", "Masterpiece.")
for ((title, review) in reviews) {
println("$title: $review")
}
val books = BTreeSet<String>()
books.insert("The Odyssey")
books.insert("The Great Gatsby")
println(books.contains("The Odyssey"))btree-kotlin is a parity-oriented port. The production source tree has direct
provenance markers back to the Rust standard library files via
// port-lint: source <path> headers, and tools/ast_distance/ is used to
measure remaining drift.
Current parity reports show the Rust source files are represented in Kotlin; the remaining report noise is mostly Rust trait-implementation shape, docs, and test-helper differences that do not map one-for-one onto Kotlin.
./gradlew build
./gradlew testThe repo-local test task runs the portable gate used for this package:
macOS arm64, JS Node, and WasmJS Node tests.
See AGENTS.md and CLAUDE.md for the translation contract: upstream ordering, provenance headers, Kotlin naming conventions, and the no-stubs policy.
The upstream Rust standard library is dual-licensed under Apache-2.0 or MIT,
at the user's option. See the Rust Project's
COPYRIGHT,
LICENSE-APACHE, and LICENSE-MIT for the
license terms mirrored by this port.
Original work: Copyright (c) The Rust Project Contributors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
This project exists because the Rust Project made a high-quality, well-tested B-tree map and set available under permissive open-source licenses. The Kotlin port aims to preserve that work faithfully for Kotlin Multiplatform users while making the original authorship visible and easy to follow.
This is a Kotlin Multiplatform port of Rust's std::collections::BTreeMap
and BTreeSet, translated from the Rust standard library implementation in
rust-lang/rust.
The upstream Rust repository is the main source repository for the Rust compiler, standard library, and documentation. This package focuses only on the standard-library B-tree collections and keeps their public behavior, tests, and documentation as the behavioral oracle for the Kotlin API.
The original implementation belongs to the Rust Project and its contributors:
rust-lang/rust
library/alloc/src/collections/btree
BTreeMap docs: std::collections::BTreeMap
BTreeSet docs: std::collections::BTreeSet
btree-kotlin is downstream translation work. The collection design, edge-case
behavior, examples, and much of the test corpus come from the Rust standard
library. Thank you to the Rust Project contributors and maintainers for the
careful B-tree implementation this port is built from.
BTreeMap<K, V> is an ordered map. Keys are stored by their natural
Comparable<K> order, iteration visits entries in ascending key order, and
lookup/update/removal follow the B-tree behavior of the upstream Rust
collection.
BTreeSet<T> is an ordered set implemented on top of the same B-tree map
machinery. Its iteration order is ascending item order, and its set operations
track the Rust standard library semantics where those operations have Kotlin
equivalents.
As in Rust, keys or set items should not change their ordering while they are stored in a collection. Kotlin cannot model Rust's exact ownership and allocator APIs, so this port keeps the observable collection behavior while adapting the memory-management pieces to Kotlin Multiplatform.
dependencies {
implementation("io.github.kotlinmania:btree-kotlin:0.2.1")
}import io.github.kotlinmania.btree.BTreeMap
import io.github.kotlinmania.btree.BTreeSet
val reviews = BTreeMap<String, String>()
reviews.insert("Office Space", "Deals with real issues in the workplace.")
reviews.insert("Pulp Fiction", "Masterpiece.")
for ((title, review) in reviews) {
println("$title: $review")
}
val books = BTreeSet<String>()
books.insert("The Odyssey")
books.insert("The Great Gatsby")
println(books.contains("The Odyssey"))btree-kotlin is a parity-oriented port. The production source tree has direct
provenance markers back to the Rust standard library files via
// port-lint: source <path> headers, and tools/ast_distance/ is used to
measure remaining drift.
Current parity reports show the Rust source files are represented in Kotlin; the remaining report noise is mostly Rust trait-implementation shape, docs, and test-helper differences that do not map one-for-one onto Kotlin.
./gradlew build
./gradlew testThe repo-local test task runs the portable gate used for this package:
macOS arm64, JS Node, and WasmJS Node tests.
See AGENTS.md and CLAUDE.md for the translation contract: upstream ordering, provenance headers, Kotlin naming conventions, and the no-stubs policy.
The upstream Rust standard library is dual-licensed under Apache-2.0 or MIT,
at the user's option. See the Rust Project's
COPYRIGHT,
LICENSE-APACHE, and LICENSE-MIT for the
license terms mirrored by this port.
Original work: Copyright (c) The Rust Project Contributors.
Kotlin port: Copyright (c) 2026 Sydney Renee and The Solace Project.
This project exists because the Rust Project made a high-quality, well-tested B-tree map and set available under permissive open-source licenses. The Kotlin port aims to preserve that work faithfully for Kotlin Multiplatform users while making the original authorship visible and easy to follow.