Search in sources :

Example 21 with ByteArray

use of com.hankcs.hanlp.corpus.io.ByteArray in project HanLP by hankcs.

the class BinTrie method load.

/**
     * 从磁盘加载二分数组树
     *
     * @param path  路径
     * @param value 额外提供的值数组,按照值的字典序。(之所以要求提供它,是因为泛型的保存不归树管理)
     * @return 是否成功
     */
public boolean load(String path, V[] value) {
    byte[] bytes = IOUtil.readBytes(path);
    if (bytes == null)
        return false;
    _ValueArray valueArray = new _ValueArray(value);
    ByteArray byteArray = new ByteArray(bytes);
    for (int i = 0; i < child.length; ++i) {
        int flag = byteArray.nextInt();
        if (flag == 1) {
            child[i] = new Node<V>();
            child[i].walkToLoad(byteArray, valueArray);
        }
    }
    size = value.length;
    return true;
}
Also used : ByteArray(com.hankcs.hanlp.corpus.io.ByteArray)

Aggregations

ByteArray (com.hankcs.hanlp.corpus.io.ByteArray)21 DataOutputStream (java.io.DataOutputStream)5 FileOutputStream (java.io.FileOutputStream)5 Nature (com.hankcs.hanlp.corpus.tag.Nature)2 DoubleArrayTrie (com.hankcs.hanlp.collection.trie.DoubleArrayTrie)1 LinkedList (java.util.LinkedList)1