Skip to content

Commit

Permalink
our own build hasher that implements clone
Browse files Browse the repository at this point in the history
  • Loading branch information
oflatt committed Oct 25, 2024
1 parent 334f911 commit c9727fc
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
7 changes: 7 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ num-integer = "0.1.45"
num-rational = "0.4.1"
num-traits = "0.2.15"
smallvec = "1.11"
foldhash = "0.1.3"

generic_symbolic_expressions = "5.0.4"

Expand Down
2 changes: 1 addition & 1 deletion src/function/table.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ use std::{
use hashbrown::raw::RawTable;

use super::binary_search::binary_search_table_by_key;
use crate::{util::BuildHasher as BH, TupleOutput, Value, ValueVec};
use crate::{util::BuildFxHasher as BH, TupleOutput, Value, ValueVec};

type Offset = usize;

Expand Down
20 changes: 14 additions & 6 deletions src/util.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
#![allow(unused)]

use std::fmt::Display;

use symbol_table::DeterministicHashBuilder;
use std::{fmt::Display, hash::BuildHasher};

use crate::core::SpecializedPrimitive;
#[allow(unused_imports)]
use crate::*;

pub(crate) type BuildHasher = std::hash::BuildHasherDefault<rustc_hash::FxHasher>;
pub(crate) type BuildFxHasher = std::hash::BuildHasherDefault<rustc_hash::FxHasher>;

#[derive(Debug, Clone, Default)]
pub struct DeterministicHashBuilder;

impl BuildHasher for DeterministicHashBuilder {
type Hasher = foldhash::fast::FoldHasher;
fn build_hasher(&self) -> Self::Hasher {
foldhash::fast::FixedState::with_seed(0).build_hasher()
}
}

/// Use deterministic hasher to make egglog deterministic
/// when rule application order matters.
Expand All @@ -17,8 +25,8 @@ pub(crate) type HashSet<K> = hashbrown::HashSet<K, DeterministicHashBuilder>;

/// Index maps don't need deterministic hashing,
/// since iteration order is guaranteed to be insertion order.
pub type IndexMap<K, V> = indexmap::IndexMap<K, V, BuildHasher>;
pub type IndexSet<K> = indexmap::IndexSet<K, BuildHasher>;
pub type IndexMap<K, V> = indexmap::IndexMap<K, V, BuildFxHasher>;
pub type IndexSet<K> = indexmap::IndexSet<K, BuildFxHasher>;

pub(crate) fn concat_vecs<T>(to: &mut Vec<T>, mut from: Vec<T>) {
if to.len() < from.len() {
Expand Down

0 comments on commit c9727fc

Please sign in to comment.