Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
pola-rs
GitHub Repository: pola-rs/polars
Path: blob/main/crates/polars-utils/src/aliases.rs
6939 views
1
use foldhash::SharedSeed;
2
3
pub type PlRandomState = foldhash::quality::RandomState;
4
pub type PlSeedableRandomStateQuality = foldhash::quality::SeedableRandomState;
5
pub type PlRandomStateQuality = foldhash::quality::RandomState;
6
pub type PlFixedStateQuality = foldhash::quality::FixedState;
7
8
pub type PlHashMap<K, V> = hashbrown::HashMap<K, V, PlRandomState>;
9
pub type PlHashSet<V> = hashbrown::HashSet<V, PlRandomState>;
10
pub type PlIndexMap<K, V> = indexmap::IndexMap<K, V, PlRandomState>;
11
pub type PlIndexSet<K> = indexmap::IndexSet<K, PlRandomState>;
12
13
pub trait SeedableFromU64SeedExt {
14
fn seed_from_u64(seed: u64) -> Self;
15
}
16
17
impl SeedableFromU64SeedExt for PlSeedableRandomStateQuality {
18
fn seed_from_u64(seed: u64) -> Self {
19
PlSeedableRandomStateQuality::with_seed(seed, SharedSeed::global_fixed())
20
}
21
}
22
23
pub trait InitHashMaps {
24
type HashMap;
25
26
fn new() -> Self::HashMap;
27
28
fn with_capacity(capacity: usize) -> Self::HashMap;
29
}
30
31
impl<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
}
42
impl<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
54
impl<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
66
impl<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
}
77
78