MCPcopy Create free account
hub / github.com/apache/datafusion / longest_consecutive_prefix

Function longest_consecutive_prefix

datafusion/common/src/utils/mod.rs:385–396  ·  view source on GitHub ↗

This function finds the longest prefix of the form 0, 1, 2, ... within the collection `sequence`. Examples: - For 0, 1, 2, 4, 5; we would produce 3, meaning 0, 1, 2 is the longest satisfying prefix. - For 1, 2, 3, 4; we would produce 0, meaning there is no such prefix.

(
    sequence: impl IntoIterator<Item = T>,
)

Source from the content-addressed store, hash-verified

383/// prefix.
384/// - For 1, 2, 3, 4; we would produce 0, meaning there is no such prefix.
385pub fn longest_consecutive_prefix<T: Borrow<usize>>(
386 sequence: impl IntoIterator<Item = T>,
387) -> usize {
388 let mut count = 0;
389 for item in sequence {
390 if !count.eq(item.borrow()) {
391 break;
392 }
393 count += 1;
394 }
395 count
396}
397
398/// Creates single element [`ListArray`], [`LargeListArray`] and
399/// [`FixedSizeListArray`] from other arrays

Callers

nothing calls this directly

Calls 1

eqMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…