mark structures with their fixity
This commit is contained in:
@@ -1,19 +1,27 @@
|
||||
use std::cell::RefCell;
|
||||
use std::collections::HashSet;
|
||||
use std::hash::Hash;
|
||||
use std::ops::Deref;
|
||||
use std::fmt;
|
||||
use std::hash::{Hash, Hasher};
|
||||
use std::ops::{Deref, DerefMut};
|
||||
use std::rc::Rc;
|
||||
|
||||
pub type TabledData<T> = HashSet<Rc<T>>;
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, PartialEq, Eq)]
|
||||
pub struct TabledRc<T: Hash + Eq> {
|
||||
atom: Rc<T>,
|
||||
table: Rc<RefCell<TabledData<T>>>
|
||||
}
|
||||
|
||||
impl<T: Hash + Eq> Hash for TabledRc<T> {
|
||||
fn hash<H: Hasher>(&self, state: &mut H)
|
||||
{
|
||||
self.atom.hash(state)
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Hash + Eq> TabledRc<T> {
|
||||
pub fn new(atom: T, table: Rc<RefCell<TabledData<T>>>) -> Self {
|
||||
pub fn new(atom: T, table: Rc<RefCell<TabledData<T>>>) -> Self {
|
||||
TabledRc { atom: Rc::new(atom), table }
|
||||
}
|
||||
}
|
||||
@@ -21,8 +29,8 @@ impl<T: Hash + Eq> TabledRc<T> {
|
||||
impl<T: Hash + Eq> Drop for TabledRc<T> {
|
||||
fn drop(&mut self) {
|
||||
if Rc::strong_count(&self.atom) == 2 {
|
||||
let table = *self.table.borrow_mut();
|
||||
table.remove(&self.atom);
|
||||
let mut table = self.table.borrow_mut();
|
||||
table.deref_mut().remove(&self.atom);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -34,3 +42,9 @@ impl<T: Hash + Eq> Deref for TabledRc<T> {
|
||||
&*self.atom
|
||||
}
|
||||
}
|
||||
|
||||
impl<T: Hash + Eq + fmt::Display> fmt::Display for TabledRc<T> {
|
||||
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
|
||||
write!(f, "{}", &*self.atom)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user