slotmap

A small typed slot map with opaque handles and reusable slots for MoonBit.

slotmap
arena
handles
free-list
collection
moon add Yoorkin/slotmap@0.2.4
Download zip
Author
Version
0.2.4
License
Apache-2.0
Last updated
25 days ago
Downloads
35
README

#Slotmap

A small typed slot map for MoonBit. It stores values in reusable slots and returns opaque Id handles that can be used for later reads and writes.

#Example

///|
test {
let slots : SlotMap[Int] = SlotMap()
let id = slots.allocate()
slots[id] = 42
inspect(slots[id], content="42")

slots.free(id)
let reused = slots.allocate()
inspect(id == reused, content="false")
slots[reused] = 7
inspect(slots[reused], content="7")
}

#
SlotMap

type SlotMap[T]

#
SlotMap::SlotMap

fn[T] SlotMap::SlotMap() -> SlotMap[T]

#
SlotMap::allocate

fn[T] SlotMap::allocate(arena : SlotMap[T]) -> Id

#
SlotMap::allocate_with

fn[T] SlotMap::allocate_with(arena : SlotMap[T], f : (Id) -> T) -> Id

#
SlotMap::free

fn[T] SlotMap::free(arena : SlotMap[T], id : Id) -> Unit

#
SlotMap::get

fn[T] SlotMap::get(arena : SlotMap[T], id : Id) -> T?

#
SlotMap::read

#alias("_[_]")
fn[T] SlotMap::read(arena : SlotMap[T], id : Id) -> T

#
SlotMap::write

#alias("_[_]=_")
fn[T] SlotMap::write(arena : SlotMap[T], id : Id, value : T) -> Unit

Source Files

Powered by MoonBit

Site sourceReport issuePackagesBuild queueSkillsStatistics

© 2026 mooncakes.io