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

#1113 in Algorithms

Download history 3150/week @ 2023-10-29 2722/week @ 2023-11-05 2601/week @ 2023-11-12 2749/week @ 2023-11-19 3371/week @ 2023-11-26 2786/week @ 2023-12-03 2884/week @ 2023-12-10 2240/week @ 2023-12-17 1095/week @ 2023-12-24 1647/week @ 2023-12-31 2756/week @ 2024-01-07 2966/week @ 2024-01-14 2741/week @ 2024-01-21 3055/week @ 2024-01-28 3541/week @ 2024-02-04 4337/week @ 2024-02-11

13,848 downloads per month
Used in 94 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