Skip to content

Commit

Permalink
More
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Taillefer committed Dec 6, 2024
1 parent 7bbbf90 commit 0b6168a
Show file tree
Hide file tree
Showing 8 changed files with 81 additions and 48 deletions.
4 changes: 4 additions & 0 deletions TODO.md
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

- Does no_std still work?

## Bug

- Seems like fmt on our maps doesn't produce the same output as what HashMap emits (we have extra {} around everything)

## Type System Nightmares

These are some things which I haven't done yet since I can't figure out how to express these things in the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ where
BH: BuildHasher,
{
fn hash(&self, value: &[T]) -> u64 {
if value.len() <= RANGE_END {
if value.len() < RANGE_END {
return 0;
}

Expand Down
6 changes: 3 additions & 3 deletions frozen-collections-core/src/hashers/right_range_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where
{
fn hash(&self, value: &String) -> u64 {
let b = value.as_bytes();
if b.len() <= self.range.end {
if b.len() < self.range.end {
return 0;
}

Expand All @@ -55,7 +55,7 @@ where
{
fn hash(&self, value: &&str) -> u64 {
let b = value.as_bytes();
if b.len() <= self.range.end {
if b.len() < self.range.end {
return 0;
}

Expand All @@ -70,7 +70,7 @@ where
{
fn hash(&self, value: &str) -> u64 {
let b = value.as_bytes();
if b.len() <= self.range.end {
if b.len() < self.range.end {
return 0;
}

Expand Down
8 changes: 4 additions & 4 deletions frozen-collections-core/src/inline_sets/inline_hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ where
T: Hash + Eq + Clone,
ST: Set<T>,
CM: CollectionMagnitude,
H: Hasher<T> + Default,
H: Hasher<T>,
{
bitor_fn!(H);
}
Expand All @@ -148,7 +148,7 @@ where
T: Hash + Eq + Clone,
ST: Set<T>,
CM: CollectionMagnitude,
H: Hasher<T> + Default,
H: Hasher<T>,
{
bitand_fn!(H);
}
Expand All @@ -159,7 +159,7 @@ where
T: Hash + Eq + Clone,
ST: Set<T>,
CM: CollectionMagnitude,
H: Hasher<T> + Default,
H: Hasher<T>,
{
bitxor_fn!(H);
}
Expand All @@ -169,7 +169,7 @@ where
T: Hash + Eq + Clone,
ST: Set<T>,
CM: CollectionMagnitude,
H: Hasher<T> + Default,
H: Hasher<T>,
{
sub_fn!(H);
}
Expand Down
6 changes: 2 additions & 4 deletions frozen-collections-core/src/macros/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,10 +352,8 @@ impl Generator {
return Ok(self.emit_inline_ordered_scan(&processed_entries));
}

let analysis = analyze_slice_keys(
processed_entries.iter().map(|x| x.parsed_key.as_bytes()),
&bh,
);
let iter = processed_entries.iter().map(|x| x.parsed_key.as_bytes());
let analysis = analyze_slice_keys(iter, &bh);

Ok(match analysis {
SliceKeyAnalysisResult::LeftHandSubslice(range) => {
Expand Down
17 changes: 16 additions & 1 deletion frozen-collections-core/src/macros/set_macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,18 +215,33 @@ mod tests {
let r = fz_string_set_macro(ts).unwrap().to_string();
assert!(r.contains(expected), "{r} doesn't contain {expected}");
}

check_impl(":: InlineScanSet", quote!({ "1", "2", "3", }));
check_impl(":: InlineOrderedScanSet", quote!({ "1", "2", "3", "4" }));
check_impl(
":: InlineOrderedScanSet",
quote!({ "1", "2", "3", "4", "5", "6"}),
);

check_impl(
":: InlineHashSet",
quote!({ "1", "2", "3", "4", "5", "6", "7" }),
);

check_impl(
":: BridgeHasher",
quote!({ "1", "2", "3", "4", "5", "6", "7" }),
);

check_impl(
":: PassthroughHasher",
quote!({ "1", "22", "333", "4444", "55555", "666666", "7777777" }),
);

check_impl(
":: InlineLeftRangeHasher",
quote!({ "1111", "1112", "1113", "1114", "1115", "1116", "1117" }),
);

check_impl(":: InlineScanSet", quote!({ x, "2", "3", }));
check_impl(":: FacadeStringSet", quote!({ x, "2", "3", "4" }));
check_impl(":: FacadeStringSet", quote!({ x, "2", "3", "4", "5", "6"}));
Expand Down
8 changes: 4 additions & 4 deletions frozen-collections-core/src/sets/hash_set.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ where
T: Hash + Eq + Clone,
ST: Set<T>,
CM: CollectionMagnitude,
H: Hasher<T> + Default,
H: Hasher<T>,
{
bitor_fn!(H);
}
Expand All @@ -140,7 +140,7 @@ where
T: Hash + Eq + Clone,
ST: Set<T>,
CM: CollectionMagnitude,
H: Hasher<T> + Default,
H: Hasher<T>,
{
bitand_fn!(H);
}
Expand All @@ -150,7 +150,7 @@ where
T: Hash + Eq + Clone,
ST: Set<T>,
CM: CollectionMagnitude,
H: Hasher<T> + Default,
H: Hasher<T>,
{
bitxor_fn!(H);
}
Expand All @@ -160,7 +160,7 @@ where
T: Hash + Eq + Clone,
ST: Set<T>,
CM: CollectionMagnitude,
H: Hasher<T> + Default,
H: Hasher<T>,
{
sub_fn!(H);
}
Expand Down
78 changes: 47 additions & 31 deletions frozen-collections/tests/omni_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,29 @@ use frozen_collections_core::sets::*;
use hashbrown::HashSet as HashbrownSet;
use std::collections::HashMap as StdHashMap;

macro_rules! test_str {
( $( $input:expr ),* ; $( $other:literal ),*) => {
// handle 8str cases

let set_reference = HashbrownSet::<&str>::from_iter(vec![ $( $input, )* ].into_iter());
let set_other = HashbrownSet::<&str>::from_iter(vec![ $( $other, )* ].into_iter());

let map_reference = StdHashMap::<_, _, ahash::RandomState>::from_iter(vec![ $( ($input, ()), )* ].into_iter());
let map_other = StdHashMap::<_, _, ahash::RandomState>::from_iter(vec![ $( ($other, ()), )* ].into_iter());

let mut m = fz_string_map!({ $( $input: (),)* });
test_map(&m, &map_reference, &map_other);
test_map_ops(&m, &map_reference);
test_map_iter(&m, &map_reference);
test_map_iter_mut(&mut m, &map_reference);

let s = fz_string_set!({ $( $input,)* });
test_set(&s, &set_reference, &set_other);
test_set_ops(&s, &set_reference, &set_other);
test_set_iter(&s, &set_reference);
}
}

macro_rules! test_all {
( $( $input:expr ),* ; $( $other:literal ),*) => {
let set_reference = HashbrownSet::from_iter(vec![ $( $input, )* ].into_iter());
Expand Down Expand Up @@ -206,25 +229,6 @@ macro_rules! test_all {
let s = hashbrown::HashSet::<_, ahash::RandomState>::from_iter(set_input.clone().into_iter());
test_set(&s, &set_reference, &set_other);

// handle 8str cases
/*
let set_reference = HashbrownSet::<&str>::from_iter(vec![ $( stringify!($input), )* ].into_iter());
let set_other = HashbrownSet::<&str>::from_iter(vec![ $( stringify!($other), )* ].into_iter());
let map_reference = StdHashMap::<_, _, ahash::RandomState>::from_iter(vec![ $( (stringify!($input), ()), )* ].into_iter());
let map_other = StdHashMap::<_, _, ahash::RandomState>::from_iter(vec![ $( (stringify!($other), ()), )* ].into_iter());
let mut m = fz_string_map!({ $( stringify!($input): (),)* });
test_map(&m, &map_reference, &map_other);
test_map_ops(&m, &map_reference);
test_map_iter(&m, &map_reference);
test_map_iter_mut(&mut m, &map_reference);
let s = fz_string_set!({ $( stringify!($input),)* });
test_set(&s, &set_reference, &set_other);
test_set_ops(&s, &set_reference, &set_other);
test_set_iter(&s, &set_reference);
*/
// handle String cases

let set_reference = HashbrownSet::<String>::from_iter(vec![ $( $input.to_string(), )* ].into_iter());
Expand Down Expand Up @@ -283,20 +287,32 @@ fn test_common() {
test_all!(1, 2, 3, 4, 5, 6, 7, 8, 9 ; 3, 10);
test_all!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ; 3);
test_all!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10 ; 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 20);

test_all!(11111, 11112, 11114, 11115, 111165, 111175 ; 2500, 333333333);

/*
let i = 1;
test_all!(i, 2, 3, 4, 5, 6, 7, 8, 9, 10 ; 3);
test_all!(1, i, 3, 4, 5, 6, 7, 8, 9, 10 ; 3);
test_all!(i, 2u8, 3, 4, 5, 6, 7, 8, 9, 10 ; 3);
test_all!(1u8, i, 3, 4, 5, 6, 7, 8, 9, 10 ; 3);
test_all!(i, 2, 3u8, 4, 5, 6, 7, 8, 9, 10 ; 3);
test_all!(1, i, 3u8, 4, 5, 6, 7, 8, 9, 10 ; 3);
test_all!(i, 2u8, 3u8, 4, 5, 6, 7, 8, 9, 10 ; 3);
test_all!(1u8, i, 3u8, 4, 5, 6, 7, 8, 9, 10 ; 3);
*/
test_str!("1", "2", "3" ; "3", "4", "5");
test_str!("0", "1" ; "0", "1");
test_str!("3", "1", "2", "3", "3" ; "3", "4", "5");
test_str!("1", "2", "3" ; "1", "2", "3", "4", "5");
test_str!("1", "2", "3" ; "1", "2");
test_str!("1", "2", "3" ; "2");
test_str!("1", "2", "4" ; "2");
test_str!("1", "2", "4" ; "3");
test_str!("1", "2", "4", "1500" ; "3");
test_str!("1", "2", "4", "1500" ; "2500");
test_str!("1" ; "3");
test_str!("1", "2" ; "3");
test_str!("1", "2", "3" ; "3");
test_str!("1", "2", "3", "4" ; "3");
test_str!("1", "2", "3", "4", "5" ; "3");
test_str!("1", "2", "3", "4", "5", "6" ; "3");
test_str!("1", "2", "3", "4", "5", "6", "7" ; "3", "5");
test_str!("1", "2", "3", "4", "5", "6", "7", "8" ; "3");
test_str!("1", "2", "3", "4", "5", "6", "7", "8", "9" ; "3", "10");
test_str!("1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ; "3");
test_str!("1", "2", "3", "4", "5", "6", "7", "8", "9", "10" ; "3", "4", "5", "6", "7", "8", "9", "10", "11", "12", "20");
test_str!("11111", "11112", "11114", "11115", "111165", "111175" ; "2500", "333333333");
test_str!("11111", "11112", "11114", "11115", "111165", "111175", "111185" ; "2500", "333333333");
test_str!("1", "22", "333", "4444", "55555", "666666", "7777777" ; "2500", "333333333");
}

#[test]
Expand Down

0 comments on commit 0b6168a

Please sign in to comment.