You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2022/11/10 03:56:25 UTC
[arrow-rs] branch master updated: Add compare to ArrowNativeTypeOp (#3070)
This is an automated email from the ASF dual-hosted git repository.
tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/master by this push:
new e44cb5b47 Add compare to ArrowNativeTypeOp (#3070)
e44cb5b47 is described below
commit e44cb5b478257751916d1674292123eaf5d80a7c
Author: Raphael Taylor-Davies <17...@users.noreply.github.com>
AuthorDate: Thu Nov 10 16:56:20 2022 +1300
Add compare to ArrowNativeTypeOp (#3070)
* Add total_cmp to ArrowNativeTypeOp
* Format
---
arrow-array/src/arithmetic.rs | 94 +++++++++++++++++--------------------------
1 file changed, 36 insertions(+), 58 deletions(-)
diff --git a/arrow-array/src/arithmetic.rs b/arrow-array/src/arithmetic.rs
index f21532364..566f3742e 100644
--- a/arrow-array/src/arithmetic.rs
+++ b/arrow-array/src/arithmetic.rs
@@ -19,6 +19,7 @@ use arrow_buffer::{i256, ArrowNativeType};
use arrow_schema::ArrowError;
use half::f16;
use num::complex::ComplexFloat;
+use std::cmp::Ordering;
/// Trait for [`ArrowNativeType`] that adds checked and unchecked arithmetic operations,
/// and totally ordered comparison operations
@@ -74,17 +75,34 @@ pub trait ArrowNativeTypeOp: ArrowNativeType {
fn is_zero(self) -> bool;
- fn is_eq(self, rhs: Self) -> bool;
-
- fn is_ne(self, rhs: Self) -> bool;
-
- fn is_lt(self, rhs: Self) -> bool;
+ fn compare(self, rhs: Self) -> Ordering;
- fn is_le(self, rhs: Self) -> bool;
-
- fn is_gt(self, rhs: Self) -> bool;
+ fn is_eq(self, rhs: Self) -> bool;
- fn is_ge(self, rhs: Self) -> bool;
+ #[inline]
+ fn is_ne(self, rhs: Self) -> bool {
+ !self.is_eq(rhs)
+ }
+
+ #[inline]
+ fn is_lt(self, rhs: Self) -> bool {
+ self.compare(rhs).is_lt()
+ }
+
+ #[inline]
+ fn is_le(self, rhs: Self) -> bool {
+ self.compare(rhs).is_le()
+ }
+
+ #[inline]
+ fn is_gt(self, rhs: Self) -> bool {
+ self.compare(rhs).is_gt()
+ }
+
+ #[inline]
+ fn is_ge(self, rhs: Self) -> bool {
+ self.compare(rhs).is_ge()
+ }
}
macro_rules! native_type_op {
@@ -209,33 +227,13 @@ macro_rules! native_type_op {
}
#[inline]
- fn is_eq(self, rhs: Self) -> bool {
- self == rhs
- }
-
- #[inline]
- fn is_ne(self, rhs: Self) -> bool {
- self != rhs
+ fn compare(self, rhs: Self) -> Ordering {
+ self.cmp(&rhs)
}
#[inline]
- fn is_lt(self, rhs: Self) -> bool {
- self < rhs
- }
-
- #[inline]
- fn is_le(self, rhs: Self) -> bool {
- self <= rhs
- }
-
- #[inline]
- fn is_gt(self, rhs: Self) -> bool {
- self > rhs
- }
-
- #[inline]
- fn is_ge(self, rhs: Self) -> bool {
- self >= rhs
+ fn is_eq(self, rhs: Self) -> bool {
+ self == rhs
}
}
};
@@ -341,6 +339,11 @@ macro_rules! native_type_float_op {
self == $zero
}
+ #[inline]
+ fn compare(self, rhs: Self) -> Ordering {
+ <$t>::total_cmp(&self, &rhs)
+ }
+
#[inline]
fn is_eq(self, rhs: Self) -> bool {
// Equivalent to `self.total_cmp(&rhs).is_eq()`
@@ -348,31 +351,6 @@ macro_rules! native_type_float_op {
// https://rust.godbolt.org/z/347nWGxoW
self.to_bits() == rhs.to_bits()
}
-
- #[inline]
- fn is_ne(self, rhs: Self) -> bool {
- !self.is_eq(rhs)
- }
-
- #[inline]
- fn is_lt(self, rhs: Self) -> bool {
- self.total_cmp(&rhs).is_lt()
- }
-
- #[inline]
- fn is_le(self, rhs: Self) -> bool {
- self.total_cmp(&rhs).is_le()
- }
-
- #[inline]
- fn is_gt(self, rhs: Self) -> bool {
- self.total_cmp(&rhs).is_gt()
- }
-
- #[inline]
- fn is_ge(self, rhs: Self) -> bool {
- self.total_cmp(&rhs).is_ge()
- }
}
};
}