pub struct Ternary { /* private fields */ }Expand description
Represents a balanced ternary number using a sequence of Digits.
Provides functions for creating, parsing, converting, and manipulating balanced ternary numbers.
Implementations§
Source§impl Ternary
impl Ternary
Sourcepub fn new(digits: Vec<Digit>) -> Ternary
pub fn new(digits: Vec<Digit>) -> Ternary
Creates a new balanced ternary number from a vector of Digits.
Sourcepub fn log(&self) -> usize
pub fn log(&self) -> usize
Returns the number of digits (length) of the balanced ternary number.
Sourcepub fn get_digit(&self, index: usize) -> Option<&Digit>
pub fn get_digit(&self, index: usize) -> Option<&Digit>
Returns a reference to the Digit indexed by index if it exists.
Digits are indexed from the right:
use balanced_ternary::Ternary;
// Indexes :
// 32
// 4||1
// 5||||0
// ||||||
// vvvvvv
let ternary = Ternary::parse("+++--+");
assert_eq!(ternary.get_digit(1).unwrap().to_char(), '-')Sourcepub fn parse(str: &str) -> Self
pub fn parse(str: &str) -> Self
Parses a string representation of a balanced ternary number into a Ternary object.
Each character in the string must be one of +, 0, or -.
Trait Implementations§
impl Eq for Ternary
impl StructuralPartialEq for Ternary
Auto Trait Implementations§
impl Freeze for Ternary
impl RefUnwindSafe for Ternary
impl Send for Ternary
impl Sync for Ternary
impl Unpin for Ternary
impl UnwindSafe for Ternary
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more