pub trait BitScan {
fn index_of_next_false_bit(self, start: u64) -> Option<u64>;
fn index_of_next_true_bit(self, start: u64) -> Option<u64>;
}
Expand description
Defines functions that search for the next true
or false
bit in a number, starting at a
specified index and searching in the more-significant direction.
Required Methods
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of a
false
bit that is greater than or equal to the starting index.
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of a true
bit that is greater than or equal to the starting index.
Implementations on Foreign Types
sourceimpl BitScan for u8
impl BitScan for u8
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
Since the number is unsigned and therefore has an implicit prefix of infinitely-many zeros, this function always returns a value.
Starting beyond the type’s width is allowed; the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, the result is
None
since there are no true
bits past that point.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for u16
impl BitScan for u16
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
Since the number is unsigned and therefore has an implicit prefix of infinitely-many zeros, this function always returns a value.
Starting beyond the type’s width is allowed; the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, the result is
None
since there are no true
bits past that point.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for u32
impl BitScan for u32
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
Since the number is unsigned and therefore has an implicit prefix of infinitely-many zeros, this function always returns a value.
Starting beyond the type’s width is allowed; the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, the result is
None
since there are no true
bits past that point.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for u64
impl BitScan for u64
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
Since the number is unsigned and therefore has an implicit prefix of infinitely-many zeros, this function always returns a value.
Starting beyond the type’s width is allowed; the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, the result is
None
since there are no true
bits past that point.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for u128
impl BitScan for u128
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
Since the number is unsigned and therefore has an implicit prefix of infinitely-many zeros, this function always returns a value.
Starting beyond the type’s width is allowed; the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, the result is
None
since there are no true
bits past that point.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for usize
impl BitScan for usize
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
Since the number is unsigned and therefore has an implicit prefix of infinitely-many zeros, this function always returns a value.
Starting beyond the type’s width is allowed; the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, the result is
None
since there are no true
bits past that point.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for i8
impl BitScan for i8
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is negative. If it is, then the result is None
since there are no false
bits past that point. If the number is non-negative,
then the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is non-negative. If it is, then the result is None
since there are no true
bits past that point. If the number is negative, then the
result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for i16
impl BitScan for i16
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is negative. If it is, then the result is None
since there are no false
bits past that point. If the number is non-negative,
then the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is non-negative. If it is, then the result is None
since there are no true
bits past that point. If the number is negative, then the
result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for i32
impl BitScan for i32
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is negative. If it is, then the result is None
since there are no false
bits past that point. If the number is non-negative,
then the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is non-negative. If it is, then the result is None
since there are no true
bits past that point. If the number is negative, then the
result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for i64
impl BitScan for i64
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is negative. If it is, then the result is None
since there are no false
bits past that point. If the number is non-negative,
then the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is non-negative. If it is, then the result is None
since there are no true
bits past that point. If the number is negative, then the
result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for i128
impl BitScan for i128
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is negative. If it is, then the result is None
since there are no false
bits past that point. If the number is non-negative,
then the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is non-negative. If it is, then the result is None
since there are no true
bits past that point. If the number is negative, then the
result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourceimpl BitScan for isize
impl BitScan for isize
sourcefn index_of_next_false_bit(self, start: u64) -> Option<u64>
fn index_of_next_false_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a false
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is negative. If it is, then the result is None
since there are no false
bits past that point. If the number is non-negative,
then the result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.
sourcefn index_of_next_true_bit(self, start: u64) -> Option<u64>
fn index_of_next_true_bit(self, start: u64) -> Option<u64>
Given a number and a starting index, searches the number for the smallest index of
a true
bit that is greater than or equal to the starting index.
If the starting index is greater than or equal to the type’s width, then the result
depends on whether the number is non-negative. If it is, then the result is None
since there are no true
bits past that point. If the number is negative, then the
result is the starting index.
Worst-case complexity
Constant time and additional memory.
Examples
See here.