Pure MoonBit minimal perfect hash functions and checked static maps
let routes = @mphf.StaticIntMap::from_entries([
{ key: 101, value: 10 },
{ key: 203, value: 20 },
]).unwrap()
assert_eq(routes.get(203), Some(20))
assert_eq(routes.get(404), None)moon check --deny-warn
moon test --deny-warn
moon bench --release --deny-warn
moon run cmd/mainpub(all) struct IntEntry {
key : Int
value : Int
}pub(all) struct IntMultiEntry {
key : Int
value : Int
}pub(all) struct LookupSummary {
query_count : Int
hit_count : Int
miss_count : Int
}fn Mphf::build_with_options(keys : Array[Int], options : MphfBuildOptions) -> Result[Mphf, MphfError]pub(all) struct MphfBuildOptions {
vertices_per_key_milli : Int
max_attempts : Int
initial_seed : Int
}pub(all) enum MphfError {
EmptyInput
EmptySegment(Int)
NegativeKey(Int)
DuplicateKey(Int)
DuplicateValue(Int)
DuplicateStringKey(String)
HashCollision(String, String)
ConstructionFailed(Int)
MissingHeader
UnsupportedVersion(Int)
InvalidPayloadLength(Int, Int)
InvalidMetadata
InvalidVertexValue(Int)
InvalidBuildOption(Int)
InvalidShardCount(Int)
InvalidRange(Int, Int)
DuplicatePatchKey(Int)
}pub(all) struct MphfStats {
key_count : Int
vertex_count : Int
seed : Int
attempts : Int
}pub(all) struct SegmentStats {
segment_count : Int
key_count : Int
}fn SegmentedIntMap::from_batches(batches : Array[Array[IntEntry]]) -> Result[SegmentedIntMap, MphfError]pub(all) struct ShardStats {
shard_count : Int
key_count : Int
smallest_shard : Int
largest_shard : Int
}fn ShardedIntMap::from_entries(entries : Array[IntEntry], shard_count : Int) -> Result[ShardedIntMap, MphfError]fn ShardedIntMap::reshard(self : ShardedIntMap, shard_count : Int) -> Result[ShardedIntMap, MphfError]pub(all) struct StaticIndexFingerprint {
key_count : Int
key_fingerprint : Int
value_fingerprint : Int
}fn StaticIntMap::apply_patch(self : StaticIntMap, patch : StaticIntMapPatch) -> Result[StaticIntMap, MphfError]fn StaticIntMap::cursor_at(self : StaticIntMap, slot : Int) -> Result[StaticIntMapCursor, MphfError]fn StaticIntMap::from_entries_with_options(entries : Array[IntEntry], options : MphfBuildOptions) -> Result[StaticIntMap, MphfError]fn StaticIntMap::merge_prefer_right(self : StaticIntMap, other : StaticIntMap) -> Result[StaticIntMap, MphfError]fn StaticIntMapPatch::new(upserts : Array[IntEntry], removals : Array[Int]) -> Result[StaticIntMapPatch, MphfError]fn StaticIntMultiMap::from_entries(entries : Array[IntMultiEntry]) -> Result[StaticIntMultiMap, MphfError]fn StaticIntMultiMap::get_all_many(self : StaticIntMultiMap, keys : Array[Int]) -> Array[Array[Int]]fn StaticIntMultiMapCursor::collect_remaining(self : StaticIntMultiMapCursor) -> Array[IntMultiEntry]fn StaticIntMultiMapCursor::next(self : StaticIntMultiMapCursor) -> (IntMultiEntry?, StaticIntMultiMapCursor)fn StaticSet::from_keys_with_options(keys : Array[Int], options : MphfBuildOptions) -> Result[StaticSet, MphfError]fn StaticSetPatch::new(additions : Array[Int], removals : Array[Int]) -> Result[StaticSetPatch, MphfError]fn StaticStringIntMap::from_entries(entries : Array[StringIntEntry]) -> Result[StaticStringIntMap, MphfError]pub(all) struct StringIntEntry {
key : String
value : Int
}fn stable_string_hash(value : String) -> IntInstall
Download zipPure MoonBit minimal perfect hash functions and checked static maps