Add std.hashset with explicit pure hash/equality policies and complete owning keys. Duplicate/full insert returns the original input, while remove/pop and nonempty free preserve explicit resource ownership. Reuse safe HashMap storage and failure/peak/refund accounting. Integrate normative contracts, RFC, references, complexity measurements, CLI/profile checks and independent Copy/owner set traces. Validation: 973 conformance cases; runtime set GC and schedule stress; unit/Quick Reference, formatting, hosted smoke, 53 CLI checks, 106 source coverage constructs and bundle generation.
23 lines
1.6 KiB
Rust
23 lines
1.6 KiB
Rust
// expect: reject E7005
|
|
// phase: 6
|
|
// spec: docs/spec/16-standard-library.md §2.15
|
|
module test.hashset
|
|
import std.hashset;
|
|
import std.option;
|
|
fn opened<K, H: fn(ref<K>) -> u64 effects [], E: fn(ref<K>,ref<K>) -> bool effects []>(capacity: usize,heap: cap<mem.alloc>) -> std.hashset.HashSet<K,fn H,fn E> effects [mem.alloc] {
|
|
match std.hashset.new::<K,fn H,fn E>(capacity,heap) { std.hashset.NewResult::<K,fn H,fn E>::ok(set) => { return move set; }, std.hashset.NewResult::<K,fn H,fn E>::err(error) => { trap; } }
|
|
}
|
|
fn inserted<K>(result: std.hashset.InsertResult<K>) -> void effects [] {
|
|
match move result { std.hashset.InsertResult::<K>::inserted => {}, std.hashset.InsertResult::<K>::present(key) => { trap; }, std.hashset.InsertResult::<K>::full(key) => { trap; } }
|
|
}
|
|
fn extracted<K>(result: std.option.Option<K>) -> K effects [] { match move result { std.option.Option::<K>::some(key) => { return move key; }, std.option.Option::<K>::none => { trap; } } }
|
|
fn released<K, H: fn(ref<K>) -> u64 effects [], E: fn(ref<K>,ref<K>) -> bool effects []>(set: std.hashset.HashSet<K,fn H,fn E>) -> void effects [] {
|
|
match std.hashset.free::<K,fn H,fn E>(move set) { std.hashset.FreeResult::<K,fn H,fn E>::ok => {}, std.hashset.FreeResult::<K,fn H,fn E>::not_empty(set) => { trap; } }
|
|
}
|
|
struct Key { id: u64, marker: u64 }
|
|
fn hash(key: ref<Key>) -> u64 effects [] { return 3; }
|
|
fn equal(a: ref<Key>,b: ref<Key>) -> bool effects [] { return a.id == b.id; }
|
|
fn other(key: ref<Key>) -> u64 effects [] { return 3; }
|
|
fn bad(q: ref<std.hashset.HashSet<Key,fn hash,fn equal>>) -> void effects [] { std.hashset.len::<Key,fn other,fn equal>(q); }
|
|
fn main() -> u64 effects [] { return 42; }
|