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

Function interleave

src/plan/pull.rs:50–76  ·  view source on GitHub ↗
(values: &[Value], constants: &[Aid])

Source from the content-addressed store, hash-verified

48}
49
50fn interleave(values: &[Value], constants: &[Aid]) -> Vec<Value> {
51 if values.is_empty() || constants.is_empty() {
52 values.to_owned()
53 } else {
54 let size: usize = values.len() + constants.len();
55 // + 2, because we know there'll be a and v coming...
56 let mut result: Vec<Value> = Vec::with_capacity(size + 2);
57
58 let mut next_value = 0;
59 let mut next_const = 0;
60
61 for i in 0..size {
62 if i % 2 == 0 {
63 // on even indices we take from the result tuple
64 result.push(values[next_value].clone());
65 next_value += 1;
66 } else {
67 // on odd indices we interleave an attribute
68 let a = constants[next_const].clone();
69 result.push(Value::Aid(a));
70 next_const += 1;
71 }
72 }
73
74 result
75 }
76}
77
78impl<P: Implementable> Implementable for PullLevel<P> {
79 fn dependencies(&self) -> Dependencies {

Callers 1

implementMethod · 0.70

Calls

no outgoing calls

Tested by

no test coverage detected