Skip to content

Commit 275e313

Browse files
authored
Merge branch 'main' into density
2 parents 3fc0cad + b1544aa commit 275e313

22 files changed

Lines changed: 321 additions & 342 deletions

.github/workflows/ci.yml

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,6 @@ jobs:
8585
run: |
8686
rustup toolchain install ${{ matrix.rust-version }}
8787
rustup default ${{ matrix.rust-version }}
88-
- name: Run examples
89-
shell: bash
90-
working-directory: examples
91-
run: |
92-
set -x
93-
METADATA=$( cargo metadata --format-version=1 --no-deps )
94-
EXAMPLES=$( echo "$METADATA" | jq -r '.packages[] | select(.name == "examples") | .targets[].name' | tr -d '\r' )
95-
while read -r example; do
96-
if [ -n "$example" ]; then
97-
echo "Running example: $example"
98-
cargo run --bin "$example"
99-
fi
100-
done <<< "$EXAMPLES"
10188
- name: Setup Java
10289
uses: actions/setup-java@v5
10390
with:

Cargo.lock

Lines changed: 0 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# under the License.
1717

1818
[workspace]
19-
members = ["datasketches", "examples", "xtask"]
19+
members = ["datasketches", "xtask"]
2020
resolver = "3"
2121

2222
[workspace.package]

NOTICE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
Apache DataSketches Rust
2-
Copyright 2025 The Apache Software Foundation
2+
Copyright 2025-2026 The Apache Software Foundation
33

44
This product includes software developed at
55
The Apache Software Foundation (http://www.apache.org/).

datasketches/src/hll/array4.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -27,10 +27,8 @@ use crate::codec::assert::insufficient_data;
2727
use crate::codec::family::Family;
2828
use crate::common::NumStdDev;
2929
use crate::error::Error;
30+
use crate::hll::Coupon;
3031
use crate::hll::estimator::HipEstimator;
31-
use crate::hll::get_slot;
32-
use crate::hll::get_value;
33-
use crate::hll::pack_coupon;
3432
use crate::hll::serialization::COUPON_SIZE_BYTES;
3533
use crate::hll::serialization::CUR_MODE_HLL;
3634
use crate::hll::serialization::HLL_PREAMBLE_SIZE;
@@ -130,10 +128,10 @@ impl Array4 {
130128
};
131129
}
132130

