MCPcopy Create free account
hub / github.com/apache/arrow-rs / find_nth_set_bit_position

Method find_nth_set_bit_position

arrow-buffer/src/buffer/boolean.rs:445–455  ·  view source on GitHub ↗

Finds the position of the n-th set bit (1-based) starting from `start` index. If fewer than `n` set bits are found, returns the length of the buffer.

(&self, start: usize, n: usize)

Source from the content-addressed store, hash-verified

443 /// Finds the position of the n-th set bit (1-based) starting from `start` index.
444 /// If fewer than `n` set bits are found, returns the length of the buffer.
445 pub fn find_nth_set_bit_position(&self, start: usize, n: usize) -> usize {
446 if n == 0 {
447 return start;
448 }
449
450 self.slice(start, self.bit_len - start)
451 .set_indices()
452 .nth(n - 1)
453 .map(|idx| start + idx + 1)
454 .unwrap_or(self.bit_len)
455 }
456
457 /// Returns a [`BitChunks`] instance which can be used to iterate over
458 /// this buffer's bits in `u64` chunks

Callers

nothing calls this directly

Calls 3

set_indicesMethod · 0.80
nthMethod · 0.45
sliceMethod · 0.45

Tested by

no test coverage detected