Expand description
Bound-STL
Bound-STL attempts to implement Rust copy of lower_bound
and upper_bound
manners in C++ STL.
This implementation is adding two traits LowerBound
and UpperBound
to the follow structures:
[..]
Vec
VecDeque
BinaryHeap
BTreeset
BTreeMap
This repo hosts at bound-stl
Usage
use bound_stl::LowerBound;
let v = vec![1, 2, 3, 4, 5];
assert_eq!(v.lower_bound(&3), Ok(2));
assert_eq!(v.lower_bound(&6), Err(5));
use bound_stl::UpperBound;
let v = vec![1, 2, 3, 4, 5];
assert_eq!(v.upper_bound(&3), Ok(3));
assert_eq!(v.upper_bound(&6), Err(5));
Traits
- find first index where arr[idx] >= v; assume arr is sorted. it is a encapsulation of
position
method, likeposition(|e| e.cmp(x) != Ordering::Less)
, but it returnsErr
when all elements are less thanx
. - find first index where arr[idx] > v; assume arr is sorted. it is a encapsulation of
position
method, likeposition(|e| e.cmp(x) == Ordering::Greater)
, but it returnsErr
when all elements are less than or equal tox
.