Skip to content

Commit

Permalink
clean up warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
jhellerstein committed Sep 26, 2024
1 parent 31ec8e0 commit d423d77
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 25 deletions.
25 changes: 11 additions & 14 deletions hydroflow/tests/surface_lattice_bimorphism.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ use std::collections::{HashMap, HashSet};

use hydroflow::util::collect_ready;
use hydroflow::{assert_graphvis_snapshots, hydroflow_syntax};
use lattices::ght::{GeneralizedHashTrieNode, GhtInner};
use lattices::ght::GeneralizedHashTrieNode;
use lattices::ght_lattice::{DeepJoinLatticeBimorphism, GhtBimorphism};
use lattices::map_union::{KeyedBimorphism, MapUnionHashMap, MapUnionSingletonMap};
use lattices::set_union::{CartesianProductBimorphism, SetUnionHashSet, SetUnionSingletonSet};
Expand Down Expand Up @@ -147,28 +147,25 @@ fn test_ght_join_bimorphism() {
// type MyGhtATrie = <MyGhtA as GeneralizedHashTrie>::Trie;
// type MyGhtBTrie = <MyGhtB as GeneralizedHashTrie>::Trie;
type MyGhtATrie = GhtType!(u32, u64, u16 => &'static str: Row);
let ght_a = MyGhtATrie::default();
type MyGhtBTrie = GhtType!(u32, u64, u16 => &'static str: Row);

type Output = variadics::var_type!(u32, u64, u16, &'static str, &'static str);

type MyNodeBim = <(MyGhtATrie, MyGhtBTrie) as DeepJoinLatticeBimorphism<
VariadicHashSet<Output>,
>>::DeepJoinLatticeBimorphism;
let me_node_bim = MyNodeBim::default();
type MyBim = GhtBimorphism<MyNodeBim>;
let me_bim = MyBim::default();

let mut hf = hydroflow_syntax! {
lhs = source_iter_delta([
var_expr!(123, 2, 5, "hello"),
var_expr!(50, 1, 1, "hi"),
var_expr!(5, 1, 7, "hi"),
var_expr!(5, 1, 7, "bye"),
])
-> map(|row| MyGhtATrie::new_from([row]))
-> state::<'tick, MyGhtATrie>();
};
// let mut hf = hydroflow_syntax! {
// lhs = source_iter_delta([
// var_expr!(123, 2, 5, "hello"),
// var_expr!(50, 1, 1, "hi"),
// var_expr!(5, 1, 7, "hi"),
// var_expr!(5, 1, 7, "bye"),
// ])
// -> map(|row| MyGhtATrie::new_from([row]))
// -> state::<'tick, MyGhtATrie>();
// };

let mut hf = hydroflow_syntax! {
lhs = source_iter_delta([
Expand Down
4 changes: 3 additions & 1 deletion lattices/src/ght.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::{HashMap, HashSet};
use std::collections::HashMap;
use std::fmt::Debug;
use std::hash::Hash;
use std::marker::PhantomData;
Expand Down Expand Up @@ -220,6 +220,7 @@ where

/// Trait for a set of Tuples
pub trait TupleSet {
/// The Schema (aka Variadic type) associated with tuples in this set
type Schema: PartialEqVariadic;

/// Insert an element into the set
Expand All @@ -236,6 +237,7 @@ pub trait TupleSet {
self.len() == 0
}

/// iterate and drain items from the set
fn drain(&mut self) -> impl Iterator<Item = Self::Schema>;

/// Check for containment
Expand Down
2 changes: 1 addition & 1 deletion lattices/src/ght_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ mod test {

#[test]
fn test_insert() {
let mut htrie = <GhtType!(u16, u32 => u64)>::default(: Row);
let mut htrie = <GhtType!(u16, u32 => u64: Row)>::default();
htrie.insert(var_expr!(42, 314, 43770));
assert_eq!(htrie.recursive_iter().count(), 1);
assert_eq!(htrie.height(), 2);
Expand Down
28 changes: 22 additions & 6 deletions variadics/src/hash_set.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::fmt;
use std::hash::{BuildHasher, Hash, Hasher, RandomState};
use std::hash::{BuildHasher, Hash, RandomState};

use hashbrown::hash_table::{Entry, HashTable};

use crate::{PartialEqVariadic, VariadicExt};

/// HashSet that stores Variadics of owned values but allows
/// for lookups with RefVariadics as well
#[derive(Clone)]
pub struct VariadicHashSet<T, S = RandomState> {
table: HashTable<T>,
Expand Down Expand Up @@ -44,18 +46,21 @@ where
S: BuildHasher,
{
fn get_hash(hasher: &S, ref_var: T::AsRefVar<'_>) -> u64 {
let mut hasher = hasher.build_hasher();
ref_var.hash(&mut hasher);
hasher.finish()
hasher.hash_one(ref_var)
// let mut hasher = hasher.build_hasher();
// ref_var.hash(&mut hasher);
// hasher.finish()
}

/// given a RefVariadic lookup key, get a RefVariadic version of a tuple in the set
pub fn get<'a>(&'a self, ref_var: T::AsRefVar<'_>) -> Option<&'a T> {
let hash = Self::get_hash(&self.hasher, ref_var);
self.table.find(hash, |item| {
<T as PartialEqVariadic>::eq_ref(ref_var, item.as_ref_var())
})
}

/// insert a tuple
pub fn insert(&mut self, element: T) -> bool {
let hash = Self::get_hash(&self.hasher, element.as_ref_var());
let entry = self.table.entry(
Expand All @@ -72,15 +77,23 @@ where
}
}

/// return the number of tuples in the set
pub fn len(&self) -> usize {
self.table.len()
}

/// return the number of tuples in the set
pub fn is_empty(&self) -> bool {
self.table.len() == 0
}

/// drain the set: iterate and remove the tuples without deallocating
pub fn drain(&mut self) -> hashbrown::hash_table::Drain<'_, T> {
self.table.drain()
}

pub fn iter<'a>(&'a self) -> impl Iterator<Item = T::AsRefVar<'a>> {
/// iterate through the set
pub fn iter(&self) -> impl Iterator<Item = T::AsRefVar<'_>> {
self.table.iter().map(|item| item.as_ref_var())
}
}
Expand All @@ -99,12 +112,14 @@ where
}

impl<T, S> VariadicHashSet<T, S> {
/// allocate a new VariadicHashSet with a specific hasher
pub fn with_hasher(hasher: S) -> Self {
Self {
table: HashTable::new(),
hasher,
}
}
/// allocate a new VariadicHashSet with a specific hasher and capacity
pub fn with_capacity_and_hasher(capacity: usize, hasher: S) -> Self {
Self {
table: HashTable::with_capacity(capacity),
Expand All @@ -129,7 +144,8 @@ where
// Otherwise reserve half the hint (rounded up), so the map
// will only resize twice in the worst case.
let iter = iter.into_iter();
let reserve = if self.len() == 0 {
// let reserve =
if self.is_empty() {
iter.size_hint().0
} else {
(iter.size_hint().0 + 1) / 2
Expand Down
8 changes: 5 additions & 3 deletions variadics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
//! ## [`var_args!`]
#![doc = include_str!("../var_args.md")]

/// VariadicHashSet module
pub mod hash_set;

use std::any::Any;
use std::iter;
use std::ops::RangeBounds;

use sealed::sealed;
Expand Down Expand Up @@ -844,15 +844,17 @@ pub trait VecVariadic: VariadicExt {
/// get the unvec'ed Variadic at position `index`
fn get(&mut self, index: usize) -> Option<<Self::UnVec as VariadicExt>::AsRefVar<'_>>;

/// result type from into_zip
type IntoZip: Iterator<Item = Self::UnVec>;
/// Turns into an iterator of items `UnVec` -- i.e. iterate through rows (not columns!).
fn into_zip(self) -> Self::IntoZip;

/// result type from drain
type Drain<'a>: Iterator<Item = Self::UnVec>
where
Self: 'a;
/// Turns into a Drain of items `UnVec` -- i.e. rows (not columns!).
fn drain<'a, R>(&'a mut self, range: R) -> Self::Drain<'a>
fn drain<R>(&mut self, range: R) -> Self::Drain<'_>
where
R: RangeBounds<usize> + Clone;
}
Expand Down Expand Up @@ -895,7 +897,7 @@ where
std::iter::zip(this, rest.into_zip())
}
type Drain<'a> = std::iter::Zip<std::vec::Drain<'a, Item>, Rest::Drain<'a>> where Self: 'a;
fn drain<'a, R>(&'a mut self, range: R) -> Self::Drain<'a>
fn drain<R>(&mut self, range: R) -> Self::Drain<'_>
where
R: RangeBounds<usize> + Clone,
{
Expand Down

0 comments on commit d423d77

Please sign in to comment.