Undo previous change and remove Sets implementation.
This commit is contained in:
parent
500ec63051
commit
805874a4c1
2 changed files with 7 additions and 58 deletions
|
|
@ -1,6 +1,5 @@
|
||||||
pub mod gc;
|
pub mod gc;
|
||||||
pub mod map;
|
pub mod map;
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod tests {
|
mod tests {
|
||||||
#[test]
|
#[test]
|
||||||
|
|
|
||||||
64
src/map.rs
64
src/map.rs
|
|
@ -33,6 +33,12 @@ pub trait Equivalent<T>: Sized {
|
||||||
fn matches(&self, other: &T) -> bool;
|
fn matches(&self, other: &T) -> bool;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl<T: PartialEq> Equivalent<T> for T {
|
||||||
|
fn matches(&self, other: &T) -> bool {
|
||||||
|
self == other
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub trait Hashes {
|
pub trait Hashes {
|
||||||
fn hashed(&self) -> Hashed;
|
fn hashed(&self) -> Hashed;
|
||||||
}
|
}
|
||||||
|
|
@ -341,60 +347,4 @@ impl<K: Debug + Hashes + PartialEq, V: Debug> Debug for Map<K, V> {
|
||||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||||
f.write_fmt(format_args!("Map")) // todo: debug and print the entire thing?
|
f.write_fmt(format_args!("Map")) // todo: debug and print the entire thing?
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(PartialEq)]
|
|
||||||
pub struct SetEntry<E: Hashes + PartialEq>(Option<E>);
|
|
||||||
|
|
||||||
pub struct Set<E: Hashes + PartialEq>(DisplacementSet<SetEntry<E>>);
|
|
||||||
|
|
||||||
impl<E: Hashes + PartialEq> Hashes for SetEntry<E> {
|
|
||||||
fn hashed(&self) -> Hashed {
|
|
||||||
todo!()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E: Hashes + PartialEq> TableEntry for SetEntry<E> {
|
|
||||||
const VACANT: Self = SetEntry(None);
|
|
||||||
fn is_vacant(&self) -> bool {
|
|
||||||
self.0.is_none()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E: Hashes + PartialEq> Equivalent<E> for SetEntry<E> {
|
|
||||||
fn matches(&self, other: &E) -> bool {
|
|
||||||
self.0.as_ref().unwrap() == other
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<K, E: PartialEq + Hashes> Equivalent<K> for SetEntry<E> where K: Equivalent<E> {
|
|
||||||
fn matches(&self, other: &K) -> bool {
|
|
||||||
other.matches(&self.0.as_ref().unwrap())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
impl<E: Hashes + PartialEq> Set<E> {
|
|
||||||
pub fn resize(&mut self, len: usize) {
|
|
||||||
self.0.resize(len)
|
|
||||||
}
|
|
||||||
pub fn set(&mut self, element: E) {
|
|
||||||
self.0.set(SetEntry(Some(element)));
|
|
||||||
}
|
|
||||||
pub fn remove(&mut self, element: E) {
|
|
||||||
self.0.remove(element);
|
|
||||||
}
|
|
||||||
pub fn get<K>(&mut self, element: K) -> Option<&E>
|
|
||||||
where
|
|
||||||
E: Equivalent<K>,
|
|
||||||
K: Hashes,
|
|
||||||
{
|
|
||||||
if let Some(ref entry) = self.0.get(element) {
|
|
||||||
Some(&entry.0.as_ref().unwrap())
|
|
||||||
} else {
|
|
||||||
None
|
|
||||||
}
|
|
||||||
}
|
|
||||||
pub fn new() -> Set<E> {
|
|
||||||
Set(DisplacementSet::new())
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue