Repairing previous unusual commit.
This commit is contained in:
parent
d45e9bd270
commit
6b521cb59f
1 changed files with 28 additions and 12 deletions
32
src/map.rs
32
src/map.rs
|
|
@ -263,13 +263,35 @@ impl<E: TableEntry> DisplacementSet<E> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
pub fn get<K>(&mut self, index: K) -> Option<&E>
|
||||||
pub fn new() -> DisplacementSet<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 {
|
DisplacementSet {
|
||||||
map: Vec::new(),
|
map: Vec::new(),
|
||||||
map_count: 0,
|
map_count: 0,
|
||||||
map_bounds: (0..0).into(),
|
map_bounds: (0..0).into(),
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone)]
|
#[derive(Clone)]
|
||||||
|
|
@ -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> {
|
impl<E: Hashes + PartialEq> Set<E> {
|
||||||
pub fn resize(&mut self, len: usize) {
|
pub fn resize(&mut self, len: usize) {
|
||||||
self.0.resize(len)
|
self.0.resize(len)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue