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

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

#1205 in Algorithms

Download history 4336/week @ 2024-07-20 5969/week @ 2024-07-27 3116/week @ 2024-08-03 4991/week @ 2024-08-10 4265/week @ 2024-08-17 4846/week @ 2024-08-24 4513/week @ 2024-08-31 4090/week @ 2024-09-07 4661/week @ 2024-09-14 4755/week @ 2024-09-21 5213/week @ 2024-09-28 6278/week @ 2024-10-05 8145/week @ 2024-10-12 7502/week @ 2024-10-19 6892/week @ 2024-10-26 5475/week @ 2024-11-02

29,233 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