Skip to content

Commit

Permalink
Remove IntGrowableArray and replace it with IntArrayList #42
Browse files Browse the repository at this point in the history
  • Loading branch information
dweiss committed May 22, 2024
1 parent 414a600 commit fa7fb32
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 71 deletions.
59 changes: 0 additions & 59 deletions hppc/src/main/java/com/carrotsearch/hppc/IntGrowableArray.java

This file was deleted.

14 changes: 7 additions & 7 deletions hppc/src/main/java/com/carrotsearch/hppc/PgmIndexUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,28 +13,28 @@
class PgmIndexUtil {

/** Adds the first key of the current segment to the segment data bytes. */
static <KType> void addKey(KType key, IntGrowableArray segmentData) {
static <KType> void addKey(KType key, IntArrayList segmentData) {
throw new UnsupportedOperationException("Invalid for generic type: " + key);
}

/** Adds the first key of the current segment to the segment data bytes. */
static void addKey(int key, IntGrowableArray segmentData) {
static void addKey(int key, IntArrayList segmentData) {
segmentData.add(key);
}

/** Adds the first key of the current segment to the segment data bytes. */
static void addKey(float key, IntGrowableArray segmentData) {
static void addKey(float key, IntArrayList segmentData) {
addKey(Float.floatToIntBits(key), segmentData);
}

/** Adds the first key of the current segment to the segment data bytes. */
static void addKey(long key, IntGrowableArray segmentData) {
static void addKey(long key, IntArrayList segmentData) {
segmentData.add((int) key);
segmentData.add((int) (key >> 32));
}

/** Adds the first key of the current segment to the segment data bytes. */
static void addKey(double key, IntGrowableArray segmentData) {
static void addKey(double key, IntArrayList segmentData) {
addKey(Double.doubleToRawLongBits(key), segmentData);
}

Expand Down Expand Up @@ -70,7 +70,7 @@ static double getKey(int segmentDataIndex, int[] segmentData, double keyType) {
*
* @param keySize The size of the key, measure in {@link Integer#BYTES}.
*/
static void addIntercept(long intercept, IntGrowableArray segmentData, int keySize) {
static void addIntercept(long intercept, IntArrayList segmentData, int keySize) {
assert keySize >= 1 && keySize <= 2;
if (keySize == 1) {
addKey((int) intercept, segmentData);
Expand Down Expand Up @@ -98,7 +98,7 @@ static long getIntercept(int segmentDataIndex, int[] segmentData, int keySize) {
*
* @param keySize The size of the key, measure in {@link Integer#BYTES}.
*/
static void addSlope(double slope, IntGrowableArray segmentData, int keySize) {
static void addSlope(double slope, IntArrayList segmentData, int keySize) {
assert keySize >= 1 && keySize <= 2;
if (keySize == 1) {
addKey((float) slope, segmentData);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -429,7 +429,7 @@ public static class KTypeBuilder<KType> implements PlaModel.SegmentConsumer, Acc
protected int epsilonRecursive = EPSILON_RECURSIVE;
protected PlaModel plam;
protected int size;
protected IntGrowableArray segmentData;
protected IntArrayList segmentData;
protected int numSegments;

/** Sets the sorted list of keys to build the index for; duplicate elements are allowed. */
Expand Down Expand Up @@ -472,8 +472,8 @@ public KTypePgmIndex<KType> build() {
plam = new PlaModel(epsilon);

int segmentsInitialCapacity = Math.min(Math.max(keys.size() / (2 * epsilon * epsilon) * SEGMENT_DATA_SIZE, 16), 1 << 19);
segmentData = new IntGrowableArray(segmentsInitialCapacity);
IntGrowableArray levelOffsets = new IntGrowableArray(16);
segmentData = new IntArrayList(segmentsInitialCapacity);
IntArrayList levelOffsets = new IntArrayList(16);

int levelOffset = 0;
levelOffsets.add(levelOffset);
Expand Down Expand Up @@ -555,7 +555,7 @@ public void accept(double firstKey, double slope, long intercept) {
PgmIndexUtil.addKey((KType)Intrinsics.<KType>cast(firstKey), segmentData);
PgmIndexUtil.addSlope(slope, segmentData, KEY_SIZE);
numSegments++;
assert segmentData.size == numSegments * SEGMENT_DATA_SIZE;
assert segmentData.size() == numSegments * SEGMENT_DATA_SIZE;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,6 @@ benmanes-versions = "com.github.ben-manes.versions:0.51.0"
dependencychecks = "com.carrotsearch.gradle.dependencychecks:0.0.7"
forbiddenapis = "de.thetaphi.forbiddenapis:3.7"
jmh = "me.champeau.jmh:0.7.2"
randomizedtesting = "com.carrotsearch.gradle.randomizedtesting:0.0.6"
spotless = "com.diffplug.spotless:6.25.0"
versionCatalogUpdate = "nl.littlerobots.version-catalog-update:0.8.4"
randomizedtesting = "com.carrotsearch.gradle.randomizedtesting:0.0.6"

0 comments on commit fa7fb32

Please sign in to comment.