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.ObjectA builder to build the AhoCorasickDoubleArrayTrie
-
-
Field Summary
Fields Modifier and Type Field Description private intallocSizethe allocSize of the dynamic arrayprivate intkeySizethe size of the key-pair setsprivate intnextCheckPosthe next position to check unused memoryprivate intprogressa parameter controls the memory growth speed of the dynamic arrayprivate StaterootStatethe root state of trieprivate boolean[]usedwhether the position has been used
-
Constructor Summary
Constructors Modifier Constructor Description privateBuilder()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private voidaddAllKeyword(java.util.Collection<java.lang.String> keywordSet)add a collection of keywordsprivate voidaddKeyword(java.lang.String keyword, int index)add a keywordvoidbuild(java.util.Map<java.lang.String,V> map)Build from a mapprivate voidbuildDoubleArrayTrie(int keySize)private voidconstructFailureStates()construct failure tableprivate voidconstructOutput(State targetState)construct output tableprivate intfetch(State parent, java.util.List<java.util.Map.Entry<java.lang.Integer,State>> siblings)fetch siblings of a parent nodeprivate intinsert(java.util.List<java.util.Map.Entry<java.lang.Integer,State>> siblings)insert the siblings to double array trieprivate voidloseWeight()free the unnecessary memoryprivate intresize(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
-
-