以下方法用于纯分词模型
分词、词性标注联合模型则直接重载segSentence
769757
@Override
    protected List<Term> segSentence(char[] sentence)
    {
        if (sentence.length == 0) return Collections.emptyList();
        List<Term> termList = roughSegSentence(sentence);
        if (!(config.ner || config.useCustomDictionary || config.speechTagging))
            return termList;
        List<Vertex> vertexList = toVertexList(termList, true);
        if (config.speechTagging)
        {
            Viterbi.compute(vertexList, CoreDictionaryTransformMatrixDictionary.transformMatrixDictionary);
            int i = 0;
            for (Term term : termList)
            {
                if (term.nature != null) term.nature = vertexList.get(i + 1).guessNature();
                ++i;
            }
        }
        if (config.useCustomDictionary)
        {
            combineByCustomDictionary(vertexList);
            termList = convert(vertexList, config.offset);
        }
        return termList;
    }
1165842
private List<Word>[] fullSeg(String text){
        //文本长度
        final int textLen = text.length();
        //以每一个字作为词的开始，所能切分的词
        final List<String>[] sequence = new LinkedList[textLen];
        if(isParallelSeg()){
            //并行化
            List<Integer> list = new ArrayList<>(textLen);
            for(int i=0; i<textLen; i++){
                list.add(i);
            }
            list.parallelStream().forEach(i->sequence[i] = fullSeg(text, i));
        }else {
            //串行化
            for (int i = 0; i < textLen; i++) {
                sequence[i] = fullSeg(text, i);
            }
        }
        if(LOGGER.isDebugEnabled()){
            LOGGER.debug("全切分中间结果：");
            int i=1;
            for(List<String> list : sequence){
                LOGGER.debug("\t"+(i++)+"、"+list);
            }
        }
        //树叶
        List<Node> leaf = new LinkedList<>();
        for(String word : sequence[0]){
            //树根
            Node node = new Node(word);
            //把全切分中间结果（二维数组）转换为合理切分
            buildNode(node, sequence, word.length(), leaf);
        }
        //清理无用数据
        for(int j=0; j<sequence.length; j++){
            sequence[j].clear();
            sequence[j] = null;
        }
        //从所有树叶开始反向遍历出全切分结果
        List<Word>[] res = toWords(leaf);
        leaf.clear();
        return res;
    }
15822
public List<Word> segDefault(String text) {
        List<String> sentences = Punctuation.seg(text, KEEP_PUNCTUATION);
        if(sentences.size() == 1){
            return segSentence(sentences.get(0));
        }
        if(!PARALLEL_SEG){
            //串行顺序处理，不能利用多核优势
            return sentences.stream().flatMap(sentence->segSentence(sentence).stream()).collect(Collectors.toList());
        }
        //如果是多个句子，可以利用多核提升分词速度
        Map<Integer, String> sentenceMap = new HashMap<>();
        int len = sentences.size();
        for(int i=0; i<len; i++){
            //记住句子的先后顺序，因为后面的parallelStream方法不保证顺序
            sentenceMap.put(i, sentences.get(i));
        }
        //用数组收集句子分词结果
        List<Word>[] results = new List[sentences.size()];
        sentenceMap.entrySet().stream().forEach(entry -> {
            int index = entry.getKey();
            String sentence = entry.getValue();
            results[index] = segSentence(sentence);
        });
        sentences.clear();
        sentences = null;
        sentenceMap.clear();
        sentenceMap = null;
        List<Word> resultList = new ArrayList<>();
        for(List<Word> result : results){
            if(result == null || result.isEmpty()){
                continue;
            }
            resultList.addAll(result);
        }
        return resultList;
    }
1183327
public List<Term> seg(char[] text)
    {
        assert text != null;
        if (HanLP.Config.Normalization)
        {
            CharTable.normalization(text);
        }
        return segSentence(text);
    }
