A hash map that preserves insertion order - MoonBit port of Rust's indexmap
let map = @aurasuisui/indexmap.new()
map.insert("b", 2) |> ignore
map.insert("a", 1) |> ignore
map.insert("c", 3) |> ignore
// Iteration follows insertion order: b, a, c
let iter = map.iter()
while true {
match iter.next() {
Some((k, v)) => println("\{k}: \{v}")
None => break
}
}{ "dependencies": { "aurasuisui/indexmap": "0.4.0" } }git clone https://github.com/aurasuisui/moonbit-indexmap| Category | Methods |
|---|---|
| Construct | new(), with_capacity(n), from_array(entries), default(), copy() |
| Query | len(), is_empty(), capacity(), load_factor(), max_probe() |
| Core | insert(k, v) -> V?, get(k) -> V?, remove(k) -> V?, contains(k) -> Bool, clear(), get_mut(k, f) |
| Entry | entry(k) -> EntryView (Occupied: get/insert/remove/key, Vacant: insert/key) |
| Index | get_index(i), get_full(k), get_index_of(k), first(), last(), pop(), swap_remove_index(i) |
| Capacity | reserve(n), shrink_to_fit() |
| Iterate | iter(), keys(), values(), for_each(f), into_iter(), into_array() |
| Bulk | retain(f), sort_by_key(), sort_by(cmp), drain(), extend_from_array(entries) |
| Traits | Debug, Default, Show, Hash, Eq, ToJson |
| Category | Methods |
|---|---|
| Construct | new(), with_capacity(n), from_array(elements), default(), copy() |
| Query | len(), is_empty(), capacity() |
| Core | insert(v) -> Bool, contains(v) -> Bool, remove(v) -> Bool, clear() |
| Set ops | is_disjoint(other), is_subset(other), is_superset(other) |
| Iterate | iter(), into_array() |
| Bulk | retain(f), drain(), extend_from_array(elements) |
| Traits | Debug, Default, Show, Hash, Eq, ToJson |
| Property | Map[K, V] | IndexMap[K, V] |
|---|---|---|
| Lookup | O(1) avg | O(1) avg |
| Iteration order | Insertion order (linked map) | Insertion order |
| Index access (get_index, first, pop, …) | No | Yes |
| Entry API (Occupied / Vacant) | No | Yes |
| Eq / Hash semantics | Independent of insertion order | Dependent on insertion order |
Released: the from_json API addition, the deletion-engine rewrite (backward-shift, tombstone-free) and the test-suite reorganization described here shipped in v0.4.0. See CHANGELOG.md [0.4.0].
Note: the cmd/* example packages are workspace members (listed in moon.work) and use pkgtype(kind: "executable") (migrated off the deprecated options("is-main")). Being in the workspace, they resolve aurasuisui/indexmap to the local source — so they're checked/formatted by the root moon check / moon fmt and run by the CI examples job without depending on the mooncakes registry (the historical reason they were excluded — the options("is-main") / version: latest conflict — is resolved by pkgtype). To run one locally: moon run cmd/<name> from the repo root.
moon check # Type check (0 warnings, 0 errors; --deny-warn clean)
moon test # Run all in-package tests (white-box + library-specific)
moon test --target <t># t = wasm-gc | wasm | js | native (CI tests all four)
moon fmt # Format codetype IndexMap[K, V]type IndexSet[K]type IntoMapIter[K, V]let LOAD_FACTOR_NUMERATOR : IntA hash map that preserves insertion order - MoonBit port of Rust's indexmap