Esempio n. 1
0
  public Set<StringSuffix> matchString(String str) {
    char[] array = str.toCharArray();
    EdgeMatch m = findEdge(root, array, 0, array.length, false);

    if (m.completedMatch()) {
      return collectSuffixes(m.lastEdge.tailNode);
    } else {
      return new TreeSet<StringSuffix>();
    }
  }
Esempio n. 2
0
  private void naiveExtendSuffix(TreeString string, int start) {
    EdgeMatch em = findEdge(root, string, start, string.length(), false);
    StringSuffix stringSuffix = new StringSuffix(string, start);

    TreeEdge leafEdge = null;
    if (em.completedMatch()) {
      leafEdge = em.lastEdge;
    } else {
      if (em.lastEdge == null) {
        leafEdge = new TreeEdge(string, start, string.length(), root);
        root.addEdge(leafEdge);
      } else {
        leafEdge = new TreeEdge(string, em.matchedTo, string.length(), em.lastEdge.tailNode);
        if (em.inEdgeMiddle()) {
          int offset = em.lastMatchLength();
          em.lastEdge.split(offset);
        }
        em.lastEdge.tailNode.addEdge(leafEdge);
      }
    }

    leafEdge.tailNode.suffixes.add(stringSuffix);
  }