Skip to content

Commit 618abd3

Browse files
committed
MP-11740 Restrict TreeMap to 1 bucket
1 parent 418872c commit 618abd3

2 files changed

Lines changed: 6 additions & 9 deletions

File tree

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,10 @@
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+
// ToDo: Identify a bucketing methodology that works for TreeMap
11+
private static final int BUCKETS = 1;
912
private short defaultValue = LongShortMap.DEFAULT_VALUE;
1013

1114
private ConcurrentLongShortTreeMapBuilder() {
@@ -15,10 +18,6 @@ public static ConcurrentLongShortTreeMapBuilder newBuilder() {
1518
return new ConcurrentLongShortTreeMapBuilder();
1619
}
1720

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

2322
public ConcurrentLongShortTreeMapBuilder withMode(MapMode mapMode) {
2423
this.mapMode = mapMode;
@@ -39,15 +38,15 @@ public enum MapMode {
3938
@Override
4039
LongShortTreeMap createMap(ConcurrentLongShortTreeMapBuilder builder) {
4140
return new ConcurrentBusyWaitingLongShortTreeMap(
42-
builder.buckets,
41+
BUCKETS,
4342
builder.defaultValue);
4443
}
4544
},
4645
BLOCKING {
4746
@Override
4847
LongShortTreeMap createMap(ConcurrentLongShortTreeMapBuilder builder) {
4948
return new ConcurrentLongShortTreeMap(
50-
builder.buckets,
49+
BUCKETS,
5150
builder.defaultValue);
5251
}
5352
};

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)