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