#popcount #distance #weight #byte-slice #bit-manipulation #compute #bithack

hamming

Count ones, fast (aka popcount, hamming weight). This provides a performant popcount and bitwise hamming distance for a slice of bytes.

4 releases

Uses old Rust 2015

0.1.3 Jun 1, 2015
0.1.2 Jun 1, 2015
0.1.1 May 31, 2015
0.1.0 May 31, 2015

#1286 in Algorithms

Download history 4813/week @ 2024-08-23 4237/week @ 2024-08-30 4095/week @ 2024-09-06 4507/week @ 2024-09-13 5146/week @ 2024-09-20 5093/week @ 2024-09-27 5825/week @ 2024-10-04 8390/week @ 2024-10-11 7808/week @ 2024-10-18 6176/week @ 2024-10-25 6839/week @ 2024-11-01 5465/week @ 2024-11-08 5470/week @ 2024-11-15 6651/week @ 2024-11-22 8811/week @ 2024-11-29 5544/week @ 2024-12-06

27,274 downloads per month
Used in 107 crates (9 directly)

MIT/Apache

18KB
316 lines

hamming

Build Status Coverage Status

A crate to compute the Hamming weight of a vector and the Hamming distance between two efficiently.

Documentation, crates.io.


lib.rs:

A crate to count ones and xor bytes, fast (aka popcount, hamming weight and hamming distance).

Installation

Add this to your Cargo.toml:

[dependencies]
hamming = "0.1"

Examples

assert_eq!(hamming::weight(&[1, 0xFF, 1, 0xFF]), 1 + 8 + 1 + 8);
assert_eq!(hamming::distance(&[1, 0xFF], &[0xFF, 1]), 7 + 7);

No runtime deps