Home / Class/ AhoCorasicSearchProcessorFactory Class — netty Architecture

AhoCorasicSearchProcessorFactory Class — netty Architecture

Architecture documentation for the AhoCorasicSearchProcessorFactory class in AhoCorasicSearchProcessorFactory.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  2bbcf65c_43ea_8f43_fbbd_a4d039d021d0["AhoCorasicSearchProcessorFactory"]
  06ec8640_ebce_33c6_030a_e7db36482963["AhoCorasicSearchProcessorFactory.java"]
  2bbcf65c_43ea_8f43_fbbd_a4d039d021d0 -->|defined in| 06ec8640_ebce_33c6_030a_e7db36482963
  271ca4a7_3cd9_b2d2_1cc9_1936872f5be2["AhoCorasicSearchProcessorFactory()"]
  2bbcf65c_43ea_8f43_fbbd_a4d039d021d0 -->|method| 271ca4a7_3cd9_b2d2_1cc9_1936872f5be2
  24cc4ebd_ede3_1677_9180_99c2eb476679["Context()"]
  2bbcf65c_43ea_8f43_fbbd_a4d039d021d0 -->|method| 24cc4ebd_ede3_1677_9180_99c2eb476679
  bef56ec2_3d63_5fe3_0a4b_a27b45c2ff42["linkSuffixes()"]
  2bbcf65c_43ea_8f43_fbbd_a4d039d021d0 -->|method| bef56ec2_3d63_5fe3_0a4b_a27b45c2ff42
  453dd6dc_4e70_d4d7_b9f0_737bfaa7d8aa["Processor()"]
  2bbcf65c_43ea_8f43_fbbd_a4d039d021d0 -->|method| 453dd6dc_4e70_d4d7_b9f0_737bfaa7d8aa

Relationship Graph

Source Code

buffer/src/main/java/io/netty/buffer/search/AhoCorasicSearchProcessorFactory.java lines 33–191

public class AhoCorasicSearchProcessorFactory extends AbstractMultiSearchProcessorFactory {

    private final int[] jumpTable;
    private final int[] matchForNeedleId;

    static final int BITS_PER_SYMBOL = 8;
    static final int ALPHABET_SIZE = 1 << BITS_PER_SYMBOL;

    private static class Context {
        int[] jumpTable;
        int[] matchForNeedleId;
    }

    public static class Processor implements MultiSearchProcessor {

        private final int[] jumpTable;
        private final int[] matchForNeedleId;
        private long currentPosition;

        Processor(int[] jumpTable, int[] matchForNeedleId) {
            this.jumpTable = jumpTable;
            this.matchForNeedleId = matchForNeedleId;
        }

        @Override
        public boolean process(byte value) {
            currentPosition = PlatformDependent.getInt(jumpTable, currentPosition | (value & 0xffL));
            if (currentPosition < 0) {
                currentPosition = -currentPosition;
                return false;
            }
            return true;
        }

        @Override
        public int getFoundNeedleId() {
            return matchForNeedleId[(int) currentPosition >> AhoCorasicSearchProcessorFactory.BITS_PER_SYMBOL];
        }

        @Override
        public void reset() {
            currentPosition = 0;
        }
    }

    AhoCorasicSearchProcessorFactory(byte[] ...needles) {

        for (byte[] needle: needles) {
            if (needle.length == 0) {
                throw new IllegalArgumentException("Needle must be non empty");
            }
        }

        Context context = buildTrie(needles);
        jumpTable = context.jumpTable;
        matchForNeedleId = context.matchForNeedleId;

        linkSuffixes();

        for (int i = 0; i < jumpTable.length; i++) {
            if (matchForNeedleId[jumpTable[i] >> BITS_PER_SYMBOL] >= 0) {
                jumpTable[i] = -jumpTable[i];
            }
        }
    }

    private static Context buildTrie(byte[][] needles) {

        ArrayList<Integer> jumpTableBuilder = new ArrayList<Integer>(ALPHABET_SIZE);
        for (int i = 0; i < ALPHABET_SIZE; i++) {
            jumpTableBuilder.add(-1);
        }

        ArrayList<Integer> matchForBuilder = new ArrayList<Integer>();
        matchForBuilder.add(-1);

        for (int needleId = 0; needleId < needles.length; needleId++) {
            byte[] needle = needles[needleId];
            int currentPosition = 0;

            for (byte ch0: needle) {

Frequently Asked Questions

What is the AhoCorasicSearchProcessorFactory class?
AhoCorasicSearchProcessorFactory is a class in the netty codebase, defined in buffer/src/main/java/io/netty/buffer/search/AhoCorasicSearchProcessorFactory.java.
Where is AhoCorasicSearchProcessorFactory defined?
AhoCorasicSearchProcessorFactory is defined in buffer/src/main/java/io/netty/buffer/search/AhoCorasicSearchProcessorFactory.java at line 33.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free