You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I have a use case to compare if 2 tdigest's are equal. Was wondering if it makes sense to override the equals and hashcode functions in MergingDigest class.
Sample code
@Override
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof MergingDigest)) {
return false;
}
MergingDigest compare = (MergingDigest) o;
if (compare.size() != this.size()){
return false;
}
byte[] bBytes = new byte[compare.byteSize()];
compare.asBytes(ByteBuffer.wrap(bBytes));
byte[] aBytes = new byte[this.byteSize()];
this.asBytes(ByteBuffer.wrap(aBytes));
return Arrays.equals(aBytes,bBytes);
}
@Override
public int hashCode() {
byte[] aBytes = new byte[this.byteSize()];
this.asBytes(ByteBuffer.wrap(aBytes));
String sketch = Base64.getEncoder().encodeToString(aBytes);
return new HashCodeBuilder(17, 37)
.append(sketch)
.toHashCode();
}
The text was updated successfully, but these errors were encountered:
This makes sense and could even be implemented at the level of the TDigest
class itself (with the addition of a comparison on class).
I don't think that it will be terribly useful, but it is a plausible
definition.
Do you want to create a pull request?
On Thu, Jul 1, 2021 at 7:48 AM Naga ***@***.***> wrote:
I have a use case to compare if 2 tdigest's are equal. Was wondering if it
makes sense to override the equals and hashcode functions in MergingDigest
class.
Sample code
@OverRide
public boolean equals(Object o) {
if (o == this) return true;
if (!(o instanceof MergingDigest)) {
return false;
}
MergingDigest compare = (MergingDigest) o;
if (compare.size() != this.size()){
return false;
}
byte[] bBytes = new byte[compare.byteSize()];
compare.asBytes(ByteBuffer.wrap(bBytes));
byte[] aBytes = new byte[this.byteSize()];
this.asBytes(ByteBuffer.wrap(aBytes));
return Arrays.equals(aBytes,bBytes);
}
@OverRide
public int hashCode() {
byte[] aBytes = new byte[this.byteSize()];
this.asBytes(ByteBuffer.wrap(aBytes));
String sketch = Base64.getEncoder().encodeToString(aBytes);
return new HashCodeBuilder(17, 37)
.append(sketch)
.toHashCode();
}
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#176>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAB5E6XPFX4PVRX4SSFIVPLTVR55HANCNFSM47U4FJKA>
.
I have a use case to compare if 2 tdigest's are equal. Was wondering if it makes sense to override the equals and hashcode functions in MergingDigest class.
Sample code
The text was updated successfully, but these errors were encountered: