diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 6898f16..639b3c9 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -26,6 +26,6 @@ jobs: - name: Build run: cargo build --verbose - name: Run tests - run: cargo test --verbose + run: cargo test --features=std - name: Run clippy run: cargo clippy -- -Dclippy::all -Dclippy::cargo diff --git a/src/hyperloglog_array.rs b/src/hyperloglog_array.rs index 2c1686f..58b1a93 100644 --- a/src/hyperloglog_array.rs +++ b/src/hyperloglog_array.rs @@ -367,9 +367,9 @@ impl< "in the HyperLogLogArray." )); let mut array = [HyperLogLog::new(); N]; - for (i, item) in items.into_iter().enumerate() { - for item in item.into_iter() { - array[i].insert(&item); + for (i, item) in items.iter().enumerate() { + for item in item.iter() { + array[i].insert(item); } } Self { counters: array } diff --git a/src/hyperloglog_trait.rs b/src/hyperloglog_trait.rs index 6321a33..bf37693 100644 --- a/src/hyperloglog_trait.rs +++ b/src/hyperloglog_trait.rs @@ -192,80 +192,6 @@ pub trait HyperLogLogTrait, const BITS: us Self::adjust_estimate(raw_estimate) } - fn second_order_cardinality_adjustment(&self) -> f32 { - assert!(PRECISION::EXPONENT == 8); - assert!(BITS == 6); - let approximation = self.estimate_cardinality(); - let number_of_zeros = self.get_number_of_zero_registers() as f32; - let number_of_zeros_rate = - self.get_number_of_zero_registers() as f32 / PRECISION::NUMBER_OF_REGISTERS as f32; - - let weights = [0.9228072, 0.0052479184, 0.16169931]; - let bias = 13.130121; - - ([approximation, number_of_zeros, number_of_zeros_rate] - .iter() - .zip(weights.iter()) - .map(|(x, w)| x * w) - .sum::() - + bias) - .max(0.0) - } - - fn second_order_union_adjustment(&self, other: &Self) -> EstimatedUnionCardinalities { - assert!(PRECISION::EXPONENT == 8); - assert!(BITS == 6); - let euc: EstimatedUnionCardinalities = self.estimate_union_and_sets_cardinality(other); - let approximation_left_cardinality = euc.get_left_cardinality(); - let approximation_right_cardinality = euc.get_right_cardinality(); - let approximation_union_cardinality = euc.get_union_cardinality(); - let approximation_intersection_cardinality = euc.get_intersection_cardinality(); - let approximation_left_difference = euc.get_left_difference_cardinality(); - let approximation_right_difference = euc.get_right_difference_cardinality(); - let approximation_symmetric_difference = euc.get_symmetric_difference_cardinality(); - let left_number_of_zeros = self.get_number_of_zero_registers(); - let right_number_of_zeros = other.get_number_of_zero_registers(); - - let input = [ - approximation_left_cardinality as f32, - approximation_right_cardinality as f32, - approximation_union_cardinality as f32, - approximation_left_difference as f32, - approximation_right_difference as f32, - approximation_symmetric_difference as f32, - approximation_intersection_cardinality as f32, - left_number_of_zeros as f32, - right_number_of_zeros as f32, - ]; - - let weights = [ - -0.4552027, - 0.87494165, - 0.41451707, - 1.0906912, - -0.23572926, - -0.13723965, - 0.08993981, - -3.9901836, - -1.0626647, - ]; - let bias = 12.55702; - - let adjusted_union = (input - .iter() - .zip(weights.iter()) - .map(|(x, w)| x * w) - .sum::() - + bias) - .max(0.0); - - EstimatedUnionCardinalities::from(( - approximation_left_cardinality, - approximation_right_cardinality, - adjusted_union, - )) - } - #[inline(always)] /// Returns an estimate of the cardinality of the union of two HyperLogLog counters. ///