MCPcopy Create free account
hub / github.com/ashvardanian/StringZilla / intersection

Function intersection

rust/stringzilla.rs:2274–2304  ·  view source on GitHub ↗

Intersects two sequences (inner join) using their default byte-slice views. Both sequences must have an output buffer provided (for first and second positions) whose length is at least the minimum of the two input lengths. # Example ```rust use stringzilla::stringzilla as sz; let set1 = ["banana", "apple", "cherry"]; let set2 = ["cherry", "orange", "pineapple", "banana"]; let mut positions1 =

(
    data1: &[T],
    data2: &[T],
    seed: u64,
    positions1: &mut [SortedIdx],
    positions2: &mut [SortedIdx],
)

Source from the content-addressed store, hash-verified

2272/// assert!(n == 2); // "banana" and "cherry" are common.
2273/// ```
2274pub fn intersection<T: AsRef<[u8]>>(
2275 data1: &[T],
2276 data2: &[T],
2277 seed: u64,
2278 positions1: &mut [SortedIdx],
2279 positions2: &mut [SortedIdx],
2280) -> Result<usize, Status> {
2281 let min_count = data1.len().min(data2.len());
2282 if positions1.len() < min_count || positions2.len() < min_count {
2283 return Err(Status::BadAlloc);
2284 }
2285
2286 // Call the lower-level implementation with accurate counts for both sequences.
2287 let adapter1 = move |i: usize| -> &'static [u8] {
2288 // SAFETY: used only during the FFI call
2289 unsafe { core::mem::transmute::<&[u8], &'static [u8]>(data1[i].as_ref()) }
2290 };
2291 let adapter2 = move |j: usize| -> &'static [u8] {
2292 // SAFETY: used only during the FFI call
2293 unsafe { core::mem::transmute::<&[u8], &'static [u8]>(data2[j].as_ref()) }
2294 };
2295 _intersection_by_impl(
2296 adapter1,
2297 adapter2,
2298 seed,
2299 positions1,
2300 positions2,
2301 data1.len(),
2302 data2.len(),
2303 )
2304}
2305
2306/// Intersects two sequences (inner join) using their elements corresponding byte-slice views.
2307/// The caller must provide a closure that maps an index to the byte slice representation of

Callers 2

intersection_defaultFunction · 0.85
intersection_debugFunction · 0.85

Calls 2

_intersection_by_implFunction · 0.85
lenMethod · 0.80

Tested by 2

intersection_defaultFunction · 0.68
intersection_debugFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…