diff --git a/src/map.rs b/src/map.rs index 8fb5bfc..04751a6 100644 --- a/src/map.rs +++ b/src/map.rs @@ -263,12 +263,34 @@ impl DisplacementSet { } } } -} -pub fn new() -> DisplacementSet { - DisplacementSet { - map: Vec::new(), - map_count: 0, - map_bounds: (0..0).into(), + pub fn get(&mut self, index: K) -> Option<&E> + where + E: Equivalent, + K: Hashes, + { + if self.map.len() == 0 { + return None; + } + let location = index.hashed() as usize % self.map.len(); + let home = &self.map[location]; + if home.entry.matches(&index) { + Some(&home.entry) + } else { + for i in 1..home.displacement as usize { + let neighbour = &self.map[(location + i) % self.map.len()]; + if neighbour.entry.matches(&index) { + return Some(&neighbour.entry); + } + } + None + } + } + pub fn new() -> DisplacementSet { + DisplacementSet { + map: Vec::new(), + map_count: 0, + map_bounds: (0..0).into(), + } } } @@ -354,12 +376,6 @@ impl Equivalent for SetEntry { } } -impl> Equivalent for SetEntry { - fn matches(&self, other: &K) -> bool { - self.0.unwrap().matches(other) - } -} - impl Set { pub fn resize(&mut self, len: usize) { self.0.resize(len)