Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions datasketches/src/req/compactor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn normalized_sort_state<T: ReqValue>(items: &[T], claimed_sorted: bool) -> Resu
if item.is_nan() {
return Err(Error::deserial("REQ compactor contains a NaN item"));
}
if sorted && previous.is_some_and(|previous| previous.total_cmp(item).is_gt()) {
if sorted && previous.is_some_and(|previous| previous.compare(item).is_gt()) {
sorted = false;
}
previous = Some(item);
Expand Down Expand Up @@ -140,7 +140,7 @@ where
self.merge_sorted(&other.items);
} else {
let mut other_items = other.items.clone();
other_items.sort_unstable_by(|a, b| a.total_cmp(b));
other_items.sort_unstable_by(|a, b| a.compare(b));
self.merge_sorted(&other_items);
}
}
Expand All @@ -158,15 +158,15 @@ where
pub(super) fn count_below(&self, item: &T, inclusive: bool) -> usize {
if self.is_sorted {
if inclusive {
self.items.partition_point(|x| x.total_cmp(item).is_le())
self.items.partition_point(|x| x.compare(item).is_le())
} else {
self.items.partition_point(|x| x.total_cmp(item).is_lt())
self.items.partition_point(|x| x.compare(item).is_lt())
}
} else {
self.items
.iter()
.filter(|x| {
let ord = x.total_cmp(item);
let ord = x.compare(item);
if inclusive { ord.is_le() } else { ord.is_lt() }
})
.count()
Expand Down Expand Up @@ -201,7 +201,7 @@ where

// Two-pointer merge into scratch buffer
while i < a.len() && j < b.len() {
if a[i].total_cmp(&b[j]).is_le() {
if a[i].compare(&b[j]).is_le() {
self.scratch_buffer.push(a[i].clone());
i += 1;
} else {
Expand Down Expand Up @@ -229,7 +229,7 @@ where
pub(super) fn sort(&mut self) {
if !self.is_sorted {
// Use unstable sort for better performance (stable not needed for REQ sketch)
self.items.sort_unstable_by(|a, b| a.total_cmp(b));
self.items.sort_unstable_by(|a, b| a.compare(b));
self.is_sorted = true;
}
}
Expand Down
14 changes: 7 additions & 7 deletions datasketches/src/req/sketch.rs
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ impl<T: ReqValue> ReqSketch<T> {
}
match &mut self.min_item {
None => self.min_item = Some(item.clone()),
Some(cur) if item.total_cmp(cur).is_lt() => *cur = item.clone(),
Some(cur) if item.compare(cur).is_lt() => *cur = item.clone(),
_ => {}
}
match &mut self.max_item {
None => self.max_item = Some(item.clone()),
Some(cur) if item.total_cmp(cur).is_gt() => *cur = item.clone(),
Some(cur) if item.compare(cur).is_gt() => *cur = item.clone(),
_ => {}
}

Expand Down Expand Up @@ -285,14 +285,14 @@ impl<T: ReqValue> ReqSketch<T> {
if let Some(m) = &other.min_item {
match &self.min_item {
None => self.min_item = Some(m.clone()),
Some(cur) if m.total_cmp(cur).is_lt() => self.min_item = Some(m.clone()),
Some(cur) if m.compare(cur).is_lt() => self.min_item = Some(m.clone()),
_ => {}
}
}
if let Some(m) = &other.max_item {
match &self.max_item {
None => self.max_item = Some(m.clone()),
Some(cur) if m.total_cmp(cur).is_gt() => self.max_item = Some(m.clone()),
Some(cur) if m.compare(cur).is_gt() => self.max_item = Some(m.clone()),
_ => {}
}
}
Expand Down Expand Up @@ -631,7 +631,7 @@ impl<T: ReqValue> ReqSketch<T> {
if min.is_nan() || max.is_nan() {
return Err(Error::deserial("REQ sketch min or max item is NaN"));
}
if min.total_cmp(max).is_gt() {
if min.compare(max).is_gt() {
return Err(Error::deserial(
"REQ sketch min item is greater than max item",
));
Expand Down Expand Up @@ -667,10 +667,10 @@ impl<T: ReqValue> ReqSketch<T> {
let mut mn = first.clone();
let mut mx = first.clone();
for x in iter {
if x.total_cmp(&mn).is_lt() {
if x.compare(&mn).is_lt() {
mn = x.clone();
}
if x.total_cmp(&mx).is_gt() {
if x.compare(&mx).is_gt() {
mx = x.clone();
}
}
Expand Down
16 changes: 9 additions & 7 deletions datasketches/src/req/sorted_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,15 @@ where
}

// Sort by item value - use unstable sort for better performance
weighted_items.sort_unstable_by(|a, b| a.0.total_cmp(&b.0));
weighted_items.sort_unstable_by(|a, b| a.0.compare(&b.0));

let mut items: Vec<T> = Vec::with_capacity(weighted_items.len());
let mut cumulative_weights = Vec::with_capacity(weighted_items.len());
let mut cumulative_weight = 0u64;

for (item, weight) in weighted_items {
if let Some(last) = items.last() {
if matches!(last.total_cmp(&item), std::cmp::Ordering::Equal) {
if matches!(last.compare(&item), std::cmp::Ordering::Equal) {
cumulative_weight += weight;
let last_idx = cumulative_weights.len() - 1;
cumulative_weights[last_idx] = cumulative_weight;
Expand Down Expand Up @@ -122,7 +122,7 @@ where
SearchCriteria::Inclusive => {
// Find the last position where items[i] <= item
// partition_point finds first index where predicate is false
let pos = self.items.partition_point(|x| x.total_cmp(item).is_le());
let pos = self.items.partition_point(|x| x.compare(item).is_le());
if pos == 0 {
Ok(0.0)
} else {
Expand All @@ -131,7 +131,7 @@ where
}
SearchCriteria::Exclusive => {
// Find the last position where items[i] < item
let pos = self.items.partition_point(|x| x.total_cmp(item).is_lt());
let pos = self.items.partition_point(|x| x.compare(item).is_lt());
if pos == 0 {
Ok(0.0)
} else {
Expand Down Expand Up @@ -259,9 +259,11 @@ where
// Private helper methods

fn validate_split_points(&self, split_points: &[T]) -> Result<(), Error> {
// Check that split points are monotonically increasing
for i in 1..split_points.len() {
if split_points[i - 1].total_cmp(&split_points[i]).is_ge() {
for (i, split_point) in split_points.iter().enumerate() {
if split_point.is_nan() {
return Err(Error::invalid_argument("Split points must not be NaN"));
}
if i > 0 && split_points[i - 1].compare(split_point).is_ge() {
return Err(Error::invalid_argument(
"Split points must be unique and monotonically increasing".to_string(),
));
Expand Down
Loading