Remove fastutil

This commit is contained in:
Andrea Cavalli 2023-01-02 14:55:56 +01:00
parent 5b724f69dd
commit ab157d2bdb
9 changed files with 148 additions and 26 deletions

View File

@ -49,11 +49,6 @@
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil-core</artifactId>
<version>8.5.9</version>
</dependency>
<dependency> <dependency>
<groupId>net.harawata</groupId> <groupId>net.harawata</groupId>
<artifactId>appdirs</artifactId> <artifactId>appdirs</artifactId>

View File

@ -0,0 +1,124 @@
package it.tdlight.common.internal;
import it.tdlight.common.utils.IntSwapper;
public class ArrayUtil {
public interface IntComparator {
int compare(int k1, int k2);
}
public static void mergeSort(int from, int to, IntComparator c, IntSwapper swapper) {
int length = to - from;
int i;
if (length >= 16) {
i = from + to >>> 1;
mergeSort(from, i, c, swapper);
mergeSort(i, to, c, swapper);
if (c.compare(i - 1, i) > 0) {
inPlaceMerge(from, i, to, c, swapper);
}
} else {
for(i = from; i < to; ++i) {
for(int j = i; j > from && c.compare(j - 1, j) > 0; --j) {
swapper.swap(j, j - 1);
}
}
}
}
private static void inPlaceMerge(int from, int mid, int to, IntComparator comp, IntSwapper swapper) {
if (from < mid && mid < to) {
if (to - from == 2) {
if (comp.compare(mid, from) < 0) {
swapper.swap(from, mid);
}
} else {
int firstCut;
int secondCut;
if (mid - from > to - mid) {
firstCut = from + (mid - from) / 2;
secondCut = lowerBound(mid, to, firstCut, comp);
} else {
secondCut = mid + (to - mid) / 2;
firstCut = upperBound(from, mid, secondCut, comp);
}
if (mid != firstCut && mid != secondCut) {
int first1 = firstCut;
int last1 = mid;
label43:
while(true) {
--last1;
if (first1 >= last1) {
first1 = mid;
last1 = secondCut;
while(true) {
--last1;
if (first1 >= last1) {
first1 = firstCut;
last1 = secondCut;
while(true) {
--last1;
if (first1 >= last1) {
break label43;
}
swapper.swap(first1++, last1);
}
}
swapper.swap(first1++, last1);
}
}
swapper.swap(first1++, last1);
}
}
mid = firstCut + (secondCut - mid);
inPlaceMerge(from, firstCut, mid, comp, swapper);
inPlaceMerge(mid, secondCut, to, comp, swapper);
}
}
}
private static int lowerBound(int from, int to, int pos, IntComparator comp) {
int len = to - from;
while(len > 0) {
int half = len / 2;
int middle = from + half;
if (comp.compare(middle, pos) < 0) {
from = middle + 1;
len -= half + 1;
} else {
len = half;
}
}
return from;
}
private static int upperBound(int from, int mid, int pos, IntComparator comp) {
int len = mid - from;
while(len > 0) {
int half = len / 2;
int middle = from + half;
if (comp.compare(pos, middle) < 0) {
len = half;
} else {
from = middle + 1;
len -= half + 1;
}
}
return from;
}
}

View File

