Package com.hankcs.algorithm
Class AhoCorasickDoubleArrayTrie.Builder
- java.lang.Object
-
- com.hankcs.algorithm.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 arrayprivate int
keySize
the size of the key-pair setsprivate int
nextCheckPos
the next position to check unused memoryprivate int
progress
a parameter controls the memory growth speed of the dynamic arrayprivate State
rootState
the root state of trieprivate 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 keywordsprivate void
addKeyword(java.lang.String keyword, int index)
add a keywordvoid
build(java.util.Map<java.lang.String,V> map)
Build from a mapprivate void
buildDoubleArrayTrie(int keySize)
private void
constructFailureStates()
construct failure tableprivate void
constructOutput(State targetState)
construct output tableprivate int
fetch(State parent, java.util.List<java.util.Map.Entry<java.lang.Integer,State>> siblings)
fetch siblings of a parent nodeprivate int
insert(java.util.List<java.util.Map.Entry<java.lang.Integer,State>> siblings)
insert the siblings to double array trieprivate void
loseWeight()
free the unnecessary memoryprivate int
resize(int newSize)
allocate the memory of the dynamic array
-
-
-
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
-
-
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 nodesiblings
- 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 keywordindex
- 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
-
-