### Create HyperLogLog from Template Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec Creates a new HyperLogLog counter with the same parameters (error rate, seed) as an existing one. The new counter starts empty. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let original_hll = HyperLogLog::new_deterministic(error_rate, seed); let new_hll = HyperLogLog::new_from_template(&original_hll); ``` -------------------------------- ### HyperLogLog Data Structure Example Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html This snippet shows the declaration of a HyperLogLog data structure, likely used for approximate distinct counting. It's part of a larger data structure definition. ```rust ], ]; ``` -------------------------------- ### Get Cardinality Estimate Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Returns the estimated cardinality (number of unique elements) of the HyperLogLog counter. The estimate is a `f64`. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let mut hll = HyperLogLog::new_deterministic(error_rate, seed); hll.insert(&"apple"); hll.insert(&"banana"); hll.insert(&"apple"); let cardinality = hll.len(); println!("Estimated cardinality: {}", cardinality); ``` -------------------------------- ### Get HyperLogLog Cardinality Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns the estimated cardinality (number of unique elements) of the HyperLogLog counter as a floating-point number. ```rust pub fn len(&self) -> f64 ``` -------------------------------- ### Get Cardinality Estimate Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec Returns the estimated cardinality (number of unique elements) of the HyperLogLog counter. The result is a floating-point number. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let mut hll = HyperLogLog::new_deterministic(error_rate, seed); hll.insert(&"apple"); hll.insert(&"banana"); let cardinality = hll.len(); println!("Estimated cardinality: {}", cardinality); ``` -------------------------------- ### Get Alpha Constant Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=u32+-%3E+bool Calculates the alpha constant used in HyperLogLog cardinality estimation based on the precision parameter `p`. Asserts that `p` is within the valid range of 4 to 16. ```rust fn get_alpha(p: u8) -> f64 { assert!((4..=16).contains(&p)); match p { 4 => 0.673, 5 => 0.697, 6 => 0.709, _ => 0.7213 / (1.0 + 1.079 / (1usize << (p as usize)) as f64), } } ``` -------------------------------- ### Get Cardinality of HyperLogLog Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=u32+-%3E+bool Estimates and returns the cardinality (number of unique elements) of the HyperLogLog counter. Handles cases for empty counters and applies bias correction. ```rust pub fn len(&self) -> f64 { let V = Self::vec_count_zero(&self.M); if V > 0 { let H = self.m as f64 * (self.m as f64 / V as f64).ln(); if H <= Self::get_threshold(self.p) { H } else { self.ep() } } else { self.ep() } } ``` -------------------------------- ### Get Cardinality of HyperLogLog Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Returns the estimated cardinality (number of unique elements) stored in the HyperLogLog counter. The result is a floating-point number. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let mut hll = HyperLogLog::new(error_rate); hll.insert(&1); hll.insert(&2); hll.insert(&3); let cardinality = hll.len(); println!("Estimated cardinality: {}", cardinality); ``` -------------------------------- ### Create HyperLogLog from Template Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=u32+-%3E+bool Initializes a new HyperLogLog counter with the same parameters (error rate, seed) as an existing one. The new counter will be empty. ```rust pub fn new_from_template(hll: &HyperLogLog) -> Self { HyperLogLog { alpha: hll.alpha, p: hll.p, m: hll.m, M: vec![0; hll.m], sip: hll.sip, } } ``` -------------------------------- ### Get Type ID of Any Type Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Gets the `TypeId` of the current type. This is part of the `Any` trait implementation. ```rust fn type_id(&self) -> TypeId ``` -------------------------------- ### HyperLogLog Serialization and Deserialization Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec Demonstrates how to serialize a HyperLogLog instance to bytes using bincode and deserialize it back. This is useful for storing or transmitting HyperLogLog states. ```rust #[cfg(feature = "with_serde")] #[test] fn hyperloglog_serialize() { let hll = HyperLogLog::new(0.00408); let bytes = bincode::serde::encode_to_vec(&hll, bincode::config::standard()).unwrap(); let (decoded, _): (HyperLogLog, _) = bincode::serde::decode_from_slice(&bytes, bincode::config::standard()).unwrap(); let _ = decoded; } ``` -------------------------------- ### Create HyperLogLog from Template Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new HyperLogLog counter with the same parameters (error rate and seed) as an existing HyperLogLog instance. ```rust pub fn new_from_template(hll: &HyperLogLog) -> Self ``` -------------------------------- ### HyperLogLog Methods Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec This section details the primary methods available for interacting with the HyperLogLog data structure. ```APIDOC ## new_deterministic ### Description Creates a new `HyperLogLog` counter with a specified error rate and a deterministic seed. This is useful for reproducible results. ### Method `pub fn new_deterministic(error_rate: f64, seed: u128) -> Self` ### Parameters - `error_rate` (f64) - The desired error rate for the counter (must be between 0.0 and 1.0). - `seed` (u128) - A 128-bit seed for the internal hash function. ## new ### Description Creates a new `HyperLogLog` counter with the given error rate, using a random seed. This is the most common way to initialize a new counter. ### Method `pub fn new(error_rate: f64) -> Self` ### Parameters - `error_rate` (f64) - The desired error rate for the counter (must be between 0.0 and 1.0). ## new_from_template ### Description Creates a new `HyperLogLog` counter with the same parameters (error rate, hash function) as an existing one. This is useful for creating multiple counters that should be mergeable. ### Method `pub fn new_from_template(hll: &HyperLogLog) -> Self` ### Parameters - `hll` (&HyperLogLog) - A reference to an existing `HyperLogLog` counter to use as a template. ## insert ### Description Inserts a value into the `HyperLogLog` counter. The value must implement the `Hash` trait. ### Method `pub fn insert(&mut self, value: &V)` ### Parameters - `value` (&V) - A reference to the value to insert. `V` must implement `Hash`. ## insert_by_hash_value ### Description Inserts a pre-computed hash value into the `HyperLogLog` counter. This can be useful if you have already computed the hash of your data. ### Method `pub fn insert_by_hash_value(&mut self, x: u64)` ### Parameters - `x` (u64) - The pre-computed hash value. ## len ### Description Returns the estimated cardinality (number of unique elements) of the `HyperLogLog` counter. The result is a `f64`. ### Method `#[must_use] pub fn len(&self) -> f64` ## is_empty ### Description Returns `true` if the `HyperLogLog` counter is empty (i.e., has an estimated cardinality of 0.0), and `false` otherwise. ### Method `#[must_use] pub fn is_empty(&self) -> bool` ## merge ### Description Merges another `HyperLogLog` counter into the current one. Both counters must have been created with the same parameters (same error rate and seed). ### Method `pub fn merge(&mut self, src: &HyperLogLog)` ### Parameters - `src` (&HyperLogLog) - A reference to the `HyperLogLog` counter to merge into the current one. ## clear ### Description Resets the `HyperLogLog` counter, removing all inserted elements and setting the estimated cardinality to 0.0. ### Method `pub fn clear(&mut self)` ``` -------------------------------- ### Create HyperLogLog from Template Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Creates a new HyperLogLog counter with the same parameters (error rate, seed) as an existing one. The new counter is initialized empty. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.02; let seed = 98765432109876543210; let original_hll = HyperLogLog::new_deterministic(error_rate, seed); let mut new_hll = HyperLogLog::new_from_template(&original_hll); new_hll.insert(&"new_data"); println!("Cardinality of new HLL: {}", new_hll.len()); ``` -------------------------------- ### Create HyperLogLog with Deterministic Seed Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec Initializes a HyperLogLog counter with a specified error rate and a deterministic seed for reproducible results. Ensure the error rate is between 0.0 and 1.0. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let hll = HyperLogLog::new_deterministic(error_rate, seed); ``` -------------------------------- ### Create HyperLogLog with Deterministic Seed Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=u32+-%3E+bool Initializes a new HyperLogLog counter with a specified error rate and a deterministic seed for reproducibility. Ensure the error rate is between 0.0 and 1.0. ```rust pub fn new_deterministic(error_rate: f64, seed: u128) -> Self { let key0 = (seed >> 64) as u64; let key1 = seed as u64; assert!(error_rate > 0.0 && error_rate < 1.0); let sr = 1.04 / error_rate; let p = f64::ln(sr * sr).ceil() as u8; assert!(p <= 64); let alpha = Self::get_alpha(p); let m = 1usize << p; HyperLogLog { alpha, p, m, M: vec![0; m], sip: SipHasher13::new_with_keys(key0, key1), } } ``` -------------------------------- ### Create HyperLogLog with Random Seed Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec Initializes a HyperLogLog counter with a specified error rate and a random seed. This is useful when reproducibility is not a primary concern. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.05; let hll = HyperLogLog::new(error_rate); ``` -------------------------------- ### HyperLogLog::new Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Creates a new HyperLogLog counter with a specified error rate, using a random seed. This is the most common way to initialize a counter. ```APIDOC ## HyperLogLog::new ### Description Creates a new `HyperLogLog` counter with the given error rate and a random seed. ### Method `HyperLogLog::new(error_rate: f64) -> Self` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let hll = HyperLogLog::new(0.05); ``` ### Response #### Success Response A new `HyperLogLog` instance with a random seed. #### Response Example ```rust // Returns a HyperLogLog instance ``` ``` -------------------------------- ### Create HyperLogLog with Deterministic Seed Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Initializes a new HyperLogLog counter with a specified error rate and a deterministic seed for reproducible results. Ensure the error rate is between 0.0 and 1.0. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890; let mut hll = HyperLogLog::new_deterministic(error_rate, seed); hll.insert(&"example_value"); println!("Estimated cardinality: {}", hll.len()); ``` -------------------------------- ### Create HyperLogLog with Deterministic Seed Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Initializes a new HyperLogLog counter with a specified error rate and a deterministic seed for reproducible results. Ensure the error rate is between 0.0 and 1.0. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let mut hll = HyperLogLog::new_deterministic(error_rate, seed); println!("HyperLogLog created with p = {}", hll.p); ``` -------------------------------- ### HyperLogLog::clone_from Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=u32+-%3E+bool Performs copy-assignment from a source HyperLogLog into the current one. ```APIDOC ## fn clone_from(&mut self, source: &Self) ### Description Performs copy-assignment from `source`. ### Parameters * `source` (&Self) - The source `HyperLogLog` to copy from. ``` -------------------------------- ### HyperLogLog Creation Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides methods to create new HyperLogLog counters with deterministic or random seeds, and from existing templates. ```APIDOC ## `new_deterministic(error_rate: f64, seed: u128) -> Self` ### Description Creates a new `HyperLogLog` counter with a specified error rate and a deterministic seed. This is useful for reproducible results. ### Parameters - `error_rate` (f64) - The desired error rate for the counter (must be between 0.0 and 1.0). - `seed` (u128) - The seed value for the hash function. ### Returns A new `HyperLogLog` instance. ## `new(error_rate: f64) -> Self` ### Description Creates a new `HyperLogLog` counter with a specified error rate and a random seed. The seed is generated using a random number generator. ### Parameters - `error_rate` (f64) - The desired error rate for the counter (must be between 0.0 and 1.0). ### Returns A new `HyperLogLog` instance. ## `new_from_template(hll: &HyperLogLog) -> Self` ### Description Creates a new `HyperLogLog` counter with the same parameters (error rate, seed, etc.) as an existing `HyperLogLog` instance. The new counter is initialized as empty. ### Parameters - `hll` (&HyperLogLog) - A reference to an existing `HyperLogLog` instance to use as a template. ### Returns A new `HyperLogLog` instance with the same parameters as the template. ``` -------------------------------- ### Create HyperLogLog with Random Seed Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Initializes a new HyperLogLog counter with a specified error rate and a random seed. This is useful when reproducibility is not required. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.05; let mut hll = HyperLogLog::new(error_rate); println!("HyperLogLog created with p = {}", hll.p); ``` -------------------------------- ### Create HyperLogLog with Random Seed Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Initializes a new HyperLogLog counter with a specified error rate and a random seed. This is useful when reproducibility is not required. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.05; let mut hll = HyperLogLog::new(error_rate); hll.insert(&12345); hll.insert(&"another_value"); println!("Estimated cardinality: {}", hll.len()); ``` -------------------------------- ### HyperLogLog Operations Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Details methods for inserting values, estimating cardinality, checking emptiness, merging counters, and clearing the counter. ```APIDOC ## `insert(&mut self, value: &V)` ### Description Inserts a value into the `HyperLogLog` counter. The value must implement the `Hash` trait. A hash of the value is computed and used to update the counter's internal state. ### Parameters - `value` (&V) - A reference to the value to insert. `V` must implement `Hash`. ## `insert_by_hash_value(&mut self, x: u64)` ### Description Inserts a pre-computed hash value into the `HyperLogLog` counter. This method is more efficient if the hash is already available. ### Parameters - `x` (u64) - The pre-computed hash value to insert. ## `len(&self) -> f64` ### Description Returns the estimated cardinality (number of unique elements) of the `HyperLogLog` counter. The result is a `f64` representing the estimated count. ### Returns The estimated cardinality as a `f64`. ## `is_empty(&self) -> bool` ### Description Returns `true` if the `HyperLogLog` counter is empty (i.e., has an estimated cardinality of 0.0), and `false` otherwise. ### Returns `true` if the counter is empty, `false` otherwise. ## `merge(&mut self, src: &HyperLogLog)` ### Description Merges another `HyperLogLog` counter (`src`) into the current one. Both counters must have the same parameters (error rate, seed, etc.). After merging, the current counter will represent the union of elements from both counters. ### Parameters - `src` (&HyperLogLog) - A reference to the `HyperLogLog` counter to merge into the current one. ## `clear(&mut self)` ### Description Wipes the `HyperLogLog` counter, resetting all internal registers to zero. This effectively makes the counter empty. ``` -------------------------------- ### Create HyperLogLog from Template Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Creates a new HyperLogLog counter with the same parameters (error rate, seed) as an existing one, but with an empty state. This is useful for merging operations. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let hll_template = HyperLogLog::new_deterministic(error_rate, seed); let mut hll_new = HyperLogLog::new_from_template(&hll_template); assert_eq!(hll_new.p, hll_template.p); ``` -------------------------------- ### HyperLogLog Methods Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=u32+-%3E+bool This section details the public methods for interacting with the HyperLogLog data structure. ```APIDOC ## new_deterministic ### Description Creates a new `HyperLogLog` counter with a specified error rate and seed for deterministic behavior. ### Signature `pub fn new_deterministic(error_rate: f64, seed: u128) -> Self` ### Parameters * `error_rate` (f64) - The desired error rate for the counter (must be between 0.0 and 1.0). * `seed` (u128) - The seed value for the hash function, ensuring deterministic results. ## new ### Description Creates a new `HyperLogLog` counter with a specified error rate, using a random seed. ### Signature `pub fn new(error_rate: f64) -> Self` ### Parameters * `error_rate` (f64) - The desired error rate for the counter (must be between 0.0 and 1.0). ## new_from_template ### Description Creates a new `HyperLogLog` counter with the same parameters (error rate, precision) as an existing one. ### Signature `pub fn new_from_template(hll: &HyperLogLog) -> Self` ### Parameters * `hll` (&HyperLogLog) - A reference to an existing `HyperLogLog` counter to use as a template. ## insert ### Description Inserts a value into the `HyperLogLog` counter. The value must implement the `Hash` trait. ### Signature `pub fn insert(&mut self, value: &V)` ### Parameters * `value` (&V) - A reference to the value to insert. `V` must implement `Hash`. ## insert_by_hash_value ### Description Inserts a pre-computed hash value into the `HyperLogLog` counter. ### Signature `pub fn insert_by_hash_value(&mut self, x: u64)` ### Parameters * `x` (u64) - The pre-computed hash value to insert. ## len ### Description Returns the estimated cardinality (number of unique elements) of the `HyperLogLog` counter. ### Signature `pub fn len(&self) -> f64` ### Returns * `f64` - The estimated cardinality. ## is_empty ### Description Returns `true` if the `HyperLogLog` counter is empty (estimated cardinality is 0), and `false` otherwise. ### Signature `pub fn is_empty(&self) -> bool` ### Returns * `bool` - `true` if the counter is empty, `false` otherwise. ## merge ### Description Merges another `HyperLogLog` counter into the current one. Both counters must have the same parameters (p and m). ### Signature `pub fn merge(&mut self, src: &HyperLogLog)` ### Parameters * `src` (&HyperLogLog) - A reference to the `HyperLogLog` counter to merge from. ## clear ### Description Resets the `HyperLogLog` counter, clearing all inserted elements and setting the estimated cardinality to 0. ### Signature `pub fn clear(&mut self)` ``` -------------------------------- ### Insert Value by Hash Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Inserts a pre-computed 64-bit hash value into the HyperLogLog counter. This is an optimization if the hash is already available. ```rust use hyperloglog::HyperLogLog; use std::hash::{Hash, Hasher}; use siphasher::sip::SipHasher13; let error_rate = 0.01; let mut hll = HyperLogLog::new_deterministic(error_rate, 123); let mut hasher = SipHasher13::new_with_keys(0, 0); hash_value.hash(&mut hasher); let hash_val = hasher.finish(); hll.insert_by_hash_value(hash_val); println!("Estimated cardinality after hash insert: {}", hll.len()); ``` -------------------------------- ### Basic HyperLogLog Operations Test Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec Tests the fundamental operations of the HyperLogLog structure, including insertion of keys, checking the estimated count, emptiness, and clearing the structure. ```rust #[test] fn hyperloglog_test_simple() { let mut hll = HyperLogLog::new(0.00408); let keys = ["test1", "test2", "test3", "test2", "test2", "test2"]; for k in &keys { hll.insert(k); } assert!((hll.len().round() - 3.0).abs() < std::f64::EPSILON); assert!(!hll.is_empty()); hll.clear(); assert!(hll.is_empty()); assert!(hll.len() == 0.0); } ``` -------------------------------- ### Try Conversion (TryFrom) Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html Implement `TryFrom` for fallible conversions between types. The `Error` type indicates potential conversion failures. ```rust fn try_from(value: U) -> Result>::Error> ``` -------------------------------- ### Clone From Another HyperLogLog Instance Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Performs copy-assignment from a source HyperLogLog instance into the current one. This is an optimization for in-place cloning. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Create HyperLogLog with Deterministic Seed Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new HyperLogLog counter with a specified error rate and a deterministic seed for reproducibility. ```rust pub fn new_deterministic(error_rate: f64, seed: u128) -> Self ``` -------------------------------- ### HyperLogLog::new Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Creates a new HyperLogLog counter with a specified error rate, using a random seed. This is the default constructor for general use. ```APIDOC ## HyperLogLog::new ### Description Creates a new `HyperLogLog` counter with the given error rate. A random seed is used, making each instance unique unless explicitly seeded. ### Method `HyperLogLog::new(error_rate: f64) -> Self` ### Parameters * `error_rate` (f64) - The desired error rate for the cardinality estimation. Must be greater than 0.0 and less than 1.0. ### Returns A new `HyperLogLog` instance configured with the provided error rate and a random seed. ``` -------------------------------- ### HyperLogLog Operations Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html Methods for inserting values, estimating cardinality, checking emptiness, merging counters, and clearing the counter. ```APIDOC ## `insert` ### Description Insert a new value into the `HyperLogLog` counter. ### Signature `pub fn insert(&mut self, value: &V)` ## `insert_by_hash_value` ### Description Insert a new u64 value into the `HyperLogLog` counter. ### Signature `pub fn insert_by_hash_value(&mut self, x: u64)` ## `len` ### Description Return the cardinality of the `HyperLogLog` counter. ### Signature `pub fn len(&self) -> f64` ## `is_empty` ### Description Return `true` if the `HyperLogLog` counter is empty. ### Signature `pub fn is_empty(&self) -> bool` ## `merge` ### Description Merge another `HyperLogLog` counter into the current one. ### Signature `pub fn merge(&mut self, src: &HyperLogLog)` ## `clear` ### Description Wipe the `HyperLogLog` counter. ### Signature `pub fn clear(&mut self)` ``` -------------------------------- ### Try Conversion (TryInto) Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html Implement `TryInto` for fallible conversions, allowing a type to be converted into another type that implements `TryFrom`. ```rust fn try_into(self) -> Result>::Error> ``` -------------------------------- ### Clone to Uninitialized Memory (Nightly) Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Nightly-only experimental API. Performs copy-assignment from `self` to uninitialized memory pointed to by `dest`. ```rust unsafe fn clone_to_uninit(&self, dest: *mut u8) ``` -------------------------------- ### Clone HyperLogLog Instance Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Returns a duplicate of the HyperLogLog value. This creates a completely independent copy. ```rust fn clone(&self) -> HyperLogLog ``` -------------------------------- ### Create HyperLogLog with Random Seed Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=u32+-%3E+bool Creates a new HyperLogLog counter with a given error rate, using a random seed. This is suitable for general-purpose use where reproducibility is not required. ```rust pub fn new(error_rate: f64) -> Self { let seed: u128 = rand::random(); Self::new_deterministic(error_rate, seed) } ``` -------------------------------- ### HyperLogLog::new Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new HyperLogLog counter with a specified error rate and a random seed. ```APIDOC ## HyperLogLog::new ### Description Creates a new `HyperLogLog` counter with the given error rate and a random seed. ### Method `pub fn new(error_rate: f64) -> Self` ### Parameters * `error_rate` (f64) - The desired error rate for the counter. ``` -------------------------------- ### HyperLogLog::new Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search= Creates a new HyperLogLog counter with a specified error rate and a random seed. ```APIDOC ## HyperLogLog::new ### Description Creates a new `HyperLogLog` counter with the given error rate and a random seed. ### Method `new(error_rate: f64) -> Self` ### Parameters * **error_rate** (f64) - The desired error rate for the counter. ``` -------------------------------- ### HyperLogLog::new Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=u32+-%3E+bool Creates a new HyperLogLog counter with a specified error rate and a random seed. ```APIDOC ## pub fn new(error_rate: f64) -> Self ### Description Create a new `HyperLogLog` counter with the given error rate and a random seed. ### Parameters * `error_rate` (f64) - The desired error rate for the counter. ### Returns A new `HyperLogLog` instance. ``` -------------------------------- ### HyperLogLog::new_from_template Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Creates a new HyperLogLog counter with the same parameters (error rate, seed, etc.) as an existing one. Useful for creating multiple counters with identical configurations. ```APIDOC ## HyperLogLog::new_from_template ### Description Creates a new `HyperLogLog` counter with the same parameters as an existing one. ### Method `HyperLogLog::new_from_template(hll: &HyperLogLog) -> Self` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let original_hll = HyperLogLog::new(0.01); let new_hll = HyperLogLog::new_from_template(&original_hll); ``` ### Response #### Success Response A new `HyperLogLog` instance with identical parameters to the template. #### Response Example ```rust // Returns a HyperLogLog instance ``` ``` -------------------------------- ### HyperLogLog::new_from_template Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=u32+-%3E+bool Creates a new HyperLogLog counter with the same parameters as an existing one. ```APIDOC ## pub fn new_from_template(hll: &HyperLogLog) -> Self ### Description Create a new `HyperLogLog` counter with the same parameters as an existing one. ### Parameters * `hll` (&HyperLogLog) - A reference to an existing `HyperLogLog` counter to use as a template. ### Returns A new `HyperLogLog` instance with identical parameters. ``` -------------------------------- ### HyperLogLog::new_from_template Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new HyperLogLog counter with the same parameters as an existing one. ```APIDOC ## HyperLogLog::new_from_template ### Description Creates a new `HyperLogLog` counter with the same parameters as an existing one. ### Method `pub fn new_from_template(hll: &HyperLogLog) -> Self` ### Parameters * `hll` (&HyperLogLog) - A reference to an existing `HyperLogLog` counter to use as a template. ``` -------------------------------- ### HyperLogLog::new_from_template Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search= Creates a new HyperLogLog counter with the same parameters as an existing one. ```APIDOC ## HyperLogLog::new_from_template ### Description Creates a new `HyperLogLog` counter with the same parameters as an existing one. ### Method `new_from_template(hll: &HyperLogLog) -> Self` ### Parameters * **hll** (&HyperLogLog) - A reference to an existing `HyperLogLog` counter to use as a template. ``` -------------------------------- ### Create HyperLogLog with Random Seed Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new HyperLogLog counter with a specified error rate and a randomly generated seed. ```rust pub fn new(error_rate: f64) -> Self ``` -------------------------------- ### HyperLogLog::new Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=std%3A%3Avec Creates a new HyperLogLog counter with a specified error rate and a random seed. The random seed ensures that each instance is unique unless explicitly seeded. ```APIDOC ## HyperLogLog::new ### Description Creates a new `HyperLogLog` counter with the given error rate and a random seed. ### Method `HyperLogLog::new(error_rate: f64) -> Self` ### Parameters * `error_rate` (f64) - The desired error rate for the HyperLogLog counter. ``` -------------------------------- ### Insert Hash Value into HyperLogLog Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec Inserts a pre-computed 64-bit hash value into the HyperLogLog counter. This is an optimization if the hash is already available. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let mut hll = HyperLogLog::new_deterministic(error_rate, seed); let hash_value = 9876543210u64; hll.insert_by_hash_value(hash_value); ``` -------------------------------- ### HyperLogLog Creation Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html Provides methods to create a new HyperLogLog counter with specified error rates and seeds. ```APIDOC ## `new_deterministic` ### Description Create a new `HyperLogLog` counter with the given error rate and seed. ### Signature `pub fn new_deterministic(error_rate: f64, seed: u128) -> Self` ## `new` ### Description Create a new `HyperLogLog` counter with the given error rate and a random seed. ### Signature `pub fn new(error_rate: f64) -> Self` ## `new_from_template` ### Description Create a new `HyperLogLog` counter with the same parameters as an existing one. ### Signature `pub fn new_from_template(hll: &HyperLogLog) -> Self` ``` -------------------------------- ### HyperLogLog::new_from_template Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Creates a new HyperLogLog counter with the same parameters (error rate, precision) as an existing one. Useful for initializing multiple counters that need to be merged later. ```APIDOC ## HyperLogLog::new_from_template ### Description Creates a new `HyperLogLog` counter with the same parameters as an existing `HyperLogLog` instance. This is useful for creating a new counter that will be merged with another, ensuring compatibility. ### Method `HyperLogLog::new_from_template(hll: &HyperLogLog) -> Self` ### Parameters * `hll` (&HyperLogLog) - A reference to an existing `HyperLogLog` instance whose parameters will be copied. ### Returns A new `HyperLogLog` instance with identical configuration to the provided template. ``` -------------------------------- ### HyperLogLog::fmt Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=u32+-%3E+bool Formats the HyperLogLog value using the given formatter. ```APIDOC ## fn fmt(&self, f: &mut Formatter<'_>) -> Result ### Description Formats the value using the given formatter. ### Parameters * `f` (&mut Formatter<'_>) - The formatter to use. ### Returns A `Result` indicating success or failure of the formatting operation. ``` -------------------------------- ### Format HyperLogLog for Debugging Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Formats the HyperLogLog counter for debugging output using the `std::fmt::Formatter`. ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` -------------------------------- ### Insert u64 Hash Value into HyperLogLog Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Inserts a pre-computed u64 hash value directly into the HyperLogLog counter. ```rust pub fn insert_by_hash_value(&mut self, x: u64) ``` -------------------------------- ### Insert Hash Value into HyperLogLog Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Inserts a pre-computed hash value (u64) into the HyperLogLog counter. This is an optimization if hashing is done elsewhere. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let mut hll = HyperLogLog::new_deterministic(error_rate, seed); let hash_value = 1234567890123456789u64; hll.insert_by_hash_value(hash_value); println!("Cardinality estimate after hash insert: {}", hll.len()); ``` -------------------------------- ### HyperLogLog::new_from_template Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=std%3A%3Avec Creates a new HyperLogLog counter that inherits its parameters (like error rate) from an existing HyperLogLog instance. This is useful for creating multiple counters with identical configurations. ```APIDOC ## HyperLogLog::new_from_template ### Description Creates a new `HyperLogLog` counter with the same parameters as an existing one. ### Method `HyperLogLog::new_from_template(hll: &HyperLogLog) -> Self` ### Parameters * `hll` (&HyperLogLog) - A reference to an existing `HyperLogLog` instance to use as a template. ``` -------------------------------- ### HyperLogLog::clone Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=u32+-%3E+bool Returns a duplicate of the HyperLogLog value. ```APIDOC ## fn clone(&self) -> HyperLogLog ### Description Returns a duplicate of the value. ### Returns A cloned `HyperLogLog` instance. ``` -------------------------------- ### HyperLogLog::new_deterministic Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search= Creates a new HyperLogLog counter with a specified error rate and seed for deterministic behavior. ```APIDOC ## HyperLogLog::new_deterministic ### Description Creates a new `HyperLogLog` counter with the given error rate and seed. ### Method `new_deterministic(error_rate: f64, seed: u128) -> Self` ### Parameters * **error_rate** (f64) - The desired error rate for the counter. * **seed** (u128) - The seed to use for deterministic hashing. ``` -------------------------------- ### HyperLogLog::new_deterministic Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Creates a new HyperLogLog counter with a specified error rate and seed for deterministic behavior. ```APIDOC ## HyperLogLog::new_deterministic ### Description Creates a new `HyperLogLog` counter with the given error rate and seed. ### Method `pub fn new_deterministic(error_rate: f64, seed: u128) -> Self` ### Parameters * `error_rate` (f64) - The desired error rate for the counter. * `seed` (u128) - The seed to use for deterministic hashing. ``` -------------------------------- ### HyperLogLog::new_deterministic Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=u32+-%3E+bool Creates a new HyperLogLog counter with a specified error rate and seed for deterministic behavior. ```APIDOC ## pub fn new_deterministic(error_rate: f64, seed: u128) -> Self ### Description Create a new `HyperLogLog` counter with the given error rate and seed. ### Parameters * `error_rate` (f64) - The desired error rate for the counter. * `seed` (u128) - The seed for deterministic behavior. ### Returns A new `HyperLogLog` instance. ``` -------------------------------- ### HyperLogLog::new_deterministic Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=std%3A%3Avec Creates a new HyperLogLog counter with a specified error rate and a deterministic seed. This is useful for reproducible results. ```APIDOC ## HyperLogLog::new_deterministic ### Description Creates a new `HyperLogLog` counter with the given error rate and seed. ### Method `HyperLogLog::new_deterministic(error_rate: f64, seed: u128) -> Self` ### Parameters * `error_rate` (f64) - The desired error rate for the HyperLogLog counter. * `seed` (u128) - The seed value to ensure deterministic behavior. ``` -------------------------------- ### HyperLogLog::new_deterministic Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Creates a new HyperLogLog counter with a specified error rate and a deterministic seed. This is useful for reproducible results. ```APIDOC ## HyperLogLog::new_deterministic ### Description Creates a new `HyperLogLog` counter with the given error rate and seed. ### Method `HyperLogLog::new_deterministic(error_rate: f64, seed: u128) -> Self` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let hll = HyperLogLog::new_deterministic(0.01, 12345); ``` ### Response #### Success Response A new `HyperLogLog` instance. #### Response Example ```rust // Returns a HyperLogLog instance ``` ``` -------------------------------- ### HyperLogLog::new_deterministic Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Creates a new HyperLogLog counter with a specified error rate and a deterministic seed. This is useful for reproducible results. ```APIDOC ## HyperLogLog::new_deterministic ### Description Creates a new `HyperLogLog` counter with the given error rate and seed. The error rate must be between 0.0 and 1.0. ### Method `HyperLogLog::new_deterministic(error_rate: f64, seed: u128) -> Self` ### Parameters * `error_rate` (f64) - The desired error rate for the cardinality estimation. Must be greater than 0.0 and less than 1.0. * `seed` (u128) - A 128-bit seed for the hash function, ensuring deterministic behavior. ### Returns A new `HyperLogLog` instance configured with the provided parameters. ``` -------------------------------- ### HyperLogLog::insert_by_hash_value Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search= Inserts a u64 hash value directly into the HyperLogLog counter. ```APIDOC ## HyperLogLog::insert_by_hash_value ### Description Insert a new u64 value into the `HyperLogLog` counter. ### Method `insert_by_hash_value(&mut self, x: u64)` ### Parameters * **x** (u64) - The u64 hash value to insert. ``` -------------------------------- ### HyperLogLog::insert_by_hash_value Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=u32+-%3E+bool Inserts a u64 hash value directly into the HyperLogLog counter. ```APIDOC ## pub fn insert_by_hash_value(&mut self, x: u64) ### Description Insert a new u64 value into the `HyperLogLog` counter. ### Parameters * `x` (u64) - The u64 hash value to insert. ``` -------------------------------- ### HyperLogLog::insert_by_hash_value Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Inserts a new u64 hash value directly into the HyperLogLog counter. ```APIDOC ## HyperLogLog::insert_by_hash_value ### Description Insert a new u64 value into the `HyperLogLog` counter. ### Method `pub fn insert_by_hash_value(&mut self, x: u64)` ### Parameters * `x` (u64) - The u64 hash value to insert. ``` -------------------------------- ### Insert Hash Value into HyperLogLog Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=u32+-%3E+bool Inserts a pre-computed 64-bit hash value into the HyperLogLog counter. This is an internal helper function used by `insert`. ```rust pub fn insert_by_hash_value(&mut self, x: u64) { let j = x as usize & (self.m - 1); let w = x >> self.p; let rho = Self::get_rho(w, 64 - self.p); let mjr = &mut self.M[j]; if rho > *mjr { *mjr = rho; } } ``` -------------------------------- ### HyperLogLog::is_empty Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Checks if the HyperLogLog counter is empty (i.e., has an estimated cardinality of zero). ```APIDOC ## HyperLogLog::is_empty ### Description Checks if the `HyperLogLog` counter is effectively empty, meaning no elements have been added or the estimated cardinality is zero. ### Method `is_empty(&self) -> bool` ### Returns `true` if the counter is empty, `false` otherwise. ``` -------------------------------- ### Check if HyperLogLog is Empty Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Returns `true` if the HyperLogLog counter contains no elements (estimated cardinality is 0.0), and `false` otherwise. ```rust use hyperloglog::HyperLogLog; let mut hll: HyperLogLog = HyperLogLog::new(0.05); println!("Is HLL empty? {}", hll.is_empty()); // true hll.insert(&"test"); println!("Is HLL empty after insert? {}", hll.is_empty()); // false ``` -------------------------------- ### Check if HyperLogLog is Empty Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=std%3A%3Avec Returns `true` if the HyperLogLog counter contains no elements (estimated cardinality is 0.0), and `false` otherwise. ```rust use hyperloglog::HyperLogLog; let error_rate = 0.01; let seed = 1234567890123456789012345678901234567890u128; let mut hll = HyperLogLog::new_deterministic(error_rate, seed); assert!(hll.is_empty()); hll.insert(&"test"); assert!(!hll.is_empty()); ``` -------------------------------- ### Check if HyperLogLog is Empty Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search=u32+-%3E+bool Returns `true` if the HyperLogLog counter has an estimated cardinality of 0.0, and `false` otherwise. ```rust pub fn is_empty(&self) -> bool { self.len() == 0.0 } ``` -------------------------------- ### HyperLogLog::insert_by_hash_value Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html Inserts a pre-hashed u64 value into the HyperLogLog counter. This method is more efficient if the hash is already computed. ```APIDOC ## HyperLogLog::insert_by_hash_value ### Description Inserts a pre-computed hash value into the `HyperLogLog` counter. This method bypasses the hashing step and directly uses the provided `u64` hash. ### Method `insert_by_hash_value(&mut self, x: u64)` ### Parameters * `x` (u64) - The pre-computed hash value of the item to insert. ``` -------------------------------- ### HyperLogLog::insert_by_hash_value Source: https://docs.rs/hyperloglog/latest/hyperloglog/struct.HyperLogLog.html?search=std%3A%3Avec Inserts a pre-hashed u64 value into the HyperLogLog counter. This method is more efficient if the hash of the value is already computed. ```APIDOC ## HyperLogLog::insert_by_hash_value ### Description Inserts a new u64 hash value into the `HyperLogLog` counter. ### Method `pub fn insert_by_hash_value(&mut self, x: u64)` ### Parameters * `x` (u64) - The pre-computed hash value to insert. ``` -------------------------------- ### HyperLogLog::is_empty Source: https://docs.rs/hyperloglog/latest/src/hyperloglog/lib.rs.html?search= Checks if the HyperLogLog counter is empty (i.e., has an estimated cardinality of 0). ```APIDOC ## HyperLogLog::is_empty ### Description Returns `true` if the `HyperLogLog` counter is empty. ### Method `is_empty(&self) -> bool` ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```rust let mut hll = HyperLogLog::new(0.01); println!("Is empty? {}", hll.is_empty()); // true hll.insert("test"); println!("Is empty? {}", hll.is_empty()); // false ``` ### Response #### Success Response (200) - **is_empty** (bool) - `true` if the counter is empty, `false` otherwise. #### Response Example ```rust // Returns a boolean, e.g., true or false ``` ```