Package com.hankcs.algorithm
Class AhoCorasickDoubleArrayTrie.Builder
java.lang.Object
com.hankcs.algorithm.AhoCorasickDoubleArrayTrie.Builder
- Enclosing class:
AhoCorasickDoubleArrayTrie<V>
A builder to build the AhoCorasickDoubleArrayTrie
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate intthe allocSize of the dynamic arrayprivate intthe size of the key-pair setsprivate intthe next position to check unused memoryprivate inta parameter controls the memory growth speed of the dynamic arrayprivate Statethe root state of trieprivate boolean[]whether the position has been used -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate voidaddAllKeyword(Collection<String> keywordSet) add a collection of keywordsprivate voidaddKeyword(String keyword, int index) add a keywordvoidBuild from a mapprivate voidbuildDoubleArrayTrie(int keySize) private voidconstruct failure tableprivate voidconstructOutput(State targetState) construct output tableprivate intfetch siblings of a parent nodeprivate intinsert the siblings to double array trieprivate voidfree the unnecessary memoryprivate intresize(int newSize) allocate the memory of the dynamic array
-
Field Details
-
rootState
the root state of trie -
used
private boolean[] usedwhether the position has been used -
allocSize
private int allocSizethe allocSize of the dynamic array -
progress
private int progressa parameter controls the memory growth speed of the dynamic array -
nextCheckPos
private int nextCheckPosthe next position to check unused memory -
keySize
private int keySizethe size of the key-pair sets
-
-
Constructor Details
-
Builder
private Builder()
-
-
Method Details
-
build
Build from a map- Parameters:
map- a map containing key-value pairs
-
fetch
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
add a keyword- Parameters:
keyword- a keywordindex- the index of the keyword
-
addAllKeyword
add a collection of keywords- Parameters:
keywordSet- the collection holding keywords
-
constructFailureStates
private void constructFailureStates()construct failure table -
constructOutput
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
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
-