Skip to content

Commit 61aa02d

Browse files
committed
add hash convenience function
1 parent e1ce6b1 commit 61aa02d

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

src/lib.rs

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,20 @@
1-
//! ## Example
1+
//! Fast, SIMD-accelerated CRC32 (IEEE) checksum computation.
2+
//!
3+
//! ## Usage
4+
//!
5+
//! ### Simple usage
6+
//!
7+
//! For simple use-cases, you can call the [`hash()`] convenience function to
8+
//! directly compute the CRC32 checksum for a given byte slice:
9+
//!
10+
//! ```rust
11+
//! let checksum = crc32fast::hash(b"foo bar baz");
12+
//! ```
13+
//!
14+
//! ### Advanced usage
15+
//!
16+
//! For use-cases that require more flexibility or performance, for example when
17+
//! processing large amounts of data, you can create and manipulate a [`Hasher`]:
218
//!
319
//! ```rust
420
//! use crc32fast::Hasher;
@@ -15,7 +31,7 @@
1531
//! - A fast baseline implementation which processes up to 16 bytes per iteration
1632
//! - An optimized implementation for modern `x86` using `sse` and `pclmulqdq` instructions
1733
//!
18-
//! Calling the `Hasher::new` constructor at runtime will perform a feature detection to select the most
34+
//! Calling the [`Hasher::new`] constructor at runtime will perform a feature detection to select the most
1935
//! optimal implementation for the current CPU feature set.
2036
2137
#![cfg_attr(not(feature = "std"), no_std)]
@@ -43,6 +59,15 @@ mod combine;
4359
mod specialized;
4460
mod table;
4561

62+
/// Computes the CRC32 hash of a byte slice.
63+
///
64+
/// Check out [`Hasher`] for more advanced use-cases.
65+
pub fn hash(buf: &[u8]) -> u32 {
66+
let mut h = Hasher::new();
67+
h.update(buf);
68+
h.finalize()
69+
}
70+
4671
#[derive(Clone)]
4772
enum State {
4873
Baseline(baseline::State),

0 commit comments

Comments
 (0)