MCPcopy Create free account
hub / github.com/LFYSec/MScan / HybridBitSet

Class HybridBitSet

src/main/java/pascal/taie/util/collection/HybridBitSet.java:50–159  ·  view source on GitHub ↗

Hybrid set that uses bit set for large set. It is important to note that batch operations such as #addAll(Collection), #removeAll(Collection), #retainAll(Collection), and #containsAll(Collection) can experience performance degradation when used with {@link Indexer

Source from the content-addressed store, hash-verified

48 * @see IndexerBitSet
49 */
50public final class HybridBitSet<E> extends AbstractHybridSet<E>
51 implements Serializable {
52
53 private final Indexer<E> indexer;
54
55 private final boolean isSparse;
56
57 public HybridBitSet(Indexer<E> indexer, boolean isSparse) {
58 this.indexer = indexer;
59 this.isSparse = isSparse;
60 }
61
62 @Override
63 protected Set<E> newLargeSet(int unused) {
64 return new IndexerBitSet<>(indexer, isSparse);
65 }
66
67 @Override
68 public boolean addAll(@Nonnull Collection<? extends E> c) {
69 // optimize when c is HybridBitSet
70 if (this.set instanceof GenericBitSet<E> thisBitSet
71 && c instanceof HybridBitSet<? extends E> other
72 && other.set instanceof GenericBitSet<? extends E> otherBitSet) {
73 return thisBitSet.addAll(otherBitSet);
74 }
75 return super.addAll(c);
76 }
77
78 @Override
79 public boolean containsAll(Collection<?> c) {
80 // optimize when c is HybridBitSet
81 if (this.set instanceof GenericBitSet<E> thisBitSet
82 && c instanceof HybridBitSet<?> other
83 && other.set instanceof GenericBitSet<?> otherBitSet) {
84 return thisBitSet.containsAll(otherBitSet);
85 }
86 return super.containsAll(c);
87 }
88
89 @Override
90 public boolean removeAll(Collection<?> c) {
91 // optimize when c is HybridBitSet
92 if (this.set instanceof GenericBitSet<E> thisBitSet
93 && c instanceof HybridBitSet<?> other
94 && other.set instanceof GenericBitSet<?> otherBitSet) {
95 return thisBitSet.removeAll(otherBitSet);
96 }
97 return super.removeAll(c);
98 }
99
100 @Override
101 public boolean retainAll(@Nonnull Collection<?> c) {
102 // optimize when c is HybridBitSet
103 if (this.set instanceof GenericBitSet<E> thisBitSet
104 && c instanceof HybridBitSet<?> other
105 && other.set instanceof GenericBitSet<?> otherBitSet) {
106 return thisBitSet.retainAll(otherBitSet);
107 }

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected