Repairing previous unusual commit.
This commit is contained in:
parent
d45e9bd270
commit
6b521cb59f
1 changed files with 28 additions and 12 deletions
40
src/map.rs
40
src/map.rs
|
|
@ -263,12 +263,34 @@ impl<E: TableEntry> DisplacementSet<E> {
|
|||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
pub fn new() -> DisplacementSet<E> {
|
||||
DisplacementSet {
|
||||
map: Vec::new(),
|
||||
map_count: 0,
|
||||
map_bounds: (0..0).into(),
|
||||
pub fn get<K>(&mut self, index: K) -> Option<&E>
|
||||
where
|
||||
E: Equivalent<K>,
|
||||
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<E> {
|
||||
DisplacementSet {
|
||||
map: Vec::new(),
|
||||
map_count: 0,
|
||||
map_bounds: (0..0).into(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -354,12 +376,6 @@ impl<E: Hashes + PartialEq> Equivalent<E> for SetEntry<E> {
|
|||
}
|
||||
}
|
||||
|
||||
impl<K, E: Hashes + PartialEq + Equivalent<K>> Equivalent<K> for SetEntry<E> {
|
||||
fn matches(&self, other: &K) -> bool {
|
||||
self.0.unwrap().matches(other)
|
||||
}
|
||||
}
|
||||
|
||||
impl<E: Hashes + PartialEq> Set<E> {
|
||||
pub fn resize(&mut self, len: usize) {
|
||||
self.0.resize(len)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue