You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2022/07/22 16:27:48 UTC
[arrow-rs] branch master updated: Use total_cmp from std (#2131)
This is an automated email from the ASF dual-hosted git repository.
alamb 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 567c45747 Use total_cmp from std (#2131)
567c45747 is described below
commit 567c45747c2fad12c6746ec8cc35ef44aa0f617f
Author: Daniƫl Heres <da...@gmail.com>
AuthorDate: Fri Jul 22 18:27:43 2022 +0200
Use total_cmp from std (#2131)
---
arrow/src/compute/kernels/sort.rs | 48 +++++++++++++--------------------------
1 file changed, 16 insertions(+), 32 deletions(-)
diff --git a/arrow/src/compute/kernels/sort.rs b/arrow/src/compute/kernels/sort.rs
index d79f2249d..912733cf1 100644
--- a/arrow/src/compute/kernels/sort.rs
+++ b/arrow/src/compute/kernels/sort.rs
@@ -113,32 +113,6 @@ where
}
}
-// implements comparison using IEEE 754 total ordering for f32
-// Original implementation from https://doc.rust-lang.org/std/primitive.f64.html#method.total_cmp
-// TODO to change to use std when it becomes stable
-fn total_cmp_32(l: f32, r: f32) -> std::cmp::Ordering {
- let mut left = l.to_bits() as i32;
- let mut right = r.to_bits() as i32;
-
- left ^= (((left >> 31) as u32) >> 1) as i32;
- right ^= (((right >> 31) as u32) >> 1) as i32;
-
- left.cmp(&right)
-}
-
-// implements comparison using IEEE 754 total ordering for f64
-// Original implementation from https://doc.rust-lang.org/std/primitive.f64.html#method.total_cmp
-// TODO to change to use std when it becomes stable
-fn total_cmp_64(l: f64, r: f64) -> std::cmp::Ordering {
- let mut left = l.to_bits() as i64;
- let mut right = r.to_bits() as i64;
-
- left ^= (((left >> 63) as u64) >> 1) as i64;
- right ^= (((right >> 63) as u64) >> 1) as i64;
-
- left.cmp(&right)
-}
-
fn cmp<T>(l: T, r: T) -> std::cmp::Ordering
where
T: Ord,
@@ -197,12 +171,22 @@ pub fn sort_to_indices(
DataType::UInt64 => {
sort_primitive::<UInt64Type, _>(values, v, n, cmp, &options, limit)
}
- DataType::Float32 => {
- sort_primitive::<Float32Type, _>(values, v, n, total_cmp_32, &options, limit)
- }
- DataType::Float64 => {
- sort_primitive::<Float64Type, _>(values, v, n, total_cmp_64, &options, limit)
- }
+ DataType::Float32 => sort_primitive::<Float32Type, _>(
+ values,
+ v,
+ n,
+ |x, y| x.total_cmp(&y),
+ &options,
+ limit,
+ ),
+ DataType::Float64 => sort_primitive::<Float64Type, _>(
+ values,
+ v,
+ n,
+ |x, y| x.total_cmp(&y),
+ &options,
+ limit,
+ ),
DataType::Date32 => {
sort_primitive::<Date32Type, _>(values, v, n, cmp, &options, limit)
}