Skip to content

Code comment inconsistency #105

Description

@YichiZhang0613

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].

/// 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.

///  * 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");
...

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions