public class DoubleArrayTrie<V> extends Object implements Serializable, ITrie<V>
| 限定符和类型 | 类和说明 |
|---|---|
class |
DoubleArrayTrie.LongestSearcher
一个最长搜索工具(注意,当调用next()返回false后不应该继续调用next(),除非reset状态)
|
class |
DoubleArrayTrie.Searcher
一个搜索工具(注意,当调用next()返回false后不应该继续调用next(),除非reset状态)
|
| 限定符和类型 | 字段和说明 |
|---|---|
protected int[] |
base |
protected int[] |
check |
protected int |
size
base 和 check 的大小
|
protected V[] |
v |
| 构造器和说明 |
|---|
DoubleArrayTrie() |
DoubleArrayTrie(TreeMap<String,V> buildFrom)
从TreeMap构造
|
| 限定符和类型 | 方法和说明 |
|---|---|
int |
build(List<String> _key,
int[] _length,
int[] _value,
int _keySize)
唯一的构建方法
|
int |
build(List<String> key,
List<V> value) |
int |
build(List<String> key,
V[] value) |
int |
build(Set<Map.Entry<String,V>> entrySet)
构建DAT
|
int |
build(TreeMap<String,V> keyValueMap)
方便地构造一个双数组trie树
|
List<Integer> |
commonPrefixSearch(String key) |
List<Integer> |
commonPrefixSearch(String key,
int pos,
int len,
int nodePos)
前缀查询
|
LinkedList<Map.Entry<String,V>> |
commonPrefixSearchWithValue(char[] keyChars,
int begin)
优化的前缀查询,可以复用字符数组
|
LinkedList<Map.Entry<String,V>> |
commonPrefixSearchWithValue(String key)
已过时。
最好用优化版的
|
boolean |
containsKey(String key) |
int |
exactMatchSearch(char[] keyChars,
int pos,
int len,
int nodePos)
精确查询
|
int |
exactMatchSearch(String key)
精确匹配
|
int |
exactMatchSearch(String key,
int pos,
int len,
int nodePos) |
V |
get(char[] key) |
V |
get(int index)
从值数组中提取下标为index的值
注意为了效率,此处不进行参数校验 |
V |
get(String key)
精确查询
|
int[] |
getBase()
获取base数组引用,不要修改base
|
int[] |
getCheck()
获取check数组引用,不要修改check
|
DoubleArrayTrie.LongestSearcher |
getLongestSearcher(char[] text,
int offset) |
DoubleArrayTrie.LongestSearcher |
getLongestSearcher(String text,
int offset) |
int |
getNonzeroSize() |
DoubleArrayTrie.Searcher |
getSearcher(char[] text,
int offset) |
DoubleArrayTrie.Searcher |
getSearcher(String text) |
DoubleArrayTrie.Searcher |
getSearcher(String text,
int offset) |
int |
getSize() |
int |
getTotalSize() |
int |
getUnitSize() |
V[] |
getValueArray(V[] a) |
V |
getValueAt(int index)
获取index对应的值
|
boolean |
load(byte[] bytes,
int offset,
V[] value)
从字节数组加载(发现在MacOS上,此方法比ByteArray更快)
|
boolean |
load(ByteArray byteArray,
V[] value) |
boolean |
load(String path)
载入双数组,但是不提供值,此时本trie相当于一个set
|
boolean |
load(String path,
List<V> value)
从磁盘加载,需要额外提供值
|
boolean |
load(String path,
V[] value)
从磁盘加载,需要额外提供值
|
void |
open(String fileName) |
V |
output(int state)
检查状态是否对应输出
|
boolean |
save(DataOutputStream out)
将base和check保存下来
|
void |
save(ObjectOutputStream out) |
boolean |
save(String fileName) |
boolean |
serializeTo(String path)
将自己序列化到
|
boolean |
set(String key,
V value)
更新某个键对应的值
|
int |
size()
树叶子节点个数
|
String |
toString() |
protected int |
transition(char[] path)
沿着节点转移状态
|
int |
transition(char c,
int from)
转移状态
|
protected int |
transition(int current,
char c)
转移状态
|
protected int |
transition(String path)
沿着路径转移状态
|
int |
transition(String path,
int from)
沿着路径转移状态
|
static <T> DoubleArrayTrie<T> |
unSerialize(String path) |
protected int[] check
protected int[] base
protected int size
protected V[] v
public int getUnitSize()
public int getSize()
public int getTotalSize()
public int getNonzeroSize()
public int build(Set<Map.Entry<String,V>> entrySet)
entrySet - 注意此entrySet一定要是字典序的!否则会失败public int build(List<String> _key, int[] _length, int[] _value, int _keySize)
_key - 值set,必须字典序_length - 对应每个key的长度,留空动态获取_value - 每个key对应的值,留空使用key的下标作为值_keySize - key的长度,应该设为_key.sizepublic void open(String fileName) throws IOException
IOExceptionpublic boolean save(String fileName)
public boolean save(DataOutputStream out)
public void save(ObjectOutputStream out) throws IOException
IOExceptionpublic boolean load(byte[] bytes,
int offset,
V[] value)
bytes - offset - value - public boolean load(String path)
path - public boolean serializeTo(String path)
path - public static <T> DoubleArrayTrie<T> unSerialize(String path)
public int exactMatchSearch(String key)
key - 键public int exactMatchSearch(String key, int pos, int len, int nodePos)
public int exactMatchSearch(char[] keyChars,
int pos,
int len,
int nodePos)
keyChars - 键的char数组pos - char数组的起始位置len - 键的长度nodePos - 开始查找的位置(本参数允许从非根节点查询)public List<Integer> commonPrefixSearch(String key, int pos, int len, int nodePos)
key - 查询字串pos - 字串的开始位置len - 字串长度nodePos - base中的开始位置public LinkedList<Map.Entry<String,V>> commonPrefixSearchWithValue(String key)
key - 键public LinkedList<Map.Entry<String,V>> commonPrefixSearchWithValue(char[] keyChars, int begin)
keyChars - begin - public int[] getCheck()
public int[] getBase()
public V getValueAt(int index)
index - public V[] getValueArray(V[] a)
getValueArray 在接口中 ITrie<V>public boolean containsKey(String key)
containsKey 在接口中 ITrie<V>protected int transition(String path)
path - protected int transition(char[] path)
path - public int transition(String path, int from)
path - 路径from - 起点(根起点为base[0]=1)public int transition(char c,
int from)
c - from - public V output(int state)
state - 双数组下标public DoubleArrayTrie.Searcher getSearcher(String text)
public DoubleArrayTrie.Searcher getSearcher(String text, int offset)
public DoubleArrayTrie.Searcher getSearcher(char[] text, int offset)
public DoubleArrayTrie.LongestSearcher getLongestSearcher(String text, int offset)
public DoubleArrayTrie.LongestSearcher getLongestSearcher(char[] text, int offset)
protected int transition(int current,
char c)
current - c - public V get(int index)
index - 下标Copyright © 2014–2018 码农场. All rights reserved.