@ -7,8 +7,9 @@ import it.tdlight.common.TelegramClient;
import it.tdlight.common.UpdatesHandler; import it.tdlight.common.UpdatesHandler;
import it.tdlight.jni.TdApi; import it.tdlight.jni.TdApi;
import it.tdlight.jni.TdApi.Function; import it.tdlight.jni.TdApi.Function;
import it.unimi.dsi.fastutil.longs.LongArrayList; import it.tdlight.jni.TdApi.Object;
import it.unimi.dsi.fastutil.objects.ObjectArrayList; import java.util.ArrayList;
import java.util.List;
import java.util.Objects; import java.util.Objects;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -47,7 +48,7 @@ public final class InternalClient implements ClientEventsHandler, TelegramClient
@Override @Override
public void handleEvents(boolean isClosed, long[] eventIds, TdApi.Object[] events, int arrayOffset, int arrayLength) { public void handleEvents(boolean isClosed, long[] eventIds, TdApi.Object[] events, int arrayOffset, int arrayLength) {
if (updatesHandler != null) { if (updatesHandler != null) {
ObjectArrayList<TdApi.Object> updatesList = new ObjectArrayList<>(arrayLength); List<Object> updatesList = new ArrayList<>(arrayLength);
for (int i = (arrayOffset + arrayLength) - 1; i >= arrayOffset; i--) { for (int i = (arrayOffset + arrayLength) - 1; i >= arrayOffset; i--) {
if (eventIds[i] != 0) { if (eventIds[i] != 0) {

View File

@ -260,7 +260,7 @@ abstract class ResponseReceiver extends Thread implements AutoCloseable {
@SuppressWarnings("SameParameterValue") @SuppressWarnings("SameParameterValue")
private int[] generateSortIndex(int from, int to, int[] data) { private int[] generateSortIndex(int from, int to, int[] data) {
int[] sortedIndices = Arrays.copyOfRange(originalSortingSource, from, to); int[] sortedIndices = Arrays.copyOfRange(originalSortingSource, from, to);
it.unimi.dsi.fastutil.Arrays.mergeSort(from, ArrayUtil.mergeSort(from,
to, to,
(o1, o2) -> Integer.compare(data[sortedIndices[o1]], data[sortedIndices[o2]]), (o1, o2) -> Integer.compare(data[sortedIndices[o1]], data[sortedIndices[o2]]),
new IntSwapper(sortedIndices) new IntSwapper(sortedIndices)

View File

@ -1,8 +1,6 @@
package it.tdlight.common.utils; package it.tdlight.common.utils;
import it.unimi.dsi.fastutil.Swapper; public final class IntSwapper {
public final class IntSwapper implements Swapper {
private final int[] array; private final int[] array;
int tmp; int tmp;
@ -12,7 +10,6 @@ public final class IntSwapper implements Swapper {
tmp = 0; tmp = 0;
} }
@Override
public void swap(int a, int b) { public void swap(int a, int b) {
tmp = array[a]; tmp = array[a];
array[a] = array[b]; array[a] = array[b];

View File

@ -2,7 +2,6 @@ module tdlight.java {
requires tdlight.api; requires tdlight.api;
requires org.reactivestreams; requires org.reactivestreams;
requires org.slf4j; requires org.slf4j;
requires it.unimi.dsi.fastutil.core;
requires com.google.zxing; requires com.google.zxing;
exports it.tdlight.tdlight; exports it.tdlight.tdlight;
exports it.tdlight.tdnative; exports it.tdlight.tdnative;

View File

@ -50,10 +50,6 @@
<groupId>it.tdlight</groupId> <groupId>it.tdlight</groupId>
<artifactId>${tdlib.api.artifact.id}</artifactId> <artifactId>${tdlib.api.artifact.id}</artifactId>
</dependency> </dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -78,6 +74,12 @@
<version>5.8.2</version> <version>5.8.2</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil-core</artifactId>
<version>8.5.9</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>

View File

@ -48,10 +48,6 @@
<groupId>it.tdlight</groupId> <groupId>it.tdlight</groupId>
<artifactId>tdlight-api-legacy</artifactId> <artifactId>tdlight-api-legacy</artifactId>
</dependency> </dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil-core</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -76,6 +72,12 @@
<version>5.9.0</version> <version>5.9.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil-core</artifactId>
<version>8.5.9</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>

View File

@ -48,10 +48,6 @@
<groupId>it.tdlight</groupId> <groupId>it.tdlight</groupId>
<artifactId>tdlight-api-sealed</artifactId> <artifactId>tdlight-api-sealed</artifactId>
</dependency> </dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil-core</artifactId>
</dependency>
<dependency> <dependency>
<groupId>org.slf4j</groupId> <groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId> <artifactId>slf4j-api</artifactId>
@ -76,6 +72,12 @@
<version>5.9.0</version> <version>5.9.0</version>
<scope>test</scope> <scope>test</scope>
</dependency> </dependency>
<dependency>
<groupId>it.unimi.dsi</groupId>
<artifactId>fastutil-core</artifactId>
<version>8.5.9</version>
<scope>test</scope>
</dependency>
</dependencies> </dependencies>
<dependencyManagement> <dependencyManagement>
<dependencies> <dependencies>