429577
private List<Word> segSentence(final String sentence){
        if(sentence.length() == 1){
            if(KEEP_WHITESPACE){
                List<Word> result = new ArrayList<>(1);
                result.add(new Word(KEEP_CASE ? sentence : sentence.toLowerCase()));
                return result;
            }else{
                if(!Character.isWhitespace(sentence.charAt(0))){
                    List<Word> result = new ArrayList<>(1);
                    result.add(new Word(KEEP_CASE ? sentence : sentence.toLowerCase()));
                    return result;
                }
            }
        }
        if(sentence.length() > 1){
            List<Word> list = segImpl(sentence);
            if(list != null){
                if(PERSON_NAME_RECOGNIZE){
                    list = PersonName.recognize(list);
                }
                return list;
            }else{
                LOGGER.error("文本 "+sentence+" 没有获得分词结果");
            }
        }
        return Collections.emptyList();
    }
1049989
function(param) {
      var step, start, res;
      //如果无参数 当成是获取第一个元素
      if (!param || !(param = param.replace(/\s+/g, ""))) {
        return {
          start: 1,
          step: 0
        };
      }
      if (res = nthCache.get(param)) return res;
      // 对even odd等转化为标准的a，b组合(即step与start)
      if (param == "even") {
        start = 2;
        step = 2;
      } else if (param == "odd") {
        step = 2;
        start = 1;
      } else {
        res = param.match(nthValueReg);
        // 对错误的nth参数抛出错误
        if (!res) step = null; // 无论其他参数，如果step为null，则永远为false
        else {
          if (res[1]) {
            step = 0;
            start = parseInt(res[1]);
          } else {
            if (res[2] == "-") res[2] = "-1";
            step = res[2] ? parseInt(res[2]) : 1;
            start = res[3] ? parseInt(res[3]) : 0;
          }
        }
      }
      if (start < 1) {
        if (step < 1) {
          step = null; //标志false
        } else {
          start = -(-start) % step + step;
        }
      }
      return nthCache.set(param, {
        start: start,
        step: step
      });
    }
992882
public static void multPlusTransA(int blockLength ,
                                      DSubmatrixD1 A , DSubmatrixD1 B ,
                                      DSubmatrixD1 C )
    {
        int heightA = Math.min( blockLength , A.row1 - A.row0 );

        for( int i = C.row0+blockLength; i < C.row1; i += blockLength ) {
            int heightC = Math.min( blockLength , C.row1 - i );

            int indexA = A.row0*A.original.numCols + (i-C.row0+A.col0)*heightA;

            for( int j = i; j < C.col1; j += blockLength ) {
                int widthC = Math.min( blockLength , C.col1 - j );

                int indexC = i*C.original.numCols + j*heightC;
                int indexB = B.row0*B.original.numCols + (j-C.col0+B.col0)*heightA;

                blockMultPlusTransA(A.original.data,B.original.data,C.original.data,
                            indexA,indexB,indexC,heightA,heightC,widthC);
            }
        }
    }
1020087
@Override
    public void recognition(Term[] terms) {
        int length = terms.length - 1;
        Term from = null;
        Term to = null;
        Term temp = null;
        for (int i = 0; i < length; i++) {
            if (terms[i] == null) {
                continue;
            } else if (".".equals(terms[i].getName()) || "．".equals(terms[i].getName())) {
                // 如果是.前后都为数字进行特殊处理
                to = terms[i].to();
                from = terms[i].from();
                if (from.termNatures().numAttr.flag && to.termNatures().numAttr.flag) {
                    from.setName(from.getName() + "." + to.getName());
                    TermUtil.termLink(from, to.to());
                    terms[to.getOffe()] = null;
                    terms[i] = null;
                    i = from.getOffe() - 1;
                }
                continue;
            } else if (!terms[i].termNatures().numAttr.flag) {
                continue;
            }

            temp = terms[i];
            // 将所有的数字合并
            while ((temp = temp.to()).termNatures().numAttr.flag) {
                terms[i].setName(terms[i].getName() + temp.getName());
            }
            // 如果是数字结尾
            if (MyStaticValue.isQuantifierRecognition && temp.termNatures().numAttr.numEndFreq > 0) {
                terms[i].setName(terms[i].getName() + temp.getName());
                temp = temp.to();
            }

            // 如果不等,说明terms[i]发生了改变
            if (terms[i].to() != temp) {
                TermUtil.termLink(terms[i], temp);
                // 将中间无用元素设置为null
                for (int j = i + 1; j < temp.getOffe(); j++) {
                    terms[j] = null;
                }
                i = temp.getOffe() - 1;
            }
        }

    }
