Skip to content

Commit

Permalink
c
Browse files Browse the repository at this point in the history
  • Loading branch information
nameexhaustion committed Feb 20, 2024
1 parent 3baf579 commit 9a084da
Show file tree
Hide file tree
Showing 18 changed files with 44 additions and 45 deletions.
10 changes: 5 additions & 5 deletions crates/polars-core/src/chunked_array/ops/unique/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ where
let mut set = PlHashSet::new();
let mut unique = Vec::with_capacity(capacity);
a.enumerate().for_each(|(idx, val)| {
if set.insert(val.into_total_ord()) {
if set.insert(val.to_total_ord()) {
unique.push(idx as IdxSize)
}
});
Expand Down Expand Up @@ -102,10 +102,10 @@ where

if !self.is_empty() {
let mut iter = self.iter();
let mut last = iter.next().unwrap().into_total_ord();
let mut last = iter.next().unwrap().to_total_ord();

let to_extend = iter.filter_map(|opt_val| {
let opt_val_tot_ord = opt_val.into_total_ord();
let opt_val_tot_ord = opt_val.to_total_ord();
if opt_val_tot_ord != last {
last = opt_val_tot_ord;
Some(opt_val)
Expand Down Expand Up @@ -150,12 +150,12 @@ where
}

let mut iter = self.iter();
let mut last = iter.next().unwrap().into_total_ord();
let mut last = iter.next().unwrap().to_total_ord();

count += 1;

iter.for_each(|opt_val| {
let opt_val = opt_val.into_total_ord();
let opt_val = opt_val.to_total_ord();
if opt_val != last {
last = opt_val;
count += 1;
Expand Down
8 changes: 4 additions & 4 deletions crates/polars-core/src/datatypes/any_value.rs
Original file line number Diff line number Diff line change
Expand Up @@ -894,8 +894,8 @@ impl AnyValue<'_> {
(Int16(l), Int16(r)) => *l == *r,
(Int32(l), Int32(r)) => *l == *r,
(Int64(l), Int64(r)) => *l == *r,
(Float32(l), Float32(r)) => l.into_total_ord() == r.into_total_ord(),
(Float64(l), Float64(r)) => l.into_total_ord() == r.into_total_ord(),
(Float32(l), Float32(r)) => l.to_total_ord() == r.to_total_ord(),
(Float64(l), Float64(r)) => l.to_total_ord() == r.to_total_ord(),
(String(l), String(r)) => l == r,
(String(l), StringOwned(r)) => l == r,
(StringOwned(l), String(r)) => l == r,
Expand Down Expand Up @@ -979,8 +979,8 @@ impl PartialOrd for AnyValue<'_> {
(Int16(l), Int16(r)) => l.partial_cmp(r),
(Int32(l), Int32(r)) => l.partial_cmp(r),
(Int64(l), Int64(r)) => l.partial_cmp(r),
(Float32(l), Float32(r)) => l.into_total_ord().partial_cmp(&r.into_total_ord()),
(Float64(l), Float64(r)) => l.into_total_ord().partial_cmp(&r.into_total_ord()),
(Float32(l), Float32(r)) => l.to_total_ord().partial_cmp(&r.to_total_ord()),
(Float64(l), Float64(r)) => l.to_total_ord().partial_cmp(&r.to_total_ord()),
(String(l), String(r)) => l.partial_cmp(*r),
(Binary(l), Binary(r)) => l.partial_cmp(*r),
_ => None,
Expand Down
6 changes: 3 additions & 3 deletions crates/polars-core/src/frame/group_by/hashing.rs
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ where
PlHashMap::with_capacity(init_size);
let mut cnt = 0;
a.for_each(|k| {
let k = k.into_total_ord();
let k = k.to_total_ord();
let idx = cnt;
cnt += 1;
let entry = hash_tbl.entry(k);
Expand Down Expand Up @@ -216,7 +216,7 @@ where

let mut cnt = 0;
keys.iter().for_each(|k| {
let k = k.into_total_ord();
let k = k.to_total_ord();
let idx = cnt + offset;
cnt += 1;

Expand Down Expand Up @@ -281,7 +281,7 @@ where

let mut cnt = 0;
keys.for_each(|k| {
let k = k.into_total_ord();
let k = k.to_total_ord();
let idx = cnt + offset;
cnt += 1;

Expand Down
6 changes: 3 additions & 3 deletions crates/polars-core/src/hashing/vector_hasher.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ where
.as_slice()
.iter()
.copied()
.map(|v| random_state.hash_one(v.into_total_ord())),
.map(|v| random_state.hash_one(v.to_total_ord())),
);
});
insert_null_hash(&ca.chunks, random_state, buf)
Expand All @@ -114,7 +114,7 @@ where
.iter()
.zip(&mut hashes[offset..])
.for_each(|(v, h)| {
*h = folded_multiply(random_state.hash_one(v.into_total_ord()) ^ *h, MULTIPLE);
*h = folded_multiply(random_state.hash_one(v.to_total_ord()) ^ *h, MULTIPLE);
}),
_ => {
let validity = arr.validity().unwrap();
Expand All @@ -124,7 +124,7 @@ where
.zip(&mut hashes[offset..])
.zip(arr.values().as_slice())
.for_each(|((valid, h), l)| {
let lh = random_state.hash_one(l.into_total_ord());
let lh = random_state.hash_one(l.to_total_ord());
let to_hash = [null_h, lh][valid as usize];

// inlined from ahash. This ensures we combine with the previous state
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-ops/src/chunked_array/list/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ where
for opt_v in arr.iter() {
match opt_v {
Some(v) => {
let r = random_state.hash_one(v.into_total_ord());
let r = random_state.hash_one(v.to_total_ord());
hash_agg = _boost_hash_combine(hash_agg, r);
},
None => {
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-ops/src/frame/join/asof/groups.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ where
results.push(None);
continue;
};
let by_left_k = by_left_k.into_total_ord();
let by_left_k = by_left_k.to_total_ord();
let idx_left = (rel_idx_left + offset) as IdxSize;
let Some(left_val) = left_val_arr.get(idx_left as usize) else {
results.push(None);
Expand Down
6 changes: 3 additions & 3 deletions crates/polars-ops/src/frame/join/hash_join/single_keys.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ where
let mut offset = 0;
for it in keys {
for k in it {
let k = k.into_total_ord();
let k = k.to_total_ord();
if !k.is_null() || join_nulls {
hm.entry(k).or_default().push(offset);
}
Expand All @@ -55,7 +55,7 @@ where
.map(|key_portion| {
let mut partition_sizes = vec![0; n_partitions];
for key in key_portion.clone() {
let key = key.into_total_ord();
let key = key.to_total_ord();
let p = hash_to_partition(key.dirty_hash(), n_partitions);
unsafe {
*partition_sizes.get_unchecked_mut(p) += 1;
Expand Down Expand Up @@ -103,7 +103,7 @@ where
let mut partition_offsets =
per_thread_partition_offsets[t * n_partitions..(t + 1) * n_partitions].to_vec();
for (i, key) in key_portion.into_iter().enumerate() {
let key = key.into_total_ord();
let key = key.to_total_ord();
unsafe {
let p = hash_to_partition(key.dirty_hash(), n_partitions);
let off = partition_offsets.get_unchecked_mut(p);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ pub(super) fn probe_inner<T, F, I>(
F: Fn(IdxSize, IdxSize) -> (IdxSize, IdxSize),
{
probe.into_iter().enumerate_idx().for_each(|(idx_a, k)| {
let k = k.into_total_ord();
let k = k.to_total_ord();
let idx_a = idx_a + local_offset;
// probe table that contains the hashed value
let current_probe_table =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ where
let mut result_idx_right = Vec::with_capacity(probe.size_hint().1.unwrap());

probe.enumerate().for_each(|(idx_a, k)| {
let k = k.into_total_ord();
let k = k.to_total_ord();
let idx_a = (idx_a + offset) as IdxSize;
// probe table that contains the hashed value
let current_probe_table = unsafe {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ where
.map(|iter| {
// create hashes and keys
iter.into_iter()
.map(|val| (build_hasher.hash_one(&val.into_total_ord()), val))
.map(|val| (build_hasher.hash_one(&val.to_total_ord()), val))
.collect_trusted::<Vec<_>>()
})
.collect()
Expand Down Expand Up @@ -63,7 +63,7 @@ where
.iter()
.enumerate()
.for_each(|(idx, (h, k))| {
let k = k.into_total_ord();
let k = k.to_total_ord();
let idx = idx as IdxSize;
// partition hashes by thread no.
// So only a part of the hashes go to this hashmap
Expand Down Expand Up @@ -125,7 +125,7 @@ fn probe_outer<T, F, G, H>(
let mut idx_a = 0;
for probe_hashes in probe_hashes {
for (h, key) in probe_hashes {
let key = key.into_total_ord();
let key = key.to_total_ord();
let h = *h;
// probe table that contains the hashed value
let current_probe_table =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ where
let mut hash_tbl: PlHashSet<T::TotalOrdItem> = PlHashSet::with_capacity(_HASHMAP_INIT_SIZE);
for keys in &keys {
keys.into_iter().for_each(|k| {
let k = k.into_total_ord();
let k = k.to_total_ord();
if partition_no == hash_to_partition(k.dirty_hash(), n_partitions) {
hash_tbl.insert(k);
}
Expand Down Expand Up @@ -67,7 +67,7 @@ where
let mut results = Vec::with_capacity(probe_iter.size_hint().1.unwrap());

probe_iter.enumerate().for_each(|(idx_a, k)| {
let k = k.into_total_ord();
let k = k.to_total_ord();
let idx_a = (idx_a + offset) as IdxSize;
// probe table that contains the hashed value
let current_probe_table =
Expand Down
4 changes: 2 additions & 2 deletions crates/polars-ops/src/frame/pivot/positioning.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ where
let mut out = Vec::with_capacity(column_agg_physical.len());

for opt_v in column_agg_physical.iter() {
let opt_v = opt_v.into_total_ord();
let opt_v = opt_v.to_total_ord();
let idx = *col_to_idx.entry(opt_v).or_insert_with(|| {
let old_idx = idx;
idx += 1;
Expand Down Expand Up @@ -306,7 +306,7 @@ where

let mut row_locations = Vec::with_capacity(index_agg_physical.len());
for opt_v in index_agg_physical.iter() {
let opt_v = opt_v.into_total_ord();
let opt_v = opt_v.to_total_ord();
let idx = *row_to_idx.entry(opt_v).or_insert_with(|| {
let old_idx = idx;
idx += 1;
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-ops/src/series/ops/approx_unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where
<Option<T::Physical<'a>> as IntoTotalOrd>::TotalOrdItem: Hash + Eq,
{
let mut hllp = HyperLogLog::new();
ca.iter().for_each(|item| hllp.add(&item.into_total_ord()));
ca.iter().for_each(|item| hllp.add(&item.to_total_ord()));
let c = hllp.count() as IdxSize;

Ok(Series::new(ca.name(), &[c]))
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-ops/src/series/ops/is_first_distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ where
let mut unique = PlHashSet::new();
let chunks = ca.downcast_iter().map(|arr| -> BooleanArray {
arr.into_iter()
.map(|opt_v| unique.insert(opt_v.into_total_ord()))
.map(|opt_v| unique.insert(opt_v.to_total_ord()))
.collect_trusted()
});

Expand Down
2 changes: 1 addition & 1 deletion crates/polars-ops/src/series/ops/is_last_distinct.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ where
let mut new_ca: BooleanChunked = arr
.into_iter()
.rev()
.map(|opt_v| unique.insert(opt_v.into_total_ord()))
.map(|opt_v| unique.insert(opt_v.to_total_ord()))
.collect_reversed::<NoNull<BooleanChunked>>()
.into_inner();
new_ca.rename(ca.name());
Expand Down
2 changes: 1 addition & 1 deletion crates/polars-ops/src/series/ops/unique.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ where
{
let mut map = PlIndexMap::with_capacity_and_hasher(_HASHMAP_INIT_SIZE, Default::default());
for item in items {
let item = item.into_total_ord();
let item = item.to_total_ord();
map.entry(item)
.and_modify(|cnt| {
*cnt += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,10 +59,10 @@ macro_rules! eval_binary_bool_type {
if let (AExpr::Literal(lit_left), AExpr::Literal(lit_right)) = ($lhs, $rhs) {
match (lit_left, lit_right) {
(LiteralValue::Float32(x), LiteralValue::Float32(y)) => {
Some(AExpr::Literal(LiteralValue::Boolean(x.into_total_ord() $operand y.into_total_ord())))
Some(AExpr::Literal(LiteralValue::Boolean(x.to_total_ord() $operand y.to_total_ord())))
}
(LiteralValue::Float64(x), LiteralValue::Float64(y)) => {
Some(AExpr::Literal(LiteralValue::Boolean(x.into_total_ord() $operand y.into_total_ord())))
Some(AExpr::Literal(LiteralValue::Boolean(x.to_total_ord() $operand y.to_total_ord())))
}
#[cfg(feature = "dtype-i8")]
(LiteralValue::Int8(x), LiteralValue::Int8(y)) => {
Expand Down
19 changes: 9 additions & 10 deletions crates/polars-utils/src/total_ord.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,6 @@ impl<T: IsNull> IsNull for TotalOrdWrap<T> {
}
}

// Require TotalOrdWrap to use DirtyHash on floats for code safety.
impl DirtyHash for f32 {
fn dirty_hash(&self) -> u64 {
canonical_f32(*self).to_bits().dirty_hash()
Expand Down Expand Up @@ -458,7 +457,7 @@ pub trait IntoTotalOrd {
type TotalOrdItem: Send + Sync;
type SourceItem;

fn into_total_ord(&self) -> Self::TotalOrdItem;
fn to_total_ord(&self) -> Self::TotalOrdItem;

fn peel_total_ord(ord_item: Self::TotalOrdItem) -> Self::SourceItem;
}
Expand All @@ -469,7 +468,7 @@ macro_rules! impl_into_total_ord_identity {
type TotalOrdItem = $T;
type SourceItem = $T;

fn into_total_ord(&self) -> Self::TotalOrdItem {
fn to_total_ord(&self) -> Self::TotalOrdItem {
self.clone()
}

Expand Down Expand Up @@ -502,7 +501,7 @@ macro_rules! impl_into_total_ord_lifetimed_identity {
type TotalOrdItem = &'a $T;
type SourceItem = &'a $T;

fn into_total_ord(&self) -> Self::TotalOrdItem {
fn to_total_ord(&self) -> Self::TotalOrdItem {
*self
}

Expand All @@ -522,7 +521,7 @@ macro_rules! impl_into_total_ord_wrapped {
type TotalOrdItem = TotalOrdWrap<$T>;
type SourceItem = $T;

fn into_total_ord(&self) -> Self::TotalOrdItem {
fn to_total_ord(&self) -> Self::TotalOrdItem {
TotalOrdWrap(self.clone())
}

Expand All @@ -540,7 +539,7 @@ impl<T: Send + Sync + Copy> IntoTotalOrd for Option<T> {
type TotalOrdItem = TotalOrdWrap<Option<T>>;
type SourceItem = Option<T>;

fn into_total_ord(&self) -> Self::TotalOrdItem {
fn to_total_ord(&self) -> Self::TotalOrdItem {
TotalOrdWrap(*self)
}

Expand All @@ -553,8 +552,8 @@ impl<'a> IntoTotalOrd for BytesHash<'a> {
type TotalOrdItem = BytesHash<'a>;
type SourceItem = BytesHash<'a>;

fn into_total_ord(&self) -> Self::TotalOrdItem {
self.clone()
fn to_total_ord(&self) -> Self::TotalOrdItem {
*self
}

fn peel_total_ord(ord_item: Self::TotalOrdItem) -> Self::SourceItem {
Expand All @@ -566,8 +565,8 @@ impl<T: IntoTotalOrd + Send + Sync> IntoTotalOrd for &T {
type TotalOrdItem = T::TotalOrdItem;
type SourceItem = T::SourceItem;

fn into_total_ord(&self) -> Self::TotalOrdItem {
(*self).into_total_ord()
fn to_total_ord(&self) -> Self::TotalOrdItem {
(*self).to_total_ord()
}

fn peel_total_ord(ord_item: Self::TotalOrdItem) -> Self::SourceItem {
Expand Down

0 comments on commit 9a084da

Please sign in to comment.