private void updateTransition()

in src/main/software/amazon/event/ruler/ByteMap.java [80:111]


    private void updateTransition(final byte utf8byte, final SingleByteTransition transition, Operation operation) {
        final int index = utf8byte & 0xFF;
        ByteTransition target =  map.higherEntry(index).getValue();

        ByteTransition coalesced;
        if (operation == Operation.PUT) {
            coalesced = coalesce(transition);
        } else {
            Iterable<SingleByteTransition> targetIterable = expand(target);
            if (!targetIterable.iterator().hasNext()) {
                coalesced = operation == Operation.ADD ? coalesce(transition) : null;
            } else {
                Set<SingleByteTransition> singles = new HashSet<>();
                targetIterable.forEach(single -> singles.add(single));
                if (operation == Operation.ADD) {
                    singles.add(transition);
                } else {
                    singles.remove(transition);
                }
                coalesced = coalesce(singles);
            }
        }

        final boolean atBottom = index == 0 || map.containsKey(index);
        if (!atBottom) {
            map.put(index, target);
        }
        map.put(index + 1, coalesced);

        // Merge adjacent mappings with the same transition.
        mergeAdjacentInMapIfNeeded(map);
    }