/rust/registry/src/index.crates.io-1949cf8c6b5b557f/fixedbitset-0.5.7/src/block/mod.rs
Line | Count | Source |
1 | | #![allow(clippy::undocumented_unsafe_blocks)] |
2 | | #![allow(dead_code)] |
3 | | // TODO: Remove once the transmutes are fixed |
4 | | #![allow(unknown_lints)] |
5 | | #![allow(clippy::missing_transmute_annotations)] |
6 | | |
7 | | use core::cmp::Ordering; |
8 | | use core::hash::{Hash, Hasher}; |
9 | | |
10 | | #[cfg(all( |
11 | | not(all(target_family = "wasm", target_feature = "simd128")), |
12 | | not(target_feature = "sse2"), |
13 | | not(target_feature = "avx"), |
14 | | not(target_feature = "avx2"), |
15 | | ))] |
16 | | mod default; |
17 | | #[cfg(all( |
18 | | not(all(target_family = "wasm", target_feature = "simd128")), |
19 | | not(target_feature = "sse2"), |
20 | | not(target_feature = "avx"), |
21 | | not(target_feature = "avx2"), |
22 | | ))] |
23 | | pub use self::default::*; |
24 | | |
25 | | #[cfg(all( |
26 | | any(target_arch = "x86", target_arch = "x86_64"), |
27 | | target_feature = "sse2", |
28 | | not(target_feature = "avx"), |
29 | | not(target_feature = "avx2"), |
30 | | ))] |
31 | | mod sse2; |
32 | | #[cfg(all( |
33 | | any(target_arch = "x86", target_arch = "x86_64"), |
34 | | target_feature = "sse2", |
35 | | not(target_feature = "avx"), |
36 | | not(target_feature = "avx2"), |
37 | | ))] |
38 | | pub use self::sse2::*; |
39 | | |
40 | | #[cfg(all( |
41 | | any(target_arch = "x86", target_arch = "x86_64"), |
42 | | target_feature = "avx", |
43 | | not(target_feature = "avx2") |
44 | | ))] |
45 | | mod avx; |
46 | | #[cfg(all( |
47 | | any(target_arch = "x86", target_arch = "x86_64"), |
48 | | target_feature = "avx", |
49 | | not(target_feature = "avx2") |
50 | | ))] |
51 | | pub use self::avx::*; |
52 | | |
53 | | #[cfg(all( |
54 | | any(target_arch = "x86", target_arch = "x86_64"), |
55 | | target_feature = "avx2" |
56 | | ))] |
57 | | mod avx2; |
58 | | #[cfg(all( |
59 | | any(target_arch = "x86", target_arch = "x86_64"), |
60 | | target_feature = "avx2" |
61 | | ))] |
62 | | pub use self::avx2::*; |
63 | | |
64 | | #[cfg(all(target_family = "wasm", target_feature = "simd128"))] |
65 | | mod wasm; |
66 | | #[cfg(all(target_family = "wasm", target_feature = "simd128"))] |
67 | | pub use self::wasm::*; |
68 | | |
69 | | impl Block { |
70 | | pub const USIZE_COUNT: usize = core::mem::size_of::<Self>() / core::mem::size_of::<usize>(); |
71 | | pub const NONE: Self = Self::from_usize_array([0; Self::USIZE_COUNT]); |
72 | | pub const ALL: Self = Self::from_usize_array([usize::MAX; Self::USIZE_COUNT]); |
73 | | pub const BITS: usize = core::mem::size_of::<Self>() * 8; |
74 | | |
75 | | #[inline] |
76 | 0 | pub fn into_usize_array(self) -> [usize; Self::USIZE_COUNT] { |
77 | 0 | unsafe { core::mem::transmute(self.0) } |
78 | 0 | } |
79 | | |
80 | | #[inline] |
81 | 0 | pub const fn from_usize_array(array: [usize; Self::USIZE_COUNT]) -> Self { |
82 | 0 | Self(unsafe { core::mem::transmute(array) }) |
83 | 0 | } |
84 | | } |
85 | | |
86 | | impl Eq for Block {} |
87 | | |
88 | | impl PartialOrd for Block { |
89 | | #[inline] |
90 | 0 | fn partial_cmp(&self, other: &Self) -> Option<Ordering> { |
91 | 0 | Some(self.cmp(other)) |
92 | 0 | } |
93 | | } |
94 | | |
95 | | impl Ord for Block { |
96 | | #[inline] |
97 | 0 | fn cmp(&self, other: &Self) -> Ordering { |
98 | 0 | self.into_usize_array().cmp(&other.into_usize_array()) |
99 | 0 | } |
100 | | } |
101 | | |
102 | | impl Default for Block { |
103 | | #[inline] |
104 | 0 | fn default() -> Self { |
105 | 0 | Self::NONE |
106 | 0 | } |
107 | | } |
108 | | |
109 | | impl Hash for Block { |
110 | | #[inline] |
111 | 0 | fn hash<H: Hasher>(&self, hasher: &mut H) { |
112 | 0 | Hash::hash_slice(&self.into_usize_array(), hasher); |
113 | 0 | } |
114 | | } |