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 int
the allocSize of the dynamic arrayprivate int
the size of the key-pair setsprivate int
the next position to check unused memoryprivate int
a parameter controls the memory growth speed of the dynamic arrayprivate State
the root state of trieprivate boolean[]
whether the position has been used -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate void
addAllKeyword
(Collection<String> keywordSet) add a collection of keywordsprivate void
addKeyword
(String keyword, int index) add a keywordvoid
Build from a mapprivate void
buildDoubleArrayTrie
(int keySize) private void
construct failure tableprivate void
constructOutput
(State targetState) construct output tableprivate int
fetch siblings of a parent nodeprivate int
insert the siblings to double array trieprivate void
free the unnecessary memoryprivate int
resize
(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
-