MCPcopy Create free account
hub / github.com/comnik/declarative-dataflow / tuples_by_variables

Method tuples_by_variables

src/lib.rs:579–632  ·  view source on GitHub ↗
(
        self,
        _nested: &mut Iterative<'a, G, u64>,
        _context: &mut I,
        variables: &[Var],
    )

Source from the content-addressed store, hash-verified

577 }
578
579 fn tuples_by_variables(
580 self,
581 _nested: &mut Iterative<'a, G, u64>,
582 _context: &mut I,
583 variables: &[Var],
584 ) -> (
585 Collection<Iterative<'a, G, u64>, (Vec<Value>, Vec<Value>), isize>,
586 ShutdownHandle,
587 ) {
588 if variables == &self.variables()[..] {
589 (
590 self.tuples.map(|x| (x, Vec::new())),
591 ShutdownHandle::empty(),
592 )
593 } else if variables.is_empty() {
594 (
595 self.tuples.map(|x| (Vec::new(), x)),
596 ShutdownHandle::empty(),
597 )
598 } else {
599 let key_length = variables.len();
600 let values_length = self.variables().len() - key_length;
601
602 let mut key_offsets: Vec<usize> = Vec::with_capacity(key_length);
603 let mut value_offsets: Vec<usize> = Vec::with_capacity(values_length);
604 let variable_set: HashSet<Var> = variables.iter().cloned().collect();
605
606 // It is important to preserve the key variables in the order
607 // they were specified.
608 for variable in variables.iter() {
609 key_offsets.push(self.binds(*variable).unwrap());
610 }
611
612 // Values we'll just take in the order they were.
613 for (idx, variable) in self.variables().iter().enumerate() {
614 if !variable_set.contains(variable) {
615 value_offsets.push(idx);
616 }
617 }
618
619 let arranged = self.tuples.map(move |tuple| {
620 let key: Vec<Value> = key_offsets.iter().map(|i| tuple[*i].clone()).collect();
621 // @TODO second clone not really neccessary
622 let values: Vec<Value> = value_offsets
623 .iter()
624 .map(move |i| tuple[*i].clone())
625 .collect();
626
627 (key, values)
628 });
629
630 (arranged, ShutdownHandle::empty())
631 }
632 }
633}
634
635impl<'a, G, I> Relation<'a, G, I> for AttributeBinding

Callers 4

implementMethod · 0.80
implementMethod · 0.80
implementMethod · 0.80
collection_collectionFunction · 0.80

Calls 3

forward_proposeMethod · 0.80
variablesMethod · 0.45
bindsMethod · 0.45

Tested by

no test coverage detected