Class ConcurrentSmallIntSet

java.lang.Object
org.infinispan.commons.util.ConcurrentSmallIntSet
All Implemented Interfaces:
Iterable<Integer>, Collection<Integer>, Set<Integer>, IntSet

@ProtoTypeId(130) public class ConcurrentSmallIntSet extends Object implements IntSet
Concurrent implementation of an IntSet. This implementation is limited in that it can only inserts ints up to an initialized maximum. Any attempt to insert/remove a larger value will result in an IllegalArgumentException thrown. Note that operations spanning multiple values (ie. containsAll(IntSet), removeAll(IntSet)) are not performed atomically and are done on a per value basis.
Since:
9.3
Author:
wburns
  • Constructor Details

    • ConcurrentSmallIntSet

      public ConcurrentSmallIntSet(int maxCapacityExclusive)
      Creates a new, empty map which can accommodate ints in value up to maxCapacityExclusive - 1. This number will be rounded up to the nearest 32.
      Parameters:
      maxCapacityExclusive - The implementation performs sizing to ensure values up to this can be stored
  • Method Details

    • nextSetBit

      public int nextSetBit(int fromIndex)
      Description copied from interface: IntSet
      Returns the next int in the set that is greater than or equal to the given value.
      Specified by:
      nextSetBit in interface IntSet
      Parameters:
      fromIndex - : inclusive index to start searching.
      Returns:
      the index of the next set bit, or -1 if there is no such bit
    • add

      public boolean add(int i)
      Description copied from interface: IntSet
      Adds the given int to this set and returns true if it was set or false if it was already present
      Specified by:
      add in interface IntSet
      Parameters:
      i - the int value to add
      Returns:
      whether this int was already present
    • set

      public void set(int i)
      Description copied from interface: IntSet
      Adds or sets the int without returning whether it was previously set
      Specified by:
      set in interface IntSet
      Parameters:
      i - the value to make sure is in the set
    • remove

      public boolean remove(int i)
      Description copied from interface: IntSet
      Removes, if present, the int from the set and returns if it was present or not
      Specified by:
      remove in interface IntSet
      Parameters:
      i - the int to remove
      Returns:
      whether the int was present in the set before it was removed
    • contains

      public boolean contains(int i)
      Description copied from interface: IntSet
      Whether this set contains the given int
      Specified by:
      contains in interface IntSet
      Parameters:
      i - the int to check
      Returns:
      if the set contains the int
    • addAll

      public boolean addAll(IntSet set)
      Description copied from interface: IntSet
      Adds all ints from the provided set into this one
      Specified by:
      addAll in interface IntSet
      Parameters:
      set - the set of ints to add
      Returns:
      if this set has a new int in it
    • containsAll

      public boolean containsAll(IntSet set)
      Description copied from interface: IntSet
      Whether this set contains all ints in the given IntSet
      Specified by:
      containsAll in interface IntSet
      Parameters:
      set - the set to check if all are present
      Returns:
      if the set contains all the ints
    • removeAll

      public boolean removeAll(IntSet set)
      Description copied from interface: IntSet
      Removes all ints from this IntSet that are in the provided IntSet
      Specified by:
      removeAll in interface IntSet
      Parameters:
      set - the ints to remove from this IntSet
      Returns:
      if this set removed any ints
    • retainAll

      public boolean retainAll(IntSet set)
      Description copied from interface: IntSet
      Modifies this set to remove all ints that are not present in the provided IntSet
      Specified by:
      retainAll in interface IntSet
      Parameters:
      set - the ints this set should kep
      Returns:
      if this set removed any ints
    • size

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

      public boolean isEmpty()
      Specified by:
      isEmpty in interface Collection<Integer>
      Specified by:
      isEmpty in interface Set<Integer>
    • contains

      public boolean contains(Object o)
      Specified by:
      contains in interface Collection<Integer>
      Specified by:
      contains in interface Set<Integer>
    • iterator

      public PrimitiveIterator.OfInt iterator()
      Description copied from interface: IntSet
      A primtive iterator that allows iteration over the int values. This iterator supports removal if the set is modifiable.
      Specified by:
      iterator in interface Collection<Integer>
      Specified by:
      iterator in interface IntSet
      Specified by:
      iterator in interface Iterable<Integer>
      Specified by:
      iterator in interface Set<Integer>
      Returns:
      the iterator
    • toArray

      public final Object[] toArray()
      Specified by:
      toArray in interface Collection<Integer>
      Specified by:
      toArray in interface Set<Integer>
    • toArray

      public final <T> T[] toArray(T[] a)
      Specified by:
      toArray in interface Collection<Integer>
      Specified by:
      toArray in interface Set<Integer>
    • add

      public boolean add(Integer integer)
      Specified by:
      add in interface Collection<Integer>
      Specified by:
      add in interface Set<Integer>
    • remove

      public boolean remove(Object o)
      Specified by:
      remove in interface Collection<Integer>
      Specified by:
      remove in interface Set<Integer>
    • containsAll

      public boolean containsAll(Collection<?> c)
      Specified by:
      containsAll in interface Collection<Integer>
      Specified by:
      containsAll in interface Set<Integer>
    • addAll

      public boolean addAll(Collection<? extends Integer> c)
      Specified by:
      addAll in interface Collection<Integer>
      Specified by:
      addAll in interface Set<Integer>
    • retainAll

      public boolean retainAll(Collection<?> c)
      Specified by:
      retainAll in interface Collection<Integer>
      Specified by:
      retainAll in interface Set<Integer>
    • removeAll

      public boolean removeAll(Collection<?> c)
      Specified by:
      removeAll in interface Collection<Integer>
      Specified by:
      removeAll in interface Set<Integer>
    • clear

      public void clear()
      Specified by:
      clear in interface Collection<Integer>
      Specified by:
      clear in interface Set<Integer>
    • intStream

      public IntStream intStream()
      Description copied from interface: IntSet
      A stream of ints representing the data in this set
      Specified by:
      intStream in interface IntSet
      Returns:
      the stream
    • intSpliterator

      public Spliterator.OfInt intSpliterator()
      Description copied from interface: IntSet
      Creates a Spliterator.OfInt over the ints in this set.

      The Spliterator.OfInt reports Spliterator.DISTINCT. Implementations should document the reporting of additional characteristic values. The default implementation creates a late-binding spliterator from the set's Iterator. The spliterator inherits the fail-fast properties of the set's iterator.

      The created Spliterator.OfInt additionally reports Spliterator.SIZED. The created Spliterator.OfInt additionally reports Spliterator.SUBSIZED.

      Specified by:
      intSpliterator in interface IntSet
      Returns:
      a Spliterator.OfInt over the ints in this set
    • toIntArray

      public int[] toIntArray()
      Description copied from interface: IntSet
      Returns an array containing all of the elements in this set. If this set makes any guarantees as to what order its elements are returned by its iterator, this method must return the elements in the same order.
      Specified by:
      toIntArray in interface IntSet
      Returns:
      this int set as an array
    • toBitSet

      public byte[] toBitSet()
      Description copied from interface: IntSet
      Returns a byte array that has a bit set for each int in this set where each byte represents 8 numbers. That is if the ints 2, 5 and 9 are set this will return a byte array consisting of 2 bytes in little-endian representation of those values.

      Depending upon the implementation this array may or may not have trailing bytes and may be condensed to save space.

      Specified by:
      toBitSet in interface IntSet
      Returns:
      a byte array containing a little-endian representation of all the ints of this int set as bits
    • forEach

      public void forEach(Consumer<? super Integer> action)
      Specified by:
      forEach in interface Iterable<Integer>
    • forEach

      public void forEach(IntConsumer action)
      Description copied from interface: IntSet
      Performs the given action for each int of the IntSet until all elements have been processed or the action throws an exception. Unless otherwise specified by the implementing class, actions are performed in the order of iteration (if an iteration order is specified). Exceptions thrown by the action are relayed to the caller.

      The default implementation behaves as if:

      
           PrimitiveIterator.OfInt iterator = iterator();
           while (iterator.hasNext()) {
              action.accept(iterator.nextInt());
           }
       
      Specified by:
      forEach in interface IntSet
      Parameters:
      action - The action to be performed for each element
    • removeIf

      public boolean removeIf(Predicate<? super Integer> filter)
      Specified by:
      removeIf in interface Collection<Integer>
    • removeIf

      public boolean removeIf(IntPredicate filter)
      Description copied from interface: IntSet
      Removes all the ints of this set that satisfy the given predicate. Errors or runtime exceptions thrown during iteration or by the predicate are relayed to the caller. The default implementation traverses all elements of the collection using its IntSet.iterator(). Each matching element is removed using Iterator.remove(). If the collection's iterator does not support removal then an UnsupportedOperationException will be thrown on the first matching element.
      Specified by:
      removeIf in interface IntSet
      Parameters:
      filter - a predicate which returns true for ints to be removed
      Returns:
      true if any ints were removed
    • equals

      public boolean equals(Object o)
      Specified by:
      equals in interface Collection<Integer>
      Specified by:
      equals in interface Set<Integer>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Specified by:
      hashCode in interface Collection<Integer>
      Specified by:
      hashCode in interface Set<Integer>
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Overrides:
      toString in class Object