Skip to content

Commit 5f6b1d5

Browse files
committed
MP-11740 Prevent instantiating TreeMap with more than 1 bucket
1 parent 1e1af20 commit 5f6b1d5

6 files changed

Lines changed: 18 additions & 10 deletions

File tree

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

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,6 @@
55

66
public final class ConcurrentLongShortTreeMapBuilder {
77
private MapMode mapMode = MapMode.BLOCKING;
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;
128
private short defaultValue = LongShortMap.DEFAULT_VALUE;
139

1410
private ConcurrentLongShortTreeMapBuilder() {
@@ -38,15 +34,13 @@ public enum MapMode {
3834
@Override
3935
LongShortTreeMap createMap(ConcurrentLongShortTreeMapBuilder builder) {
4036
return new ConcurrentBusyWaitingLongShortTreeMap(
41-
BUCKETS,
4237
builder.defaultValue);
4338
}
4439
},
4540
BLOCKING {
4641
@Override
4742
LongShortTreeMap createMap(ConcurrentLongShortTreeMapBuilder builder) {
4843
return new ConcurrentLongShortTreeMap(
49-
BUCKETS,
5044
builder.defaultValue);
5145
}
5246
};

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

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,12 @@
66
* A sorted {@link LongShortMap} that additionally supports a {@code floorEntry()} operation.
77
*/
88
public interface LongShortTreeMap extends LongShortMap {
9+
10+
// floorEntry() requires all keys to reside in a single bucket to return
11+
// correct results, so the bucket count is fixed at 1.
12+
// ToDo: Identify a bucketing methodology that works for TreeMap
13+
public static final int BUCKETS = 1;
14+
915
/**
1016
* Returns the entry with the greatest key less than or equal to the given key,
1117
* or {@code null} if no such key exists.

src/main/java/com/trivago/fastutilconcurrentwrapper/map/ConcurrentBusyWaitingLongShortTreeMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,11 @@ public class ConcurrentBusyWaitingLongShortTreeMap extends PrimitiveConcurrentMa
1313
private final LongShortTreeMap[] maps;
1414
private final short defaultValue;
1515

16-
public ConcurrentBusyWaitingLongShortTreeMap(int numBuckets,
16+
public ConcurrentBusyWaitingLongShortTreeMap(short defaultValue) {
17+
this(LongShortTreeMap.BUCKETS,defaultValue);
18+
}
19+
20+
private ConcurrentBusyWaitingLongShortTreeMap(int numBuckets,
1721
short defaultValue) {
1822
super(numBuckets);
1923

src/main/java/com/trivago/fastutilconcurrentwrapper/map/ConcurrentLongShortTreeMap.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,11 @@ public class ConcurrentLongShortTreeMap extends PrimitiveConcurrentMap implement
1212
private final LongShortTreeMap[] maps;
1313
private final short defaultValue;
1414

15-
public ConcurrentLongShortTreeMap(int numBuckets, short defaultValue) {
15+
public ConcurrentLongShortTreeMap(short defaultValue) {
16+
this(LongShortTreeMap.BUCKETS,defaultValue);
17+
}
18+
19+
private ConcurrentLongShortTreeMap(int numBuckets, short defaultValue) {
1620
super(numBuckets);
1721
this.maps = new LongShortTreeMap[numBuckets];
1822
this.defaultValue = defaultValue;

src/test/java/com/trivago/fastutilconcurrentwrapper/longshort/ConcurrentBusyWaitingLongShortTreeMapTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
public class ConcurrentBusyWaitingLongShortTreeMapTest extends AbstractLongShortTreeMapTest {
77
@Override
88
LongShortTreeMap createMap() {
9-
return new ConcurrentBusyWaitingLongShortTreeMap(1, defaultValue);
9+
return new ConcurrentBusyWaitingLongShortTreeMap(defaultValue);
1010
}
1111
}

src/test/java/com/trivago/fastutilconcurrentwrapper/longshort/ConcurrentPrimitiveLongShortTreeMapTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@
66
public class ConcurrentPrimitiveLongShortTreeMapTest extends AbstractLongShortTreeMapTest {
77
@Override
88
LongShortTreeMap createMap() {
9-
return new ConcurrentLongShortTreeMap(1, defaultValue);
9+
return new ConcurrentLongShortTreeMap(defaultValue);
1010
}
1111
}

0 commit comments

Comments
 (0)