Function broadword::select1
[−]
[src]
pub fn select1(r: usize, x: u64) -> Option<usize>
Finds the index of the r
th one bit in x
.
Uses the broadword algorithm from Vigna. Note that bits are numbered from least-significant to most.
Examples
use broadword::select1; assert_eq!( select1(0, 0x0000_0000_0000_0000), None ); assert_eq!( select1(0, 0x0000_0000_0000_0001), Some(0) ); assert_eq!( select1(0, 0x0000_0000_0000_0002), Some(1) ); assert_eq!( select1(0, 0x0000_0000_0000_0004), Some(2) ); assert_eq!( select1(2, 0x0000_0000_0000_0004), None ); assert_eq!( select1(2, 0x0000_1010_1010_0114), Some(8) ); assert_eq!( select1(3, 0x0000_1010_1010_0114), Some(20) ); assert_eq!( select1(4, 0x0000_1010_1010_0114), Some(28) );