Skip to content

Commit 263ff64

Browse files
authored
Merge pull request #33 from loyispa/refactor
clean code & fix doc
2 parents cba521d + dda184d commit 263ff64

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

README.md

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,9 @@ sketches-rust = "0.2.1"
2727
```
2828

2929
# Demos
30+
Query quantile:
3031
```rust
31-
// query quantile
32+
use sketches_rust::DDSketch;
3233
let mut d = DDSketch::collapsing_lowest_dense(0.02,100).unwrap();
3334
d.accept(1.0);
3435
d.accept(2.0);
@@ -37,9 +38,11 @@ sketches-rust = "0.2.1"
3738
assert_eq!(c, 3.0);
3839
let q = d.get_value_at_quantile(0.5).unwrap();
3940
assert!(q < 2.01 && q > 1.99);
41+
```
4042

41-
42-
// merge with other instance
43+
Merge with other instance:
44+
```rust
45+
use sketches_rust::DDSketch;
4346
let mut d1 = DDSketch::collapsing_lowest_dense(0.02,100).unwrap();
4447
d1.accept(1.0);
4548
d1.accept(2.0);
@@ -52,8 +55,11 @@ sketches-rust = "0.2.1"
5255
assert_eq!(3.0, d2.get_count());
5356
d2.merge_with(&mut d1).unwrap();
5457
assert_eq!(6.0, d2.get_count());
58+
```
5559

56-
// serialize to bytes:
60+
Serialize to bytes:
61+
```rust
62+
use sketches_rust::DDSketch;
5763
let mut d = DDSketch::unbounded_dense(2e-2).unwrap();
5864
d.accept(1.0);
5965
d.accept(2.0);
@@ -62,7 +68,11 @@ sketches-rust = "0.2.1"
6268
d.accept(5.0);
6369
println!("encode: {:?}", d.encode().unwrap());
6470

65-
// deserialize from bytes
71+
```
72+
73+
Deserialize from bytes:
74+
```rust
75+
use sketches_rust::DDSketch;
6676
let mut input = vec![
6777
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,
6878
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,

src/sketch.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,8 +80,8 @@ impl DDSketch {
8080
}
8181

8282
let mut sum = 0.0;
83-
sum -= self.negative_value_store.sum(&self.index_mapping);
84-
sum += self.positive_value_store.sum(&self.index_mapping);
83+
sum -= self.negative_value_store.get_sum(&self.index_mapping);
84+
sum += self.positive_value_store.get_sum(&self.index_mapping);
8585

8686
Some(sum)
8787
}

src/store/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,7 @@ pub trait Store {
143143
fn get_ascending_stream(&self) -> Vec<(i32, f64)>;
144144
fn get_descending_iter(&self) -> StoreIter;
145145
fn get_ascending_iter(&self) -> StoreIter;
146-
fn sum(&self, index_mapping: &IndexMapping) -> f64 {
146+
fn get_sum(&self, index_mapping: &IndexMapping) -> f64 {
147147
let mut sum = 0.0;
148148
if self.is_empty() {
149149
return sum;

0 commit comments

Comments
 (0)