133-
pub fn update(&mut self, coupon: u32) {
131+
pub fn update(&mut self, coupon: Coupon) {
134132
let mask = (1 << self.lg_config_k) - 1;
135-
let slot = get_slot(coupon) & mask;
136-
let new_value = get_value(coupon);
133+
let slot = coupon.slot() & mask;
134+
let new_value = coupon.value();
137135

138136
// Quick rejection: if new value <= cur_min, no update needed
139137
if new_value <= self.cur_min {
@@ -341,8 +339,9 @@ impl Array4 {
341339
"expected {aux_count} aux coupons, failed at index {i}",
342340
))
343341
})?;
344-
let slot = get_slot(coupon) & ((1 << lg_config_k) - 1);
345-
let value = get_value(coupon);
342+
let coupon = Coupon(coupon);
343+
let slot = coupon.slot() & ((1 << lg_config_k) - 1);
344+
let value = coupon.value();
346345
aux.insert(slot, value);
347346
}
348347
aux_map = Some(aux);
@@ -418,8 +417,7 @@ impl Array4 {
418417

419418
// Write aux map entries if present
420419
for (slot, value) in aux_entries.iter().copied() {
421-
let coupon = pack_coupon(slot, value);
422-
bytes.write_u32_le(coupon);
420+
bytes.write_u32_le(Coupon::pack(slot, value).raw());
423421
}
424422

425423
bytes.into_bytes()
@@ -429,8 +427,7 @@ impl Array4 {
429427
#[cfg(test)]
430428
mod tests {
431429
use super::*;
432-
use crate::hll::coupon;
433-
use crate::hll::pack_coupon;
430+
use crate::hll::Coupon;
434431

435432
#[test]
436433
fn test_get_set_raw() {
@@ -463,8 +460,7 @@ mod tests {
463460

464461
// Add some unique values to different slots
465462
for i in 0..10_000u32 {
466-
let coupon = coupon(i);
467-
arr.update(coupon);
463+
arr.update(Coupon::from_hash(i));
468464
}
469465

470466
// Estimate should be positive and roughly in the ballpark
@@ -492,8 +488,8 @@ mod tests {
492488
let mut arr = Array4::new(8); // 256 buckets
493489

494490
// Test that values < 32 and >= 32 are handled correctly
495-
arr.update(pack_coupon(0, 10)); // value < 32, goes to kxq0
496-
arr.update(pack_coupon(1, 40)); // value >= 32, goes to kxq1
491+
arr.update(Coupon::pack(0, 10)); // value < 32, goes to kxq0
492+
arr.update(Coupon::pack(1, 40)); // value >= 32, goes to kxq1
497493

498494
// Verify registers were updated (not exact values, just check they changed)
499495
// kxq0 should have decreased (we removed a 0 and added a 10)

datasketches/src/hll/array6.rs

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,8 @@ use crate::codec::assert::insufficient_data;
2727
use crate::codec::family::Family;
2828
use crate::common::NumStdDev;
2929
use crate::error::Error;
30+
use crate::hll::Coupon;
3031
use crate::hll::estimator::HipEstimator;
31-
use crate::hll::get_slot;
32-
use crate::hll::get_value;
3332
use crate::hll::serialization::CUR_MODE_HLL;
3433
use crate::hll::serialization::HLL_PREAMBLE_SIZE;
3534
use crate::hll::serialization::HLL_PREINTS;
@@ -124,10 +123,10 @@ impl Array6 {
124123
}
125124

126125
/// Update with a coupon
127-
pub fn update(&mut self, coupon: u32) {
126+
pub fn update(&mut self, coupon: Coupon) {
128127
let mask = (1 << self.lg_config_k) - 1;
129-
let slot = get_slot(coupon) & mask;
130-
let new_value = get_value(coupon);
128+
let slot = coupon.slot() & mask;
129+
let new_value = coupon.value();
131130

132131
let old_value = self.get_raw(slot);
133132

@@ -285,8 +284,7 @@ fn num_bytes_for_k(k: u32) -> usize {
285284
#[cfg(test)]
286285
mod tests {
287286
use super::*;
288-
use crate::hll::coupon;
289-
use crate::hll::pack_coupon;
287+
use crate::hll::Coupon;
290288

291289
#[test]
292290
fn test_num_bytes_calculation() {
@@ -358,8 +356,7 @@ mod tests {
358356

359357
// Add some unique values using real coupon hashing
360358
for i in 0..10_000u32 {
361-
let coupon = coupon(i);
362-
arr.update(coupon);
359+
arr.update(Coupon::from_hash(i));
363360
}
364361

365362
let estimate = arr.estimate();
@@ -392,8 +389,8 @@ mod tests {
392389
let mut arr = Array6::new(8); // 256 buckets
393390

394391
// Test that values < 32 and >= 32 are handled correctly
395-
arr.update(pack_coupon(0, 10)); // value < 32, goes to kxq0
396-
arr.update(pack_coupon(1, 40)); // value >= 32, goes to kxq1
392+
arr.update(Coupon::pack(0, 10)); // value < 32, goes to kxq0
393+
arr.update(Coupon::pack(1, 40)); // value >= 32, goes to kxq1
397394

398395
// Initial kxq0 = 256 (all zeros = 1.0 each)
399396
assert!(arr.estimator.kxq0() < 256.0, "kxq0 should have decreased");

datasketches/src/hll/array8.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,8 @@ use crate::codec::assert::insufficient_data;
2626
use crate::codec::family::Family;
2727
use crate::common::NumStdDev;
2828
use crate::error::Error;
29+
use crate::hll::Coupon;
2930
use crate::hll::estimator::HipEstimator;
30-
use crate::hll::get_slot;
31-
use crate::hll::get_value;
3231
use crate::hll::serialization::CUR_MODE_HLL;
3332
use crate::hll::serialization::HLL_PREAMBLE_SIZE;
3433
use crate::hll::serialization::HLL_PREINTS;
@@ -78,10 +77,10 @@ impl Array8 {
7877
}
7978

8079
/// Update with a coupon
81-
pub fn update(&mut self, coupon: u32) {
80+
pub fn update(&mut self, coupon: Coupon) {
8281
let mask = (1 << self.lg_config_k) - 1;
83-
let slot = get_slot(coupon) & mask;
84-
let new_value = get_value(coupon);
82+
let slot = coupon.slot() & mask;
83+
let new_value = coupon.value();
8584

8685
let old_value = self.get(slot);
8786

@@ -350,8 +349,7 @@ impl Array8 {
350349
#[cfg(test)]
351350
mod tests {
352351
use super::*;
353-
use crate::hll::coupon;
354-
use crate::hll::pack_coupon;
352+
use crate::hll::Coupon;
355353

356354
#[test]
357355
fn test_array8_basic() {
@@ -391,20 +389,20 @@ mod tests {
391389
let mut arr = Array8::new(4);
392390

393391
// Update slot 0 with value 5
394-
arr.update(pack_coupon(0, 5));
392+
arr.update(Coupon::pack(0, 5));
395393
assert_eq!(arr.get(0), 5);
396394

397395
// Update with a smaller value (should be ignored)
398-
arr.update(pack_coupon(0, 3));
396+
arr.update(Coupon::pack(0, 3));
399397
assert_eq!(arr.get(0), 5);
400398

401399
// Update with a larger value
402-
arr.update(pack_coupon(0, 42));
400+
arr.update(Coupon::pack(0, 42));
403401
assert_eq!(arr.get(0), 42);
404402

405403
// Test value at max coupon range (63)
406-
// Note: pack_coupon only stores 6 bits (0-63)
407-
arr.update(pack_coupon(1, 63));
404+
// Note: Coupon::pack only stores 6 bits (0-63)
405+
arr.update(Coupon::pack(1, 63));
408406
assert_eq!(arr.get(1), 63);
409407
}
410408

@@ -417,8 +415,7 @@ mod tests {
417415

418416
// Add some unique values using real coupon hashing
419417
for i in 0..10_000u32 {
420-
let coupon = coupon(i);
421-
arr.update(coupon);
418+
arr.update(Coupon::from_hash(i));
422419
}
423420

424421
let estimate = arr.estimate();
@@ -471,8 +468,8 @@ mod tests {
471468
let mut arr = Array8::new(8); // 256 buckets
472469

473470
// Test that values < 32 and >= 32 are handled correctly
474-
arr.update(pack_coupon(0, 10)); // value < 32, goes to kxq0
475-
arr.update(pack_coupon(1, 50)); // value >= 32, goes to kxq1
471+
arr.update(Coupon::pack(0, 10)); // value < 32, goes to kxq0
472+
arr.update(Coupon::pack(1, 50)); // value >= 32, goes to kxq1
476473

477474
// Initial kxq0 = 256 (all zeros = 1.0 each)
478475
assert!(arr.estimator.kxq0() < 256.0, "kxq0 should have decreased");

0 commit comments

Comments
 (0)