1270443
public static void seg(File input, File output, SegmentationAlgorithm segmentationAlgorithm) throws Exception{
        Utils.seg(input, output, true, segmentationAlgorithm);
    }
1069207
public List<Term> seg(String text)
    {
        char[] charArray = text.toCharArray();
        if (HanLP.Config.Normalization)
        {
            CharTable.normalization(charArray);
        }
        if (config.threadNumber > 1 && charArray.length > 10000)    // 小文本多线程没意义，反而变慢了
        {
            List<String> sentenceList = SentencesUtil.toSentenceList(charArray);
            String[] sentenceArray = new String[sentenceList.size()];
            sentenceList.toArray(sentenceArray);
            //noinspection unchecked
            List<Term>[] termListArray = new List[sentenceArray.length];
            final int per = sentenceArray.length / config.threadNumber;
            WorkThread[] threadArray = new WorkThread[config.threadNumber];
            for (int i = 0; i < config.threadNumber - 1; ++i)
            {
                int from = i * per;
                threadArray[i] = new WorkThread(sentenceArray, termListArray, from, from + per);
                threadArray[i].start();
            }
            threadArray[config.threadNumber - 1] = new WorkThread(sentenceArray, termListArray, (config.threadNumber - 1) * per, sentenceArray.length);
            threadArray[config.threadNumber - 1].start();
            try
            {
                for (WorkThread thread : threadArray)
                {
                    thread.join();
                }
            }
            catch (InterruptedException e)
            {
                logger.severe("线程同步异常：" + TextUtility.exceptionToString(e));
                return Collections.emptyList();
            }
            List<Term> termList = new LinkedList<Term>();
            if (config.offset || config.indexMode > 0)  // 由于分割了句子，所以需要重新校正offset
            {
                int sentenceOffset = 0;
                for (int i = 0; i < sentenceArray.length; ++i)
                {
                    for (Term term : termListArray[i])
                    {
                        term.offset += sentenceOffset;
                        termList.add(term);
                    }
                    sentenceOffset += sentenceArray[i].length();
                }
            }
            else
            {
                for (List<Term> list : termListArray)
                {
                    termList.addAll(list);
                }
            }

            return termList;
        }
//        if (text.length() > 10000)  // 针对大文本，先拆成句子，后分词，避免内存峰值太大
//        {
//            List<Term> termList = new LinkedList<Term>();
//            if (config.offset || config.indexMode)
//            {
//                int sentenceOffset = 0;
//                for (String sentence : SentencesUtil.toSentenceList(charArray))
//                {
//                    List<Term> termOfSentence = segSentence(sentence.toCharArray());
//                    for (Term term : termOfSentence)
//                    {
//                        term.offset += sentenceOffset;
//                        termList.add(term);
//                    }
//                    sentenceOffset += sentence.length();
//                }
//            }
//            else
//            {
//                for (String sentence : SentencesUtil.toSentenceList(charArray))
//                {
//                    termList.addAll(segSentence(sentence.toCharArray()));
//                }
//            }
//
//            return termList;
//        }
        return segSentence(charArray);
    }
