|
8 | 8 | import it.unimi.dsi.fastutil.longs.LongSet;
|
9 | 9 | import it.unimi.dsi.fastutil.objects.ObjectCollection;
|
10 | 10 | import it.unimi.dsi.fastutil.objects.ObjectSet;
|
| 11 | +import org.jctools.maps.NonBlockingHashMapLong; |
11 | 12 | import org.jspecify.annotations.Nullable;
|
12 | 13 |
|
13 | 14 | import java.util.Map;
|
| 15 | +import java.util.concurrent.CancellationException; |
14 | 16 | import java.util.concurrent.ConcurrentMap;
|
15 | 17 | import java.util.concurrent.locks.Lock;
|
16 | 18 | import java.util.function.BiConsumer;
|
17 | 19 | import java.util.function.BiFunction;
|
18 | 20 | import java.util.function.Function;
|
| 21 | +import java.util.function.LongConsumer; |
19 | 22 |
|
20 | 23 | /**
|
21 | 24 | Similar to {@link ConcurrentLongObjectMap}, but backed with NonBlockingHashMapLong ⇒ non-blocking reads 🚀
|
@@ -200,6 +203,14 @@ public long nextLong () {
|
200 | 203 |
|
201 | 204 | public StripedLongIterator keys (){ return new StripedLongIterator(this); }
|
202 | 205 |
|
| 206 | + public void forEachKey (LongConsumer action) { |
| 207 | + var it = (NonBlockingHashMapLong<E>.IteratorLong) m.keys(); |
| 208 | + try { |
| 209 | + while (it.hasNext()) |
| 210 | + action.accept(it.nextLong()); |
| 211 | + } catch (CancellationException ignored){} |
| 212 | + } |
| 213 | + |
203 | 214 | @Override
|
204 | 215 | public LongSet keySet () {
|
205 | 216 | throw new UnsupportedOperationException("keySet");
|
@@ -276,6 +287,7 @@ public void defaultReturnValue (E rv) {
|
276 | 287 | public ObjectSet<Long2ObjectMap.Entry<E>> long2ObjectEntrySet () {
|
277 | 288 | throw new UnsupportedOperationException();
|
278 | 289 | }
|
| 290 | + |
279 | 291 | public <R> R withLock (long key, Function<Long2ObjectMap.Entry<E>,R> withLock) {
|
280 | 292 | try (var __ = write(key)){
|
281 | 293 | Long2ObjectMap.Entry<E> x = new Long2ObjectMap.Entry<E>() {
|
|
0 commit comments