Class AhoCorasickDoubleArrayTrie.Builder

java.lang.Object
com.hankcs.algorithm.AhoCorasickDoubleArrayTrie.Builder
Enclosing class:
AhoCorasickDoubleArrayTrie<V>

private class AhoCorasickDoubleArrayTrie.Builder extends Object
A builder to build the AhoCorasickDoubleArrayTrie
  • Field Details

    • rootState

      private State rootState
      the root state of trie
    • used

      private boolean[] used
      whether the position has been used
    • allocSize

      private int allocSize
      the allocSize of the dynamic array
    • progress

      private int progress
      a parameter controls the memory growth speed of the dynamic array
    • nextCheckPos

      private int nextCheckPos
      the next position to check unused memory
    • keySize

      private int keySize
      the size of the key-pair sets
  • Constructor Details

    • Builder

      private Builder()
  • Method Details

    • build

      public void build(Map<String,V> map)
      Build from a map
      Parameters:
      map - a map containing key-value pairs
    • fetch

      private int fetch(State parent, List<Map.Entry<Integer,State>> siblings)
      fetch siblings of a parent node
      Parameters:
      parent - parent node
      siblings - parent node's child nodes, i . e . the siblings
      Returns:
      the amount of the siblings
    • addKeyword

      private void addKeyword(String keyword, int index)
      add a keyword
      Parameters:
      keyword - a keyword
      index - the index of the keyword
    • addAllKeyword

      private void addAllKeyword(Collection<String> keywordSet)
      add a collection of keywords
      Parameters:
      keywordSet - the collection holding keywords
    • constructFailureStates

      private void constructFailureStates()
      construct failure table
    • constructOutput

      private void constructOutput(State targetState)
      construct output table
    • buildDoubleArrayTrie

      private void buildDoubleArrayTrie(int keySize)
    • resize

      private int resize(int newSize)
      allocate the memory of the dynamic array
      Parameters:
      newSize -
      Returns:
    • insert

      private int insert(List<Map.Entry<Integer,State>> siblings)
      insert the siblings to double array trie
      Parameters:
      siblings - the siblings being inserted
      Returns:
      the position to insert them
    • loseWeight

      private void loseWeight()
      free the unnecessary memory