vortex_compute/comparison/
mod.rs1use vortex_dtype::half::f16;
7use vortex_dtype::i256;
8
9mod binaryview_scalar;
10mod binaryview_vector;
11mod bool;
12mod collection;
13mod datum;
14mod decimal_scalar;
15mod decimal_vector;
16mod dvector;
17mod primitive_scalar;
18mod primitive_vector;
19mod pvector;
20
21pub trait Compare<Op, Rhs = Self> {
23 type Output;
25
26 fn compare(self, rhs: Rhs) -> Self::Output;
28}
29
30pub trait ComparisonOperator<T> {
32 fn apply(a: &T, b: &T) -> bool;
34}
35
36pub struct Equal;
38pub struct NotEqual;
40pub struct LessThan;
42pub struct LessThanOrEqual;
44pub struct GreaterThan;
46pub struct GreaterThanOrEqual;
48
49pub trait ComparableItem {
51 fn is_equal(lhs: &Self, rhs: &Self) -> bool;
53
54 fn is_less_than(lhs: &Self, rhs: &Self) -> bool;
56}
57
58impl<T: ComparableItem> ComparisonOperator<T> for Equal {
59 fn apply(a: &T, b: &T) -> bool {
60 T::is_equal(a, b)
61 }
62}
63
64impl<T: ComparableItem> ComparisonOperator<T> for NotEqual {
65 fn apply(a: &T, b: &T) -> bool {
66 !T::is_equal(a, b)
67 }
68}
69
70impl<T: ComparableItem> ComparisonOperator<T> for LessThan {
71 fn apply(a: &T, b: &T) -> bool {
72 T::is_less_than(a, b)
73 }
74}
75
76impl<T: ComparableItem> ComparisonOperator<T> for GreaterThanOrEqual {
77 fn apply(a: &T, b: &T) -> bool {
78 !T::is_less_than(a, b)
79 }
80}
81
82impl<T: ComparableItem> ComparisonOperator<T> for GreaterThan {
83 fn apply(a: &T, b: &T) -> bool {
84 T::is_less_than(b, a)
85 }
86}
87
88impl<T: ComparableItem> ComparisonOperator<T> for LessThanOrEqual {
89 fn apply(a: &T, b: &T) -> bool {
90 !T::is_less_than(b, a)
91 }
92}
93
94macro_rules! impl_integer {
95 ($T:ty) => {
96 impl ComparableItem for $T {
97 #[inline(always)]
98 fn is_equal(lhs: &Self, rhs: &Self) -> bool {
99 lhs == rhs
100 }
101
102 #[inline(always)]
103 fn is_less_than(lhs: &Self, rhs: &Self) -> bool {
104 lhs < rhs
105 }
106 }
107 };
108}
109
110impl_integer!(i8);
111impl_integer!(i16);
112impl_integer!(i32);
113impl_integer!(i64);
114impl_integer!(i128);
115impl_integer!(u8);
116impl_integer!(u16);
117impl_integer!(u32);
118impl_integer!(u64);
119impl_integer!(u128);
120impl_integer!(i256);
121
122macro_rules! impl_float {
123 ($T:ty) => {
124 impl ComparableItem for $T {
125 #[inline(always)]
126 fn is_equal(lhs: &Self, rhs: &Self) -> bool {
127 lhs.to_bits().eq(&rhs.to_bits())
128 }
129
130 #[inline(always)]
131 fn is_less_than(lhs: &Self, rhs: &Self) -> bool {
132 lhs.total_cmp(rhs).is_lt()
133 }
134 }
135 };
136}
137
138impl_float!(f16);
139impl_float!(f32);
140impl_float!(f64);