polars_utils/
aliases.rs

1use foldhash::SharedSeed;
2
3pub type PlRandomState = foldhash::quality::RandomState;
4pub type PlSeedableRandomStateQuality = foldhash::quality::SeedableRandomState;
5pub type PlRandomStateQuality = foldhash::quality::RandomState;
6pub type PlFixedStateQuality = foldhash::quality::FixedState;
7
8pub type PlHashMap<K, V> = hashbrown::HashMap<K, V, PlRandomState>;
9pub type PlHashSet<V> = hashbrown::HashSet<V, PlRandomState>;
10pub type PlIndexMap<K, V> = indexmap::IndexMap<K, V, PlRandomState>;
11pub type PlIndexSet<K> = indexmap::IndexSet<K, PlRandomState>;
12
13pub trait SeedableFromU64SeedExt {
14    fn seed_from_u64(seed: u64) -> Self;
15}
16
17impl SeedableFromU64SeedExt for PlSeedableRandomStateQuality {
18    fn seed_from_u64(seed: u64) -> Self {
19        PlSeedableRandomStateQuality::with_seed(seed, SharedSeed::global_fixed())
20    }
21}
22
23pub trait InitHashMaps {
24    type HashMap;
25
26    fn new() -> Self::HashMap;
27
28    fn with_capacity(capacity: usize) -> Self::HashMap;
29}
30
31impl<K, V> InitHashMaps for PlHashMap<K, V> {
32    type HashMap = Self;
33
34    fn new() -> Self::HashMap {
35        Self::with_capacity_and_hasher(0, Default::default())
36    }
37
38    fn with_capacity(capacity: usize) -> Self {
39        Self::with_capacity_and_hasher(capacity, Default::default())
40    }
41}
42impl<K> InitHashMaps for PlHashSet<K> {
43    type HashMap = Self;
44
45    fn new() -> Self::HashMap {
46        Self::with_capacity_and_hasher(0, Default::default())
47    }
48
49    fn with_capacity(capacity: usize) -> Self {
50        Self::with_capacity_and_hasher(capacity, Default::default())
51    }
52}
53
54impl<K> InitHashMaps for PlIndexSet<K> {
55    type HashMap = Self;
56
57    fn new() -> Self::HashMap {
58        Self::with_capacity_and_hasher(0, Default::default())
59    }
60
61    fn with_capacity(capacity: usize) -> Self::HashMap {
62        Self::with_capacity_and_hasher(capacity, Default::default())
63    }
64}
65
66impl<K, V> InitHashMaps for PlIndexMap<K, V> {
67    type HashMap = Self;
68
69    fn new() -> Self::HashMap {
70        Self::with_capacity_and_hasher(0, Default::default())
71    }
72
73    fn with_capacity(capacity: usize) -> Self::HashMap {
74        Self::with_capacity_and_hasher(capacity, Default::default())
75    }
76}