Class SparseLongSet

  • All Implemented Interfaces:
    LongSet
    Direct Known Subclasses:
    MutableSparseLongSet

    public class SparseLongSet
    extends java.lang.Object
    implements LongSet
    A sparse ordered, duplicate-free, fully-encapsulated set of longs; not necessary mutable
    • Field Detail

      • elements

        protected long[] elements
        The backing store of int arrays
      • size

        protected int size
        The number of entries in the backing store that are valid.
    • Constructor Detail

      • SparseLongSet

        protected SparseLongSet​(int size)
      • SparseLongSet

        protected SparseLongSet​(long[] backingArray)
        Subclasses should use this with extreme care. Do not allow the backing array to escape elsewhere.
      • SparseLongSet

        public SparseLongSet()
        Subclasses should use this with extreme care.
      • SparseLongSet

        public SparseLongSet​(IntSet S)
                      throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException
    • Method Detail

      • contains

        public final boolean contains​(long x)
        Does this set contain value x?
        Specified by:
        contains in interface LongSet
        Returns:
        true iff this set contains long i
        See Also:
        IntSet.contains(int)
      • getIndex

        public final int getIndex​(long x)
        Returns:
        index i s.t. elements[i] == x, or -1 if not found.
      • size

        public final int size()
        Specified by:
        size in interface LongSet
        Returns:
        the number of elements in this set
      • isEmpty

        public final boolean isEmpty()
        Specified by:
        isEmpty in interface LongSet
        Returns:
        true iff this set is empty
      • elementAt

        public final long elementAt​(int idx)
                             throws java.util.NoSuchElementException
        Throws:
        java.util.NoSuchElementException
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • parseLongArray

        public static long[] parseLongArray​(java.lang.String str)
                                     throws java.lang.NumberFormatException,
                                            java.lang.IllegalArgumentException
        Reverse of toString(): "{2,3}" -> [2,3]
        Throws:
        java.lang.IllegalArgumentException - if str is null
        java.lang.NumberFormatException
      • intersection

        public LongSet intersection​(LongSet that)
                             throws java.lang.IllegalArgumentException,
                                    UnimplementedError
        Description copied from interface: LongSet
        This implementation must not despoil the original value of "this"
        Specified by:
        intersection in interface LongSet
        Returns:
        a new IntSet which is the intersection of this and that
        Throws:
        java.lang.IllegalArgumentException
        UnimplementedError
      • foreach

        public void foreach​(LongSetAction action)
        Description copied from interface: LongSet
        Invoke an action on each element of the Set
        Specified by:
        foreach in interface LongSet
      • foreachExcluding

        public void foreachExcluding​(LongSet X,
                                     LongSetAction action)
        Description copied from interface: LongSet
        Invoke an action on each element of the Set, excluding elements of Set X
        Specified by:
        foreachExcluding in interface LongSet
      • max

        public final long max()
                       throws java.lang.IllegalStateException
        Specified by:
        max in interface LongSet
        Returns:
        the largest element in the set
        Throws:
        java.lang.IllegalStateException
      • containsAny

        public boolean containsAny​(LongSet set)
        Specified by:
        containsAny in interface LongSet
        Returns:
        true iff this set contains integer i
      • containsAny

        public boolean containsAny​(SparseLongSet set)
                            throws java.lang.IllegalArgumentException
        Throws:
        java.lang.IllegalArgumentException