Which data structures are supported in FQL?

As far as I know, Fauna provides Array and Object. I am going to port some data-logic to FQL, probably with a suffix tree for better performance. I suppose it should be possible to reimplement the suffix tree in FQL, am I correct?

Hi @Daniel_Steigerwald,

May you provide us with an example of what’s your goal?

Luigi

Here is non-functional code. I believe it should be possible to rewrite it to FQL, but I am not sure.

class Node {
  value: string;
  leaves: string[];
  nodes: Node[];

  constructor() {
    this.value = '';
    this.leaves = [];
    this.nodes = [];
  }

  addSuffix(suf: string) {
    if (!suf.length) return;
    if (!this.checkNodes(suf)) this.checkLeaves(suf);
  }

  checkLeaves(suf: string) {
    for (let i = 0; i < this.leaves.length; i++) {
      const leaf = this.leaves[i];
      if (leaf[0] === suf[0]) {
        const node = new Node();
        node.value = leaf[0];
        node.addSuffix(suf.slice(1));
        node.addSuffix(leaf.slice(1));
        this.nodes.push(node);
        this.leaves.splice(i, 1);
        return;
      }
    }
    this.leaves.push(suf);
  }

  checkNodes(suf: string) {
    for (const node of this.nodes)
      if (node.value === suf[0]) {
        node.addSuffix(suf.slice(1));
        return true;
      }
    return false;
  }

  getLongestRepeatedSubString() {
    let str = '';
    for (let i = 0; i < this.nodes.length; i++) {
      const temp = this.nodes[i].getLongestRepeatedSubString();
      if (temp.length > str.length) {
        str = temp;
      }
    }
    return this.value + str;
  }
}

const str = 'dfkjdh lkjdshf lkdh lakhdf lkaghfkafjhdgf k';
const node = new Node();
for (let i = 0; i < str.length; i++) {
  node.addSuffix(str.slice(i));
}
// 'dh l'
console.log(node.getLongestRepeatedSubString());

@ben I think you know the answer. Am I correct that FQL supports only Array?