moa_idalloc 0.1.4

id 分配工具箱:单调号 / 回收位图 / 世代槽位表
Documentation
  • Coverage
  • 100%
    22 out of 22 items documented0 out of 18 items with examples
  • Size
  • Source code size: 20.37 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 345.79 kB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 2s Average build duration of successful builds.
  • all releases: 2s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • Repository
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • hengtianzhang

id 分配工具箱

提供三种互补的 id 分配机制,按需求选用:

类型 机制 用途 号的形态
[monotonic::IdGen] 单调递增 AtomicU64 全局对象身份(koid) 稀疏大整数、永不复用、ABA 免疫、无锁
[dense::IdAllocator] 回收位图 小而密的可复用号(pid) 最小空闲优先、自动增长、可复用
[table::IdTable] 世代槽位表 号↔对象表(handle) 密集索引 + generation 防 ABA、O(1)

选择要点:

  • 只需要一个永不重复的标识(对外暴露、做比较或 map key)→ [monotonic::IdGen], 机制最简、从根上免疫复用问题,64 位空间实际不可能耗尽。
  • 需要小而密、可读、可回收的号(典型如 pid)→ [dense::IdAllocator]。
  • 需要按号存取对象且担心裸号被缓存后复用指向错对象 → [table::IdTable], id 自带 generation,旧号在查找时被拒。