Class AhoCorasickDoubleArrayTrie.Builder

  • Enclosing class:
    AhoCorasickDoubleArrayTrie<V>

    private class AhoCorasickDoubleArrayTrie.Builder
    extends java.lang.Object
    A builder to build the AhoCorasickDoubleArrayTrie
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private int allocSize
      the allocSize of the dynamic array
      private int keySize
      the size of the key-pair sets
      private int nextCheckPos
      the next position to check unused memory
      private int progress
      a parameter controls the memory growth speed of the dynamic array
      private State rootState
      the root state of trie
      private boolean[] used
      whether the position has been used
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private Builder()  
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private void addAllKeyword​(java.util.Collection<java.lang.String> keywordSet)
      add a collection of keywords
      private void addKeyword​(java.lang.String keyword, int index)
      add a keyword
      void build​(java.util.Map<java.lang.String,​V> map)
      Build from a map
      private void buildDoubleArrayTrie​(int keySize)  
      private void constructFailureStates()
      construct failure table
      private void constructOutput​(State targetState)
      construct output table
      private int fetch​(State parent, java.util.List<java.util.Map.Entry<java.lang.Integer,​State>> siblings)
      fetch siblings of a parent node
      private int insert​(java.util.List<java.util.Map.Entry<java.lang.Integer,​State>> siblings)
      insert the siblings to double array trie
      private void loseWeight()
      free the unnecessary memory
      private int resize​(int newSize)
      allocate the memory of the dynamic array
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • 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 Detail

      • Builder

        private Builder()
    • Method Detail

      • build

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

        private int fetch​(State parent,
                          java.util.List<java.util.Map.Entry<java.lang.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​(java.lang.String keyword,
                                int index)
        add a keyword
        Parameters:
        keyword - a keyword
        index - the index of the keyword
      • addAllKeyword

        private void addAllKeyword​(java.util.Collection<java.lang.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​(java.util.List<java.util.Map.Entry<java.lang.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