moonbitstack/moonstl/sketch does not have a README file
pub struct BloomFilter[T] {
hash_seed : Int
hashes : Int
expected_items : Int
false_positive_rate : Double
growth : Growth
layers : Array[BloomLayer]
items : Int64
}impl Eq for BloomFilter[T]impl Hash for BloomFilter[T]impl Show for BloomFilter[T]fn[T] BloomFilter::intersection(self : BloomFilter[T], other : BloomFilter[T]) -> BloomFilter[T] raise Refusedfn[T] BloomFilter::new(expected_items~ : Int, bloom_options? : BloomOptions, hash_seed? : Int) -> BloomFilter[T] raise Refusedtest {
let filter : @sketch.BloomFilter[String] = @sketch.BloomFilter::new(
expected_items=1000,
) catch {
_ => abort("valid parameters")
}
assert_false(filter.may_contain("absent"))
assert_true(filter.insert("present"))
assert_true(filter.may_contain("present"))
}fn[T] BloomFilter::union(self : BloomFilter[T], other : BloomFilter[T]) -> BloomFilter[T] raise Refusedpub struct BloomLayer {
words : Array[UInt64]
bit_count : Int
capacity : Int
items : Int64
rate : Double
}pub struct CountMinSketch[T] {
seed : Int
width : Int
depth : Int
counters : Array[Int]
total : Int64
}test {
let sketch : @sketch.CountMinSketch[String] = @sketch.CountMinSketch::new(
epsilon=0.01,
confidence=0.99,
)
for _ in 0..<5 {
sketch.insert("a")
}
assert_true(sketch.estimate("a") >= 5)
assert_true(sketch.estimate("b") == 0)
assert_true(sketch.total() == 5L)
}fn[T] CountMinSketch::merge(self : CountMinSketch[T], other : CountMinSketch[T]) -> Unit raise Refusedfn[T] CountMinSketch::new(epsilon? : Double, confidence? : Double, hash_seed? : Int) -> CountMinSketch[T] raise Refusedpub struct CuckooFilter[T] {
seed : Int
slots : Array[Int]
buckets : Int
bucket_size : Int
bits : Int
mask : UInt64
items : Int64
}test {
let filter : @sketch.CuckooFilter[String] = @sketch.CuckooFilter::new(
expected_items=100,
)
assert_true(filter.insert("a"))
assert_true(filter.may_contain("a"))
assert_true(filter.remove("a"))
assert_true(!filter.may_contain("a"))
}fn[T] CuckooFilter::new(expected_items~ : Int, cuckoo_options? : CuckooOptions, hash_seed? : Int) -> CuckooFilter[T] raise Refusedtest {
let log : @sketch.HyperLogLog[Int32] = @sketch.HyperLogLog::new(precision=12)
for i in 0..<1000 {
log.add(i)
}
let estimate = log.estimate()
assert_true(estimate > 900.0)
assert_true(estimate < 1100.0)
}test {
let digest : @sketch.TDigest = @sketch.TDigest::new()
for i in 0..<1000 {
digest.add(i.to_double())
}
let median = digest.quantile(0.5)
assert_true(median > 450.0)
assert_true(median < 550.0)
assert_true(digest.count() == 1000.0)
}test {
let sketch : @sketch.ThetaSketch[Int32] = @sketch.ThetaSketch::new(
nominal_entries=1024,
)
for i in 0..<500 {
sketch.add(i)
}
assert_true(sketch.estimate() > 450.0)
assert_true(sketch.estimate() < 550.0)
}Install
Download zipData structures and algorithms the MoonBit core library leaves out.