#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

#979 in Algorithms

Download history 2666/week @ 2024-12-22 3440/week @ 2024-12-29 5628/week @ 2025-01-05 7174/week @ 2025-01-12 7478/week @ 2025-01-19 6371/week @ 2025-01-26 6763/week @ 2025-02-02 8005/week @ 2025-02-09 9684/week @ 2025-02-16 9610/week @ 2025-02-23 9926/week @ 2025-03-02 9359/week @ 2025-03-09 9079/week @ 2025-03-16 7868/week @ 2025-03-23 8595/week @ 2025-03-30 9677/week @ 2025-04-06

36,008 downloads per month
Used in 123 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