cli: add safe owning numeric-key maps
Register std.map with bounded U64Map<V>, exact key equality and explicit allocation/growth. Preserve returned ownership, old slots on reserve failure and original-authority refunds; support Copy values, owners and resources. Cover collision/tombstone/wrap behavior, independent dictionary traces, quota/cleanup/borrow/task rules, source/AIR parity and hosted/package CLI. Publish the API, roadmap and measured documentation cost. General key hashing/equality remains Q-037; numeric maps do not satisfy that gate.
This commit is contained in:
1 parent
fc23f1b23a
commit
57603860df
46 files changed
+2430
-15
No files matched your search
@@ -0,0 +1,30 @@
|
||||
module example.map
|
||||
import std.map;
|
||||
import std.option;
|
||||
fn main(heap: cap<mem.alloc>) -> u64 effects [mem.alloc] {
|
||||
match std.map.new::<own<u64>>(1, heap) {
|
||||
std.map.NewResult::<own<u64>>::err(error) => { trap; }
|
||||
std.map.NewResult::<own<u64>>::ok(map) => {
|
||||
let owner = own.new(42u64, heap) or trap;
|
||||
{ mut q = map;
|
||||
match std.map.insert::<own<u64>>(q, 7, move owner) {
|
||||
std.map.InsertResult::<own<u64>>::inserted => {}
|
||||
std.map.InsertResult::<own<u64>>::replaced(old) => { trap; }
|
||||
std.map.InsertResult::<own<u64>>::full(returned) => { trap; }
|
||||
}
|
||||
}
|
||||
var answer: u64 = 0;
|
||||
{ mut q = map;
|
||||
match std.map.remove::<own<u64>>(q, 7) {
|
||||
std.option.Option::<own<u64>>::none => { trap; }
|
||||
std.option.Option::<own<u64>>::some(value) => { answer = own.take(move value); }
|
||||
}
|
||||
}
|
||||
match std.map.free::<own<u64>>(move map) {
|
||||
std.map.FreeResult::<own<u64>>::ok => {}
|
||||
std.map.FreeResult::<own<u64>>::not_empty(returned) => { trap; }
|
||||
}
|
||||
return answer;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user