예제 #1
0
  // [core#191]
  @SuppressWarnings("deprecation")
  public void testShortNameCollisionsDirect() throws IOException {
    final int COUNT = 600;

    // First, char-based
    {
      CharsToNameCanonicalizer symbols = CharsToNameCanonicalizer.createRoot(1);
      for (int i = 0; i < COUNT; ++i) {
        String id = String.valueOf((char) i);
        char[] ch = id.toCharArray();
        symbols.findSymbol(ch, 0, ch.length, symbols.calcHash(id));
      }
      assertEquals(COUNT, symbols.size());
      assertEquals(1024, symbols.bucketCount());

      assertEquals(16, symbols.collisionCount());
      assertEquals(1, symbols.maxCollisionLength());
    }

    // then byte-based
    {
      BytesToNameCanonicalizer symbols =
          BytesToNameCanonicalizer.createRoot(1).makeChild(JsonFactory.Feature.collectDefaults());
      for (int i = 0; i < COUNT; ++i) {
        String id = String.valueOf((char) i);
        int[] quads = calcQuads(id.getBytes("UTF-8"));
        symbols.addName(id, quads, quads.length);
      }
      assertEquals(COUNT, symbols.size());
      assertEquals(1024, symbols.bucketCount());

      assertEquals(209, symbols.collisionCount());
      assertEquals(1, symbols.maxCollisionLength());
    }
  }
예제 #2
0
  @SuppressWarnings("deprecation")
  public void testShortQuotedDirectBytesOld() throws IOException {
    final int COUNT = 400;
    BytesToNameCanonicalizer symbols =
        BytesToNameCanonicalizer.createRoot(1).makeChild(JsonFactory.Feature.collectDefaults());
    for (int i = 0; i < COUNT; ++i) {
      String id = String.format("\\u%04x", i);
      int[] quads = BytesToNameCanonicalizer.calcQuads(id.getBytes("UTF-8"));
      symbols.addName(id, quads, quads.length);
    }
    assertEquals(COUNT, symbols.size());
    assertEquals(1024, symbols.bucketCount());

    assertEquals(44, symbols.collisionCount());
    assertEquals(2, symbols.maxCollisionLength());
  }
예제 #3
0
  // [core#187]: unexpectedly high number of collisions for straight numbers
  @SuppressWarnings("deprecation")
  public void testCollisionsWithBytes187() throws IOException {
    BytesToNameCanonicalizer symbols =
        BytesToNameCanonicalizer.createRoot(1).makeChild(JsonFactory.Feature.collectDefaults());
    final int COUNT = 30000;
    for (int i = 0; i < COUNT; ++i) {
      String id = String.valueOf(10000 + i);
      int[] quads = BytesToNameCanonicalizer.calcQuads(id.getBytes("UTF-8"));
      symbols.addName(id, quads, quads.length);
    }

    // System.out.printf("Byte stuff: collisions %d, max-coll %d\n", symbols.collisionCount(),
    // symbols.maxCollisionLength());

    assertEquals(COUNT, symbols.size());
    assertEquals(65536, symbols.bucketCount());

    // collision count acceptable
    assertEquals(5782, symbols.collisionCount());
    // as well as collision counts
    assertEquals(24, symbols.maxCollisionLength());
  }
예제 #4
0
  // Test for verifying stability of hashCode, wrt collisions, using
  // synthetic field name generation and byte-based input (UTF-8)
  @SuppressWarnings("deprecation")
  public void testSyntheticWithBytesOld() throws IOException {
    // pass seed, to keep results consistent:
    final int SEED = 33333;
    BytesToNameCanonicalizer symbols =
        BytesToNameCanonicalizer.createRoot(SEED).makeChild(JsonFactory.Feature.collectDefaults());

    final int COUNT = 12000;
    for (int i = 0; i < COUNT; ++i) {
      String id = fieldNameFor(i);
      int[] quads = calcQuads(id.getBytes("UTF-8"));
      symbols.addName(id, quads, quads.length);
    }
    assertEquals(COUNT, symbols.size());
    assertEquals(16384, symbols.bucketCount());

    // System.out.printf("Byte stuff: collisions %d, max-coll %d\n", symbols.collisionCount(),
    // symbols.maxCollisionLength());
    assertEquals(3476, symbols.collisionCount());
    // longest collision chain not optimal but ok:
    assertEquals(15, symbols.maxCollisionLength());

    // But also verify entries are actually found?
  }