Class IntAVLTreeSet

  • All Implemented Interfaces:
    IntBidirectionalIterable, IntCollection, IntIterable, IntSet, IntSortedSet, java.io.Serializable, java.lang.Cloneable, java.lang.Iterable<java.lang.Integer>, java.util.Collection<java.lang.Integer>, java.util.Set<java.lang.Integer>, java.util.SortedSet<java.lang.Integer>

    public class IntAVLTreeSet
    extends AbstractIntSortedSet
    implements java.io.Serializable, java.lang.Cloneable, IntSortedSet
    A type-specific AVL tree set with a fast, small-footprint implementation.

    The iterators provided by this class are type-specific bidirectional iterators. Moreover, the iterator returned by iterator() can be safely cast to a type-specific list iterator.

    See Also:
    Serialized Form
    • Constructor Summary

      Constructors 
      Constructor Description
      IntAVLTreeSet()
      Creates a new empty tree set.
      IntAVLTreeSet​(int[] a)
      Creates a new tree set copying the elements of an array.
      IntAVLTreeSet​(int[] a, int offset, int length)
      Creates a new tree set and fills it with the elements of a given array.
      IntAVLTreeSet​(int[] a, int offset, int length, java.util.Comparator<? super java.lang.Integer> c)
      Creates a new tree set and fills it with the elements of a given array using a given Comparator.
      IntAVLTreeSet​(int[] a, java.util.Comparator<? super java.lang.Integer> c)
      Creates a new tree set copying the elements of an array using a given Comparator.
      IntAVLTreeSet​(IntCollection c)
      Creates a new tree set copying a given type-specific collection.
      IntAVLTreeSet​(IntIterator i)
      Creates a new tree set using elements provided by a type-specific iterator.
      IntAVLTreeSet​(IntSortedSet s)
      Creates a new tree set copying a given type-specific sorted set (and its Comparator).
      IntAVLTreeSet​(java.util.Collection<? extends java.lang.Integer> c)
      Creates a new tree set copying a given set.
      IntAVLTreeSet​(java.util.Comparator<? super java.lang.Integer> c)
      Creates a new empty tree set with the given comparator.
      IntAVLTreeSet​(java.util.Iterator<?> i)
      Creates a new tree set using elements provided by an iterator.
      IntAVLTreeSet​(java.util.SortedSet<java.lang.Integer> s)
      Creates a new tree set copying a given sorted set (and its Comparator).
    • Constructor Detail

      • IntAVLTreeSet

        public IntAVLTreeSet()
        Creates a new empty tree set.
      • IntAVLTreeSet

        public IntAVLTreeSet​(java.util.Comparator<? super java.lang.Integer> c)
        Creates a new empty tree set with the given comparator.
        Parameters:
        c - a Comparator (even better, a type-specific comparator).
      • IntAVLTreeSet

        public IntAVLTreeSet​(java.util.Collection<? extends java.lang.Integer> c)
        Creates a new tree set copying a given set.
        Parameters:
        c - a collection to be copied into the new tree set.
      • IntAVLTreeSet

        public IntAVLTreeSet​(java.util.SortedSet<java.lang.Integer> s)
        Creates a new tree set copying a given sorted set (and its Comparator).
        Parameters:
        s - a SortedSet to be copied into the new tree set.
      • IntAVLTreeSet

        public IntAVLTreeSet​(IntCollection c)
        Creates a new tree set copying a given type-specific collection.
        Parameters:
        c - a type-specific collection to be copied into the new tree set.
      • IntAVLTreeSet

        public IntAVLTreeSet​(IntSortedSet s)
        Creates a new tree set copying a given type-specific sorted set (and its Comparator).
        Parameters:
        s - a type-specific sorted set to be copied into the new tree set.
      • IntAVLTreeSet

        public IntAVLTreeSet​(IntIterator i)
        Creates a new tree set using elements provided by a type-specific iterator.
        Parameters:
        i - a type-specific iterator whose elements will fill the set.
      • IntAVLTreeSet

        public IntAVLTreeSet​(java.util.Iterator<?> i)
        Creates a new tree set using elements provided by an iterator.
        Parameters:
        i - an iterator whose elements will fill the set.
      • IntAVLTreeSet

        public IntAVLTreeSet​(int[] a,
                             int offset,
                             int length,
                             java.util.Comparator<? super java.lang.Integer> c)
        Creates a new tree set and fills it with the elements of a given array using a given Comparator.
        Parameters:
        a - an array whose elements will be used to fill the set.
        offset - the first element to use.
        length - the number of elements to use.
        c - a Comparator (even better, a type-specific comparator).
      • IntAVLTreeSet

        public IntAVLTreeSet​(int[] a,
                             int offset,
                             int length)
        Creates a new tree set and fills it with the elements of a given array.
        Parameters:
        a - an array whose elements will be used to fill the set.
        offset - the first element to use.
        length - the number of elements to use.
      • IntAVLTreeSet

        public IntAVLTreeSet​(int[] a)
        Creates a new tree set copying the elements of an array.
        Parameters:
        a - an array to be copied into the new tree set.
      • IntAVLTreeSet

        public IntAVLTreeSet​(int[] a,
                             java.util.Comparator<? super java.lang.Integer> c)
        Creates a new tree set copying the elements of an array using a given Comparator.
        Parameters:
        a - an array to be copied into the new tree set.
        c - a Comparator (even better, a type-specific comparator).
    • Method Detail

      • add

        public boolean add​(int k)
        Description copied from class: AbstractIntCollection
        Ensures that this collection contains the specified element (optional operation).

        This implementation always throws an UnsupportedOperationException.

        Specified by:
        add in interface IntCollection
        Overrides:
        add in class AbstractIntCollection
        See Also:
        Collection.add(Object)
      • remove

        public boolean remove​(int k)
        Description copied from class: AbstractIntSet
        Removes an element from this set.

        Note that the corresponding method of a type-specific collection is rem(). This unfortunate situation is caused by the clash with the similarly named index-based method in the List interface. Delegates to the type-specific rem() method implemented by type-specific abstract Collection superclass.

        Specified by:
        remove in interface IntSet
        Overrides:
        remove in class AbstractIntSet
        See Also:
        Collection.remove(Object)
      • contains

        public boolean contains​(int k)
        Description copied from class: AbstractIntCollection
        Returns true if this collection contains the specified element.

        This implementation iterates over the elements in the collection, looking for the specified element.

        Specified by:
        contains in interface IntCollection
        Overrides:
        contains in class AbstractIntCollection
        See Also:
        Collection.contains(Object)
      • clear

        public void clear()
        Specified by:
        clear in interface java.util.Collection<java.lang.Integer>
        Specified by:
        clear in interface java.util.Set<java.lang.Integer>
        Overrides:
        clear in class java.util.AbstractCollection<java.lang.Integer>
      • size

        public int size()
        Specified by:
        size in interface java.util.Collection<java.lang.Integer>
        Specified by:
        size in interface java.util.Set<java.lang.Integer>
        Specified by:
        size in class java.util.AbstractCollection<java.lang.Integer>
      • isEmpty

        public boolean isEmpty()
        Specified by:
        isEmpty in interface java.util.Collection<java.lang.Integer>
        Specified by:
        isEmpty in interface java.util.Set<java.lang.Integer>
        Overrides:
        isEmpty in class java.util.AbstractCollection<java.lang.Integer>
      • firstInt

        public int firstInt()
        Description copied from interface: IntSortedSet
        Returns the first (lowest) element currently in this set.
        Specified by:
        firstInt in interface IntSortedSet
        See Also:
        SortedSet.first()
      • lastInt

        public int lastInt()
        Description copied from interface: IntSortedSet
        Returns the last (highest) element currently in this set.
        Specified by:
        lastInt in interface IntSortedSet
        See Also:
        SortedSet.last()
      • iterator

        public IntBidirectionalIterator iterator()
        Description copied from interface: IntCollection
        Returns a type-specific iterator on the elements of this collection.

        Note that this specification strengthens the one given in Iterable.iterator(), which was already strengthened in the corresponding type-specific class, but was weakened by the fact that this interface extends Collection.

        Specified by:
        iterator in interface java.util.Collection<java.lang.Integer>
        Specified by:
        iterator in interface IntBidirectionalIterable
        Specified by:
        iterator in interface IntCollection
        Specified by:
        iterator in interface IntIterable
        Specified by:
        iterator in interface IntSet
        Specified by:
        iterator in interface IntSortedSet
        Specified by:
        iterator in interface java.lang.Iterable<java.lang.Integer>
        Specified by:
        iterator in interface java.util.Set<java.lang.Integer>
        Specified by:
        iterator in class AbstractIntSortedSet
        Returns:
        a type-specific iterator on the elements of this collection.
        See Also:
        Iterable.iterator()
      • iterator

        public IntBidirectionalIterator iterator​(int from)
        Description copied from interface: IntSortedSet
        Returns a type-specific BidirectionalIterator on the elements in this set, starting from a given element of the domain (optional operation).

        This method returns a type-specific bidirectional iterator with given starting point. The starting point is any element comparable to the elements of this set (even if it does not actually belong to the set). The next element of the returned iterator is the least element of the set that is greater than the starting point (if there are no elements greater than the starting point, hasNext() will return false). The previous element of the returned iterator is the greatest element of the set that is smaller than or equal to the starting point (if there are no elements smaller than or equal to the starting point, hasPrevious() will return false).

        Note that passing the last element of the set as starting point and calling previous() you can traverse the entire set in reverse order.

        Specified by:
        iterator in interface IntSortedSet
        Parameters:
        from - an element to start from.
        Returns:
        a bidirectional iterator on the element in this set, starting at the given element.
      • comparator

        public IntComparator comparator()
        Description copied from interface: IntSortedSet

        Note that this specification strengthens the one given in SortedSet.comparator().

        Specified by:
        comparator in interface IntSortedSet
        Specified by:
        comparator in interface java.util.SortedSet<java.lang.Integer>
      • headSet

        public IntSortedSet headSet​(int to)
        Description copied from interface: IntSortedSet
        Returns a view of the portion of this sorted set whose elements are strictly less than toElement.

        Note that this specification strengthens the one given in SortedSet.headSet(Object).

        Specified by:
        headSet in interface IntSortedSet
        See Also:
        SortedSet.headSet(Object)
      • tailSet

        public IntSortedSet tailSet​(int from)
        Description copied from interface: IntSortedSet
        Returns a view of the portion of this sorted set whose elements are greater than or equal to fromElement.

        Note that this specification strengthens the one given in SortedSet.headSet(Object).

        Specified by:
        tailSet in interface IntSortedSet
        See Also:
        SortedSet.tailSet(Object)
      • subSet

        public IntSortedSet subSet​(int from,
                                   int to)
        Description copied from interface: IntSortedSet
        Returns a view of the portion of this sorted set whose elements range from fromElement, inclusive, to toElement, exclusive.

        Note that this specification strengthens the one given in SortedSet.subSet(Object,Object).

        Specified by:
        subSet in interface IntSortedSet
        See Also:
        SortedSet.subSet(Object,Object)
      • clone

        public java.lang.Object clone()
        Returns a deep copy of this tree set.

        This method performs a deep copy of this tree set; the data stored in the set, however, is not cloned. Note that this makes a difference only for object keys.

        Returns:
        a deep copy of this tree set.