diff --git a/src/cell_space.rs b/src/cell_space.rs index e0af6a2..b3babc5 100644 --- a/src/cell_space.rs +++ b/src/cell_space.rs @@ -1,4 +1,6 @@ +use std::collections::HashSet; use std::fmt::Debug; +use std::hash::Hash; use std::marker; use std::ops::Index; @@ -16,7 +18,7 @@ struct CellDictionary { impl CellDictionary where - V: Clone + Ord + Debug, + V: Clone + Ord + Debug + Hash, K: Debug + Index, { pub fn new(table: &T, dimension: usize, cell_bits: usize) -> Self @@ -25,16 +27,15 @@ where R: Record + Debug, { // 1. Retrieve a list of distinct values for the coordinate `dimension` - let mut distinct = vec![]; - let records = table.get_table(); + let mut distinct: HashSet = table + .get_table() + .iter() + .map(|&record| record.key()[dimension].clone()) + .collect(); - for record in records { - distinct.push(record.key()[dimension].clone()); - } - - // 2. Build sorted, distinct lists + // 2. Build a sorted list, of distinct elements + let mut distinct = distinct.drain().collect::>(); distinct.sort_unstable(); - distinct.dedup(); info!( "Number of distinct coordinates on dim[{}]: {}", @@ -190,7 +191,7 @@ pub struct CellSpace { impl CellSpace where - V: Clone + Ord + Debug, + V: Clone + Ord + Debug + Hash, K: Debug + Index, { pub fn new(table: &T, dimensions: usize, cell_bits: usize) -> Self diff --git a/src/sfc.rs b/src/sfc.rs index c20a972..5e6cb75 100644 --- a/src/sfc.rs +++ b/src/sfc.rs @@ -1,4 +1,5 @@ use std::fmt::Debug; +use std::hash::Hash; use std::io; use std::iter::FromIterator; use std::marker; @@ -71,7 +72,7 @@ impl SpaceFillingCurve where T: Table, R: Record + RecordFields + RecordBuild + Debug, - V: Clone + Ord + Debug + From, + V: Clone + Debug + From + Hash + Ord, K: Debug + Index + FromIterator, { //FIXME: Should accept indexing 0 elements, at least not crash! @@ -239,7 +240,7 @@ where T: Table, R: Record + RecordFields + RecordBuild + Debug, K: Debug + Index + FromIterator, - V: Clone + Debug + Ord + From + Debug, + V: Clone + Debug + From + Hash + Ord, { fn find(&self, key: &K) -> Vec { let mut values = vec![];