684641
function(uid, sid, group) {
  if(!uid || !sid || !group) {
    return false;
  }

  for(let i=0, l=group.length; i<l; i++) {
    if(group[i] === uid) {
      group.splice(i, 1);
      return true;
    }
  }

  return false;
}
1006136
private void ssSwapMerge(int PA, int first, int middle, int last, int buf,
                             int bufsize, int depth) {
        // Pa, first, middle, last and buf - pointers in SA array

        final int STACK_SIZE = SS_SMERGE_STACKSIZE;
        StackElement[] stack = new StackElement[STACK_SIZE];
        int l, r, lm, rm;// pointers in SA
        int m, len, half;
        int ssize;
        int check, next;

        for (check = 0, ssize = 0; ; ) {

            if ((last - middle) <= bufsize) {
                if ((first < middle) && (middle < last)) {
                    ssMergeBackward(PA, first, middle, last, buf, depth);
                }
                if (((check & 1) != 0)
                    || (((check & 2) != 0) && (ssCompare(PA + getIDX(SA[first - 1]), PA
                    + SA[first], depth) == 0))) {
                    SA[first] = ~SA[first];
                }
                if (((check & 4) != 0)
                    && ((ssCompare(PA + getIDX(SA[last - 1]), PA + SA[last], depth) == 0))) {
                    SA[last] = ~SA[last];
                }

                if (ssize > 0) {
                    StackElement se = stack[--ssize];
                    first = se.a;
                    middle = se.b;
                    last = se.c;
                    check = se.d;
                } else {
                    return;
                }
                continue;
            }

            if ((middle - first) <= bufsize) {
                if (first < middle) {
                    ssMergeForward(PA, first, middle, last, buf, depth);
                }
                if (((check & 1) != 0)
                    || (((check & 2) != 0) && (ssCompare(PA + getIDX(SA[first - 1]), PA
                    + SA[first], depth) == 0))) {
                    SA[first] = ~SA[first];
                }
                if (((check & 4) != 0)
                    && ((ssCompare(PA + getIDX(SA[last - 1]), PA + SA[last], depth) == 0))) {
                    SA[last] = ~SA[last];
                }

                if (ssize > 0) {
                    StackElement se = stack[--ssize];
                    first = se.a;
                    middle = se.b;
                    last = se.c;
                    check = se.d;
                } else {
                    return;
                }

                continue;
            }

            for (m = 0, len = min(middle - first, last - middle), half = len >> 1; 0 < len; len = half, half >>= 1) {
                if (ssCompare(PA + getIDX(SA[middle + m + half]), PA
                    + getIDX(SA[middle - m - half - 1]), depth) < 0) {
                    m += half + 1;
                    half -= (len & 1) ^ 1;
                }
            }

            if (0 < m) {
                lm = middle - m;
                rm = middle + m;
                ssBlockSwap(lm, middle, m);
                l = r = middle;
                next = 0;
                if (rm < last) {
                    if (SA[rm] < 0) {
                        SA[rm] = ~SA[rm];
                        if (first < lm) {
                            for (; SA[--l] < 0; ) {
                            }
                            next |= 4;
                        }
                        next |= 1;
                    } else if (first < lm) {
                        for (; SA[r] < 0; ++r) {
                        }
                        next |= 2;
                    }
                }

                if ((l - first) <= (last - r)) {
                    stack[ssize++] = new StackElement(r, rm, last, (next & 3)
                        | (check & 4));

                    middle = lm;
                    last = l;
                    check = (check & 3) | (next & 4);
                } else {
                    if (((next & 2) != 0) && (r == middle)) {
                        next ^= 6;
                    }
                    stack[ssize++] = new StackElement(first, lm, l, (check & 3)
                        | (next & 4));

                    first = r;
                    middle = rm;
                    check = (next & 3) | (check & 4);
                }
            } else {
                if (ssCompare(PA + getIDX(SA[middle - 1]), PA + SA[middle], depth) == 0) {
                    SA[middle] = ~SA[middle];
                }

                if (((check & 1) != 0)
                    || (((check & 2) != 0) && (ssCompare(PA + getIDX(SA[first - 1]), PA
                    + SA[first], depth) == 0))) {
                    SA[first] = ~SA[first];
                }
                if (((check & 4) != 0)
                    && ((ssCompare(PA + getIDX(SA[last - 1]), PA + SA[last], depth) == 0))) {
                    SA[last] = ~SA[last];
                }

                if (ssize > 0) {
                    StackElement se = stack[--ssize];
                    first = se.a;
                    middle = se.b;
                    last = se.c;
                    check = se.d;
                } else {
                    return;
                }

            }

        }

    }
