/** * Compares bytes of this {@code Data} to the given bytes {@code source}, starting from the * given offset. * <p> * <p>Default implementation compares {@link #bytes()} of this {@code Data}, but custom * implementation may only check if {@linkplain #get() object} of this {@code Data} <i>would</i> * be serialized to the same bytes sequence, if this {@code Data} wraps an object and obtaining * {@link #bytes()} requires serialization internally. * * @param source the bytes source, to compare this {@code Data}'s bytes with * @param sourceOffset the offset in the bytes source, the bytes sequence starts from * @return {@code true} if the given bytes sequence is equivalent to this {@code Data}'s bytes, * byte-by-byte */ default boolean equivalent(RandomDataInput source, long sourceOffset) { return BytesUtil.bytesEqual(source, sourceOffset, bytes(), offset(), size()); }
/** * converts the bytes to a ISO-8859-1 String, the end of the string is either the bytes .limit * () or a byte containing the stopByte ( which ever comes first ). If the string can be * obtained from the pool, this string is used instead. otherwise, the string is added to the * pool. * * @param bytes the bytes to convert to a string * @param length parse the string up to the length * @return the string made from bytes only ( rather than chars ) */ public String intern(@NotNull final Bytes bytes, int length) { try { int hash32 = BytesStoreHash.hash32(bytes, length); int h = hash32 & mask; String s = interner[h]; long position = bytes.readPosition(); if (BytesUtil.bytesEqual(s, bytes, position, length)) return s; int h2 = (hash32 >> shift) & mask; String s2 = interner[h2]; if (BytesUtil.bytesEqual(s2, bytes, position, length)) return s2; char[] chars = toCharArray(bytes, position, length); return interner[s == null || (s2 != null && toggle()) ? h : h2] = StringUtils.newString(chars); } finally { bytes.readSkip(length); } } }
BytesUtil.bytesEqual(s.segmentBS, currentKeyOffset, s.segmentBS, e.keyOffset, currentKeySize)) { report(corruptionListener, corruption, segmentIndex, () ->
break checkDuplicateKeys; if (((this.keySize()) == currentKeySize) && (BytesUtil.bytesEqual(this.segmentBS(), currentKeyOffset, this.segmentBS(), this.keyOffset(), currentKeySize))) { ChronicleHashCorruptionImpl.report(corruptionListener, corruption, segmentIndex, () -> ChronicleHashCorruptionImpl.format(("Entries with duplicate keys within a tier: " + "at pos {} and {} with key {}, first value is {}"), entryPos, anotherEntryPos, this.key(), this.value())); this.freeList().clearRange(entryPos, (entryPos + currentEntrySizeInChunks));
break checkDuplicateKeys; if (((this.keySize()) == currentKeySize) && (BytesUtil.bytesEqual(this.segmentBS(), currentKeyOffset, this.segmentBS(), this.keyOffset(), currentKeySize))) { ChronicleHashCorruptionImpl.report(corruptionListener, corruption, segmentIndex, () -> ChronicleHashCorruptionImpl.format(("Entries with duplicate keys within a tier: " + "at pos {} and {} with key {}, first value is {}"), entryPos, anotherEntryPos, this.key(), this.value())); this.freeList().clearRange(entryPos, (entryPos + currentEntrySizeInChunks));