Skip to main content

PopcntExt

Trait PopcntExt 

Source
pub trait PopcntExt {
    // Required method
    fn popcnt(&self) -> u64;
}
Expand description

Adds a popcnt method to slices of the built-in integer types, counting their bits without a manual byte cast. Implemented for slices, arrays and Vecs of u8/u16/u32/u64/u128/usize and their signed counterparts; bring it into scope with use simd_popcnt::PopcntExt;.

use simd_popcnt::PopcntExt;

let words: &[u64] = &[u64::MAX, 0x0F0F_0F0F_0F0F_0F0F];
assert_eq!(words.popcnt(), 64 + 32);
assert_eq!(vec![1u32, 2, 3].popcnt(), 4);

Required Methods§

Source

fn popcnt(&self) -> u64

Count the total number of 1 bits across all elements of the slice.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl PopcntExt for [i8]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [i16]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [i32]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [i64]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [i128]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [isize]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [u8]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [u16]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [u32]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [u64]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [u128]

Source§

fn popcnt(&self) -> u64

Source§

impl PopcntExt for [usize]

Source§

fn popcnt(&self) -> u64

Implementors§