BalancedKey

Struct BalancedKey 

Source
pub struct BalancedKey(/* private fields */);
Expand description

create it like:

let _  = bisection_key::BalancedKey::new("a");

Implementations§

Source§

impl BalancedKey

Source

pub fn new(s: &str) -> Result<Self, String>

Examples found in repository?
examples/debug_balanced.rs (line 10)
5fn main() -> Result<(), String> {
6  // let a = BalancedKey::new("aV")?;
7  // let b = BalancedKey::new("b")?;
8  // println!("{}", a.bisect(&b)?);
9
10  let a0 = BalancedKey::new("aV")?;
11  let a1 = BalancedKey::new("b-")?;
12  a0.bisect(&a1)?;
13
14  let mut base = BalancedKey::new("a")?;
15  let next = BalancedKey::new("b")?;
16  let mut ret: Vec<String> = vec![];
17  for _ in 0..100 {
18    base = base.bisect(&next)?;
19    println!("{}", base);
20    ret.push(base.to_string());
21  }
22
23  println!("{:?}", ret);
24
25  let mut base = BalancedKey::new("a")?;
26  let mut ret: Vec<String> = vec![];
27  for _ in 0..100 {
28    base = base.bisect_end()?;
29    println!("{}", base);
30    ret.push(base.to_string());
31  }
32
33  println!("{:?}", ret);
34
35  Ok(())
36}
Source

pub fn strip_last_mut(&mut self)

Source

pub fn strip_last(&self) -> Self

Source

pub fn bisect(&self, next: &Self) -> Result<Self, String>

Examples found in repository?
examples/debug_balanced.rs (line 12)
5fn main() -> Result<(), String> {
6  // let a = BalancedKey::new("aV")?;
7  // let b = BalancedKey::new("b")?;
8  // println!("{}", a.bisect(&b)?);
9
10  let a0 = BalancedKey::new("aV")?;
11  let a1 = BalancedKey::new("b-")?;
12  a0.bisect(&a1)?;
13
14  let mut base = BalancedKey::new("a")?;
15  let next = BalancedKey::new("b")?;
16  let mut ret: Vec<String> = vec![];
17  for _ in 0..100 {
18    base = base.bisect(&next)?;
19    println!("{}", base);
20    ret.push(base.to_string());
21  }
22
23  println!("{:?}", ret);
24
25  let mut base = BalancedKey::new("a")?;
26  let mut ret: Vec<String> = vec![];
27  for _ in 0..100 {
28    base = base.bisect_end()?;
29    println!("{}", base);
30    ret.push(base.to_string());
31  }
32
33  println!("{:?}", ret);
34
35  Ok(())
36}
Source

pub fn bisect_end(&self) -> Result<Self, String>

Examples found in repository?
examples/debug_balanced.rs (line 28)
5fn main() -> Result<(), String> {
6  // let a = BalancedKey::new("aV")?;
7  // let b = BalancedKey::new("b")?;
8  // println!("{}", a.bisect(&b)?);
9
10  let a0 = BalancedKey::new("aV")?;
11  let a1 = BalancedKey::new("b-")?;
12  a0.bisect(&a1)?;
13
14  let mut base = BalancedKey::new("a")?;
15  let next = BalancedKey::new("b")?;
16  let mut ret: Vec<String> = vec![];
17  for _ in 0..100 {
18    base = base.bisect(&next)?;
19    println!("{}", base);
20    ret.push(base.to_string());
21  }
22
23  println!("{:?}", ret);
24
25  let mut base = BalancedKey::new("a")?;
26  let mut ret: Vec<String> = vec![];
27  for _ in 0..100 {
28    base = base.bisect_end()?;
29    println!("{}", base);
30    ret.push(base.to_string());
31  }
32
33  println!("{:?}", ret);
34
35  Ok(())
36}
Source

pub fn bisect_beginning(&self) -> Result<Self, String>

Source

pub fn promote_from( &self, idx: usize, change: NumberChange, ) -> Result<Self, String>

Source

pub fn checked(self) -> Result<Self, String>

Trait Implementations§

Source§

impl Debug for BalancedKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for BalancedKey

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Display for BalancedKey

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Ord for BalancedKey

missing length are filled with 32s, then compare like a vector

Source§

fn cmp(&self, other: &BalancedKey) -> Ordering

This method returns an Ordering between self and other. Read more
1.21.0 · Source§

fn max(self, other: Self) -> Self
where Self: Sized,

Compares and returns the maximum of two values. Read more
1.21.0 · Source§

fn min(self, other: Self) -> Self
where Self: Sized,

Compares and returns the minimum of two values. Read more
1.50.0 · Source§

fn clamp(self, min: Self, max: Self) -> Self
where Self: Sized,

Restrict a value to a certain interval. Read more
Source§

impl PartialEq for BalancedKey

missing length are filled with 32s, then compare like a vector

Source§

fn eq(&self, other: &BalancedKey) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl PartialOrd for BalancedKey

Source§

fn partial_cmp(&self, other: &BalancedKey) -> Option<Ordering>

This method returns an ordering between self and other values if one exists. Read more
1.0.0 · Source§

fn lt(&self, other: &Rhs) -> bool

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

fn le(&self, other: &Rhs) -> bool

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

fn gt(&self, other: &Rhs) -> bool

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

fn ge(&self, other: &Rhs) -> bool

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Eq for BalancedKey

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.