Skip to content

why char for trits? #1

@Rudxain

Description

@Rudxain

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions