diff --git a/kermit-algos/tests/leapfrog_triejoin.rs b/kermit-algos/tests/leapfrog_triejoin.rs index 7d5d21e..a3cb25d 100644 --- a/kermit-algos/tests/leapfrog_triejoin.rs +++ b/kermit-algos/tests/leapfrog_triejoin.rs @@ -91,10 +91,11 @@ mod tests { // vec![vec![1], vec![2], vec![3]]; // "1-ary" // )] - // fn test_inputs_outputs(arity: usize, inputs: Vec>>, + // fn test_inputs_outputs(cardinality: usize, inputs: Vec>>, // expected: Vec>) { let tries: Vec<_> = inputs // .into_iter() - // .map(|input| TrieBuilder::::new(arity).add_tuples(input).build()) + // .map(|input| + // TrieBuilder::::new(cardinality).add_tuples(input).build()) // .collect(); // let res = leapfrog_triejoin(tries.iter().collect()); // assert_eq!(res, expected); diff --git a/kermit-ds/benches/main.rs b/kermit-ds/benches/main.rs index b730fe8..e42d576 100644 --- a/kermit-ds/benches/main.rs +++ b/kermit-ds/benches/main.rs @@ -6,10 +6,12 @@ use { std::fmt, }; -fn generate_vector(arity: usize, min: T, max: T) -> Vec { +fn generate_vector( + cardinality: usize, min: T, max: T, +) -> Vec { let mut rng = rand::thread_rng(); let mut vector = Vec::::new(); - for _ in 0..arity { + for _ in 0..cardinality { vector.push(rng.gen_range(min..max)); } vector @@ -18,7 +20,7 @@ fn generate_vector(arity: usize, min: T, m fn generate_tuples(params: &BenchParams) -> Vec> { let mut vectors = Vec::>::new(); while vectors.len() < params.size { - let vector = generate_vector(params.arity, params.min, params.max); + let vector = generate_vector(params.cardinality, params.min, params.max); if !vectors.contains(&vector) { vectors.push(vector); } @@ -28,16 +30,16 @@ fn generate_tuples(params: &BenchParams struct BenchParams { size: usize, - arity: usize, + cardinality: usize, min: T, max: T, } impl BenchParams { - fn new(size: usize, arity: usize, min: T, max: T) -> BenchParams { + fn new(size: usize, cardinality: usize, min: T, max: T) -> BenchParams { BenchParams { size, - arity, + cardinality, min, max, } @@ -48,8 +50,8 @@ impl fmt::Display for Bench fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!( f, - "size: {}, arity: {}, min: {}, max: {}", - self.size, self.arity, self.min, self.max + "size: {}, cardinality: {}, min: {}, max: {}", + self.size, self.cardinality, self.min, self.max ) } } @@ -90,7 +92,10 @@ pub fn criterion_benchmark(c: &mut Criterion) { b.iter_batched( || generate_tuples(bench_param), |tuples| { - black_box(RelationTrie::from_tuples_presort(bench_param.arity, tuples)) + black_box(RelationTrie::from_tuples_presort( + bench_param.cardinality, + tuples, + )) }, BatchSize::SmallInput, ) @@ -110,7 +115,7 @@ pub fn criterion_benchmark(c: &mut Criterion) { b.iter_batched( || { RelationTrie::from_tuples_presort( - bench_param.arity, + bench_param.cardinality, generate_tuples(bench_param), ) }, diff --git a/kermit-ds/src/relation_trie/mod.rs b/kermit-ds/src/relation_trie/mod.rs index 7f9fb29..5553338 100644 --- a/kermit-ds/src/relation_trie/mod.rs +++ b/kermit-ds/src/relation_trie/mod.rs @@ -20,7 +20,7 @@ mod tests { #[test] fn trie_new() { let empty_tri = RelationTrie::::new(1); - assert_eq!(empty_tri.arity(), 1); + assert_eq!(empty_tri.cardinality(), 1); assert!(empty_tri.is_empty()); } diff --git a/kermit-ds/src/relation_trie/node.rs b/kermit-ds/src/relation_trie/node.rs index 2d0b52c..4812fc1 100644 --- a/kermit-ds/src/relation_trie/node.rs +++ b/kermit-ds/src/relation_trie/node.rs @@ -7,7 +7,7 @@ use std::{ #[derive(Clone, Debug)] pub struct Node { /// Maximum height (1-based index of key in tuple) - arity: usize, + cardinality: usize, /// Key for tuple value key: KT, /// Children @@ -28,7 +28,7 @@ impl Node { /// Construct a Node with a tuple-value key fn new(key: KT) -> Node { Node { - arity: 0, + cardinality: 0, key, children: vec![], } @@ -50,13 +50,13 @@ pub trait TrieFields { 0 } } - fn arity(&self) -> usize; + fn cardinality(&self) -> usize; } impl TrieFields for Node { fn children(&self) -> &Vec> { &self.children } - fn arity(&self) -> usize { self.arity } + fn cardinality(&self) -> usize { self.cardinality } } pub(crate) trait Internal: TrieFields { @@ -201,7 +201,7 @@ mod tests { fn node_new() { let node = Node::new(1); assert_eq!(node.key(), &1); - assert_eq!(node.arity(), 0); + assert_eq!(node.cardinality(), 0); } #[test] @@ -209,13 +209,13 @@ mod tests { let node = { let child = Node::new(2); Node { - arity: child.arity() + 1, + cardinality: child.cardinality() + 1, key: 1, children: vec![child], } }; assert_eq!(node.key(), &1); - assert_eq!(node.arity(), 1); + assert_eq!(node.cardinality(), 1); assert_eq!(node.children()[0].key(), &2); } diff --git a/kermit-ds/src/relation_trie/trie.rs b/kermit-ds/src/relation_trie/trie.rs index 7410e7c..b5b0837 100644 --- a/kermit-ds/src/relation_trie/trie.rs +++ b/kermit-ds/src/relation_trie/trie.rs @@ -6,7 +6,7 @@ use { /// Trie root #[derive(Clone, Debug)] pub struct RelationTrie { - arity: usize, + cardinality: usize, children: Vec>, } @@ -22,22 +22,22 @@ impl IndexMut for RelationTrie { impl RelationTrie { /// Construct an empty Trie - pub fn new(arity: usize) -> RelationTrie { + pub fn new(cardinality: usize) -> RelationTrie { RelationTrie { - arity, + cardinality, children: vec![], } } - pub fn from_tuples(arity: usize, tuples: Vec>) -> RelationTrie { - let mut trie = RelationTrie::new(arity); + pub fn from_tuples(cardinality: usize, tuples: Vec>) -> RelationTrie { + let mut trie = RelationTrie::new(cardinality); for tuple in tuples { trie.insert(tuple).unwrap(); } trie } - pub fn from_tuples_presort(arity: usize, mut tuples: Vec>) -> RelationTrie { + pub fn from_tuples_presort(cardinality: usize, mut tuples: Vec>) -> RelationTrie { tuples.sort_unstable_by(|a, b| { for i in 0..a.len() { if a[i] < b[i] { @@ -48,7 +48,7 @@ impl RelationTrie { } std::cmp::Ordering::Equal }); - let mut trie = RelationTrie::new(arity); + let mut trie = RelationTrie::new(cardinality); for tuple in tuples { trie.insert(tuple).unwrap(); } @@ -56,7 +56,7 @@ impl RelationTrie { } pub fn insert(&mut self, tuple: Vec) -> Result<(), &'static str> { - if tuple.len() != self.arity { + if tuple.len() != self.cardinality { return Err("Arity doesn't match."); } self.insert_linear(tuple); @@ -64,14 +64,14 @@ impl RelationTrie { } pub fn search(&self, tuple: Vec) -> Result>, &'static str> { - if tuple.len() != self.arity { + if tuple.len() != self.cardinality { return Err("Arity doesn't match."); } Ok(self.search_linear(tuple)) } pub fn remove(&mut self, tuple: Vec) -> Result<(), &'static str> { - if tuple.len() != self.arity { + if tuple.len() != self.cardinality { return Err("Arity doesn't match."); } self.remove_deque(tuple.into()); @@ -82,7 +82,7 @@ impl RelationTrie { impl TrieFields for RelationTrie { fn children(&self) -> &Vec> { &self.children } - fn arity(&self) -> usize { self.arity } + fn cardinality(&self) -> usize { self.cardinality } } impl Internal for RelationTrie { diff --git a/kermit-ds/src/relation_trie/trie_builder.rs b/kermit-ds/src/relation_trie/trie_builder.rs index b972dca..621752a 100644 --- a/kermit-ds/src/relation_trie/trie_builder.rs +++ b/kermit-ds/src/relation_trie/trie_builder.rs @@ -5,20 +5,20 @@ use { }; pub struct TrieBuilder { - arity: usize, + cardinality: usize, tuples: Vec>, } impl TrieBuilder { - pub fn new(arity: usize) -> TrieBuilder { + pub fn new(cardinality: usize) -> TrieBuilder { TrieBuilder { - arity, + cardinality, tuples: vec![], } } pub fn build(self) -> RelationTrie { - RelationTrie::from_tuples_presort(self.arity, self.tuples) + RelationTrie::from_tuples_presort(self.cardinality, self.tuples) } pub fn add_tuple(mut self, tuple: Vec) -> TrieBuilder {