FileDocCategorySizeDatePackage
ListIntSet.javaAPI DocAndroid 5.1 API3320Thu Mar 12 22:18:30 GMT 2015com.android.dx.util

ListIntSet

public class ListIntSet extends Object implements IntSet
A set of integers, represented by a list

Fields Summary
final IntList
ints
also accessed in BitIntSet
Constructors Summary
public ListIntSet()
Constructs an instance

        ints = new IntList();
        ints.sort();
    
Methods Summary
public voidadd(int value)

inheritDoc

        int index = ints.binarysearch(value);

        if (index < 0) {
            ints.insert(-(index + 1), value);
        }
    
public intelements()

inheritDoc

        return ints.size();
    
public booleanhas(int value)

inheritDoc

        return ints.indexOf(value) >= 0;
    
public IntIteratoriterator()

inheritDoc

        return new IntIterator() {
            private int idx = 0;

            /** @inheritDoc */
            public boolean hasNext() {
                return idx < ints.size();
            }

            /** @inheritDoc */
            public int next() {
                if (!hasNext()) {
                    throw new NoSuchElementException();
                }

                return ints.get(idx++);
            }
        };
    
public voidmerge(IntSet other)

inheritDoc

        if (other instanceof ListIntSet) {
            ListIntSet o = (ListIntSet) other;
            int szThis = ints.size();
            int szOther = o.ints.size();

            int i = 0;
            int j = 0;

            while (j < szOther && i < szThis) {
                while (j < szOther && o.ints.get(j) < ints.get(i)) {
                    add(o.ints.get(j++));
                }
                if (j == szOther) {
                    break;
                }
                while (i < szThis && o.ints.get(j) >= ints.get(i)) {
                    i++;
                }
            }

            while (j < szOther) {
                add(o.ints.get(j++));
            }

            ints.sort();
        } else if (other instanceof BitIntSet) {
            BitIntSet o = (BitIntSet) other;

            for (int i = 0; i >= 0; i = Bits.findFirst(o.bits, i + 1)) {
                ints.add(i);
            }
            ints.sort();
        } else {
            IntIterator iter = other.iterator();
            while (iter.hasNext()) {
                add(iter.next());
            }
        }
    
public voidremove(int value)

inheritDoc

        int index = ints.indexOf(value);

        if (index >= 0) {
            ints.removeIndex(index);
        }
    
public java.lang.StringtoString()

inheritDoc

        return ints.toString();