Intersects two sequences (inner join) using their elements corresponding byte-slice views. The caller must provide a closure that maps an index to the byte slice representation of the corresponding element in the first and second sequences. # Example ```rust use stringzilla::stringzilla as sz; #[derive(Debug)] struct Person { name: &'static str, age: u32 } let people1 = [ Person { name: "Charl
(
mapper1: F,
mapper2: G,
seed: u64,
positions1: &mut [SortedIdx],
positions2: &mut [SortedIdx],
)
| 2337 | /// assert!(n == 3); // "Alice", "Bob", and "Charlie" are common. |
| 2338 | /// ``` |
| 2339 | pub fn intersection_by<F, G, A, B>( |
| 2340 | mapper1: F, |
| 2341 | mapper2: G, |
| 2342 | seed: u64, |
| 2343 | positions1: &mut [SortedIdx], |
| 2344 | positions2: &mut [SortedIdx], |
| 2345 | ) -> Result<usize, Status> |
| 2346 | where |
| 2347 | F: Fn(usize) -> A, |
| 2348 | A: AsRef<[u8]>, |
| 2349 | G: Fn(usize) -> B, |
| 2350 | B: AsRef<[u8]>, |
| 2351 | { |
| 2352 | if positions1.len() != positions2.len() { |
| 2353 | return Err(Status::BadAlloc); |
| 2354 | } |
| 2355 | |
| 2356 | // Adapter closure: given an index, call the provided mapper and then transmute the |
| 2357 | // resulting slice to have a `'static` lifetime. This transmute is safe as long as |
| 2358 | // the FFI call is synchronous and the returned slices are only used during the call. |
| 2359 | let adapter1 = move |i: usize| -> &'static [u8] { |
| 2360 | let binding = mapper1(i); |
| 2361 | let slice = binding.as_ref(); |
| 2362 | unsafe { core::mem::transmute(slice) } |
| 2363 | }; |
| 2364 | let adapter2 = move |i: usize| -> &'static [u8] { |
| 2365 | let binding = mapper2(i); |
| 2366 | let slice = binding.as_ref(); |
| 2367 | unsafe { core::mem::transmute(slice) } |
| 2368 | }; |
| 2369 | |
| 2370 | _intersection_by_impl( |
| 2371 | adapter1, |
| 2372 | adapter2, |
| 2373 | seed, |
| 2374 | positions1, |
| 2375 | positions2, |
| 2376 | positions1.len(), |
| 2377 | positions2.len(), |
| 2378 | ) |
| 2379 | } |
| 2380 | |
| 2381 | fn _intersection_by_impl<FAdapter, GAdapter>( |
| 2382 | adapter1: FAdapter, |
searching dependent graphs…