private WriteChecksumBuilder(List<Type> types) { this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); ImmutableList.Builder<XxHash64> columnHashes = ImmutableList.builder(); for (Type ignored : types) { columnHashes.add(new XxHash64()); } this.columnHashes = columnHashes.build(); }
private WriteChecksumBuilder(List<Type> types) { this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); ImmutableList.Builder<XxHash64> columnHashes = ImmutableList.builder(); for (Type ignored : types) { columnHashes.add(new XxHash64()); } this.columnHashes = columnHashes.build(); }
private WriteChecksumBuilder(List<Type> types) { this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); ImmutableList.Builder<XxHash64> columnHashes = ImmutableList.builder(); for (Type ignored : types) { columnHashes.add(new XxHash64()); } this.columnHashes = columnHashes.build(); }
private WriteChecksumBuilder(List<Type> types) { this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); ImmutableList.Builder<XxHash64> columnHashes = ImmutableList.builder(); for (Type ignored : types) { columnHashes.add(new XxHash64()); } this.columnHashes = columnHashes.build(); }
private WriteChecksumBuilder(List<Type> types) { this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); ImmutableList.Builder<XxHash64> columnHashes = ImmutableList.builder(); for (Type ignored : types) { columnHashes.add(new XxHash64()); } this.columnHashes = columnHashes.build(); }
private WriteChecksumBuilder(List<Type> types) { this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); ImmutableList.Builder<XxHash64> columnHashes = ImmutableList.builder(); for (Type ignored : types) { columnHashes.add(new XxHash64()); } this.columnHashes = columnHashes.build(); }
private WriteChecksumBuilder(List<Type> types) { this.types = ImmutableList.copyOf(requireNonNull(types, "types is null")); ImmutableList.Builder<XxHash64> columnHashes = ImmutableList.builder(); for (Type ignored : types) { columnHashes.add(new XxHash64()); } this.columnHashes = columnHashes.build(); }
public static long hash(long seed, InputStream in) throws IOException { XxHash64 hash = new XxHash64(seed); byte[] buffer = new byte[8192]; while (true) { int length = in.read(buffer); if (length == -1) { break; } hash.update(buffer, 0, length); } return hash.hash(); }
public static long hash(long seed, InputStream in) throws IOException { XxHash64 hash = new XxHash64(seed); byte[] buffer = new byte[8192]; while (true) { int length = in.read(buffer); if (length == -1) { break; } hash.update(buffer, 0, length); } return hash.hash(); }
@Test public void testEmpty() throws Exception { long expected = 0xEF46DB3751D8E999L; assertEquals(hash(EMPTY_SLICE), expected); assertEquals(hash(EMPTY_SLICE, 0, 0), expected); assertEquals(hash(0, EMPTY_SLICE), expected); assertEquals(hash(0, EMPTY_SLICE, 0, 0), expected); assertEquals(new XxHash64().update(EMPTY_SLICE).hash(), expected); assertEquals(new XxHash64().update(EMPTY_SLICE, 0, 0).hash(), expected); assertEquals(new XxHash64().update(EMPTY_BYTES).hash(), expected); assertEquals(new XxHash64().update(EMPTY_BYTES, 0, 0).hash(), expected); assertEquals( new XxHash64() .update(EMPTY_BYTES) .update(EMPTY_BYTES, 0, 0) .update(EMPTY_SLICE) .update(EMPTY_SLICE, 0, 0) .hash(), expected); }
@Test public void testEmpty() throws Exception { long expected = 0xEF46DB3751D8E999L; assertEquals(hash(EMPTY_SLICE), expected); assertEquals(hash(EMPTY_SLICE, 0, 0), expected); assertEquals(hash(0, EMPTY_SLICE), expected); assertEquals(hash(0, EMPTY_SLICE, 0, 0), expected); assertEquals(new XxHash64().update(EMPTY_SLICE).hash(), expected); assertEquals(new XxHash64().update(EMPTY_SLICE, 0, 0).hash(), expected); assertEquals(new XxHash64().update(EMPTY_BYTES).hash(), expected); assertEquals(new XxHash64().update(EMPTY_BYTES, 0, 0).hash(), expected); assertEquals( new XxHash64() .update(EMPTY_BYTES) .update(EMPTY_BYTES, 0, 0) .update(EMPTY_SLICE) .update(EMPTY_SLICE, 0, 0) .hash(), expected); }
private static void assertHash(long seed, Slice data, int length, long expected) throws IOException { assertEquals(hash(seed, data, 0, length), expected); assertEquals(hash(seed, data.slice(0, length)), expected); assertEquals(new XxHash64(seed).update(data.slice(0, length)).hash(), expected); assertEquals(new XxHash64(seed).update(data, 0, length).hash(), expected); assertEquals(new XxHash64(seed).update(data.getBytes(0, length)).hash(), expected); assertEquals(new XxHash64(seed).update(data.getBytes(), 0, length).hash(), expected); assertEquals(hash(seed, new ByteArrayInputStream(data.getBytes(0, length))), expected); for (int chunkSize = 1; chunkSize <= length; chunkSize++) { XxHash64 hash = new XxHash64(seed); for (int i = 0; i < length; i += chunkSize) { int updateSize = min(length - i, chunkSize); hash.update(data.slice(i, updateSize)); assertEquals(hash.hash(), hash(seed, data, 0, i + updateSize)); } assertEquals(hash.hash(), expected); } }
private static void assertHash(long seed, Slice data, int length, long expected) throws IOException { assertEquals(hash(seed, data, 0, length), expected); assertEquals(hash(seed, data.slice(0, length)), expected); assertEquals(new XxHash64(seed).update(data.slice(0, length)).hash(), expected); assertEquals(new XxHash64(seed).update(data, 0, length).hash(), expected); assertEquals(new XxHash64(seed).update(data.getBytes(0, length)).hash(), expected); assertEquals(new XxHash64(seed).update(data.getBytes(), 0, length).hash(), expected); assertEquals(hash(seed, new ByteArrayInputStream(data.getBytes(0, length))), expected); for (int chunkSize = 1; chunkSize <= length; chunkSize++) { XxHash64 hash = new XxHash64(seed); for (int i = 0; i < length; i += chunkSize) { int updateSize = min(length - i, chunkSize); hash.update(data.slice(i, updateSize)); assertEquals(hash.hash(), hash(seed, data, 0, i + updateSize)); } assertEquals(hash.hash(), expected); } }