Git Product home page Git Product logo

sketches-rust's Introduction

sketches-rust

The port of the DDSketch rust implementation.

Features

  • CubicallyInterpolatedMapping
  • LogarithmicMapping
  • CollapsingHighestDenseStore: collapse the highest bucket when reach specified size
  • CollapsingLowestDenseStore: collapse the lowest bucket when reach specified size
  • UnboundedSizeDenseStore: unlimited bucket
  • Merge with other instance
  • Serialize & Deserialize

Usage

Run the following Cargo command in your project directory:

cargo add sketches-rust

Or add the following line to your Cargo.toml:

sketches-rust = "0.2.2"

Query:

    use sketches_rust::DDSketch;
    let mut d = DDSketch::collapsing_lowest_dense(0.02,100).unwrap();
    d.accept(1.0);
    d.accept(2.0);
    d.accept(3.0);
    let c = d.get_count();
    assert_eq!(c, 3.0);
    let q = d.get_value_at_quantile(0.5).unwrap();
    assert!(q < 2.01 && q > 1.99);

Merge:

    use sketches_rust::DDSketch;
    let mut d1 = DDSketch::collapsing_lowest_dense(0.02,100).unwrap();
    d1.accept(1.0);
    d1.accept(2.0);
    d1.accept(3.0);
    assert_eq!(3.0,  d1.get_count());
    let mut d2 = DDSketch::collapsing_lowest_dense(0.02,100).unwrap();
    d2.accept(1.0);
    d2.accept(2.0);
    d2.accept(3.0);
    assert_eq!(3.0,  d2.get_count());
    d2.merge_with(&mut d1).unwrap();
    assert_eq!(6.0,  d2.get_count());

Serialize:

    use sketches_rust::DDSketch;
    let mut d = DDSketch::unbounded_dense(2e-2).unwrap();
    d.accept(1.0);
    d.accept(2.0);
    d.accept(3.0);
    d.accept(4.0);
    d.accept(5.0);
    println!("encode: {:?}", d.encode().unwrap());

Deserialize:

    use sketches_rust::DDSketch;
    let mut input = vec![
        2, 42, 120, 57, 5, 47, 167, 240, 63, 0, 0, 0, 0, 0, 0, 0, 0, 13, 50, 130, 1, 2, 136, 32, 0,
        3, 0, 0, 0, 3, 0, 2, 0, 0, 3, 3, 2, 2, 3, 3, 2, 0, 0, 0, 0, 2, 0, 2, 2, 2, 4, 4, 132, 64,
        0, 4, 2, 0, 2, 2, 3, 132, 64, 4, 132, 64, 4, 2, 2, 0, 6, 4, 6, 132, 64, 2, 6,
    ];
    let mut d = DDSketch::decode(&input).unwrap();
    assert_eq!(d.get_count(), 100.0);

sketches-rust's People

Contributors

loyispa avatar pseitz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

sketches-rust's Issues

cargo test fails

Not sure that's an actual bug, but cargo test fails

failures:

