hiroyannnn/sketch/lib does not have a README file

    SketchError

    pub(all) suberror SketchError {
    PrecisionMismatch
    InvalidPrecision
    InvalidDimension
    }

    Error type for sketch operations.

    • PrecisionMismatch — two sketches have incompatible parameters.
    • InvalidPrecision — precision is outside the allowed range (4–18).
    • InvalidDimension — width or depth is not positive.
    impl Show for SketchError

    CountMinSketch

    pub struct CountMinSketch {
    // private fields
    }

    A Count-Min Sketch frequency estimator.

    CountMinSketch::add

    fn CountMinSketch::add(self : CountMinSketch, value : String, count? : Int) -> Unit

    Increments the frequency of value by count (default 1).

    CountMinSketch::estimate

    fn CountMinSketch::estimate(self : CountMinSketch, value : String) -> Int

    Returns the estimated frequency of value.

    CountMinSketch::merge

    Merges other into self and returns a new CountMinSketch.

    Both sketches must have the same width and depth; otherwise Err(PrecisionMismatch) is returned.

    CountMinSketch::new

    fn CountMinSketch::new(width? : Int, depth? : Int) -> CountMinSketch raise SketchError

    Creates a new CountMinSketch.

    • width — number of counters per row (default 1000).
    • depth — number of hash functions / rows (default 5).

    Returns Err(InvalidDimension) when width or depth is not positive.

    CuckooFilter

    pub struct CuckooFilter {
    // private fields
    }

    A Cuckoo Filter for approximate set membership testing.

    CuckooFilter::contains

    fn CuckooFilter::contains(self : CuckooFilter, value : String) -> Bool

    Returns true if value may be in the filter (with possible false positives).

    CuckooFilter::count

    fn CuckooFilter::count(self : CuckooFilter) -> Int

    Returns the number of items currently in the filter.

    CuckooFilter::insert

    fn CuckooFilter::insert(self : CuckooFilter, value : String) -> Bool

    Inserts value into the filter. Returns true on success, false when the filter is too full to relocate fingerprints.

    CuckooFilter::new

    fn CuckooFilter::new(capacity? : Int, bucket_size? : Int) -> CuckooFilter raise SketchError

    Creates a new CuckooFilter.

    • capacity — approximate maximum number of items (default 1024).
    • bucket_size — fingerprints per bucket (default 4).

    Returns Err(InvalidDimension) when capacity or bucket_size is not positive.

    CuckooFilter::remove

    fn CuckooFilter::remove(self : CuckooFilter, value : String) -> Bool

    Removes one occurrence of value from the filter. Returns true if the fingerprint was found and removed.

    Only remove items that were actually inserted to avoid corrupting the filter state.

    HyperLogLog

    pub struct HyperLogLog {
    // private fields
    }

    A HyperLogLog cardinality estimator.
    impl Show for HyperLogLog

    HyperLogLog::add

    fn HyperLogLog::add(self : HyperLogLog, value : String) -> Unit

    Adds value to the sketch.

    HyperLogLog::count

    fn HyperLogLog::count(self : HyperLogLog) -> Double

    Estimates the number of distinct values added so far.

    HyperLogLog::merge

    fn HyperLogLog::merge(self : HyperLogLog, other : HyperLogLog) -> HyperLogLog raise SketchError

    Merges other into self and returns a new HyperLogLog.

    Both sketches must have the same precision; otherwise Err(PrecisionMismatch) is returned.

    HyperLogLog::new

    fn HyperLogLog::new(precision? : Int) -> HyperLogLog raise SketchError

    Creates a new HyperLogLog with the given precision (4–18).

    The number of registers is 2^precision; higher precision gives lower relative error at the cost of more memory.

    Returns Err(InvalidPrecision) when precision is outside [4, 18].

    murmurhash3

    fn murmurhash3(key : String, seed? : Int) -> Int

    Computes the MurmurHash3 32-bit hash of key.

    The input string is UTF-8 encoded before hashing, so the result matches the standard MurmurHash3_x86_32 applied to the UTF-8 byte representation.

    seed allows generating multiple independent hash functions from the same key — pass different seed values (e.g. 0, 1, 2 …) to obtain independent hashes for structures like Count-Min Sketch.