Trait lib_rapid::compsci::general::BinaryInsert
source · pub trait BinaryInsert<T> {
// Required methods
fn binary_insert(&mut self, value: T);
fn binary_insert_no_dup(&mut self, value: T);
}
Expand description
Trait for binary_insert
.
Required Methods§
sourcefn binary_insert(&mut self, value: T)
fn binary_insert(&mut self, value: T)
Insert an element into a sorted vec
whilst maintaining the order, consuming other
.
Arguments
value
- The value which needs to be inserted.
Returns
Nothing.
Warning
This function will not check if the parsed vec
is sorted.
Examples
use lib_rapid::compsci::general::BinaryInsert;
let mut v = vec![0, 1, 2, 3, 4, 5];
v.binary_insert(3);
assert_eq!(vec![0, 1, 2, 3, 3, 4, 5], v);
use lib_rapid::compsci::general::BinaryInsert;
let mut v = vec![0, 2, 3, 4, 5];
v.binary_insert(1);
assert_eq!(vec![0, 1, 2, 3, 4, 5], v);
sourcefn binary_insert_no_dup(&mut self, value: T)
fn binary_insert_no_dup(&mut self, value: T)
The same as binary_insert
, but doesn’t insert a value that is already present.
Examples
use lib_rapid::compsci::general::BinaryInsert;
let mut v = vec![0, 1, 2, 3, 4, 5];
v.binary_insert_no_dup(3);
assert_eq!(vec![0, 1, 2, 3, 4, 5], v);
use lib_rapid::compsci::general::BinaryInsert;
let mut v = vec![0, 1, 2, 3, 4, 5];
v.binary_insert(6);
assert_eq!(vec![0, 1, 2, 3, 4, 5, 6], v);