sclass SuffixTree { Node root; S fullText; sclass Node { Substring text; Set children = new TreeSet<>((a, b) -> cmp(a.text, b.text)); Set positions; *() {} *(Substring *text, Set *positions) {} } *() {} *(S *fullText) { root = new Node(Substring(fullText, 0, 0), new Set); for i over fullText: addSuffix(Substring(fullText, i), i); } void addSuffix(Substring s, int position) { Node node = root; while (!empty(s)) { int n = lCommonPrefix(node.text, s); if (n >= l(node.text)) { } } } public L indicesOf(S pattern) { new IntBuffer out; getIndicesOf(out, root, pattern, 0); ret out.asVirtualList(); } void getIndicesOf(IntBuffer out, Node node, S pattern, int iPattern) { if (iPattern >= l(pattern)) collectPositions(out, node); else { // TODO } } L getPositions(Node node) { new IntBuffer out; collectPositions(out, node); ret out.asVirtualList(); } void collectPositions(IntBuffer out, Node node) { if (node == null) ret; addAll(out, node.positions); fOr (Node n : node.children) collectPositions(out, n); } }