Skip to content

Commit

Permalink
nondeterministic feature
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Oct 28, 2024
1 parent abf7d57 commit 0a47d4e
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 4 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ default = ["bin"]

bin = ["dep:clap", "dep:env_logger", "egraph-serialize/serde", "dep:serde_json"]
wasm-bindgen = ["instant/wasm-bindgen", "dep:getrandom"]
nondeterministic = []

[dependencies]
hashbrown = { version = "0.15" }
Expand Down
15 changes: 11 additions & 4 deletions src/gj.rs
Original file line number Diff line number Diff line change
Expand Up @@ -791,7 +791,14 @@ impl Debug for LazyTrie {
}
}

#[cfg(feature = "nondeterministic")]
type SparseMap = HashMap<Value, LazyTrie>;
#[cfg(feature = "nondeterministic")]
type SEntry<'a, A, B, D> = hashbrown::hash_map::Entry<'a, A, B, D>;
#[cfg(not(feature = "nondeterministic"))]
type SparseMap = IndexMap<Value, LazyTrie>;
#[cfg(not(feature = "nondeterministic"))]
type SEntry<'a, A, B> = Entry<'a, A, B>;
type RowIdx = u32;

#[derive(Debug)]
Expand Down Expand Up @@ -887,8 +894,8 @@ impl LazyTrie {
LazyTrieInner::Borrowed { index, map } => {
let ixs = index.get(&value)?;
match map.entry(value) {
Entry::Occupied(o) => Some(o.into_mut()),
Entry::Vacant(v) => {
SEntry::Occupied(o) => Some(o.into_mut()),
SEntry::Vacant(v) => {
Some(v.insert(LazyTrie::from_indexes(access.filter_live(ixs))?))
}
}
Expand Down Expand Up @@ -940,14 +947,14 @@ impl<'a> TrieAccess<'a> {
&& self.constraints.iter().all(|c| c.check(tup, out))
{
match map.entry(val) {
indexmap::map::Entry::Occupied(mut e) => {
SEntry::Occupied(mut e) => {
if let LazyTrieInner::Delayed(ref mut v) = e.get_mut().0.get_mut() {
v.push(i as RowIdx)
} else {
unreachable!()
}
}
indexmap::map::Entry::Vacant(e) => {
SEntry::Vacant(e) => {
e.insert(LazyTrie(UnsafeCell::new(LazyTrieInner::Delayed(
smallvec::smallvec![i as RowIdx,],
))));
Expand Down

0 comments on commit 0a47d4e

Please sign in to comment.