#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

#1092 in Algorithms

Download history 2118/week @ 2023-06-07 2013/week @ 2023-06-14 2110/week @ 2023-06-21 1816/week @ 2023-06-28 2898/week @ 2023-07-05 2158/week @ 2023-07-12 2731/week @ 2023-07-19 1920/week @ 2023-07-26 2251/week @ 2023-08-02 1894/week @ 2023-08-09 2076/week @ 2023-08-16 2230/week @ 2023-08-23 2021/week @ 2023-08-30 2786/week @ 2023-09-06 2462/week @ 2023-09-13 2321/week @ 2023-09-20

10,157 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