private void insert(Queue<SiblingGroup> siblingGroupQueue, SiblingGroup siblingGroup) {
        List<NodeEntry> siblings = siblingGroup.siblings;
        int siblingCount = siblings.size();
        int firstSiblingPos = siblings.getFirst().pos;
        int lastSiblingPos = siblingCount > 1
                ? siblings.get(siblingCount - 1).pos
                : firstSiblingPos;
        // begin is always greater than 0 because base[0] is for the root state
        int begin;
        int checkPos = Math.max(firstSiblingPos, checkPosForNextRun);
        int usedPositionCount = 0;
        boolean isFirstFreeCheckPosFound = false;

        // Find the "checkPos" and "begin" to ensure there are
        // consecutive free positions for siblings that satisfy
        // base[begin + siblings[0].pos...siblings[n].pos]
        findBeginLoop: while (true) {
            checkPos++;
            ensureSize(checkPos + 1);
            if (check[checkPos] != 0) {
                usedPositionCount++;
                continue;
            }
            if (!isFirstFreeCheckPosFound) {
                checkPosForNextRun = checkPos;
                isFirstFreeCheckPosFound = true;
            }
            begin = checkPos - firstSiblingPos;
            ensureSize(begin + lastSiblingPos + 1);
            for (NodeEntry sibling : siblings) {
                if (check[begin + sibling.pos] != 0) {
                    continue findBeginLoop;
                }
            }
            if (checkPosForNextRun == checkPos) {
                checkPosForNextRun += siblingCount;
            }
            break;
        }

        currentMaxPos = Math.max(currentMaxPos, begin + lastSiblingPos);
        // if 95% positions of check between "nextCheckPos" and "pos"
        // is taken, set "checkPosForNextRun" to "pos" to find the next check position next time
        if (((float) usedPositionCount) / (checkPos - checkPosForNextRun + 1) >= 0.95F) {
            checkPosForNextRun = checkPos;
        }
        for (NodeEntry sibling : siblings) {
            int targetPos = begin + sibling.pos;
            check[targetPos] = begin;
            State parent = sibling.state;
            RichIterable<CharObjectPair<State>> siblingEntries = parent.success.keyValuesView();
            List<NodeEntry> newSiblings = new ArrayList<>(siblingEntries.size() + 1);
            if (parent.isTermination()) {
                State child = new State(-parent.depth - 1);
                child.addEmit(parent.getLargestTermIndex());
                newSiblings.add(new NodeEntry(0, child));
            }
            for (CharObjectPair<State> entry : siblingEntries) {
                newSiblings.add(new NodeEntry(entry.getOne() + 1, entry.getTwo()));
            }
            if (newSiblings.isEmpty()) {
                base[targetPos] = -parent.getLargestTermIndex() - 1;
            } else {
                siblingGroupQueue.add(new SiblingGroup(targetPos, newSiblings));
            }
            parent.indexInDat = targetPos;
        }

        // insert siblings
        int parentBaseIndex = siblingGroup.parentBaseIndex;
        if (parentBaseIndex != -1) {
            base[parentBaseIndex] = begin;
        }
    }
currentMaxPos = max code + 1. Add 1 to avoid occupying the position of root
turms-plugins/turms-plugin-antispam/src/main/java/im/turms/plugin/antispam/core/ac/DoubleArrayTrie.java