public static BitSet range(int a, int b) { BitSet s = new BitSet(b + 1); for (int i = a; i <= b; i++) { int n = wordNumber(i); s.bits[n] |= bitMask(i); } return s; }
/**Is this contained within a? */ public boolean subset(BitSet a) { if (a == null) return false; return this.and(a).equals(this); }
/** or this element into this set (grow as necessary to accommodate) */ @Override public void add(int el) { //System.out.println("add("+el+")"); int n = wordNumber(el); //System.out.println("word number is "+n); //System.out.println("bits.length "+bits.length); if (n >= bits.length) { growToInclude(el); } bits[n] |= bitMask(el); }
public IntSet complement() { BitSet s = (BitSet)this.clone(); s.notInPlace(); return s; }
public void addAll(int[] elements) { if ( elements==null ) { return; } for (int i = 0; i < elements.length; i++) { int e = elements[i]; add(e); } }
@Override public IntSet subtract(IntSet a) { if (a == null || !(a instanceof BitSet)) return null; BitSet s = (BitSet)this.clone(); s.subtractInPlace((BitSet)a); return s; }
@Override public IntSet and(IntSet a) { BitSet s = (BitSet)this.clone(); s.andInPlace((BitSet)a); return s; }
public static BitSet of(IntSet set) { if ( set==null ) { return null; } if ( set instanceof BitSet ) { return (BitSet)set; } if ( set instanceof IntervalSet ) { BitSet s = new BitSet(); s.addAll(set); return s; } throw new IllegalArgumentException("can't create BitSet from "+set.getClass().getName()); }
/** Get the first element you find and return it. Return Label.INVALID * otherwise. */ @Override public int getSingleElement() { for (int i = 0; i < (bits.length << LOG_BITS); i++) { if (member(i)) { return i; } } return Label.INVALID; }
public boolean member(int el) { int n = wordNumber(el); if (n >= bits.length) return false; return (bits[n] & bitMask(el)) != 0; }
/**Create a string representation where instead of integer elements, the * ith element of vocabulary is displayed instead. Vocabulary is a Vector * of Strings. * separator The string to put in between elements * @return A commma-separated list of character constants. */ public String toString(String separator, List vocabulary) { if (vocabulary == null) { return toString(null); } String str = ""; for (int i = 0; i < (bits.length << LOG_BITS); i++) { if (member(i)) { if (str.length() > 0) { str += separator; } if (i >= vocabulary.size()) { str += "'" + (char)i + "'"; } else if (vocabulary.get(i) == null) { str += "'" + (char)i + "'"; } else { str += (String)vocabulary.get(i); } } } return str; }
public IntSet complement(IntSet set) { if ( set==null ) { return this.complement(); } return set.subtract(this); }
/** complement bits in the range minBit..maxBit.*/ public void notInPlace(int minBit, int maxBit) { // make sure that we have room for maxBit growToInclude(maxBit); for (int i = minBit; i <= maxBit; i++) { int n = wordNumber(i); bits[n] ^= bitMask(i); } }
public static void error(int msgID, Throwable e) { getErrorState().errors++; getErrorState().errorMsgIDs.add(msgID); getErrorListener().error(new ToolMessage(msgID,e)); }
public IntSet complement() { BitSet s = (BitSet)this.clone(); s.notInPlace(); return s; }
@Override public IntSet subtract(IntSet a) { if (a == null || !(a instanceof BitSet)) return null; BitSet s = (BitSet)this.clone(); s.subtractInPlace((BitSet)a); return s; }