Staquia API
    Preparing search index...

    Class Digits

    The default class of the numbers: the digits of a number in the base of a system, stored by key. The key is the power of the base, so a higher key is a more significant digit: the base 10 number 123 is 1 at the key 2, 2 at the key 1 and 3 at the key 0. Negative keys are the digits after the point.

    The systems create and initialize their numbers, you get them from a position with digits(). Extend it to replace the numbers of a system, see IStaquiaOptions.

    import Staquia from "staquia";

    const system = Staquia.create("!", "a", "z", 5, 15, 0.15);

    const next = system.next(system.start()); // "mmmmn!"
    if (next.ok) {
    const digits = next.value.digits();
    console.log(digits.upperBound, digits.lowerBound); // 4 -1
    console.log(digits.get(4), digits.get(0)); // 13 14, "m" and "n"
    }

    Implements

    Index

    Constructors

    Properties

    _map: Map<number, number>

    The digits by key (the power of the base).

    clone: (this: IDigits) => IDigits = ...

    Creates a copy of this object in a new instance.

    compact: (this: IDigits) => void = compact

    Removes the zeroes from the most significant side (the leading zeroes). A number of only zeroes keeps a single 0.

    compare: (this: IDigits, other: IDigits) => Ordering = compare

    Compares this with other, like a sort comparator.

    Type Declaration

      • (this: IDigits, other: IDigits): Ordering
      • Parameters

        Returns Ordering

        "less" if this goes before other, "equal" if they have the same value, "greater" if it goes after.

    import Staquia from "staquia";

    const system = Staquia.create("!", "a", "z", 5, 15, 0.15);
    const a = system.forge("mmmmm!m");
    const b = system.forge("mmmmn");

    if (a.ok && b.ok) console.log(a.value.compare(b.value)); // "less"
    equal: (this: IDigits, other: IDigits) => boolean = equal

    Checks if this and other have the same value.

    Type Declaration

      • (this: IDigits, other: IDigits): boolean
      • Parameters

        Returns boolean

        true if both have the same value.

    import Staquia from "staquia";

    const system = Staquia.create("!", "a", "z", 5, 15, 0.15);
    const a = system.forge("mmmmm");
    const b = system.forge("mmmmm!");

    // Zeroes to the right don't change the value
    if (a.ok && b.ok) console.log(a.value.equal(b.value)); // true
    expand: (this: IDigits, size: number) => void = expand

    Adds zeroes above the most significant digit (on the left of the number).

    Type Declaration

      • (this: IDigits, size: number): void
      • Parameters

        • this: IDigits
        • size: number

          How many zeroes to add.

        Returns void

    extend: (this: IDigits, size: number) => void = extend

    Shifts the digits up and adds zeroes at the lowest keys (on the right of the number), like multiplying it by base ^ size.

    Type Declaration

      • (this: IDigits, size: number): void
      • Parameters

        • this: IDigits
        • size: number

          How many zeroes to add.

        Returns void

    get: (this: IDigits, key: number) => number = getDigit

    Gets the digit at a key, 0 if there is none.

    Type Declaration

      • (this: IDigits, key: number): number
      • Parameters

        • this: IDigits
        • key: number

          The key of the digit.

        Returns number

    greater: (this: IDigits, other: IDigits) => boolean = greater

    Checks if this goes after other.

    Type Declaration

      • (this: IDigits, other: IDigits): boolean
      • Parameters

        • this: IDigits

          The left side of the comparison.

        • other: IDigits

          The right side of the comparison.

        Returns boolean

        true if this > other.

    greaterOrEqual: (this: IDigits, other: IDigits) => boolean = greaterOrEqual

    Checks if this goes after other or has the same value.

    Type Declaration

      • (this: IDigits, other: IDigits): boolean
      • Parameters

        • this: IDigits

          The left side of the comparison.

        • other: IDigits

          The right side of the comparison.

        Returns boolean

        true if this >= other.

    isEmpty: (this: IDigits) => boolean = isEmpty

    Checks if the number has no digit set at all: nothing at the key 0 and both bounds 0.

    isKeyZero: (this: IDigits, key: number) => boolean = isKeyZero

    Checks if the digit at a key is 0 (or missing).

    Type Declaration

      • (this: IDigits, key: number): boolean
      • Parameters

        • this: IDigits
        • key: number

          The key of the digit.

        Returns boolean

    isZero: (this: IDigits) => boolean = isZero

    Checks if the number is a single 0: both bounds are 0 and the digit at the key 0 is 0 or missing.

    less: (this: IDigits, other: IDigits) => boolean = less

    Checks if this goes before other.

    Type Declaration

      • (this: IDigits, other: IDigits): boolean
      • Parameters

        • this: IDigits

          The left side of the comparison.

        • other: IDigits

          The right side of the comparison.

        Returns boolean

        true if this < other.

    import Staquia from "staquia";

    const system = Staquia.create("!", "a", "z", 5, 15, 0.15);
    const a = system.forge("mmmmm!m");
    const b = system.forge("mmmmn");

    if (a.ok && b.ok) {
    console.log(a.value.less(b.value)); // true
    console.log(a.value.greater(b.value)); // false
    }
    lessOrEqual: (this: IDigits, other: IDigits) => boolean = lessOrEqual

    Checks if this goes before other or has the same value.

    Type Declaration

      • (this: IDigits, other: IDigits): boolean
      • Parameters

        • this: IDigits

          The left side of the comparison.

        • other: IDigits

          The right side of the comparison.

        Returns boolean

        true if this <= other.

    lowerBound: number

    The key of the least significant digit.

    pop: (this: IDigits) => void = pop

    Removes the most significant digit.

    reference: (this: IDigits, reference: IDigits) => void = reference

    Moves the digits and bounds of another number into this one, without copying them. The other number is left without digits and must not be used after it.

    remove: (this: IDigits, key: number) => boolean = remove

    Removes the digit at a key.

    Type Declaration

      • (this: IDigits, key: number): boolean
      • Parameters

        • this: IDigits
        • key: number

          The key of the digit.

        Returns boolean

        true if there was a digit to remove, false otherwise.

    set: (this: IDigits, key: number, value: number) => void = setDigit

    Sets the digit at a key.

    Type Declaration

      • (this: IDigits, key: number, value: number): void
      • Parameters

        • this: IDigits
        • key: number

          The key of the digit.

        • value: number

          The digit.

        Returns void

    stack: (this: IDigits, other: IDigits) => void = stack

    Adds the digits of another number above the most significant digit of this one.

    Type Declaration

    update: (this: IDigits, key: number, offset: number) => void = update

    Adds an offset to the digit at a key. It doesn't carry: resolveOverflow does.

    Type Declaration

      • (this: IDigits, key: number, offset: number): void
      • Parameters

        • this: IDigits
        • key: number

          The key of the digit.

        • offset: number

          The value to add (negative to subtract).

        Returns void

    upperBound: number

    The key of the most significant digit.