### Creating a Hasher with Initial State Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=u32+-%3E+bool Initialize a `Hasher` with a specific CRC32 state using `new_with_initial()`. This is useful when continuing a checksum computation or when a non-default starting value is required. ```rust let mut hasher = Hasher::new_with_initial(0x12345678); ``` -------------------------------- ### Hasher Initialization with Initial State Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Initialize a `Hasher` with a specific starting CRC32 value. This is useful when chaining checksums or resuming computations. ```rust pub fn new_with_initial(init: u32) -> Self { Self::new_with_initial_len(init, 0) } ``` -------------------------------- ### Advanced Usage Source: https://docs.rs/crc32fast/latest/crc32fast/index.html?search=std%3A%3Avec For use-cases that require more flexibility or performance, for example when processing large amounts of data, you can create and manipulate a `Hasher`. ```APIDOC ## Hasher ### Description Represents an in-progress CRC32 computation. Allows for incremental updates and finalization. ### Methods #### `new()` Creates a new `Hasher` instance. This constructor performs feature detection at runtime to select the most optimal CRC32 implementation for the current CPU. * **Return Value**: `Hasher` #### `update(data: &[u8])` Updates the hasher state with the provided byte slice. * **Parameters**: * `data` (slice of bytes) - The data to incorporate into the checksum. #### `finalize()` Computes the final CRC32 checksum from the accumulated data. * **Return Value**: `u32` - The computed CRC32 checksum. ### Example ```rust use crc32fast::Hasher; let mut hasher = Hasher::new(); hasher.update(b"foo bar baz"); let checksum = hasher.finalize(); ``` ``` -------------------------------- ### Create Hasher with Initial State Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Creates a new Hasher with a specified initial CRC32 state. This is useful when continuing a CRC computation or when a specific starting state is required. ```rust pub fn new_with_initial(init: u32) -> Self ``` -------------------------------- ### Finalizing Hasher and Getting CRC32 Value Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Completes the CRC32 computation and returns the final checksum value. This consumes the `Hasher` instance. ```rust pub fn finalize(self) -> u32 { match self.state { State::Baseline(state) => state.finalize(), State::Specialized(state) => state.finalize(), } } ``` -------------------------------- ### impl Any for T Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `type_id` method to get the `TypeId` of an object. ```APIDOC ## fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ``` -------------------------------- ### Hasher Initialization Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Create a new `Hasher` instance. The `new()` method automatically selects the most optimal CRC32 implementation for the current CPU at runtime. ```rust pub fn new() -> Self { Self::new_with_initial(DEFAULT_INIT_STATE) } ``` -------------------------------- ### impl CloneToUninit for T Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `clone_to_uninit` method for nightly-only experimental API. This method performs copy-assignment from `self` to `dest`. ```APIDOC ## unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. ``` -------------------------------- ### Creating a Hasher with Initial State and Length Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=u32+-%3E+bool Use `new_with_initial_len()` to create a `Hasher` with both an initial CRC32 state and a byte length. This is particularly useful when working with the `combine` functionality. ```rust let mut hasher = Hasher::new_with_initial_len(0x12345678, 1024); ``` -------------------------------- ### Hasher::new_with_initial Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Creates a new Hasher with a specified initial CRC32 state. ```APIDOC ## Hasher::new_with_initial ### Description Create a new `Hasher` with an initial CRC32 state. This works just like `Hasher::new`, except that it allows for an initial CRC32 state to be passed in. ### Signature ```rust pub fn new_with_initial(init: u32) -> Self ``` ``` -------------------------------- ### Get 128-bit Chunk from Byte Slice Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Loads a 128-bit value from a byte slice and advances the slice pointer. Asserts that the slice has at least 16 bytes. ```rust unsafe fn get(a: &mut &[u8]) -> arch::__m128i { debug_assert!(a.len() >= 16); let r = arch::_mm_loadu_si128(a.as_ptr() as *const arch::__m128i); *a = &a[16..]; r } ``` -------------------------------- ### Hasher Initialization with Initial State and Length Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Create a `Hasher` with an initial CRC32 state and a specified byte length. This variant is particularly useful when working with the `combine` functionality. ```rust pub fn new_with_initial_len(init: u32, amount: u64) -> Self { Self::internal_new_specialized(init, amount) .unwrap_or_else(|| Self::internal_new_baseline(init, amount)) } ``` -------------------------------- ### Hasher::new Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=std%3A%3Avec Creates a new Hasher instance. It performs runtime CPU feature detection to select the most optimal implementation for the current processor architecture. ```APIDOC ## Hasher::new ### Description Create a new `Hasher`. This will perform a CPU feature detection at runtime to select the most optimal implementation for the current processor architecture. ### Signature ```rust pub fn new() -> Self ``` ``` -------------------------------- ### Test CRC32Fast PCLMULQDQ Implementation Against Baseline Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html?search= Uses quickcheck to verify that the PCLMULQDQ-accelerated CRC32Fast implementation produces the same results as the baseline implementation across various inputs and alignments. ```rust quickcheck::quickcheck! { fn check_against_baseline(init: u32, chunks: Vec<(Vec, usize)>) -> bool { let mut baseline = super::super::super::baseline::State::new(init); let mut pclmulqdq = super::State::new(init).expect("not supported"); for (chunk, mut offset) in chunks { offset &= 0xF; if chunk.len() <= offset { baseline.update(&chunk); pclmulqdq.update(&chunk); } else { baseline.update(&chunk[offset..]); pclmulqdq.update(&chunk[offset..]); } } pclmulqdq.finalize() == baseline.finalize() } } ``` -------------------------------- ### Hasher::new Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Creates a new Hasher, performing runtime CPU feature detection to select the most optimal implementation. ```APIDOC ## Hasher::new ### Description Create a new `Hasher`. This will perform a CPU feature detection at runtime to select the most optimal implementation for the current processor architecture. ### Signature ```rust pub fn new() -> Self ``` ``` -------------------------------- ### Hasher::new_with_initial Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=std%3A%3Avec Creates a new Hasher with a specified initial CRC32 state. This allows for continuing a CRC32 computation from a previous state. ```APIDOC ## Hasher::new_with_initial ### Description Create a new `Hasher` with an initial CRC32 state. This works just like `Hasher::new`, except that it allows for an initial CRC32 state to be passed in. ### Signature ```rust pub fn new_with_initial(init: u32) -> Self ``` ``` -------------------------------- ### Creating a New Hasher Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=u32+-%3E+bool Instantiate a new `Hasher` using `Hasher::new()`. This method performs runtime CPU feature detection to select the most optimal CRC32 implementation for the current architecture. ```rust let mut hasher = Hasher::new(); ``` -------------------------------- ### Hasher::new_with_initial_len Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Creates a new Hasher with an initial CRC32 state and byte length. ```APIDOC ## Hasher::new_with_initial_len ### Description Create a new `Hasher` with an initial CRC32 state. As `new_with_initial`, but also accepts a length (in bytes). The resulting object can then be used with `combine` to compute `crc(a || b)` from `crc(a)`, `crc(b)`, and `len(b)`. ### Signature ```rust pub fn new_with_initial_len(init: u32, amount: u64) -> Self ``` ``` -------------------------------- ### QuickCheck Test for CRC32Fast pclmulqdq Implementation Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html?search=u32+-%3E+bool Verifies the correctness of the pclmulqdq-based CRC32Fast implementation against a baseline implementation using QuickCheck. It simulates random data alignments. ```rust quickcheck::quickcheck! { fn check_against_baseline(init: u32, chunks: Vec<(Vec, usize)>) -> bool { let mut baseline = super::super::super::baseline::State::new(init); let mut pclmulqdq = super::State::new(init).expect("not supported"); for (chunk, mut offset) in chunks { // simulate random alignments by offsetting the slice by up to 15 bytes offset &= 0xF; if chunk.len() <= offset { baseline.update(&chunk); pclmulqdq.update(&chunk); } else { baseline.update(&chunk[offset..]); pclmulqdq.update(&chunk[offset..]); } } pclmulqdq.finalize() == baseline.finalize() } } ``` -------------------------------- ### impl From for T Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `from` method which returns the argument unchanged. ```APIDOC ## fn from(t: T) -> T Returns the argument unchanged. ``` -------------------------------- ### QuickCheck Test for CRC32 Fast Implementation Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Verifies the correctness of the PCLMULQDQ-accelerated CRC32 implementation against a baseline implementation using QuickCheck. It tests various initial values and chunked data with random offsets. ```rust #[cfg(test)] mod test { quickcheck::quickcheck! { fn check_against_baseline(init: u32, chunks: Vec<(Vec, usize)>) -> bool { let mut baseline = super::super::super::baseline::State::new(init); let mut pclmulqdq = super::State::new(init).expect("not supported"); for (chunk, mut offset) in chunks { // simulate random alignments by offsetting the slice by up to 15 bytes offset &= 0xF; if chunk.len() <= offset { baseline.update(&chunk); pclmulqdq.update(&chunk); } else { baseline.update(&chunk[offset..]); pclmulqdq.update(&chunk[offset..]); } } pclmulqdq.finalize() == baseline.finalize() } } } ``` -------------------------------- ### Implement Default for Hasher Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html Allows creating a new Hasher instance using the default constructor. ```rust impl Default for Hasher { fn default() -> Self { Self::new() } } ``` -------------------------------- ### Test `Hasher::combine` functionality Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Uses quickcheck to test the `combine` method of the `Hasher`. It verifies that combining two hashes results in the same CRC32 value as hashing the concatenated byte slices. ```rust quickcheck::quickcheck! { fn combine(bytes_1: Vec, bytes_2: Vec) -> bool { let mut hash_a = Hasher::new(); hash_a.update(&bytes_1); hash_a.update(&bytes_2); let mut hash_b = Hasher::new(); hash_b.update(&bytes_2); let mut hash_c = Hasher::new(); hash_c.update(&bytes_1); hash_c.combine(&hash_b); hash_a.finalize() == hash_c.finalize() } fn combine_from_len(bytes_1: Vec, bytes_2: Vec) -> bool { let mut hash_a = Hasher::new(); hash_a.update(&bytes_1); let mut hash_b = Hasher::new(); hash_b.update(&bytes_2); let mut hash_ab = Hasher::new(); hash_ab.update(&bytes_1); hash_ab.update(&bytes_2); let ab = hash_ab.finalize(); hash_a.combine(&hash_b); hash_a.finalize() == ab } } ``` -------------------------------- ### Advanced CRC32 Hashing with Hasher Source: https://docs.rs/crc32fast/latest/crc32fast/index.html?search= For more control or when processing large data, instantiate a `Hasher`. This allows for incremental updates and finalization of the CRC32 checksum. Ensure `crc32fast::Hasher` is imported. ```rust use crc32fast::Hasher; let mut hasher = Hasher::new(); hasher.update(b"foo bar baz"); let checksum = hasher.finalize(); ``` -------------------------------- ### Create Hasher with Initial State and Length Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Creates a new Hasher with an initial CRC32 state and a byte length. This is useful for combining CRC computations, allowing the calculation of `crc(a || b)` from `crc(a)`, `crc(b)`, and `len(b)`. ```rust pub fn new_with_initial_len(init: u32, amount: u64) -> Self ``` -------------------------------- ### Hasher::write_length_prefix (from std::hash::Hasher) Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=std%3A%3Avec Writes a length prefix into the hasher, as part of being prefix-free. This is an experimental API. ```APIDOC ## Hasher::write_length_prefix ### Description Writes a length prefix into this hasher, as part of being prefix-free. ### Signature ```rust fn write_length_prefix(&mut self, len: usize) ``` ### Note This is a nightly-only experimental API. (`hasher_prefixfree_extras`) ``` -------------------------------- ### Hasher::write_str (experimental) Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Writes a string slice into the hasher. This is an experimental API. ```APIDOC ## Hasher::write_str (experimental) ### Description Writes a single `str` into this hasher. This is a nightly-only experimental API. ### Parameters * `s` (&str) - The string slice to write. ``` -------------------------------- ### QuickCheck Test for CRC32 PCLMULQDQ Implementation Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html Tests the `pclmulqdq` CRC32 implementation against a baseline implementation using `quickcheck`. It simulates random alignments of data chunks to ensure correctness. ```rust #[cfg(test)] mod test { use super::super::State; use crate::baseline::State as BaselineState; quickcheck::quickcheck! { fn check_against_baseline(init: u32, chunks: Vec<(Vec, usize)>) -> bool { let mut baseline = BaselineState::new(init); let mut pclmulqdq = State::new(init).expect("not supported"); for (chunk, mut offset) in chunks { // simulate random alignments by offsetting the slice by up to 15 bytes offset &= 0xF; if chunk.len() <= offset { baseline.update(&chunk); pclmulqdq.update(&chunk); } else { baseline.update(&chunk[offset..]); pclmulqdq.update(&chunk[offset..]); } } pclmulqdq.finalize() == baseline.finalize() } } } ``` -------------------------------- ### Initialize CRC32 State (No Std) Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html Creates a new `State` for CRC32 calculation when the `std` feature is not enabled. Requires the `pclmulqdq`, `sse2`, and `sse4.1` CPU features to be available. ```rust pub fn new(state: u32) -> Option { if cfg!(target_feature = "pclmulqdq") && cfg!(target_feature = "sse2") && cfg!(target_feature = "sse4.1") { // SAFETY: The conditions above ensure that all // required instructions are supported by the CPU. Some(Self { state }) } else { None } } ``` -------------------------------- ### Initialize CRC32 State (With Std) Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html Creates a new `State` for CRC32 calculation when the `std` feature is enabled. It dynamically checks for the `pclmulqdq`, `sse2`, and `sse4.1` CPU features at runtime. ```rust pub fn new(state: u32) -> Option { if is_x86_feature_detected!("pclmulqdq") && is_x86_feature_detected!("sse2") && is_x86_feature_detected!("sse4.1") { // SAFETY: The conditions above ensure that all // required instructions are supported by the CPU. Some(Self { state }) } else { None } } ``` -------------------------------- ### impl Into for T Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `into` method which calls `U::from(self)`. The conversion behavior is determined by the `From for U` implementation. ```APIDOC ## fn into(self) -> U Calls `U::from(self)`. ``` -------------------------------- ### Create New Hasher Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Creates a new Hasher instance. This method performs runtime CPU feature detection to select the most optimal implementation for the current processor architecture. ```rust pub fn new() -> Self ``` -------------------------------- ### State::new for PCLMULQDQ Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Constructs a new State for PCLMULQDQ-accelerated CRC32 calculation. Returns None if the required CPU features (pclmulqdq, sse2, sse4.1) are not detected. ```rust pub fn new(state: u32) -> Option { if cfg!(target_feature = "pclmulqdq") && cfg!(target_feature = "sse2") && cfg!(target_feature = "sse4.1") { // SAFETY: The conditions above ensure that all // required instructions are supported by the CPU. Some(Self { state }) } else { None } } ``` ```rust pub fn new(state: u32) -> Option { if is_x86_feature_detected!("pclmulqdq") && is_x86_feature_detected!("sse2") && is_x86_feature_detected!("sse4.1") { // SAFETY: The conditions above ensure that all // required instructions are supported by the CPU. Some(Self { state }) } else { None } } ``` -------------------------------- ### Property-based test for CRC32 fast vs slow Source: https://docs.rs/crc32fast/latest/src/crc32fast/baseline.rs.html Uses the `quickcheck` crate to perform property-based testing, ensuring that the `update_fast_16` function produces the same results as `update_slow` for arbitrary CRC values and byte sequences. ```rust quickcheck::quickcheck! { fn fast_16_is_the_same_as_slow(crc: u32, bytes: Vec) -> bool { super::update_fast_16(crc, &bytes) == super::update_slow(crc, &bytes) } } ``` -------------------------------- ### Write String (Nightly) Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Writes a string slice into the hasher. This is a nightly-only experimental API, likely for prefix-free encoding. ```rust fn write_str(&mut self, s: &str) ``` -------------------------------- ### Hasher::fmt Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search= Formats the Hasher state for debugging purposes. ```APIDOC ## Hasher::fmt ### Description Formats the value using the given formatter. ### Signature ```rust fn fmt(&self, f: &mut Formatter<'_>) -> Result ``` ``` -------------------------------- ### Clone Hasher From Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Performs copy-assignment from a source Hasher to the current one. This is an optimization for cloning when the destination is already allocated. ```rust fn clone_from(&mut self, source: &Self) ``` -------------------------------- ### Hasher::clone_from Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search= Copies the state from another Hasher into the current one. ```APIDOC ## Hasher::clone_from ### Description Performs copy-assignment from `source`. ### Signature ```rust fn clone_from(&mut self, source: &Self) ``` ``` -------------------------------- ### State Enum and Methods (Fallback) Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/mod.rs.html?search= The generic `State` enum and its associated methods provide a fallback implementation when specialized hardware features are not available. It includes methods for initialization, updating, finalizing, resetting, and combining CRC states. ```APIDOC ## State Enum and Methods (Fallback) ### Description This section documents the generic `State` enum and its methods, which serve as a fallback implementation for CRC32 calculations when specialized hardware acceleration is not detected. ### Type ```rust #[derive(Clone)] pub enum State {} ``` ### Methods #### `new(initial_crc: u32) -> Option` * **Description**: Creates a new `State` instance. Returns `None` in the fallback implementation. * **Parameters**: * `initial_crc` (u32) - The initial CRC value. * **Returns**: * `Option` - Always `None` for the fallback. #### `update(&mut self, buf: &[u8])` * **Description**: Updates the CRC state with the provided buffer. This method is a no-op in the fallback implementation. * **Parameters**: * `buf` (&[u8]) - The buffer containing data to process. #### `finalize(self) -> u32` * **Description**: Finalizes the CRC calculation and returns the result. This method is a no-op in the fallback implementation. * **Returns**: * `u32` - The final CRC value (always 0 in the fallback). #### `reset(&mut self)` * **Description**: Resets the CRC state. This method is a no-op in the fallback implementation. #### `combine(&mut self, other: u32, amount: u64)` * **Description**: Combines the current CRC state with another CRC value. This method is a no-op in the fallback implementation. * **Parameters**: * `other` (u32) - The other CRC value to combine. * `amount` (u64) - The amount of data associated with the `other` CRC value. ``` -------------------------------- ### Write Length Prefix (Nightly) Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Writes a length prefix into the hasher, intended for use with prefix-free encoding schemes. This is a nightly-only experimental API. ```rust fn write_length_prefix(&mut self, len: usize) ``` -------------------------------- ### Hasher::write_str (from std::hash::Hasher) Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=std%3A%3Avec Writes a string slice into the hasher. This is an experimental API. ```APIDOC ## Hasher::write_str ### Description Writes a single `str` into this hasher. ### Signature ```rust fn write_str(&mut self, s: &str) ``` ### Note This is a nightly-only experimental API. (`hasher_prefixfree_extras`) ``` -------------------------------- ### QuickCheck Test for combine_from_len Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=u32+-%3E+bool Verifies that combining two hashers results in the same final hash as hashing the concatenated byte slices directly. ```rust fn combine_from_len(bytes_1: Vec, bytes_2: Vec) -> bool { let mut hash_a = Hasher::new(); hash_a.update(&bytes_1); let mut hash_b = Hasher::new(); hash_b.update(&bytes_2); let mut hash_ab = Hasher::new(); hash_ab.update(&bytes_1); hash_ab.update(&bytes_2); let ab = hash_ab.finalize(); hash_a.combine(&hash_b); hash_a.finalize() == ab } ``` -------------------------------- ### Hasher::write_length_prefix Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=u32+-%3E+bool Writes a length prefix into the Hasher, as part of being prefix-free. This is a nightly-only experimental API. ```APIDOC ## Hasher::write_length_prefix (Hasher trait - experimental) ### Description Writes a length prefix into this hasher, as part of being prefix-free. ### Signature ```rust fn write_length_prefix(&mut self, len: usize) ``` ``` -------------------------------- ### QuickCheck for update_fast_16 vs update_slow Source: https://docs.rs/crc32fast/latest/src/crc32fast/baseline.rs.html?search=u32+-%3E+bool A QuickCheck property that ensures the `update_fast_16` function produces the same results as `update_slow` for any given CRC and byte slice. ```APIDOC ## QuickCheck: fast_16_is_the_same_as_slow ### Description This property test uses QuickCheck to verify that the optimized `update_fast_16` function is equivalent to the `update_slow` function across a wide range of inputs. ### Property `super::update_fast_16(crc: u32, bytes: Vec) == super::update_slow(crc, &bytes)` ``` -------------------------------- ### Hasher::new_with_initial_len Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=std%3A%3Avec Creates a new Hasher with an initial CRC32 state and a specified length. This is useful for combining CRC32 computations of concatenated data. ```APIDOC ## Hasher::new_with_initial_len ### Description Create a new `Hasher` with an initial CRC32 state. As `new_with_initial`, but also accepts a length (in bytes). The resulting object can then be used with `combine` to compute `crc(a || b)` from `crc(a)`, `crc(b)`, and `len(b)`. ### Signature ```rust pub fn new_with_initial_len(init: u32, amount: u64) -> Self ``` ``` -------------------------------- ### Combine Function Test Cases Source: https://docs.rs/crc32fast/latest/src/crc32fast/combine.rs.html?search= Provides various test cases to verify the correctness of the `combine` function under different scenarios, including zero lengths and specific checksum values. ```rust @test fn golden() { assert_eq!(combine(0x0, 0x1, 0x0), 0x0); assert_eq!(combine(0xc401f8c9, 0x00000000, 0x0), 0xc401f8c9); assert_eq!(combine(0x7cba3d5e, 0xe7466d39, 0xb), 0x76365c4f); assert_eq!(combine(0x576c62d6, 0x123256e1, 0x47), 0x579a636); assert_eq!(combine(0x4f626f9a, 0x9e5ccbf5, 0xa59d), 0x98d43168); assert_eq!(combine(0xa09b8a88, 0x815b0f48, 0x40f39511), 0xd7a5f79); assert_eq!( combine(0x7f6a4306, 0xbc929646, 0x828cde72b3e25301), 0xef922dda ); } ``` -------------------------------- ### Quickcheck Test for Combine Functionality Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html Tests the `combine` method by ensuring that hashing two byte slices sequentially is equivalent to combining their individual hash states. ```rust quickcheck::quickcheck! { fn combine(bytes_1: Vec, bytes_2: Vec) -> bool { let mut hash_a = Hasher::new(); hash_a.update(&bytes_1); hash_a.update(&bytes_2); let mut hash_b = Hasher::new(); hash_b.update(&bytes_2); let mut hash_c = Hasher::new(); hash_c.update(&bytes_1); hash_c.combine(&hash_b); hash_a.finalize() == hash_c.finalize() } } ``` -------------------------------- ### Generic Trait Implementations for Hasher Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Details blanket implementations of common Rust traits for types that can be used with Hasher, such as Any, Borrow, CloneToUninit, From, Into, ToOwned, TryFrom, and TryInto. ```APIDOC ## Blanket Implementations ### impl Any for T where T: 'static + ?Sized, #### fn type_id(&self) -> TypeId Gets the `TypeId` of `self`. ### impl Borrow for T where T: ?Sized, #### fn borrow(&self) -> &T Immutably borrows from an owned value. ### impl BorrowMut for T where T: ?Sized, #### fn borrow_mut(&mut self) -> &mut T Mutably borrows from an owned value. ### impl CloneToUninit for T where T: Clone, #### unsafe fn clone_to_uninit(&self, dest: *mut u8) Performs copy-assignment from `self` to `dest`. ### impl From for T #### fn from(t: T) -> T Returns the argument unchanged. ### impl Into for T where U: From, #### fn into(self) -> U Calls `U::from(self)`. ### impl ToOwned for T where T: Clone, #### type Owned = T The resulting type after obtaining ownership. #### fn to_owned(&self) -> T Creates owned data from borrowed data, usually by cloning. #### fn clone_into(&self, target: &mut T) Uses borrowed data to replace owned data, usually by cloning. ### impl TryFrom for T where U: Into, #### type Error = Infallible The type returned in the event of a conversion error. #### fn try_from(value: U) -> Result>::Error> Performs the conversion. ### impl TryInto for T where U: TryFrom, #### type Error = >::Error The type returned in the event of a conversion error. #### fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### impl Borrow for T Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `borrow` method for immutable borrowing. ```APIDOC ## fn borrow(&self) -> &T Immutably borrows from an owned value. ``` -------------------------------- ### Quickcheck Test for Combine from Length Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html Verifies that combining hash states produces the same result as hashing the concatenated byte slices. ```rust fn combine_from_len(bytes_1: Vec, bytes_2: Vec) -> bool { let mut hash_a = Hasher::new(); hash_a.update(&bytes_1); let mut hash_b = Hasher::new(); hash_b.update(&bytes_2); let mut hash_ab = Hasher::new(); hash_ab.update(&bytes_1); hash_ab.update(&bytes_2); let ab = hash_ab.finalize(); hash_a.combine(&hash_b); hash_a.finalize() == ab } ``` -------------------------------- ### Hasher::default Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search= Returns the default Hasher state, equivalent to `Hasher::new()`. ```APIDOC ## Hasher::default ### Description Returns the “default value” for a type. ### Signature ```rust fn default() -> Self ``` ``` -------------------------------- ### Hasher::clone Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search= Creates a duplicate of the current Hasher state. ```APIDOC ## Hasher::clone ### Description Returns a duplicate of the value. ### Signature ```rust fn clone(&self) -> Hasher ``` ``` -------------------------------- ### Internal Specialized Hasher Creation Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Internal function to attempt creating a `Hasher` using a specialized (SIMD) implementation. Returns `None` if the specialized implementation cannot be initialized. ```rust pub fn internal_new_specialized(init: u32, amount: u64) -> Option { { if let Some(state) = specialized::State::new(init) { return Some(Hasher { amount, state: State::Specialized(state), }); } } None } ``` -------------------------------- ### Implement Hash for Hasher Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html Integrates the Hasher with Rust's standard hashing traits. ```rust impl hash::Hasher for Hasher { fn write(&mut self, bytes: &[u8]) { self.update(bytes) } fn finish(&self) -> u64 { u64::from(self.clone().finalize()) } } ``` -------------------------------- ### CRC32fast Combine Function Tests Source: https://docs.rs/crc32fast/latest/src/crc32fast/combine.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides test cases for the `combine` function, verifying its correctness with various inputs including zero length, zero checksums, and different chunk lengths. ```rust #[test] fn golden() { assert_eq!(combine(0x0, 0x1, 0x0), 0x0); assert_eq!(combine(0xc401f8c9, 0x00000000, 0x0), 0xc401f8c9); assert_eq!(combine(0x7cba3d5e, 0xe7466d39, 0xb), 0x76365c4f); assert_eq!(combine(0x576c62d6, 0x123256e1, 0x47), 0x579a636); assert_eq!(combine(0x4f626f9a, 0x9e5ccbf5, 0xa59d), 0x98d43168); assert_eq!(combine(0xa09b8a88, 0x815b0f48, 0x40f39511), 0xd7a5f79); assert_eq!( combine(0x7f6a4306, 0xbc929646, 0x828cde72b3e25301), 0xef922dda ); } ``` -------------------------------- ### impl TryInto for T Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `try_into` method for attempting conversion from type `T` to type `U`, returning a `Result`. ```APIDOC ## type Error = >::Error The type returned in the event of a conversion error. ``` ```APIDOC ## fn try_into(self) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### State Struct and Methods Source: https://docs.rs/crc32fast/latest/src/crc32fast/specialized/pclmulqdq.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E The `State` struct holds the current CRC checksum and provides methods for initialization, updating, finalizing, resetting, and combining checksums. The `new` method conditionally returns `Some(Self)` if the required CPU features (pclmulqdq, sse2, sse4.1) are detected, otherwise `None`. ```APIDOC ## `State` Struct Represents the state of the CRC32 calculation. ### Methods #### `new(state: u32) -> Option` Creates a new `State` instance. Returns `Some(Self)` if the CPU supports `pclmulqdq`, `sse2`, and `sse4.1` instructions, otherwise returns `None`. #### `update(&mut self, buf: &[u8])` Updates the CRC checksum with the provided buffer of bytes. This method relies on the `calculate` function, which is safe to call due to the checks performed in `State::new`. #### `finalize(self) -> u32` Finalizes the CRC calculation and returns the resulting checksum. #### `reset(&mut self)` Resets the CRC checksum to its initial state (0). #### `combine(&mut self, other: u32, amount: u64)` Combines the current CRC state with another CRC checksum and an amount. This is used for combining CRC values of non-contiguous data. ``` -------------------------------- ### Internal Baseline Hasher Creation Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Internal function to create a `Hasher` using the baseline implementation. This is typically used when specialized implementations are not available or suitable. ```rust pub fn internal_new_baseline(init: u32, amount: u64) -> Self { Hasher { amount, state: State::Baseline(baseline::State::new(init)), } } ``` -------------------------------- ### impl BorrowMut for T Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `borrow_mut` method for mutable borrowing. ```APIDOC ## fn borrow_mut(&mut self) -> &mut T Mutably borrows from an owned value. ``` -------------------------------- ### Advanced Usage with crc32fast::Hasher Source: https://docs.rs/crc32fast/latest/crc32fast/index.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E For more flexibility or when processing large amounts of data, you can create and manipulate a `Hasher` instance. ```APIDOC ## Struct: Hasher ### Description Represents an in-progress CRC32 computation. ### Usage ```rust use crc32fast::Hasher; let mut hasher = Hasher::new(); hasher.update(b"foo bar baz"); let checksum = hasher.finalize(); ``` ``` -------------------------------- ### Hasher::write (from std::io::Write trait) Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Writes data into the hasher. This is part of the `std::io::Write` trait implementation. ```APIDOC ## Hasher::write ### Description Writes some data into this `Hasher`. This method is part of the `std::io::Write` trait implementation. ### Parameters * `bytes` (&[u8]) - The data to write. ``` -------------------------------- ### Implement Debug for Hasher Source: https://docs.rs/crc32fast/latest/src/crc32fast/lib.rs.html Provides a debug representation for the Hasher struct. ```rust impl fmt::Debug for Hasher { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { f.debug_struct("crc32fast::Hasher").finish() } } ``` -------------------------------- ### impl TryFrom for T Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html?search=Option%3CT%3E%2C+%28T+-%3E+U%29+-%3E+Option%3CU%3E Provides the `try_from` method for attempting conversion from type `U` to type `T`, returning a `Result`. ```APIDOC ## type Error = Infallible The type returned in the event of a conversion error. ``` ```APIDOC ## fn try_from(value: U) -> Result>::Error> Performs the conversion. ``` -------------------------------- ### Default Hasher Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Returns the default value for a Hasher, which is equivalent to creating a new Hasher with default initial state. ```rust fn default() -> Self ``` -------------------------------- ### Hasher::combine Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Combines the current hash state with the hash state of a subsequent block of bytes. ```APIDOC ## Hasher::combine ### Description Combine the hash state with the hash state for the subsequent block of bytes. ### Signature ```rust pub fn combine(&mut self, other: &Self) ``` ``` -------------------------------- ### Simple CRC32 Hash Calculation Source: https://docs.rs/crc32fast/latest/crc32fast/index.html?search= Use the `hash()` convenience function for straightforward CRC32 checksum computation on a byte slice. ```APIDOC ## hash ### Description Computes the CRC32 hash of a byte slice. ### Usage ```rust let checksum = crc32fast::hash(b"foo bar baz"); ``` ``` -------------------------------- ### Hasher Trait Implementations Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html This section outlines the automatic trait implementations for the Hasher struct, indicating its compatibility with various Rust features like Send, Sync, and UnwindSafe. ```APIDOC ## Auto Trait Implementations ### impl Freeze for Hasher ### impl RefUnwindSafe for Hasher ### impl Send for Hasher ### impl Sync for Hasher ### impl Unpin for Hasher ### impl UnsafeUnpin for Hasher ### impl UnwindSafe for Hasher ``` -------------------------------- ### Advanced CRC32 Hashing with Hasher Source: https://docs.rs/crc32fast/latest/crc32fast/index.html?search= For more complex scenarios or large data processing, utilize the `Hasher` struct to manage CRC32 computations incrementally. ```APIDOC ## Hasher ### Description Represents an in-progress CRC32 computation. ### Usage ```rust use crc32fast::Hasher; let mut hasher = Hasher::new(); hasher.update(b"foo bar baz"); let checksum = hasher.finalize(); ``` ``` -------------------------------- ### Tests for update_slow Source: https://docs.rs/crc32fast/latest/src/crc32fast/baseline.rs.html?search=u32+-%3E+bool Unit tests verifying the correctness of the `update_slow` function with various inputs, including test vectors from iPXE and Rosetta code. ```APIDOC ## Tests for update_slow ### Description Contains unit tests to validate the `update_slow` function against known CRC32 values. ### Test Cases - Empty byte slice. - Test vectors from the iPXE project (bitwise negated input and output). - Test vectors from Rosetta code. ``` -------------------------------- ### Hasher::write_i32 Source: https://docs.rs/crc32fast/latest/crc32fast/struct.Hasher.html Writes a single i32 into the hasher. This method is part of the `Hasher` trait. ```APIDOC ## Hasher::write_i32 ### Description Writes a single `i32` into this hasher. ### Signature ```rust fn write_i32(&mut self, i: i32) ``` ```