1121772
def simple_seg(hans):
    """"""
    assert not isinstance(hans, bytes_type), \
        'must be unicode string or [unicode, ...] list'

    if isinstance(hans, text_type):
        return _seg(hans)
    else:
        hans = list(hans)
        if len(hans) == 1:
            return simple_seg(hans[0])
        return list(chain(*[simple_seg(x) for x in hans]))
585805
private boolean checkUnGetSlotAt(LogPosition startPosition, int batchSize) {
        if (batchMode.isItemSize()) {
            long current = getSequence.get();
            long maxAbleSequence = putSequence.get();
            long next = current;
            if (startPosition == null || !startPosition.getPostion().isIncluded()) { // 第一次订阅之后，需要包含一下start位置，防止丢失第一条记录
                next = next + 1;// 少一条数据
            }

            if (current < maxAbleSequence && next + batchSize - 1 <= maxAbleSequence) {
                return true;
            } else {
                return false;
            }
        } else {
            // 处理内存大小判断
            long currentSize = getMemSize.get();
            long maxAbleSize = putMemSize.get();

            if (maxAbleSize - currentSize >= batchSize * bufferMemUnit) {
                return true;
            } else {
                return false;
            }
        }
    }
1027790
private void select(int dataIndex, String[] resultList, int resultIndex, List<String[]> result) {
		int resultLen = resultList.length;
		int resultCount = resultIndex + 1;
		if (resultCount > resultLen) { // 全部选择完时，输出组合结果
			result.add(Arrays.copyOf(resultList, resultList.length));
			return;
		}

		// 递归选择下一个
		for (int i = dataIndex; i < datas.length + resultCount - resultLen; i++) {
			resultList[resultIndex] = datas[i];
			select(i + 1, resultList, resultIndex + 1, result);
		}
	}
514772
private int segdir(double xend, double yend, int[] ij) {
        if (YMATCH(yend, y[ij[1]])) {
            if (ij[1] == 0) {
                return 0;
            }
            ij[1] -= 1;
            return 3;
        }

        if (XMATCH(xend, x[ij[0]])) {
            if (ij[0] == 0) {
                return 0;
            }
            ij[0] -= 1;
            return 4;
        }

        if (YMATCH(yend, y[ij[1] + 1])) {
            if (ij[1] >= y.length - 1) {
                return 0;
            }
            ij[1] += 1;
            return 1;
        }

        if (XMATCH(xend, x[ij[0] + 1])) {
            if (ij[0] >= x.length - 1) {
                return 0;
            }
            ij[0] += 1;
            return 2;
        }

        return 0;
    }
927939
function heapSnapShotCalculateP(heapData, options) {
        return co(_heapSnapShot, heapData, options)

        /**
         * 内部方法，具体处理逻辑
         */
        function* _heapSnapShot(heapData, options) {
            const jsHeapSnapShot = new common.worker.JSHeapSnapshot(heapData, {
                updateStatusP(msg, end) {
                    const cb = options.callback;
                    const params = options.params.apply(options, [msg, Date.now(), end]);
                    return cb(params.message, params.socket);
                },

                consoleWarn(str) {
                    // console.warn(str);
                }
            });
            //load data
            yield jsHeapSnapShot.initializeP();

            const needed = [`_statistics`, `_aggregates`, `_metaNode`, `nodes`, `containmentEdges`, `strings`, `_nodeFieldCount`, `_edgeFieldsCount`, `_firstEdgeIndexes`, `_retainedSizes`, `_nodeDistances`];
            //taken out
            Object.keys(jsHeapSnapShot).forEach(key => { if (!~needed.indexOf(key)) jsHeapSnapShot[key] = null; });
            //release heapData
            heapData = null;

            return jsHeapSnapShot;
        }
    }