#popcount #distance #weight #byte #ones #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

#1763 in Algorithms

Download history 1909/week @ 2024-01-03 2884/week @ 2024-01-10 2833/week @ 2024-01-17 2821/week @ 2024-01-24 3038/week @ 2024-01-31 3964/week @ 2024-02-07 5267/week @ 2024-02-14 6421/week @ 2024-02-21 5101/week @ 2024-02-28 5083/week @ 2024-03-06 4053/week @ 2024-03-13 4128/week @ 2024-03-20 3688/week @ 2024-03-27 3330/week @ 2024-04-03 3035/week @ 2024-04-10 3451/week @ 2024-04-17

14,349 downloads per month
Used in 97 crates (8 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