vortex_array/arrays/primitive/
native_value.rs1use std::cmp::Ordering;
5
6use vortex_dtype::NativePType;
7use vortex_dtype::half;
8
9#[repr(transparent)]
15#[derive(Copy, Clone, Debug)]
16pub struct NativeValue<T>(pub T);
17
18impl<T: NativePType> PartialEq<NativeValue<T>> for NativeValue<T> {
19 fn eq(&self, other: &NativeValue<T>) -> bool {
20 self.0.is_eq(other.0)
21 }
22}
23
24impl<T: NativePType> Eq for NativeValue<T> {}
25
26macro_rules! prim_value {
27 ($typ:ty) => {
28 impl core::hash::Hash for NativeValue<$typ> {
29 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
30 self.0.hash(state);
31 }
32 }
33 };
34}
35
36impl<T: NativePType> PartialOrd<NativeValue<T>> for NativeValue<T> {
37 fn partial_cmp(&self, other: &NativeValue<T>) -> Option<Ordering> {
38 Some(self.0.total_compare(other.0))
39 }
40}
41
42macro_rules! float_value {
43 ($typ:ty) => {
44 impl core::hash::Hash for NativeValue<$typ> {
45 fn hash<H: core::hash::Hasher>(&self, state: &mut H) {
46 self.0.to_bits().hash(state);
47 }
48 }
49 };
50}
51
52prim_value!(u8);
53prim_value!(u16);
54prim_value!(u32);
55prim_value!(u64);
56prim_value!(i8);
57prim_value!(i16);
58prim_value!(i32);
59prim_value!(i64);
60float_value!(half::f16);
61float_value!(f32);
62float_value!(f64);