Expand description
A balanced ternary data structure.
A Ternary object in this module represents a number in the balanced ternary numeral system.
Balanced ternary is a non-standard positional numeral system that uses three digits: {-1, 0, +1}
represented here as Neg for -1, Zero for 0, and Pos for +1. It is useful in some domains
of computer science and mathematics due to its arithmetic properties and representation
symmetry.
§Data Structures
DigitEnum: Represents a single digit for balanced ternary values, with possible values:Negfor -1Zerofor 0Posfor +1
§Features
All features are enabled by default.
To enable only some features, use the default-features option
in your dependency declaration:
[dependencies.balanced-ternary]
version = "*.*"
default-features = false
# Choose which one to enable
features = ["ternary-string", "tryte", "ternary-store"]§Featureless
Without any feature, this library provide the type Digit and all its operations and the trait DigitOperate.
§ternary-string
Add the structure Ternary which is a vector of Digits and a lot of utilities to manipulate digits into the ternary number. Implements DigitOperate.
§tryte
Needs the feature
ternary-string.
Add the type Tryte<N> which is a fixed size copy-type ternary number. Implements DigitOperate.
§ternary-store
Needs the feature
ternary-string.
Add structures to store ternaries efficiently. These types are provided:
- DataTernary: a variable length ternary number stored into TritsChunks,
- TritsChunk: a fixed size copy-type 5 digits stored into one byte,
- Ter40: a fixed size copy-type 40 digits stored into one 64 bits integer. Implements DigitOperate.
Re-exports§
pub use crate::digit::Digit::Neg;pub use crate::digit::Digit::Pos;pub use crate::digit::Digit::Zero;
Modules§
Structs§
- Data
Ternary - Offers a compact structure to store a ternary number.
- Parse
Ternary Error - Error returned when parsing a string into a
Ternaryfails. - Ter40
- A struct to store 40 ternary digits (~63.398 bits) value into one
i64. - Ternary
- Represents a balanced ternary number using a sequence of
Digits. - Trits
Chunk - A struct to store 5 ternary digits (~7.8 bits) value into one byte.
- Tryte
- The
Tryte<S>struct represents a Copy type balanced ternary number with exactly S digits (6 by default). Each digit in a balanced ternary system can have one of three values: -1, 0, or 1.
Enums§
- Digit
- Module: Balanced Ternary
Digit
Functions§
- dter
- Creates a
DataTernaryobject from a string representation of a balanced ternary number. - ter
- Converts a string representation of a balanced ternary number into a
Ternaryobject. - trit
- Converts a character into a
Digit. - tryte
- Creates a
Tryteobject from a string representation of a balanced ternary number. It contains approximately 9.5 bits of information.