Skip to content

Commit 58d050d

Browse files
committed
MP-11740 Restrict TreeMap to 1 bucket
1 parent 418872c commit 58d050d

2 files changed

Lines changed: 5 additions & 9 deletions

File tree

src/main/java/com/trivago/fastutilconcurrentwrapper/ConcurrentLongShortTreeMapBuilder.java

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55

66
public final class ConcurrentLongShortTreeMapBuilder {
77
private MapMode mapMode = MapMode.BLOCKING;
8-
private int buckets = 8;
8+
// floorEntry() requires all keys to reside in a single bucket to return
9+
// correct results, so the bucket count is fixed at 1.
10+
private static final int BUCKETS = 1;
911
private short defaultValue = LongShortMap.DEFAULT_VALUE;
1012

1113
private ConcurrentLongShortTreeMapBuilder() {
@@ -15,10 +17,6 @@ public static ConcurrentLongShortTreeMapBuilder newBuilder() {
1517
return new ConcurrentLongShortTreeMapBuilder();
1618
}
1719

18-
public ConcurrentLongShortTreeMapBuilder withBuckets(int buckets) {
19-
this.buckets = buckets;
20-
return this;
21-
}
2220

2321
public ConcurrentLongShortTreeMapBuilder withMode(MapMode mapMode) {
2422
this.mapMode = mapMode;
@@ -39,15 +37,15 @@ public enum MapMode {
3937
@Override
4038
LongShortTreeMap createMap(ConcurrentLongShortTreeMapBuilder builder) {
4139
return new ConcurrentBusyWaitingLongShortTreeMap(
42-
builder.buckets,
40+
BUCKETS,
4341
builder.defaultValue);
4442
}
4543
},
4644
BLOCKING {
4745
@Override
4846
LongShortTreeMap createMap(ConcurrentLongShortTreeMapBuilder builder) {
4947
return new ConcurrentLongShortTreeMap(
50-
builder.buckets,
48+
BUCKETS,
5149
builder.defaultValue);
5250
}
5351
};

src/test/java/com/trivago/fastutilconcurrentwrapper/ConcurrentLongShortTreeMapBuilderTest.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ public class ConcurrentLongShortTreeMapBuilderTest {
1313
@Test
1414
public void buildsBusyWaitingMap() {
1515
ConcurrentLongShortTreeMapBuilder b = ConcurrentLongShortTreeMapBuilder.newBuilder()
16-
.withBuckets(2)
1716
.withDefaultValue(DEFAULT_VALUE)
1817
.withMode(ConcurrentLongShortTreeMapBuilder.MapMode.BUSY_WAITING);
1918
LongShortTreeMap map = b.build();
@@ -27,7 +26,6 @@ public void buildsBusyWaitingMap() {
2726
@Test
2827
public void buildsBlockingMap() {
2928
ConcurrentLongShortTreeMapBuilder b = ConcurrentLongShortTreeMapBuilder.newBuilder()
30-
.withBuckets(2)
3129
.withDefaultValue(DEFAULT_VALUE)
3230
.withMode(ConcurrentLongShortTreeMapBuilder.MapMode.BLOCKING);
3331
LongShortTreeMap map = b.build();

0 commit comments

Comments
 (0)