Class ByteRBTreeSet

java.lang.Object
java.util.AbstractCollection<Byte>
it.unimi.dsi.fastutil.bytes.AbstractByteCollection
All Implemented Interfaces:
it.unimi.dsi.fastutil.bytes.ByteBidirectionalIterable, it.unimi.dsi.fastutil.bytes.ByteCollection, it.unimi.dsi.fastutil.bytes.ByteIterable, ByteSet, ByteSortedSet, Serializable, Cloneable, Iterable<Byte>, Collection<Byte>, SequencedCollection<Byte>, SequencedSet<Byte>, Set<Byte>, SortedSet<Byte>

public class ByteRBTreeSet extends AbstractByteSortedSet implements Serializable, Cloneable, ByteSortedSet
A type-specific red-black 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:
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    protected it.unimi.dsi.fastutil.bytes.ByteComparator
    This set's actual comparator; it may differ from storedComparator because it is always a type-specific comparator, so it could be derived from the former by wrapping.
    protected int
    Number of elements in this set.
    protected it.unimi.dsi.fastutil.bytes.ByteRBTreeSet.Entry
    The entry of the first element of this set.
    protected it.unimi.dsi.fastutil.bytes.ByteRBTreeSet.Entry
    The entry of the last element of this set.
    protected Comparator<? super Byte>
    This set's comparator, as provided in the constructor.
    protected it.unimi.dsi.fastutil.bytes.ByteRBTreeSet.Entry
    A reference to the root entry.
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a new empty tree set.
    ByteRBTreeSet(byte[] a)
    Creates a new tree set copying the elements of an array.
    ByteRBTreeSet(byte[] a, int offset, int length)
    Creates a new tree set and fills it with the elements of a given array.
    ByteRBTreeSet(byte[] a, int offset, int length, Comparator<? super Byte> c)
    Creates a new tree set and fills it with the elements of a given array using a given Comparator.
    ByteRBTreeSet(byte[] a, Comparator<? super Byte> c)
    Creates a new tree set copying the elements of an array using a given Comparator.
    ByteRBTreeSet(it.unimi.dsi.fastutil.bytes.ByteCollection c)
    Creates a new tree set copying a given type-specific collection.
    ByteRBTreeSet(it.unimi.dsi.fastutil.bytes.ByteIterator i)
    Creates a new tree set using elements provided by a type-specific iterator.
    Creates a new tree set copying a given type-specific sorted set (and its Comparator).
    Creates a new tree set copying a given collection.
    Creates a new empty tree set with the given comparator.
    Creates a new tree set using elements provided by an iterator.
    Creates a new tree set copying a given sorted set (and its Comparator).
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    add(byte k)
     
    void
     
    Returns a deep copy of this tree set.
    it.unimi.dsi.fastutil.bytes.ByteComparator
    boolean
    contains(byte k)
     
    byte
    Returns the first (lowest) element currently in this set.
    headSet(byte to)
    Returns a view of the portion of this sorted set whose elements are strictly less than toElement.
    boolean
     
    it.unimi.dsi.fastutil.bytes.ByteBidirectionalIterator
    Returns a type-specific iterator on the elements of this set.
    it.unimi.dsi.fastutil.bytes.ByteBidirectionalIterator
    iterator(byte from)
    Returns a type-specific BidirectionalIterator on the elements in this set, starting from a given element of the domain (optional operation).
    byte
    Returns the last (highest) element currently in this set.
    boolean
    remove(byte k)
    Removes an element from this set.
    int
     
    subSet(byte from, byte to)
    Returns a view of the portion of this sorted set whose elements range from fromElement, inclusive, to toElement, exclusive.
    tailSet(byte from)
    Returns a view of the portion of this sorted set whose elements are greater than or equal to fromElement.

    Methods inherited from class it.unimi.dsi.fastutil.bytes.AbstractByteSet

    equals, hashCode, rem

    Methods inherited from class it.unimi.dsi.fastutil.bytes.AbstractByteCollection

    add, addAll, addAll, contains, containsAll, containsAll, remove, removeAll, removeAll, retainAll, retainAll, toArray, toByteArray, toByteArray, toString

    Methods inherited from class java.util.AbstractCollection

    toArray, toArray

    Methods inherited from class java.lang.Object

    finalize, getClass, notify, notifyAll, wait, wait, wait

    Methods inherited from interface it.unimi.dsi.fastutil.bytes.ByteCollection

    addAll, containsAll, intIterator, intParallelStream, intSpliterator, intStream, parallelStream, removeAll, removeIf, removeIf, removeIf, retainAll, stream, toArray, toByteArray, toByteArray

    Methods inherited from interface it.unimi.dsi.fastutil.bytes.ByteIterable

    forEach, forEach, forEach

    Methods inherited from interface it.unimi.dsi.fastutil.bytes.ByteSet

    add, contains, rem, remove

    Methods inherited from interface it.unimi.dsi.fastutil.bytes.ByteSortedSet

    first, headSet, last, spliterator, subSet, tailSet

    Methods inherited from interface java.util.Collection

    toArray

    Methods inherited from interface java.util.Set

    add, addAll, contains, containsAll, equals, hashCode, remove, removeAll, retainAll, toArray, toArray

    Methods inherited from interface java.util.SortedSet

    addFirst, addLast, getFirst, getLast, removeFirst, removeLast, reversed
  • Field Details

    • tree

      protected transient it.unimi.dsi.fastutil.bytes.ByteRBTreeSet.Entry tree
      A reference to the root entry.
    • count

      protected int count
      Number of elements in this set.
    • firstEntry

      protected transient it.unimi.dsi.fastutil.bytes.ByteRBTreeSet.Entry firstEntry
      The entry of the first element of this set.
    • lastEntry

      protected transient it.unimi.dsi.fastutil.bytes.ByteRBTreeSet.Entry lastEntry
      The entry of the last element of this set.
    • storedComparator

      protected Comparator<? super Byte> storedComparator
      This set's comparator, as provided in the constructor.
    • actualComparator

      protected transient it.unimi.dsi.fastutil.bytes.ByteComparator actualComparator
      This set's actual comparator; it may differ from storedComparator because it is always a type-specific comparator, so it could be derived from the former by wrapping.
  • Constructor Details

    • ByteRBTreeSet

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

      public ByteRBTreeSet(Comparator<? super Byte> c)
      Creates a new empty tree set with the given comparator.
      Parameters:
      c - a Comparator (even better, a type-specific comparator).
    • ByteRBTreeSet

      public ByteRBTreeSet(Collection<? extends Byte> c)
      Creates a new tree set copying a given collection.
      Parameters:
      c - a collection to be copied into the new tree set.
    • ByteRBTreeSet

      public ByteRBTreeSet(SortedSet<Byte> 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.
    • ByteRBTreeSet

      public ByteRBTreeSet(it.unimi.dsi.fastutil.bytes.ByteCollection 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.
    • ByteRBTreeSet

      public ByteRBTreeSet(ByteSortedSet 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.
    • ByteRBTreeSet

      public ByteRBTreeSet(it.unimi.dsi.fastutil.bytes.ByteIterator 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.
    • ByteRBTreeSet

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

      public ByteRBTreeSet(byte[] a, int offset, int length, Comparator<? super Byte> 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).
    • ByteRBTreeSet

      public ByteRBTreeSet(byte[] 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.
    • ByteRBTreeSet

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

      public ByteRBTreeSet(byte[] a, Comparator<? super Byte> 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 Details

    • add

      public boolean add(byte k)
      Specified by:
      add in interface it.unimi.dsi.fastutil.bytes.ByteCollection
      Overrides:
      add in class it.unimi.dsi.fastutil.bytes.AbstractByteCollection
    • remove

      public boolean remove(byte k)
      Description copied from class: AbstractByteSet
      Removes an element from this set. Delegates to the type-specific rem() method implemented by type-specific abstract Collection superclass.
      Specified by:
      remove in interface ByteSet
      Overrides:
      remove in class AbstractByteSet
      See Also:
    • contains

      public boolean contains(byte k)
      Specified by:
      contains in interface it.unimi.dsi.fastutil.bytes.ByteCollection
      Overrides:
      contains in class it.unimi.dsi.fastutil.bytes.AbstractByteCollection
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<Byte>
      Specified by:
      clear in interface Set<Byte>
      Overrides:
      clear in class AbstractCollection<Byte>
    • size

      public int size()
      Specified by:
      size in interface Collection<Byte>
      Specified by:
      size in interface Set<Byte>
      Specified by:
      size in class AbstractCollection<Byte>
    • isEmpty

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<Byte>
      Specified by:
      isEmpty in interface Set<Byte>
      Overrides:
      isEmpty in class AbstractCollection<Byte>
    • firstByte

      public byte firstByte()
      Description copied from interface: ByteSortedSet
      Returns the first (lowest) element currently in this set.
      Specified by:
      firstByte in interface ByteSortedSet
      See Also:
    • lastByte

      public byte lastByte()
      Description copied from interface: ByteSortedSet
      Returns the last (highest) element currently in this set.
      Specified by:
      lastByte in interface ByteSortedSet
      See Also:
    • iterator

      public it.unimi.dsi.fastutil.bytes.ByteBidirectionalIterator iterator()
      Description copied from interface: ByteSet
      Returns a type-specific iterator on the elements of this set.
      Specified by:
      iterator in interface it.unimi.dsi.fastutil.bytes.ByteBidirectionalIterable
      Specified by:
      iterator in interface it.unimi.dsi.fastutil.bytes.ByteCollection
      Specified by:
      iterator in interface it.unimi.dsi.fastutil.bytes.ByteIterable
      Specified by:
      iterator in interface ByteSet
      Specified by:
      iterator in interface ByteSortedSet
      Specified by:
      iterator in interface Collection<Byte>
      Specified by:
      iterator in interface Iterable<Byte>
      Specified by:
      iterator in interface Set<Byte>
      Specified by:
      iterator in class AbstractByteSortedSet
      Returns:
      a type-specific iterator on the elements of this set.
    • iterator

      public it.unimi.dsi.fastutil.bytes.ByteBidirectionalIterator iterator(byte from)
      Description copied from interface: ByteSortedSet
      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 ByteSortedSet
      Parameters:
      from - an element to start from.
      Returns:
      a bidirectional iterator on the element in this set, starting at the given element.
    • comparator

      public it.unimi.dsi.fastutil.bytes.ByteComparator comparator()
      Description copied from interface: ByteSortedSet
      Specified by:
      comparator in interface ByteSortedSet
      Specified by:
      comparator in interface SortedSet<Byte>
    • headSet

      public ByteSortedSet headSet(byte to)
      Description copied from interface: ByteSortedSet
      Returns a view of the portion of this sorted set whose elements are strictly less than toElement.
      Specified by:
      headSet in interface ByteSortedSet
      See Also:
    • tailSet

      public ByteSortedSet tailSet(byte from)
      Description copied from interface: ByteSortedSet
      Returns a view of the portion of this sorted set whose elements are greater than or equal to fromElement.
      Specified by:
      tailSet in interface ByteSortedSet
      See Also:
    • subSet

      public ByteSortedSet subSet(byte from, byte to)
      Description copied from interface: ByteSortedSet
      Returns a view of the portion of this sorted set whose elements range from fromElement, inclusive, to toElement, exclusive.
      Specified by:
      subSet in interface ByteSortedSet
      See Also:
    • clone

      public 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.

      Overrides:
      clone in class Object
      Returns:
      a deep copy of this tree set.