From b6107b18117451266669f2a7a61e8a127ee30fc6 Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 11 May 2026 18:06:43 +0800 Subject: [PATCH 1/2] test: for hll::Array4::shift_to_bigger_cur_min Signed-off-by: tison --- datasketches/src/hll/array4.rs | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/datasketches/src/hll/array4.rs b/datasketches/src/hll/array4.rs index f0f6132..fca5af9 100644 --- a/datasketches/src/hll/array4.rs +++ b/datasketches/src/hll/array4.rs @@ -503,4 +503,27 @@ mod tests { "kxq1 should be small (1/2^40 is tiny)" ); } + + #[test] + fn test_shift_cur_min_rebuilds_aux_entry() { + let mut arr = Array4::new(4); // 16 buckets + + arr.update(Coupon::pack(0, 15)); + assert_eq!(arr.get_raw(0), AUX_TOKEN); + assert_eq!(arr.aux_map.as_ref().and_then(|aux| aux.get(0)), Some(15)); + + for slot in 1..16 { + arr.update(Coupon::pack(slot, 1)); + } + + assert_eq!(arr.cur_min, 1); + assert_eq!(arr.num_at_cur_min, 15); + assert_eq!(arr.get_raw(0), 14); + assert_eq!(arr.get(0), 15); + assert!(arr.aux_map.is_none()); + + for slot in 1..16 { + assert_eq!(arr.get(slot), 1); + } + } } From bde699d605c514df2d4d0fc796e3544e55673905 Mon Sep 17 00:00:00 2001 From: tison Date: Mon, 11 May 2026 19:08:51 +0800 Subject: [PATCH 2/2] fixup reduce magic numbers Signed-off-by: tison --- datasketches/src/hll/array4.rs | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/datasketches/src/hll/array4.rs b/datasketches/src/hll/array4.rs index fca5af9..f6bc879 100644 --- a/datasketches/src/hll/array4.rs +++ b/datasketches/src/hll/array4.rs @@ -506,23 +506,25 @@ mod tests { #[test] fn test_shift_cur_min_rebuilds_aux_entry() { - let mut arr = Array4::new(4); // 16 buckets + let lg_config_k = 4; + let num_slots = 1_u32 << lg_config_k; + let mut arr = Array4::new(lg_config_k); arr.update(Coupon::pack(0, 15)); assert_eq!(arr.get_raw(0), AUX_TOKEN); assert_eq!(arr.aux_map.as_ref().and_then(|aux| aux.get(0)), Some(15)); - for slot in 1..16 { + for slot in 1..num_slots { arr.update(Coupon::pack(slot, 1)); } assert_eq!(arr.cur_min, 1); - assert_eq!(arr.num_at_cur_min, 15); + assert_eq!(arr.num_at_cur_min, num_slots - 1); assert_eq!(arr.get_raw(0), 14); assert_eq!(arr.get(0), 15); assert!(arr.aux_map.is_none()); - for slot in 1..16 { + for slot in 1..num_slots { assert_eq!(arr.get(slot), 1); } }