Skip to content

Commit 0713a18

Browse files
committed
Fix Formattng Issues
1 parent 93c10f7 commit 0713a18

9 files changed

Lines changed: 133 additions & 58 deletions

File tree

asap-common/sketch-core/src/bin/sketchlib_fidelity.rs

Lines changed: 87 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,10 @@ fn run_hydra_kll_once(seed: u64, p: &HydraKllParams) -> HydraKllResult {
294294
for key in &keys {
295295
let mut vals = exact.get(key).cloned().unwrap_or_default();
296296
vals.sort_by(f64::total_cmp);
297-
for (q, mean_ref, max_ref) in [(0.5, &mut mean_50, &mut max_50), (0.9, &mut mean_90, &mut max_90)] {
297+
for (q, mean_ref, max_ref) in [
298+
(0.5, &mut mean_50, &mut max_50),
299+
(0.9, &mut mean_90, &mut max_90),
300+
] {
298301
let est = hydra.query(key, q);
299302
let err = (rank_fraction(&vals, est) - q).abs();
300303
*mean_ref += err;
@@ -327,10 +330,30 @@ fn main() {
327330

328331
// CountMinSketch: multiple (depth, width, n, domain)
329332
let cms_param_sets: Vec<CmsParams> = vec![
330-
CmsParams { depth: 3, width: 1024, n: 100_000, domain: 1000 },
331-
CmsParams { depth: 5, width: 2048, n: 200_000, domain: 2000 },
332-
CmsParams { depth: 7, width: 4096, n: 200_000, domain: 2000 },
333-
CmsParams { depth: 5, width: 2048, n: 50_000, domain: 500 },
333+
CmsParams {
334+
depth: 3,
335+
width: 1024,
336+
n: 100_000,
337+
domain: 1000,
338+
},
339+
CmsParams {
340+
depth: 5,
341+
width: 2048,
342+
n: 200_000,
343+
domain: 2000,
344+
},
345+
CmsParams {
346+
depth: 7,
347+
width: 4096,
348+
n: 200_000,
349+
domain: 2000,
350+
},
351+
CmsParams {
352+
depth: 5,
353+
width: 2048,
354+
n: 50_000,
355+
domain: 500,
356+
},
334357
];
335358

336359
println!("## CountMinSketch ({mode})");
@@ -346,9 +369,27 @@ fn main() {
346369

347370
// CountMinSketchWithHeap
348371
let cmwh_param_sets: Vec<CmwhParams> = vec![
349-
CmwhParams { depth: 3, width: 1024, n: 100_000, domain: 1000, heap_size: 10 },
350-
CmwhParams { depth: 5, width: 2048, n: 200_000, domain: 2000, heap_size: 20 },
351-
CmwhParams { depth: 5, width: 2048, n: 200_000, domain: 2000, heap_size: 50 },
372+
CmwhParams {
373+
depth: 3,
374+
width: 1024,
375+
n: 100_000,
376+
domain: 1000,
377+
heap_size: 10,
378+
},
379+
CmwhParams {
380+
depth: 5,
381+
width: 2048,
382+
n: 200_000,
383+
domain: 2000,
384+
heap_size: 20,
385+
},
386+
CmwhParams {
387+
depth: 5,
388+
width: 2048,
389+
n: 200_000,
390+
domain: 2000,
391+
heap_size: 50,
392+
},
352393
];
353394

354395
println!("\n## CountMinSketchWithHeap ({mode})");
@@ -371,8 +412,12 @@ fn main() {
371412
];
372413

373414
println!("\n## KllSketch ({mode})");
374-
println!("| k | n_updates | q=0.5 abs_rank_error | q=0.9 abs_rank_error | q=0.99 abs_rank_error |");
375-
println!("|---|-----------|----------------------|----------------------|-----------------------|");
415+
println!(
416+
"| k | n_updates | q=0.5 abs_rank_error | q=0.9 abs_rank_error | q=0.99 abs_rank_error |"
417+
);
418+
println!(
419+
"|---|-----------|----------------------|----------------------|-----------------------|"
420+
);
376421
for p in &kll_param_sets {
377422
let r = run_kll_once(seed, p);
378423
println!(
@@ -383,10 +428,38 @@ fn main() {
383428

384429
// HydraKllSketch
385430
let hydra_param_sets: Vec<HydraKllParams> = vec![
386-
HydraKllParams { rows: 2, cols: 64, k: 20, n: 200_000, domain: 200, eval_keys: 50 },
387-
HydraKllParams { rows: 3, cols: 128, k: 20, n: 200_000, domain: 200, eval_keys: 50 },
388-
HydraKllParams { rows: 3, cols: 128, k: 50, n: 200_000, domain: 200, eval_keys: 50 },
389-
HydraKllParams { rows: 3, cols: 128, k: 20, n: 100_000, domain: 100, eval_keys: 50 },
431+
HydraKllParams {
432+
rows: 2,
433+
cols: 64,
434+
k: 20,
435+
n: 200_000,
436+
domain: 200,
437+
eval_keys: 50,
438+
},
439+
HydraKllParams {
440+
rows: 3,
441+
cols: 128,
442+
k: 20,
443+
n: 200_000,
444+
domain: 200,
445+
eval_keys: 50,
446+
},
447+
HydraKllParams {
448+
rows: 3,
449+
cols: 128,
450+
k: 50,
451+
n: 200_000,
452+
domain: 200,
453+
eval_keys: 50,
454+
},
455+
HydraKllParams {
456+
rows: 3,
457+
cols: 128,
458+
k: 20,
459+
n: 100_000,
460+
domain: 100,
461+
eval_keys: 50,
462+
},
390463
];
391464

392465
println!("\n## HydraKllSketch ({mode})");

asap-common/sketch-core/src/config.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,17 +23,15 @@ static COUNTMIN_MODE: OnceLock<ImplMode> = OnceLock::new();
2323

2424
/// Returns true if Count-Min operations should use sketchlib-rust internally.
2525
pub fn use_sketchlib_for_count_min() -> bool {
26-
*COUNTMIN_MODE
27-
.get_or_init(|| parse_mode(std::env::var("SKETCH_CORE_CMS_IMPL")))
26+
*COUNTMIN_MODE.get_or_init(|| parse_mode(std::env::var("SKETCH_CORE_CMS_IMPL")))
2827
== ImplMode::Sketchlib
2928
}
3029

3130
static KLL_MODE: OnceLock<ImplMode> = OnceLock::new();
3231

3332
/// Returns true if KLL operations should use sketchlib-rust internally.
3433
pub fn use_sketchlib_for_kll() -> bool {
35-
*KLL_MODE
36-
.get_or_init(|| parse_mode(std::env::var("SKETCH_CORE_KLL_IMPL")))
34+
*KLL_MODE.get_or_init(|| parse_mode(std::env::var("SKETCH_CORE_KLL_IMPL")))
3735
== ImplMode::Sketchlib
3836
}
3937

@@ -42,7 +40,6 @@ static COUNTMIN_WITH_HEAP_MODE: OnceLock<ImplMode> = OnceLock::new();
4240
/// Returns true if Count-Min-With-Heap operations should use sketchlib-rust internally for the
4341
/// Count-Min portion.
4442
pub fn use_sketchlib_for_count_min_with_heap() -> bool {
45-
*COUNTMIN_WITH_HEAP_MODE
46-
.get_or_init(|| parse_mode(std::env::var("SKETCH_CORE_CMWH_IMPL")))
43+
*COUNTMIN_WITH_HEAP_MODE.get_or_init(|| parse_mode(std::env::var("SKETCH_CORE_CMWH_IMPL")))
4744
== ImplMode::Sketchlib
4845
}

asap-common/sketch-core/src/count_min.rs

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ impl CountMinSketch {
140140
}
141141

142142
if use_sketchlib_for_count_min() {
143-
let mut sketchlib_inners: Vec<SketchlibCms> =
144-
Vec::with_capacity(accumulators.len());
143+
let mut sketchlib_inners: Vec<SketchlibCms> = Vec::with_capacity(accumulators.len());
145144
for acc in accumulators {
146145
let matrix = acc.sketch();
147146
let inner = sketchlib_cms_from_matrix(acc.row_num, acc.col_num, &matrix);
@@ -200,8 +199,7 @@ impl CountMinSketch {
200199
}
201200

202201
if use_sketchlib_for_count_min() {
203-
let mut sketchlib_inners: Vec<SketchlibCms> =
204-
Vec::with_capacity(accumulators.len());
202+
let mut sketchlib_inners: Vec<SketchlibCms> = Vec::with_capacity(accumulators.len());
205203
for acc in accumulators {
206204
let acc_matrix = acc.sketch();
207205
let matrix_has_values = acc_matrix
@@ -282,9 +280,10 @@ impl CountMinSketch {
282280
row_num: usize,
283281
col_num: usize,
284282
}
285-
let wire: WireFormat = rmp_serde::from_slice(buffer).map_err(|e| -> Box<dyn std::error::Error> {
286-
format!("Failed to deserialize CountMinSketch from MessagePack: {e}").into()
287-
})?;
283+
let wire: WireFormat =
284+
rmp_serde::from_slice(buffer).map_err(|e| -> Box<dyn std::error::Error> {
285+
format!("Failed to deserialize CountMinSketch from MessagePack: {e}").into()
286+
})?;
288287

289288
let backend = if use_sketchlib_for_count_min() {
290289
CountMinBackend::Sketchlib(sketchlib_cms_from_matrix(

asap-common/sketch-core/src/count_min_sketchlib.rs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,11 @@ pub fn new_sketchlib_cms(row_num: usize, col_num: usize) -> SketchlibCms {
99
}
1010

1111
/// Builds a sketchlib Count-Min sketch from an existing `sketch` matrix.
12-
pub fn sketchlib_cms_from_matrix(row_num: usize, col_num: usize, sketch: &[Vec<f64>]) -> SketchlibCms {
12+
pub fn sketchlib_cms_from_matrix(
13+
row_num: usize,
14+
col_num: usize,
15+
sketch: &[Vec<f64>],
16+
) -> SketchlibCms {
1317
let matrix = Vector2D::from_fn(row_num, col_num, |r, c| {
1418
// Values are stored as f64 in the wire format; treat them as integer counts.
1519
sketch

asap-common/sketch-core/src/count_min_with_heap.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,7 @@ impl Clone for CountMinSketchWithHeap {
139139
impl CountMinSketchWithHeap {
140140
pub fn new(row_num: usize, col_num: usize, heap_size: usize) -> Self {
141141
let backend = if use_sketchlib_for_count_min_with_heap() {
142-
CountMinWithHeapBackend::Sketchlib(new_sketchlib_cms_heap(
143-
row_num, col_num, heap_size,
144-
))
142+
CountMinWithHeapBackend::Sketchlib(new_sketchlib_cms_heap(row_num, col_num, heap_size))
145143
} else {
146144
CountMinWithHeapBackend::Legacy {
147145
sketch: vec![vec![0.0; col_num]; row_num],
@@ -201,7 +199,9 @@ impl CountMinSketchWithHeap {
201199
pub fn sketch_matrix(&self) -> Vec<Vec<f64>> {
202200
match &self.backend {
203201
CountMinWithHeapBackend::Legacy { sketch, .. } => sketch.clone(),
204-
CountMinWithHeapBackend::Sketchlib(cms_heap) => matrix_from_sketchlib_cms_heap(cms_heap),
202+
CountMinWithHeapBackend::Sketchlib(cms_heap) => {
203+
matrix_from_sketchlib_cms_heap(cms_heap)
204+
}
205205
}
206206
}
207207

@@ -236,7 +236,9 @@ impl CountMinSketchWithHeap {
236236
value,
237237
});
238238
} else if let Some(min_item) = heap.iter_mut().min_by(|a, b| {
239-
a.value.partial_cmp(&b.value).unwrap_or(std::cmp::Ordering::Equal)
239+
a.value
240+
.partial_cmp(&b.value)
241+
.unwrap_or(std::cmp::Ordering::Equal)
240242
}) {
241243
if value > min_item.value {
242244
*min_item = HeapItem {
@@ -366,7 +368,7 @@ impl CountMinSketchWithHeap {
366368
CountMinWithHeapBackend::Legacy { sketch, .. } => sketch,
367369
CountMinWithHeapBackend::Sketchlib(_) => {
368370
return Err(
369-
"Cannot mix Legacy and Sketchlib backends when merging".into(),
371+
"Cannot mix Legacy and Sketchlib backends when merging".into()
370372
);
371373
}
372374
};
@@ -413,10 +415,7 @@ impl CountMinSketchWithHeap {
413415
}
414416

415417
pub fn serialize_msgpack(&self) -> Vec<u8> {
416-
let (sketch, topk_heap) = (
417-
self.sketch_matrix(),
418-
self.topk_heap_items(),
419-
);
418+
let (sketch, topk_heap) = (self.sketch_matrix(), self.topk_heap_items());
420419

421420
let serialized = CountMinSketchWithHeapSerialized {
422421
sketch: CmsData {

asap-common/sketch-core/src/count_min_with_heap_sketchlib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
//! Uses CMSHeap (CountMin + HHHeap) from sketchlib-rust instead of CountMin + local heap,
44
//! providing automatic top-k tracking during insert and merge.
55
6-
use sketchlib_rust::{CMSHeap, SketchInput, Vector2D};
76
use sketchlib_rust::RegularPath;
7+
use sketchlib_rust::{CMSHeap, SketchInput, Vector2D};
88

99
/// Wire-format heap item (key, value) to avoid circular dependency with count_min_with_heap.
1010
pub struct WireHeapItem {

asap-common/sketch-core/src/kll.rs

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,8 @@ use serde::{Deserialize, Serialize};
1818

1919
use crate::config::use_sketchlib_for_kll;
2020
use crate::kll_sketchlib::{
21-
bytes_from_sketchlib_kll, sketchlib_kll_from_bytes, sketchlib_kll_merge,
22-
sketchlib_kll_quantile, sketchlib_kll_update, new_sketchlib_kll, SketchlibKll,
21+
bytes_from_sketchlib_kll, new_sketchlib_kll, sketchlib_kll_from_bytes, sketchlib_kll_merge,
22+
sketchlib_kll_quantile, sketchlib_kll_update, SketchlibKll,
2323
};
2424

2525
/// Wire format used in MessagePack serialization (matches Arroyo UDF output).
@@ -179,10 +179,7 @@ impl KllSketch {
179179
)
180180
};
181181

182-
Ok(Self {
183-
k: wire.k,
184-
backend,
185-
})
182+
Ok(Self { k: wire.k, backend })
186183
}
187184

188185
/// Merge from references without cloning.
@@ -263,10 +260,7 @@ impl Clone for KllSketch {
263260
KllBackend::Sketchlib(sketchlib_kll_from_bytes(&bytes).unwrap())
264261
}
265262
};
266-
Self {
267-
k: self.k,
268-
backend,
269-
}
263+
Self { k: self.k, backend }
270264
}
271265
}
272266

asap-common/sketch-core/src/kll_sketchlib.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use sketchlib_rust::{KLL, SketchInput};
1+
use sketchlib_rust::{SketchInput, KLL};
22

33
/// Concrete KLL type from sketchlib-rust when sketchlib backend is enabled.
44
pub type SketchlibKll = KLL;
@@ -34,4 +34,3 @@ pub fn bytes_from_sketchlib_kll(inner: &SketchlibKll) -> Vec<u8> {
3434
pub fn sketchlib_kll_from_bytes(bytes: &[u8]) -> Result<SketchlibKll, Box<dyn std::error::Error>> {
3535
Ok(KLL::deserialize_from_bytes(bytes)?)
3636
}
37-

asap-query-engine/src/precompute_operators/count_min_sketch_with_heap_accumulator.rs

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -248,14 +248,26 @@ mod tests {
248248
sketch[1][1] = 15.0;
249249
}
250250
for item in [
251-
HeapItem { key: "key1".to_string(), value: 100.0 },
252-
HeapItem { key: "key2".to_string(), value: 50.0 },
251+
HeapItem {
252+
key: "key1".to_string(),
253+
value: 100.0,
254+
},
255+
HeapItem {
256+
key: "key2".to_string(),
257+
value: 50.0,
258+
},
253259
] {
254260
cms1.inner.update(&item.key, item.value);
255261
}
256262
for item in [
257-
HeapItem { key: "key3".to_string(), value: 75.0 },
258-
HeapItem { key: "key1".to_string(), value: 80.0 },
263+
HeapItem {
264+
key: "key3".to_string(),
265+
value: 75.0,
266+
},
267+
HeapItem {
268+
key: "key1".to_string(),
269+
value: 80.0,
270+
},
259271
] {
260272
cms2.inner.update(&item.key, item.value);
261273
}
@@ -301,9 +313,7 @@ mod tests {
301313
value: 99.0,
302314
}];
303315
let cms = CountMinSketchWithHeapAccumulator {
304-
inner: CountMinSketchWithHeap::from_legacy_matrix(
305-
sketch, topk_heap, 2, 3, 5,
306-
),
316+
inner: CountMinSketchWithHeap::from_legacy_matrix(sketch, topk_heap, 2, 3, 5),
307317
};
308318

309319
let bytes = cms.serialize_to_bytes();

0 commit comments

Comments
 (0)