code wiki / (root) / nx_bloom_capacity_test.nx

nx_bloom_capacity_test.nx source

↩ module page · 48 lines · 2074 B

1// nx_bloom_capacity_test.nx -- smoke for FPR-profile bloom construction. 2 3import "nx_syscalls.nx" 4import "nx_tier.nx" 5import "nx_bloom.nx" 6import "nx_bloom_capacity.nx" 7 8func main() -> nx_exit { 9 // T1: next_pow2 10 if nx_bloom_next_pow2(1) != 8 { return 11 } 11 if nx_bloom_next_pow2(8) != 8 { return 12 } 12 if nx_bloom_next_pow2(9) != 16 { return 13 } 13 if nx_bloom_next_pow2(1023) != 1024 { return 14 } 14 if nx_bloom_next_pow2(1024) != 1024 { return 15 } 15 if nx_bloom_next_pow2(1025) != 2048 { return 16 } 16 17 // T2: target_bits 18 if nx_bloom_target_bits(1000, NX_BLOOM_PROFILE_1PCT) != 9587 { return 21 } 19 if nx_bloom_target_bits(1000, NX_BLOOM_PROFILE_10PCT) != 4790 { return 22 } 20 if nx_bloom_target_bits(1000, NX_BLOOM_PROFILE_P1PCT) != 14376 { return 23 } 21 22 // T3: byte_cost 23 if nx_bloom_byte_cost(1000, NX_BLOOM_PROFILE_1PCT) != 2048 { return 31 } 24 let big_cost: nx_int = nx_bloom_byte_cost(1000000, NX_BLOOM_PROFILE_1PCT) 25 if big_cost != 2097152 { return 32 } 26 27 // T4: profile_k 28 if nx_bloom_profile_k(NX_BLOOM_PROFILE_10PCT) != 3 { return 41 } 29 if nx_bloom_profile_k(NX_BLOOM_PROFILE_5PCT) != 4 { return 42 } 30 if nx_bloom_profile_k(NX_BLOOM_PROFILE_1PCT) != 7 { return 43 } 31 if nx_bloom_profile_k(NX_BLOOM_PROFILE_P1PCT) != 10 { return 44 } 32 if nx_bloom_profile_k(NX_BLOOM_PROFILE_P01PCT) != 13 { return 45 } 33 34 // T5: end-to-end 35 let b: *Bloom = nx_bloom_new_for_capacity(1000, NX_BLOOM_PROFILE_1PCT) 36 if b == (0 as *Bloom) { return 51 } 37 bloom_insert(b, "lean.mathlib.Nat.add_comm", 26) 38 bloom_insert(b, "coq.stdlib.Lists.List.app_nil", 29) 39 bloom_insert(b, "isabelle.AFP.Algebra.Group", 26) 40 if bloom_contains(b, "lean.mathlib.Nat.add_comm", 26) != 1 { return 52 } 41 if bloom_contains(b, "coq.stdlib.Lists.List.app_nil", 29) != 1 { return 53 } 42 if bloom_contains(b, "isabelle.AFP.Algebra.Group", 26) != 1 { return 54 } 43 44 // T6: never-inserted, hash-distant 45 if bloom_contains(b, "metamath.set.mm.thm_foo", 23) != 0 { return 61 } 46 47 return 0 48}