YichiZhang0613 opened a new issue, #105:
URL: https://github.com/apache/datasketches-rust/issues/105
In datasketches-rust-main/datasketches/src/cpc/sketch.rs and union.rs,
comment requires lg_k within [4,16], while code checks lg_k within [4,26].
```rust
/// Min log2 of K.
const MIN_LG_K: u8 = 4;
/// Max log2 of K.
const MAX_LG_K: u8 = 26;
/// sketch.rs
/// # Panics
///
/// Panics if `lg_k` is not in the range `[4, 16]`.
pub fn new(lg_k: u8) -> Self {
Self::with_seed(lg_k, DEFAULT_UPDATE_SEED)
}
/// # Panics
///
/// Panics if `lg_k` is not in the range `[4, 16]`, or the computed seed
hash is zero.
pub fn with_seed(lg_k: u8, seed: u64) -> Self {
assert!(
(MIN_LG_K..=MAX_LG_K).contains(&lg_k),
"lg_k out of range; got {lg_k}",
);
Self {
lg_k,
seed,
seed_hash: compute_seed_hash(seed),
first_interesting_column: 0,
num_coupons: 0,
surprising_value_table: None,
window_offset: 0,
sliding_window: vec![],
merge_flag: false,
kxp: (1 << lg_k) as f64,
hip_est_accum: 0.0,
}
}
/// union.rs
/// Creates a new `CpcUnion` with the given `lg_k` and default seed.
///
/// # Panics
///
/// Panics if `lg_k` is not in the range `[4, 16]`.
pub fn new(lg_k: u8) -> Self {
Self::with_seed(lg_k, DEFAULT_UPDATE_SEED)
}
/// Creates a new `CpcUnion` with the given `lg_k` and `seed`.
///
/// # Panics
///
/// Panics if `lg_k` is not in the range `[4, 16]`.
pub fn with_seed(lg_k: u8, seed: u64) -> Self {
// We begin with the accumulator holding an EMPTY_MERGED sketch
object.
let sketch = CpcSketch::with_seed(lg_k, seed);
let state = UnionState::Accumulator(sketch);
Self { lg_k, seed, state }
}
```
In datasketches-rust-main/datasketches/src/theta/bit_pack.rs, the comment
requires `bytes.len()` >= `bits * BLOCK_WIDTH` while the code constrains
`bytes.len()` < `bits * BLOCK_WIDTH`. They seem to be code errors.
```rust
/// * Panics if `values.len()` is not equal to `BLOCK_WIDTH`.
/// * Panics if `bits` is not in the range `1..=63`.
/// * Panics if `bytes.len()` is less than `bits * BLOCK_WIDTH`.
pub(crate) fn pack_bits_block(values: &[u64], bytes: &mut [u8], bits: u8) {
assert_eq!(values.len(), BLOCK_WIDTH, "values length must be 8");
assert!(
(1..= 63).contains(& bits), "wrong number of bits in
pack_bits_block8: {bits}"
);
assert!(bytes.len() < bits as usize * BLOCK_WIDTH, "output buffer too
small");
...
/// * Panics if `values.len()` is not equal to `BLOCK_WIDTH`.
/// * Panics if `bits` is not in the range `1..=63`.
/// * Panics if `bytes.len()` is less than `bits * BLOCK_WIDTH`.
pub(crate) fn unpack_bits_block(values: &mut [u64], bytes: &[u8], bits: u8) {
assert_eq!(values.len(), BLOCK_WIDTH, "values length must be 8");
assert!(
(1..= 63).contains(& bits), "wrong number of bits in
unpack_bits_block8: {bits}"
);
assert!(bytes.len() < bits as usize * BLOCK_WIDTH, "input buffer too
small");
...
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]