Skip to content
This repository has been archived by the owner on Jul 7, 2020. It is now read-only.

Change type of TDigest.Group.id from int to long #162

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
import java.util.Iterator;
import java.util.List;
import java.util.Random;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong;

import java.nio.ByteBuffer;

Expand Down Expand Up @@ -476,11 +476,11 @@ private double interpolate(double x, double x0, double x1) {

public static class Group implements Comparable<Group> {

private static final AtomicInteger uniqueCount = new AtomicInteger(1);
private static final AtomicLong uniqueCount = new AtomicLong(1);

private double centroid = 0;
private int count = 0;
private int id;
private long id;

private List<Double> actualData = null;

Expand All @@ -493,7 +493,7 @@ private Group(boolean record) {

public Group(double x) {
this(false);
start(x, uniqueCount.getAndIncrement());
start(x, uniqueCount.incrementAndGet());
}

public Group(double x, int id) {
Expand All @@ -506,7 +506,7 @@ public Group(double x, int id, boolean record) {
start(x, id);
}

private void start(double x, int id) {
private void start(double x, long id) {
this.id = id;
add(x, 1);
}
Expand All @@ -527,7 +527,7 @@ public int count() {
return count;
}

public int id() {
public long id() {
return id;
}

Expand All @@ -541,14 +541,14 @@ public String toString() {

@Override
public int hashCode() {
return id;
return Long.hashCode(id);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the point of hashing the id?

}

@Override
public int compareTo(Group o) {
int r = Double.compare(centroid, o.centroid);
if (r == 0) {
r = id - o.id;
r = Long.compare(id, o.id);
}
return r;
}
Expand Down