Staquia API
    Preparing search index...

    Interface IPosition

    A position: the place of an item in a list, created by a Staquia system.

    It has two sections, printed one after the other:

    • N, with a fixed length (ln): it moves up and down to stack items at the start or the end.
    • Z, with a flexible length (up to lz): it grows when an item is placed between two others.

    A position only contains data and keeps no reference to its system. Store it as a string (toString()) and recreate it with system.forge(string).

    import Staquia from "staquia";

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

    const position = system.forge("mmmmm!m");
    if (position.ok) {
    console.log(position.value.toString()); // "mmmmm!m", N = "mmmmm" and Z = "!m"
    console.log(position.value.length); // 7
    }
    interface IPosition {
        length: number;
        n: IDigits;
        z: IDigits;
        compare(other: IPosition): Ordering;
        digits(): IDigits;
        equal(other: IPosition): boolean;
        greater(this: IPosition, other: IPosition): boolean;
        greaterOrEqual(this: IPosition, other: IPosition): boolean;
        less(this: IPosition, other: IPosition): boolean;
        lessOrEqual(this: IPosition, other: IPosition): boolean;
        toString(): string;
    }

    Hierarchy (View Summary)

    Implemented by

    Index

    Properties

    length: number

    The length measured when the position was created (N plus Z), the one the threshold and the max length are compared with. It doesn't count the zeroes that complete the string: "mmmmm!" created by start has 5, "ab!!!!" forged from "ab" has 2.

    The digits of the N section.

    The digits of the Z section.

    Methods

    • Compares this with other, like a sort comparator.

      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"
    • Gets all the digits of the position in a single number: N as the integer part and Z below it. It is used to compare positions, and system.from creates a position back from it.

      Returns IDigits

    • Checks if this and other have the same value.

      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
    • Checks if this goes before other.

      Parameters

      • this: IPosition

        The left side of the comparison.

      • other: IPosition

        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
      }
    • Builds the string of the position with the characters of the system that created it. This is the value to store and to sort by.

      Returns string

      import Staquia from "staquia";

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

      const next = system.next(system.start());
      if (next.ok) {
      console.log(next.value.toString()); // "mmmmn!"
      console.log(`${next.value}`); // "mmmmn!", also in templates and String()
      }