---- index_mapping::tests::test_cubically_interpolated_mapping_validity stdout ----
test_cubically_interpolated_mapping_validity 0.3749889967909962 0.37127623444653085
test_cubically_interpolated_mapping_validity 0.38252642564907285 0.37873903529611175
test_cubically_interpolated_mapping_validity 0.3902265142353609 0.38636288538154545
test_cubically_interpolated_mapping_validity 0.3980918753953614 0.39415037167857564
test_cubically_interpolated_mapping_validity 0.4061244959895842 0.402103461375826
test_cubically_interpolated_mapping_validity 0.4143255934819437 0.4102233598831126
test_cubically_interpolated_mapping_validity 0.4226954580756281 0.4185103545303248
test_cubically_interpolated_mapping_validity 0.4312332828530113 0.4269636463891201
test_cubically_interpolated_mapping_validity 0.43993698603085424 0.4355811742879745
test_cubically_interpolated_mapping_validity 0.4488030314074022 0.44435943703703185
test_cubically_interpolated_mapping_validity 0.4578262552555936 0.4532933220352412
test_cubically_interpolated_mapping_validity 0.4669997101208343 0.46237595061468745
test_cubically_interpolated_mapping_validity 0.47631453792792017 0.4715985524038814
test_cubically_interpolated_mapping_validity 0.4857598861122004 0.4809503822893073
test_cubically_interpolated_mapping_validity 0.49532288072992153 0.49041869379200154
test_cubically_interpolated_mapping_validity 0.5049886692506151 0.49998878143625264
test_cubically_interpolated_mapping_validity 0.5151741473384301 0.5100734132063665
test_cubically_interpolated_mapping_validity 0.525535542291845 0.5203322200909356
test_cubically_interpolated_mapping_validity 0.5360783965863695 0.5307706896894747
test_cubically_interpolated_mapping_validity 0.5468089470049666 0.5413949970346205
test_cubically_interpolated_mapping_validity 0.5577336755097266 0.5522115599106204
test_cubically_interpolated_mapping_validity 0.5688593116454119 0.5632270412330811
test_cubically_interpolated_mapping_validity 0.5801928328282546 0.5744483493349055
test_cubically_interpolated_mapping_validity 0.5917414619512565 0.5858826355953035
test_cubically_interpolated_mapping_validity 0.6035126616227442 0.5975372887353902
test_cubically_interpolated_mapping_validity 0.615514124221722 0.609419924972002
test_cubically_interpolated_mapping_validity 0.6277537567998935 0.6215383730692016
test_cubically_interpolated_mapping_validity 0.6402396596850185 0.6339006531534837
test_cubically_interpolated_mapping_validity 0.6529800974432469 0.6465149479636108
test_cubically_interpolated_mapping_validity 0.6659834606405226 0.6593895649906164
test_cubically_interpolated_mapping_validity 0.6792582166086102 0.6725328877312972
test_cubically_interpolated_mapping_validity 0.6928128471767524 0.6859533140363885
test_cubically_interpolated_mapping_validity 0.7066557710870243 0.6996591792940834
test_cubically_interpolated_mapping_validity 0.7207952485883544 0.7136586619686678
test_cubically_interpolated_mapping_validity 0.7352392655276423 0.7279596688392498
test_cubically_interpolated_mapping_validity 0.7499953941640406 0.7425696971921194
test_cubically_interpolated_mapping_validity 0.7650706279750474 0.7574956712624232
test_cubically_interpolated_mapping_validity 0.7804711879664415 0.7727437504618233
test_cubically_interpolated_mapping_validity 0.7962022985236613 0.7883191074491696
test_cubically_interpolated_mapping_validity 0.8122679317454762 0.804225674995521
test_cubically_interpolated_mapping_validity 0.8286705205852711 0.820465861965615
test_cubically_interpolated_mapping_validity 0.8454106430913562 0.837040240684511
test_cubically_interpolated_mapping_validity 0.8624866826628949 0.8539472105573216
test_cubically_interpolated_mapping_validity 0.8798944725481854 0.8711826460873123
test_cubically_interpolated_mapping_validity 0.8976269367434111 0.88873954133011
test_cubically_interpolated_mapping_validity 0.9156737438054822 0.9066076671341408
test_cubically_interpolated_mapping_validity 0.9340209945008495 0.9247732618820292
test_cubically_interpolated_mapping_validity 0.9526509681034275 0.9432187803004233
test_cubically_interpolated_mapping_validity 0.9715419547737787 0.9619227274987908
test_cubically_interpolated_mapping_validity 0.9906682019284151 0.9808596058697179
thread 'index_mapping::tests::test_cubically_interpolated_mapping_validity' panicked at 'assertion failed: mapping.index(mapping.upper_bound(index) - EPSILON) <= index', src/index_mapping/mod.rs:158:13
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace


failures:
    index_mapping::tests::test_cubically_interpolated_mapping_validity

test result: FAILED. 22 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out; finished in 0.00s

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.