Skip to content

Commit

Permalink
migrate cmpmore into riff
Browse files Browse the repository at this point in the history
  • Loading branch information
ngtkana committed Nov 12, 2024
1 parent b14b54c commit bf1ae29
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 130 deletions.
9 changes: 0 additions & 9 deletions libs/cmpmore/Cargo.toml

This file was deleted.

104 changes: 0 additions & 104 deletions libs/cmpmore/src/lib.rs

This file was deleted.

2 changes: 1 addition & 1 deletion libs/riff/src/binary_search.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::cmp::Ordering::Equal;
use std::cmp::Ordering::Greater;
use std::cmp::Ordering::Less;

/// Method versions of functions.
/// `{lower,upper}_bound`, etc
pub trait BinarySearch<T> {
fn partition_point<F: FnMut(&T) -> bool>(&self, pred: F) -> usize;
fn lower_bound_by<F: FnMut(&T) -> Ordering>(&self, mut f: F) -> usize {
Expand Down
16 changes: 16 additions & 0 deletions libs/riff/src/change_min_max.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/// `change_min` and `change_max`
pub trait ChangeMinMax: PartialOrd + Sized {
fn change_min(&mut self, rhs: Self) {
if *self > rhs {
*self = rhs
}
}

fn change_max(&mut self, rhs: Self) {
if *self < rhs {
*self = rhs
}
}
}

impl<T: PartialOrd + Sized> ChangeMinMax for T {}
2 changes: 2 additions & 0 deletions libs/riff/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
//! Future and otherworldly Rust features.
mod binary_search;
mod change_min_max;
mod pop_if;

pub use binary_search::BinarySearch;
pub use change_min_max::ChangeMinMax;
pub use pop_if::PopIf;
17 changes: 1 addition & 16 deletions libs/riff/src/pop_if.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,6 @@
use std::collections::BinaryHeap;

/// Removes and returns the "top" element in a vector if the predicate
/// returns `true`, or [`None`] if the predicate returns false or the container
/// is empty.
///
/// # Examples
///
/// ```
/// use riff::PopIf;
///
/// let mut vec = vec![1, 2, 3, 4];
/// let pred = |x: &mut i32| *x % 2 == 0;
///
/// assert_eq!(vec.pop_if(pred), Some(4));
/// assert_eq!(vec, [1, 2, 3]);
/// assert_eq!(vec.pop_if(pred), None);
/// ```
/// Conditional `pop` function.
pub trait PopIf {
type Value;

Expand Down

0 comments on commit bf1ae29

Please sign in to comment.