The supported concurrency model is one writer and any number of readers. Removals are not + * supported. Iteration must use the captured-table helper in {@code MapUtils.kt}; the inherited + * fastutil iterators are not concurrent-read-safe.
+ */ +public final class ConcurrentReadSafeLong2ObjectMapThe supported concurrency model is one writer and any number of readers. Removals are not + * supported. Iteration must use the captured-table helper in {@code MapUtils.kt}; the inherited + * fastutil iterators are not concurrent-read-safe.
+ */ +public final class ConcurrentReadSafeLongSet extends LongOpenHashSet { + @Override + public boolean contains(long k) { + if (k == 0) return containsNull; + + while (true) { + long[] key = this.key; + int n = this.n; + + // Capture one complete table generation to allow a read during rehash. + if (key.length != n + 1) continue; + + int mask = n - 1; + int pos = (int) HashCommon.mix(k) & mask; + long curr = key[pos]; + if (curr == 0) return false; + + if (k == curr) return true; + + // There's always an unused entry. + while (true) { + pos = (pos + 1) & mask; + curr = key[pos]; + if (curr == 0) return false; + + if (k == curr) return true; + } + } + } + + @Override + public boolean remove(long k) { + throw new UnsupportedOperationException("Removals are not allowed"); + } + + public long[] getKeys() { + return this.key; + } + + public int getN() { + return this.n; + } + + public boolean getContainsNull() { + return this.containsNull; + } + + private static final long serialVersionUID = 0L; +} diff --git a/core/opentaint-dataflow-core/opentaint-dataflow/src/main/java/org/opentaint/dataflow/util/ConcurrentReadSafeObject2IntMap.java b/core/opentaint-dataflow-core/opentaint-dataflow/src/main/java/org/opentaint/dataflow/util/ConcurrentReadSafeObject2IntMap.java index edbabe33c..00ecd584d 100644 --- a/core/opentaint-dataflow-core/opentaint-dataflow/src/main/java/org/opentaint/dataflow/util/ConcurrentReadSafeObject2IntMap.java +++ b/core/opentaint-dataflow-core/opentaint-dataflow/src/main/java/org/opentaint/dataflow/util/ConcurrentReadSafeObject2IntMap.java @@ -4,9 +4,18 @@ import it.unimi.dsi.fastutil.objects.Object2IntOpenHashMap; import org.jetbrains.annotations.Nullable; +/** + * A flat object-to-int map supporting one writer and multiple concurrent point readers. + * + *Writes are published through a sequence counter. Readers retry if a write overlaps their + * lookup, which prevents observing a key before its primitive value or a partially published + * rehash. Removals are not supported.
+ */ public final class ConcurrentReadSafeObject2IntMap