Home / Class/ HashCollisionTest Class — netty Architecture

HashCollisionTest Class — netty Architecture

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

Entity Profile

Dependency Diagram

graph TD
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42["HashCollisionTest"]
  882e4796_ce2c_a5ee_a3c3_c0d1d234d208["HashCollisionTest.java"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|defined in| 882e4796_ce2c_a5ee_a3c3_c0d1d234d208
  167600aa_cd5a_cbbc_26a2_393115effe20["HashCollisionTest()"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|method| 167600aa_cd5a_cbbc_26a2_393115effe20
  d3f29c04_06bf_6ce4_7812_c30e675e84d2["main()"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|method| d3f29c04_06bf_6ce4_7812_c30e675e84d2
  b0a46d64_ef56_16c8_d893_46e179546484["addHttpHeaderNames()"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|method| b0a46d64_ef56_16c8_d893_46e179546484
  c1c1b2a8_7e01_bbd3_e859_075672382f97["addHttpHeaderValues()"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|method| c1c1b2a8_7e01_bbd3_e859_075672382f97
  1131f878_0f64_82e9_f57e_a06fb3aae797["addHttp2HeaderNames()"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|method| 1131f878_0f64_82e9_f57e_a06fb3aae797
  48563d23_b563_7f71_5ec9_a6538fc1835e["addWordsFromFile()"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|method| 48563d23_b563_7f71_5ec9_a6538fc1835e
  cd4b5b2a_2c94_0086_358c_df261e897a65["calculateDuplicates()"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|method| cd4b5b2a_2c94_0086_358c_df261e897a65
  ed88f1e5_c2b8_3ec1_2ae5_1cff27cab91d["printResults()"]
  7f4340a8_96bd_ab16_3f24_b4cd9d2cac42 -->|method| ed88f1e5_c2b8_3ec1_2ae5_1cff27cab91d

Relationship Graph

Source Code

codec-http2/src/test/java/io/netty/handler/codec/http2/HashCollisionTest.java lines 40–177

@Disabled
public final class HashCollisionTest {
    private HashCollisionTest() { }

    public static void main(String[] args) throws IllegalAccessException, IOException, URISyntaxException {
        // Big initial size for when all name sources are pulled in.
        List<CharSequence> strings = new ArrayList<CharSequence>(350000);
        addHttpHeaderNames(strings);
        addHttpHeaderValues(strings);
        addHttp2HeaderNames(strings);
        addWordsFromFile(new File("/usr/share/dict/words"), strings);
        // More "english words" can be found here:
        // https://gist.github.com/Scottmitch/de2f03912778016ecee3c140478f07e0#file-englishwords-txt

        Map<Integer, List<CharSequence>> dups = calculateDuplicates(strings, new Function<CharSequence, Integer>() {
            @Override
            public Integer apply(CharSequence string) {
                int h = 0;
                for (int i = 0; i < string.length(); ++i) {
                    // masking with 0x1F reduces the number of overall bits that impact the hash code but makes the hash
                    // code the same regardless of character case (upper case or lower case hash is the same).
                    h = h * 31 + (string.charAt(i) & 0x1F);
                }
                return h;
            }
        });
        PrintStream writer = System.out;
        writer.println("==Old Duplicates==");
        printResults(writer, dups);

        dups = calculateDuplicates(strings, new Function<CharSequence, Integer>() {
            @Override
            public Integer apply(CharSequence string) {
                return PlatformDependent.hashCodeAscii(string);
            }
        });
        writer.println();
        writer.println("==New Duplicates==");
        printResults(writer, dups);
    }

    private static void addHttpHeaderNames(List<CharSequence> values) throws IllegalAccessException {
        for (Field f : HttpHeaderNames.class.getFields()) {
            if (f.getType() == AsciiString.class) {
                values.add((AsciiString) f.get(null));
            }
        }
    }

    private static void addHttpHeaderValues(List<CharSequence> values) throws IllegalAccessException {
        for (Field f : HttpHeaderValues.class.getFields()) {
            if (f.getType() == AsciiString.class) {
                values.add((AsciiString) f.get(null));
            }
        }
    }

    private static void addHttp2HeaderNames(List<CharSequence> values) throws IllegalAccessException {
        for (Http2Headers.PseudoHeaderName name : Http2Headers.PseudoHeaderName.values()) {
            values.add(name.value());
        }
    }

    private static void addWordsFromFile(File file, List<CharSequence> values)
            throws IllegalAccessException, IOException {
        BufferedReader br = new BufferedReader(new FileReader(file));
        try {
            String line;
            while ((line = br.readLine()) != null) {
                // Make a "best effort" to prune input which contains characters that are not valid in HTTP header names
                if (line.indexOf('\'') < 0) {
                    values.add(line);
                }
            }
        } finally {
            br.close();
        }
    }

    private static Map<Integer, List<CharSequence>> calculateDuplicates(List<CharSequence> strings,
                                                                        Function<CharSequence, Integer> hasher) {

Frequently Asked Questions

What is the HashCollisionTest class?
HashCollisionTest is a class in the netty codebase, defined in codec-http2/src/test/java/io/netty/handler/codec/http2/HashCollisionTest.java.
Where is HashCollisionTest defined?
HashCollisionTest is defined in codec-http2/src/test/java/io/netty/handler/codec/http2/HashCollisionTest.java at line 40.

Analyze Your Own Codebase

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

Try Supermodel Free