|
21 | 21 | import sun.misc.Unsafe; |
22 | 22 |
|
23 | 23 | import java.nio.ByteOrder; |
| 24 | +import java.util.AbstractMap; |
24 | 25 | import java.util.Arrays; |
25 | 26 | import java.util.ConcurrentModificationException; |
26 | 27 | import java.util.Objects; |
| 28 | +import java.util.Set; |
27 | 29 |
|
28 | 30 | import static io.timeandspace.smoothie.SmoothieMap.LONG_PHI_MAGIC; |
29 | 31 | import static io.timeandspace.smoothie.UnsafeUtils.ARRAY_OBJECT_BASE_OFFSET_AS_LONG; |
30 | 32 | import static io.timeandspace.smoothie.UnsafeUtils.ARRAY_OBJECT_INDEX_SCALE_AS_LONG; |
31 | 33 | import static io.timeandspace.smoothie.UnsafeUtils.U; |
32 | 34 | import static io.timeandspace.smoothie.Utils.BYTE_SIZE_DIVISION_SHIFT; |
33 | 35 |
|
34 | | -public final class SwissTable<K, V> { |
| 36 | +public final class SwissTable<K, V> extends AbstractMap<K, V> { |
35 | 37 |
|
36 | 38 | private static final boolean LITTLE_ENDIAN = ByteOrder.nativeOrder() == ByteOrder.LITTLE_ENDIAN; |
37 | 39 | private static final int CONTROL_BITS = 7; |
@@ -177,6 +179,7 @@ private void init(int capacity) { |
177 | 179 | Arrays.fill(controls, EMPTY_CONTROL_GROUP); |
178 | 180 | } |
179 | 181 |
|
| 182 | + @Override |
180 | 183 | public int size() { |
181 | 184 | return size; |
182 | 185 | } |
@@ -266,7 +269,8 @@ private long lowestMatchIndexFromTrailingZeros(long groupFirstSlotIndex, int tra |
266 | 269 | (long) trailingZeros >>> BYTE_SIZE_DIVISION_SHIFT); |
267 | 270 | } |
268 | 271 |
|
269 | | - public @Nullable V get(K key) { |
| 272 | + @Override |
| 273 | + public @Nullable V get(Object key) { |
270 | 274 | Utils.checkNonNull(key); |
271 | 275 | long hash = keyHashCode(key); |
272 | 276 | long hashControlBits = hashControlBits(hash); |
@@ -295,12 +299,18 @@ private long lowestMatchIndexFromTrailingZeros(long groupFirstSlotIndex, int tra |
295 | 299 | } |
296 | 300 | } |
297 | 301 |
|
| 302 | + @Override |
298 | 303 | public @Nullable V put(K key, V value) { |
299 | 304 | Utils.checkNonNull(key); |
300 | 305 | long hash = keyHashCode(key); |
301 | 306 | return putInternal(key, hash, value); |
302 | 307 | } |
303 | 308 |
|
| 309 | + @Override |
| 310 | + public Set<Entry<K, V>> entrySet() { |
| 311 | + throw new UnsupportedOperationException(); |
| 312 | + } |
| 313 | + |
304 | 314 | private @Nullable V putInternal(K key, long hash, V value) { |
305 | 315 | long hashControlBits = hashControlBits(hash); |
306 | 316 | long initialGroupFirstSlotIndex = firstSlotIndex(hash); |
|
0 commit comments