Implements the bitset interface via a hash set. It is more efficient for only a few entries. @author Peter Karich
| 28 | * @author Peter Karich |
| 29 | */ |
| 30 | public class GHTBitSet implements GHBitSet { |
| 31 | private final GHIntHashSet tHash; |
| 32 | |
| 33 | public GHTBitSet(GHIntHashSet set) { |
| 34 | tHash = set; |
| 35 | } |
| 36 | |
| 37 | public GHTBitSet(int no) { |
| 38 | tHash = new GHIntHashSet(no, 0.7f); |
| 39 | } |
| 40 | |
| 41 | public GHTBitSet() { |
| 42 | this(1000); |
| 43 | } |
| 44 | |
| 45 | @Override |
| 46 | public final boolean contains(int index) { |
| 47 | return tHash.contains(index); |
| 48 | } |
| 49 | |
| 50 | @Override |
| 51 | public final void add(int index) { |
| 52 | tHash.add(index); |
| 53 | } |
| 54 | |
| 55 | @Override |
| 56 | public final String toString() { |
| 57 | return tHash.toString(); |
| 58 | } |
| 59 | |
| 60 | @Override |
| 61 | public final int getCardinality() { |
| 62 | return tHash.size(); |
| 63 | } |
| 64 | |
| 65 | @Override |
| 66 | public final void clear() { |
| 67 | tHash.clear(); |
| 68 | } |
| 69 | |
| 70 | @Override |
| 71 | public void remove(int index) { |
| 72 | tHash.remove(index); |
| 73 | } |
| 74 | |
| 75 | @Override |
| 76 | public final GHBitSet copyTo(GHBitSet bs) { |
| 77 | bs.clear(); |
| 78 | if (bs instanceof GHTBitSet) { |
| 79 | ((GHTBitSet) bs).tHash.addAll(this.tHash); |
| 80 | } else { |
| 81 | Iterator<IntCursor> iter = tHash.iterator(); |
| 82 | while (iter.hasNext()) { |
| 83 | bs.add(iter.next().value); |
| 84 | } |
| 85 | } |
| 86 | return bs; |
| 87 | } |
nothing calls this directly
no outgoing calls
no test coverage detected