#popcount #hamming #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

#941 in Algorithms

Download history 5509/week @ 2025-01-04 7155/week @ 2025-01-11 7291/week @ 2025-01-18 6626/week @ 2025-01-25 6557/week @ 2025-02-01 7935/week @ 2025-02-08 9628/week @ 2025-02-15 9579/week @ 2025-02-22 9917/week @ 2025-03-01 9369/week @ 2025-03-08 9187/week @ 2025-03-15 7922/week @ 2025-03-22 8407/week @ 2025-03-29 9704/week @ 2025-04-05 29950/week @ 2025-04-12 8298/week @ 2025-04-19

57,602 downloads per month
Used in 126 crates (10 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