/** * equal if obj is a bitset and contains the same bits as this * * @param obj Object * @return boolean */ public boolean equals(Object obj) { boolean equalOk = false; if ((obj != null) && (obj instanceof NodeIdSet)) { NodeIdSet objBS = (NodeIdSet) obj; equalOk = (this.contains(objBS) && (this.cardinality() == objBS.cardinality())); } return equalOk; }
/** * modify this bitset by adding all the bits that are in s (logically bitwise: this = this OR s) * return true if any modification, otherwise false * * @param s BitSet * @return BitSet */ public boolean merge(NodeIdSet s) { boolean mergeOk = false; int msb = s.getMaxBitPos(); if (msb > this.size()) storage = createByteArray(msb, storage); byte[] test = s.getBytes(); byte oldValue = 0; for (int i = 0; i < storage.length; ++i) { oldValue = storage[i]; storage[i] |= test[i]; if (storage[i] != oldValue) mergeOk = true; } return mergeOk; }
/** * modify this bitset by removing anything that is in s (logically bitwise: this = this AND ( NOT * s)) return true if any modification, otherwise false * * @param s BitSet * @return BitSet */ public boolean subtract(NodeIdSet s) { boolean subOk = false; byte[] test = s.getBytes(); int minLength = ((storage.length < test.length) ? storage.length : test.length); byte oldValue = 0; for (int i = 0; i < minLength; ++i) { oldValue = storage[i]; storage[i] &= ~test[i]; if (storage[i] != oldValue) subOk = true; } return subOk; }
/** * modify this bitset by removing anything that is NOT also in s (logically bitwise: this = this * AND s) return true if any modification, otherwise false * * @param s BitSet * @return boolean */ public boolean removeComplement(NodeIdSet s) { boolean rcOk = false; byte[] test = s.getBytes(); int minLength = ((storage.length < test.length) ? storage.length : test.length); byte oldValue = 0; for (int i = 0; i < minLength; ++i) { oldValue = storage[i]; storage[i] &= test[i]; if (storage[i] != oldValue) rcOk = true; } return rcOk; }
/** * are there any bits in both this and s? * * @param s BitSet * @return boolean */ public boolean overlap(NodeIdSet s) { boolean overlapOk = false; byte[] test = s.getBytes(); int minLength = ((storage.length < test.length) ? storage.length : test.length); for (int i = 0; i < minLength; ++i) { if ((storage[i] & test[i]) != 0) { overlapOk = true; break; } } return overlapOk; }
/** * Return a new identical copy * * @return BitSet */ public Object clone() { NodeIdSet cloneBS = new NodeIdSet(this.size()); byte[] cloneStorage = cloneBS.getBytes(); for (int i = 0; i < storage.length; ++i) cloneStorage[i] = storage[i]; return cloneBS; }
/** * are all the bits in this contained in s? * * @param s BitSet * @return boolean */ public boolean containedIn(NodeIdSet s) { return compare(s.getBytes(), storage); }
/** * Are all the bits in s contained in this? * * @param s BitSet * @return boolean */ public boolean contains(NodeIdSet s) { return compare(storage, s.getBytes()); }