fn cartesian_product(relations: Vec<Relation>) -> Relation {
    relations.iter().fold(Relation(vec![], vec!()), |acc, relation| {
        let Relation(old_vars, old_vals) = acc;
        let Relation(new_vars, new_vals) = relation;

        let mut next_vars = vec![];
        next_vars.extend(old_vars);
        next_vars.extend(new_vars.clone());

        let mut next_vals = vec![];
        for old_val in old_vals {
            for new_val in new_vals {
                let mut tuple = old_val.clone();
                tuple.extend(new_val.clone());
                next_vals.push(tuple);
            }
        }

        Relation(next_vars, next_vals)
    })
}
/// Implements the cartesian product of relations, none of which
/// should share fields (otherwise they should be joined).
/// Horribly inefficient implementation!
Implements the cartesian product of relations, none of which
should share fields (otherwise they should be joined).
Horribly inefficient implementation!
Implements the cartesian product of relations none of which should share fields ( otherwise they should be joined ) . Horribly inefficient implementation!
fn cartesian_product(relations: Vec<Relation>) -> Relation {
    relations.iter().fold(Relation(vec![], vec!()), |acc, relation| {
        let Relation(old_vars, old_vals) = acc;
        let Relation(new_vars, new_vals) = relation;
        let mut next_vars = vec![];
        next_vars.extend(old_vars);
        next_vars.extend(new_vars.clone());
        let mut next_vals = vec![];
        for old_val in old_vals {
            for new_val in new_vals {
                let mut tuple = old_val.clone();
                tuple.extend(new_val.clone());
                next_vals.push(tuple);
            }
        }
        Relation(next_vars, next_vals)
    })
}
fn cartesian_product ( relations : Vec < Relation > ) -> Relation { relations . iter ( ) . fold ( Relation ( vec ! [ ] , vec ! ( ) ) , | acc , relation | { let Relation ( old_vars , old_vals ) = acc ; let Relation ( new_vars , new_vals ) = relation ; let mut next_vars = vec ! [ ] ; next_vars . extend ( old_vars ) ; next_vars . extend ( new_vars . clone ( ) ) ; let mut next_vals = vec ! [ ] ; for old_val in old_vals { for new_val in new_vals { let mut tuple = old_val . clone ( ) ; tuple . extend ( new_val . clone ( ) ) ; next_vals . push ( tuple ) ; } } Relation ( next_vars , next_vals ) } ) }
Implements the cartesian product of relations, none of which
should share fields (otherwise they should be joined).
Implements the cartesian product of relations none of which should share fields ( otherwise they should be joined ) .
relations
Vec<Relation>
relations
Vec<Relation>