Skip to content

Instantly share code, notes, and snippets.

@jamii
Created June 5, 2015 04:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jamii/ae46e8e0c9757330e9ea to your computer and use it in GitHub Desktop.
Save jamii/ae46e8e0c9757330e9ea to your computer and use it in GitHub Desktop.
fn join_step<'a>(join: &'a Join, ix: usize, inputs: &[&'a Relation], state: &mut Vec<&'a Value>, index: &mut BTreeSet<Vec<Value>>) {
if ix == join.sources.len() {
index.insert(join.select.select(&state[..]));
} else {
match join.sources[ix] {
JoinSource::Relation{input} => {
for values in inputs[input].index.iter() {
push_all(state, values);
if join.constraints[ix].iter().all(|constraint| constraint.is_satisfied_by(&state[..])) {
join_step(join, ix+1, inputs, state, index)
}
pop_all(state, values);
}
}
JoinSource::Primitive{ref primitive, ref arguments, ..} => {
for values in primitive.eval_from_join(&arguments[..], &state[..]).into_iter() {
// promise the borrow checker that we will pop values before we exit this scope
let values = unsafe { ::std::mem::transmute::<&Vec<Value>, &'a Vec<Value>>(&values) };
push_all(state, values);
if join.constraints[ix].iter().all(|constraint| constraint.is_satisfied_by(&state[..])) {
join_step(join, ix+1, inputs, state, index)
}
pop_all(state, values);
}
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment