Crate lib [−] [src]

Joins

Sequences sorted by a common key can be joined (like a table inner join) into an iterator or via an internal iteration.

Iterator

This module extends the IntoIterator trait with a join method via the Joinable trait, taking another IntoIterator along with two key extracting closures and produces a new iterator, the output of which will be a joined row for each next().

use join_it::Joinable;

let v = vec![(0,'a'),(2,'c')];
let w = vec![33,44,55,66];
let i = v.iter();
let j = w.iter().enumerate();

for (&(k0,a),(k1,b)) in i.join(j, |&(k,_)| k, |(k,_)| k) {
    assert_eq!(k0, k1);
    println!("Join result: ({},{})", a, *b);
}Run

Inner iteration

You're also provided with a function that runs an inner iteration. join_it takes two IntoIterators, their key extractor closures and finally a body closure to handle the joined rows.

The algorithm

Given two sequences with the values sorted by a unique key, you're able to make a join between keys with O(n) complexity. The keys of the current iterator values are compared. It's a match whenever the two keys are equal, whereby a tuple of the two values are returned as a result of a joined row. If the keys don't match, the lesser key's iterator will increment until they do or until one of the iterators returns None.

Structs

JoinIt

Traits

Joinable

Functions

join_it

Maps f over the join between i and j, based on the key extractors ki and kj.