Skip to content

Commit

Permalink
Merge remote-tracking branch 'refs/remotes/origin/4.0.0-1.20.5-fabric…
Browse files Browse the repository at this point in the history
…' into 4.0.0-1.21-fabric
  • Loading branch information
melontini committed Jul 16, 2024
2 parents def8743 + 0f457ff commit 87ae043
Showing 1 changed file with 3 additions and 6 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
package me.melontini.dark_matter.api.base.util.functions;

import java.util.HashMap;
import java.util.IdentityHashMap;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.*;
import java.util.function.Function;
import java.util.function.Supplier;

Expand Down Expand Up @@ -52,12 +49,12 @@ public static <T, R> Function<T, R> identityFunction(Function<T, R> delegate) {
* Unlike previous functions, this one will evict unused entries when capacity is too high.
*/
public static <T, R> Function<T, R> lruFunction(Function<T, R> delegate, int capacity) {
return cachedFunction(new LinkedHashMap<>(Math.min(16, capacity), 0.75f, true) {
return cachedFunction(Collections.synchronizedMap(new LinkedHashMap<>(capacity + 1, 0.75f, true) {
@Override
protected boolean removeEldestEntry(Map.Entry<T, R> eldest) {
return size() > capacity;
}
}, delegate);
}), delegate);
}

public static <T, R> Function<T, R> cachedFunction(Map<T, R> cache, Function<T, R> delegate) {
Expand Down

0 comments on commit 87ae043

Please sign in to comment.