Skip to content

Commit

Permalink
Clean up backing_store
Browse files Browse the repository at this point in the history
Moves over some changes in #124 to keep things clean!

- removes duplicate `UniqueTable`
- reverts `backing_store::UniqueTable` to only have `get_or_insert` as part of its interface; move the other methods to just `BackedRobinhoodTable`
- tidies up trait bounds (`Eq` implies `PartialEq`, `Debug` is no longer needed)
- removes unneeded size check in `get_by_hash`
  • Loading branch information
mattxwang authored Jul 10, 2023
1 parent 003069e commit 8a9f56a
Show file tree
Hide file tree
Showing 5 changed files with 15 additions and 31 deletions.
26 changes: 13 additions & 13 deletions src/backing_store/bump_table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,16 +158,23 @@ where
}
}

impl<'a, T: Eq + PartialEq + Hash + Clone + std::fmt::Debug> UniqueTable<'a, T>
for BackedRobinhoodTable<'a, T>
{
impl<'a, T: Eq + Hash + Clone> UniqueTable<'a, T> for BackedRobinhoodTable<'a, T> {
fn get_or_insert(&'a mut self, elem: T) -> &'a T {
let mut hasher = FxHasher::default();
elem.hash(&mut hasher);
let hash = hasher.finish();
self.get_or_insert_by_hash(hash, elem, false)
}
fn get_or_insert_by_hash(&'a mut self, hash: u64, elem: T, equality_by_hash: bool) -> &'a T {
}

impl<'a, T: Eq + Hash + Clone> BackedRobinhoodTable<'a, T> {
/// use a hash to both allocate space in table, *and* form equalitySS
pub fn get_or_insert_by_hash(
&'a mut self,
hash: u64,
elem: T,
equality_by_hash: bool,
) -> &'a T {
if (self.len + 1) as f64 > (self.cap as f64 * LOAD_FACTOR) {
self.grow();
}
Expand Down Expand Up @@ -215,11 +222,7 @@ impl<'a, T: Eq + PartialEq + Hash + Clone + std::fmt::Debug> UniqueTable<'a, T>
}
}

fn get_by_hash(&'a mut self, hash: u64) -> Option<&'a T> {
if (self.len + 1) as f64 > (self.cap as f64 * LOAD_FACTOR) {
self.grow();
}

pub fn get_by_hash(&'a mut self, hash: u64) -> Option<&'a T> {
// the current index into the array
let mut pos: usize = (hash as usize) % self.cap;
// the distance this item is from its desired location
Expand All @@ -245,10 +248,7 @@ impl<'a, T: Eq + PartialEq + Hash + Clone + std::fmt::Debug> UniqueTable<'a, T>
}
}

impl<'a, T: Clone> Default for BackedRobinhoodTable<'a, T>
where
T: Hash + PartialEq + Eq + Clone,
{
impl<'a, T: Hash + Eq + Clone> Default for BackedRobinhoodTable<'a, T> {
fn default() -> Self {
Self::new()
}
Expand Down
7 changes: 2 additions & 5 deletions src/backing_store/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,7 @@ pub mod bump_table;

use std::hash::Hash;

pub trait UniqueTable<'a, T: Eq + PartialEq + Hash> {
fn get_by_hash(&'a mut self, hash: u64) -> Option<&'a T>;
/// use a hash to allocate space in table, but use strict equality
pub trait UniqueTable<'a, T: Eq + Hash> {
/// use a hash to allocate space in table, but use strict equality for probing/checking
fn get_or_insert(&'a mut self, item: T) -> &'a T;
/// use a hash to both allocate space in table, *and* form equality
fn get_or_insert_by_hash(&'a mut self, hash: u64, item: T, equality_by_hash: bool) -> &'a T;
}
1 change: 0 additions & 1 deletion src/builder/sdd/semantic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use std::hash::{Hash, Hasher};
use rustc_hash::FxHasher;

use crate::backing_store::bump_table::BackedRobinhoodTable;
use crate::backing_store::UniqueTable;
use crate::builder::cache::ite::Ite;
use crate::repr::bdd::create_semantic_hash_map;
use crate::repr::ddnnf::DDNNFPtr;
Expand Down
1 change: 0 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ pub mod plan;
pub mod repr;
pub mod sample;
pub mod serialize;
pub mod unique_table;

#[cfg(target_arch = "wasm32")]
pub mod wasm;
11 changes: 0 additions & 11 deletions src/unique_table/mod.rs

This file was deleted.

0 comments on commit 8a9f56a

Please sign in to comment.