#hamming-distance #popcount

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

#1574 in Algorithms

Download history 23829/week @ 2026-02-20 23890/week @ 2026-02-27 23347/week @ 2026-03-06 16925/week @ 2026-03-13 14929/week @ 2026-03-20 15459/week @ 2026-03-27 15315/week @ 2026-04-03 16703/week @ 2026-04-10 17879/week @ 2026-04-17 17210/week @ 2026-04-24 12879/week @ 2026-05-01 15192/week @ 2026-05-08 18593/week @ 2026-05-15 18699/week @ 2026-05-22 14031/week @ 2026-05-29 14871/week @ 2026-06-05

69,806 downloads per month
Used in 148 crates (13 directly)

MIT/Apache

18KB
316 lines

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);

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.

No runtime deps