Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why char for trits? #1

Open
Rudxain opened this issue Dec 2, 2024 · 0 comments
Open

why char for trits? #1

Rudxain opened this issue Dec 2, 2024 · 0 comments

Comments

@Rudxain
Copy link

Rudxain commented Dec 2, 2024

Why is it used almost everywhere in the code? Its size is 4 times as big as u8, and it's less ergonomic to write collections of chars than binary strings and byte arrays:

['0','-','+',]; // char array: clunky
*b"0-+"; // octet array: terser and efficient

An even better approach is:

/// Balanced Ternary digit ("Trit")
#[derive(Debug, Copy, Clone, Eq, PartialEq, Ord, PartialOrd)]
#[repr(i8)]
enum BT {
    /// Negative
    N = -1,
    /// Zero
    Z = 0,
    /// Positive
    P = 1,
}

Then define a macro that takes a string of BT chars and maps them to an array or Vec of BT variants.

Then, in the future, instead of Vec<BT>, we could copy the code from bitvec (is the license compatible?) and adapt it to ternary, for better optimization

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant