major refactor.

This commit is contained in:
Mark Thom
2018-02-25 12:13:07 -07:00
parent 05c1275acf
commit cf9db43d5b
20 changed files with 735 additions and 813 deletions

View File

@@ -1,4 +1,5 @@
use std::cell::RefCell;
use std::cmp::Ordering;
use std::collections::HashSet;
use std::fmt;
use std::hash::{Hash, Hasher};
@@ -6,13 +7,27 @@ use std::ops::Deref;
use std::rc::Rc;
pub type TabledData<T> = Rc<RefCell<HashSet<Rc<T>>>>;
#[derive(Clone)]
pub struct TabledRc<T: Hash + Eq> {
atom: Rc<T>,
table: TabledData<T>
}
impl<T: Ord + Hash + Eq> PartialOrd for TabledRc<T> {
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
{
Some(self.atom.cmp(&other.atom))
}
}
impl<T: Ord + Hash + Eq> Ord for TabledRc<T> {
fn cmp(&self, other: &Self) -> Ordering
{
self.atom.cmp(&other.atom)
}
}
impl<T: Hash + Eq> PartialEq for TabledRc<T> {
fn eq(&self, other: &TabledRc<T>) -> bool
{
@@ -23,9 +38,8 @@ impl<T: Hash + Eq> PartialEq for TabledRc<T> {
impl<T: Hash + Eq> Eq for TabledRc<T> {}
impl<T: Hash + Eq> Hash for TabledRc<T> {
fn hash<H: Hasher>(&self, state: &mut H)
{
self.atom.hash(state)
fn hash<H: Hasher>(&self, state: &mut H) {
self.atom.hash(state)
}
}
@@ -40,10 +54,6 @@ impl<T: Hash + Eq> TabledRc<T> {
TabledRc { atom, table }
}
pub fn table(&self) -> TabledData<T> {
self.table.clone()
}
}
impl<T: Hash + Eq> Drop for TabledRc<T> {