Class MappeableArrayContainer

java.lang.Object
org.roaringbitmap.buffer.MappeableContainer
org.roaringbitmap.buffer.MappeableArrayContainer
All Implemented Interfaces:
Externalizable, Serializable, Cloneable, Iterable<Character>, WordStorage<MappeableContainer>

public final class MappeableArrayContainer extends MappeableContainer implements Cloneable
Simple container made of an array of 16-bit integers. Unlike org.roaringbitmap.ArrayContainer, this class uses a CharBuffer to store data.
See Also:
  • Field Details

    • DEFAULT_MAX_SIZE

      protected static final int DEFAULT_MAX_SIZE
      See Also:
    • cardinality

      protected int cardinality
    • content

      protected CharBuffer content
  • Constructor Details

    • MappeableArrayContainer

      public MappeableArrayContainer()
      Create an array container with default capacity
    • MappeableArrayContainer

      public MappeableArrayContainer(ArrayContainer bc)
      Creates a new container from a non-mappeable one. This copies the data.
      Parameters:
      bc - the original container
    • MappeableArrayContainer

      public MappeableArrayContainer(int capacity)
      Create an array container with specified capacity
      Parameters:
      capacity - The capacity of the container
    • MappeableArrayContainer

      public MappeableArrayContainer(int firstOfRun, int lastOfRun)
      Create an array container with a run of ones from firstOfRun to lastOfRun, exclusive. Caller is responsible for making sure the range is small enough that ArrayContainer is appropriate.
      Parameters:
      firstOfRun - first index
      lastOfRun - last index (range is exclusive)
    • MappeableArrayContainer

      public MappeableArrayContainer(CharBuffer array, int cardinality)
      Construct a new ArrayContainer backed by the provided CharBuffer. Note that if you modify the ArrayContainer a new CharBuffer may be produced.
      Parameters:
      array - CharBuffer where the data is stored
      cardinality - cardinality (number of values stored)
  • Method Details

    • getArraySizeInBytes

      protected static int getArraySizeInBytes(int cardinality)
    • serializedSizeInBytes

      protected static int serializedSizeInBytes(int cardinality)
    • empty

      public static MappeableArrayContainer empty()
    • add

      public MappeableContainer add(int begin, int end)
      Description copied from class: MappeableContainer
      Return a new container with all chars in [begin,end) added using an unsigned interpretation.
      Specified by:
      add in class MappeableContainer
      Parameters:
      begin - start of range (inclusive)
      end - end of range (exclusive)
      Returns:
      the new container
    • add

      public MappeableContainer add(char x)
      running time is in O(n) time if insert is not in order.
      Specified by:
      add in interface WordStorage<MappeableContainer>
      Specified by:
      add in class MappeableContainer
      Parameters:
      x - char to be added
      Returns:
      the new container
    • isEmpty

      public boolean isEmpty()
      Description copied from class: MappeableContainer
      Checks whether the container is empty or not.
      Specified by:
      isEmpty in interface WordStorage<MappeableContainer>
      Specified by:
      isEmpty in class MappeableContainer
      Returns:
      true if the container is empty.
    • isFull

      public boolean isFull()
      Description copied from class: MappeableContainer
      Checks whether the container is full or not.
      Specified by:
      isFull in class MappeableContainer
      Returns:
      true if the container is full.
    • orInto

      public void orInto(long[] bits)
      Description copied from class: MappeableContainer
      Computes the union of this container with the bits present in the array, modifying the array.
      Specified by:
      orInto in class MappeableContainer
      Parameters:
      bits - a 1024 element array to be interpreted as a bit set
    • andInto

      public void andInto(long[] bits)
      Description copied from class: MappeableContainer
      Computes the intersection of this container with the bits present in the array, modifying the array.
      Specified by:
      andInto in class MappeableContainer
      Parameters:
      bits - a 1024 element array to be interpreted as a bit set
    • removeFrom

      public void removeFrom(long[] bits)
      Description copied from class: MappeableContainer
      Computes the intersection of the negation of this container with the bits present in the array, modifying the array.
      Specified by:
      removeFrom in class MappeableContainer
      Parameters:
      bits - a 1024 element array to be interpreted as a bit set
    • and

      Description copied from class: MappeableContainer
      Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.
      Specified by:
      and in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • and

      Description copied from class: MappeableContainer
      Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.
      Specified by:
      and in class MappeableContainer
      Parameters:
      x - other container
      Returns:
      aggregated container
    • and

      Description copied from class: MappeableContainer
      Computes the bitwise AND of this container with another (intersection). This container as well as the provided container are left unaffected.
      Specified by:
      and in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • andNot

      Description copied from class: MappeableContainer
      Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.
      Specified by:
      andNot in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • andNot

      Description copied from class: MappeableContainer
      Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.
      Specified by:
      andNot in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • andNot

      Description copied from class: MappeableContainer
      Computes the bitwise ANDNOT of this container with another (difference). This container as well as the provided container are left unaffected.
      Specified by:
      andNot in class MappeableContainer
      Parameters:
      x - other container
      Returns:
      aggregated container
    • clear

      public void clear()
      Description copied from class: MappeableContainer
      Empties the container
      Specified by:
      clear in class MappeableContainer
    • clone

      public MappeableArrayContainer clone()
      Specified by:
      clone in class MappeableContainer
    • contains

      public boolean contains(char x)
      Description copied from class: MappeableContainer
      Checks whether the contain contains the provided value
      Specified by:
      contains in class MappeableContainer
      Parameters:
      x - value to check
      Returns:
      whether the value is in the container
    • contains

      public static boolean contains(ByteBuffer buf, int position, char x, int cardinality)
      Checks whether the container contains the value x.
      Parameters:
      buf - underlying buffer
      position - starting position of the container in the ByteBuffer
      x - target value x
      cardinality - container cardinality
      Returns:
      whether the container contains the value x
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • fillLeastSignificant16bits

      public void fillLeastSignificant16bits(int[] x, int i, int mask)
      Description copied from class: MappeableContainer
      Fill the least significant 16 bits of the integer array, starting at index index, with the char values from this container. The caller is responsible to allocate enough room. The most significant 16 bits of each integer are given by the most significant bits of the provided mask.
      Specified by:
      fillLeastSignificant16bits in class MappeableContainer
      Parameters:
      x - provided array
      i - starting index
      mask - indicates most significant bits
    • flip

      public MappeableContainer flip(char x)
      Description copied from class: MappeableContainer
      Add a char to the container if it is not present, otherwise remove it. May generate a new container.
      Specified by:
      flip in class MappeableContainer
      Parameters:
      x - char to be added
      Returns:
      the new container
    • getArraySizeInBytes

      protected int getArraySizeInBytes()
      Description copied from class: MappeableContainer
      Size of the underlying array
      Specified by:
      getArraySizeInBytes in class MappeableContainer
      Returns:
      size in bytes
    • getCardinality

      public int getCardinality()
      Description copied from class: MappeableContainer
      Computes the distinct number of char values in the container. Can be expected to run in constant time.
      Specified by:
      getCardinality in class MappeableContainer
      Returns:
      the cardinality
    • getReverseCharIterator

      public CharIterator getReverseCharIterator()
      Description copied from class: MappeableContainer
      Iterator to visit the char values in the container in descending order.
      Specified by:
      getReverseCharIterator in class MappeableContainer
      Returns:
      iterator
    • getCharIterator

      public PeekableCharIterator getCharIterator()
      Description copied from class: MappeableContainer
      Iterator to visit the char values in the container in ascending order.
      Specified by:
      getCharIterator in class MappeableContainer
      Returns:
      iterator
    • getBatchIterator

      public ContainerBatchIterator getBatchIterator()
      Description copied from class: MappeableContainer
      Gets an iterator to visit the contents of the container in batches
      Specified by:
      getBatchIterator in class MappeableContainer
      Returns:
      iterator
    • getSizeInBytes

      public int getSizeInBytes()
      Description copied from class: MappeableContainer
      Computes an estimate of the memory usage of this container. The estimate is not meant to be exact.
      Specified by:
      getSizeInBytes in class MappeableContainer
      Returns:
      estimated memory usage in bytes
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • iadd

      public MappeableContainer iadd(int begin, int end)
      Description copied from class: MappeableContainer
      Add all chars in [begin,end) using an unsigned interpretation. May generate a new container.
      Specified by:
      iadd in class MappeableContainer
      Parameters:
      begin - start of range (inclusive)
      end - end of range (exclusive)
      Returns:
      the new container
    • iand

      Description copied from class: MappeableContainer
      Computes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      iand in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • iand

      Description copied from class: MappeableContainer
      Computes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      iand in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • iand

      Description copied from class: MappeableContainer
      Computes the in-place bitwise AND of this container with another (intersection). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      iand in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • iandNot

      Description copied from class: MappeableContainer
      Computes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      iandNot in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • iandNot

      Description copied from class: MappeableContainer
      Computes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      iandNot in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • iandNot

      public MappeableContainer iandNot(MappeableRunContainer value2)
      Description copied from class: MappeableContainer
      Computes the in-place bitwise ANDNOT of this container with another (difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      iandNot in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • inot

      public MappeableContainer inot(int firstOfRange, int lastOfRange)
      Description copied from class: MappeableContainer
      Computes the in-place bitwise NOT of this container (complement). Only those bits within the range are affected. The current container is generally modified. May generate a new container.
      Specified by:
      inot in class MappeableContainer
      Parameters:
      firstOfRange - beginning of range (inclusive); 0 is beginning of this container.
      lastOfRange - ending of range (exclusive)
      Returns:
      (partially) completmented container
    • intersects

      public boolean intersects(MappeableArrayContainer value2)
      Description copied from class: MappeableContainer
      Returns true if the current container intersects the other container.
      Specified by:
      intersects in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      whether they intersect
    • intersects

      public boolean intersects(MappeableBitmapContainer x)
      Description copied from class: MappeableContainer
      Returns true if the current container intersects the other container.
      Specified by:
      intersects in class MappeableContainer
      Parameters:
      x - other container
      Returns:
      whether they intersect
    • intersects

      public boolean intersects(MappeableRunContainer x)
      Description copied from class: MappeableContainer
      Returns true if the current container intersects the other container.
      Specified by:
      intersects in class MappeableContainer
      Parameters:
      x - other container
      Returns:
      whether they intersect
    • ior

      Description copied from class: MappeableContainer
      Computes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      ior in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • ior

      Description copied from class: MappeableContainer
      Computes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      ior in class MappeableContainer
      Parameters:
      x - other container
      Returns:
      aggregated container
    • ior

      Description copied from class: MappeableContainer
      Computes the in-place bitwise OR of this container with another (union). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      ior in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • iremove

      public MappeableContainer iremove(int begin, int end)
      Description copied from class: MappeableContainer
      Remove chars in [begin,end) using an unsigned interpretation. May generate a new container.
      Specified by:
      iremove in class MappeableContainer
      Parameters:
      begin - start of range (inclusive)
      end - end of range (exclusive)
      Returns:
      the new container
    • isArrayBacked

      protected boolean isArrayBacked()
      Specified by:
      isArrayBacked in class MappeableContainer
    • iterator

      public Iterator<Character> iterator()
      Specified by:
      iterator in interface Iterable<Character>
    • ixor

      Description copied from class: MappeableContainer
      Computes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      ixor in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • ixor

      Description copied from class: MappeableContainer
      Computes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      ixor in class MappeableContainer
      Parameters:
      x - other container
      Returns:
      aggregated container
    • ixor

      Description copied from class: MappeableContainer
      Computes the in-place bitwise XOR of this container with another (symmetric difference). The current container is generally modified, whereas the provided container (x) is unaffected. May generate a new container.
      Specified by:
      ixor in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • limit

      public MappeableContainer limit(int maxcardinality)
      Description copied from class: MappeableContainer
      Create a new MappeableContainer containing at most maxcardinality integers.
      Specified by:
      limit in class MappeableContainer
      Parameters:
      maxcardinality - maximal cardinality
      Returns:
      a new bitmap with cardinality no more than maxcardinality
    • not

      public MappeableContainer not(int firstOfRange, int lastOfRange)
      Description copied from class: MappeableContainer
      Computes the bitwise NOT of this container (complement). Only those bits within the range are affected. The current container is left unaffected.
      Specified by:
      not in class MappeableContainer
      Parameters:
      firstOfRange - beginning of range (inclusive); 0 is beginning of this container.
      lastOfRange - ending of range (exclusive)
      Returns:
      (partially) completmented container
    • or

      Description copied from class: MappeableContainer
      Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.
      Specified by:
      or in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • lazyor

      protected MappeableContainer lazyor(MappeableArrayContainer value2)
    • or

      Description copied from class: MappeableContainer
      Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.
      Specified by:
      or in class MappeableContainer
      Parameters:
      x - other container
      Returns:
      aggregated container
    • or

      Description copied from class: MappeableContainer
      Computes the bitwise OR of this container with another (union). This container as well as the provided container are left unaffected.
      Specified by:
      or in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • or

      protected MappeableContainer or(CharIterator it)
    • rank

      public int rank(char lowbits)
      Description copied from class: MappeableContainer
      Rank returns the number of integers that are smaller or equal to x (Rank(infinity) would be GetCardinality()).
      Specified by:
      rank in class MappeableContainer
      Parameters:
      lowbits - upper limit
      Returns:
      the rank
    • readExternal

      public void readExternal(ObjectInput in) throws IOException
      Specified by:
      readExternal in interface Externalizable
      Throws:
      IOException
    • remove

      public MappeableContainer remove(int begin, int end)
      Description copied from class: MappeableContainer
      Return a new container with all chars in [begin,end) remove using an unsigned interpretation.
      Specified by:
      remove in class MappeableContainer
      Parameters:
      begin - start of range (inclusive)
      end - end of range (exclusive)
      Returns:
      the new container
    • remove

      public MappeableContainer remove(char x)
      Description copied from class: MappeableContainer
      Remove the char from this container. May create a new container.
      Specified by:
      remove in class MappeableContainer
      Parameters:
      x - to be removed
      Returns:
      New container
    • repairAfterLazy

      public MappeableContainer repairAfterLazy()
      Description copied from class: MappeableContainer
      The output of a lazyOR or lazyIOR might be an invalid container, this should be called on it.
      Specified by:
      repairAfterLazy in class MappeableContainer
      Returns:
      a new valid container
    • runOptimize

      public MappeableContainer runOptimize()
      Description copied from class: MappeableContainer
      Convert to MappeableRunContainers, when the result is smaller. Overridden by MappeableRunContainer to possibly switch from MappeableRunContainer to a smaller alternative.
      Specified by:
      runOptimize in interface WordStorage<MappeableContainer>
      Specified by:
      runOptimize in class MappeableContainer
      Returns:
      the new container
    • select

      public char select(int j)
      Description copied from class: MappeableContainer
      Return the jth value
      Specified by:
      select in class MappeableContainer
      Parameters:
      j - index of the value
      Returns:
      the value
    • serializedSizeInBytes

      public int serializedSizeInBytes()
      Description copied from class: MappeableContainer
      Report the number of bytes required to serialize this container.
      Specified by:
      serializedSizeInBytes in class MappeableContainer
      Returns:
      the size in bytes
    • toBitmapContainer

      public MappeableBitmapContainer toBitmapContainer()
      Copies the data in a bitmap container.
      Specified by:
      toBitmapContainer in class MappeableContainer
      Returns:
      the bitmap container
    • first

      public int first()
      Description copied from class: MappeableContainer
      Get the first integer held in the container
      Specified by:
      first in class MappeableContainer
      Returns:
      the first integer in the container
    • last

      public int last()
      Description copied from class: MappeableContainer
      Get the last integer held in the container
      Specified by:
      last in class MappeableContainer
      Returns:
      the last integer in the container
    • nextValue

      public int nextValue(char fromValue)
      Description copied from class: MappeableContainer
      Gets the first value greater than or equal to the lower bound, or -1 if no such value exists.
      Specified by:
      nextValue in class MappeableContainer
      Parameters:
      fromValue - the lower bound (inclusive)
      Returns:
      the next value
    • previousValue

      public int previousValue(char fromValue)
      Description copied from class: MappeableContainer
      Gets the last value less than or equal to the upper bound, or -1 if no such value exists.
      Specified by:
      previousValue in class MappeableContainer
      Parameters:
      fromValue - the upper bound (inclusive)
      Returns:
      the previous value
    • nextAbsentValue

      public int nextAbsentValue(char fromValue)
      Description copied from class: MappeableContainer
      Gets the first absent value greater than or equal to the lower bound.
      Specified by:
      nextAbsentValue in class MappeableContainer
      Parameters:
      fromValue - the lower bound (inclusive)
      Returns:
      the next absent value
    • previousAbsentValue

      public int previousAbsentValue(char fromValue)
      Description copied from class: MappeableContainer
      Gets the last value less than or equal to the upper bound.
      Specified by:
      previousAbsentValue in class MappeableContainer
      Parameters:
      fromValue - the upper bound (inclusive)
      Returns:
      the previous absent value
    • toContainer

      public Container toContainer()
      Description copied from class: MappeableContainer
      Convert to a non-mappeable container.
      Specified by:
      toContainer in class MappeableContainer
      Returns:
      the non-mappeable container
    • toShortArray

      public char[] toShortArray()
      Create a copy of the content of this container as a char array. This creates a copy.
      Returns:
      copy of the content as a char array
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • trim

      public void trim()
      Description copied from class: MappeableContainer
      If possible, recover wasted memory.
      Specified by:
      trim in class MappeableContainer
    • writeArray

      protected void writeArray(DataOutput out) throws IOException
      Description copied from class: MappeableContainer
      Write just the underlying array.
      Specified by:
      writeArray in class MappeableContainer
      Parameters:
      out - output stream
      Throws:
      IOException - in case of failure
    • writeArray

      protected void writeArray(ByteBuffer buffer)
      Description copied from class: MappeableContainer
      Write just the underlying array.
      Specified by:
      writeArray in class MappeableContainer
      Parameters:
      buffer - the buffer to write to
    • writeExternal

      public void writeExternal(ObjectOutput out) throws IOException
      Specified by:
      writeExternal in interface Externalizable
      Throws:
      IOException
    • xor

      Description copied from class: MappeableContainer
      Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.
      Specified by:
      xor in class MappeableContainer
      Parameters:
      value2 - other container
      Returns:
      aggregated container
    • xor

      Description copied from class: MappeableContainer
      Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.
      Specified by:
      xor in class MappeableContainer
      Parameters:
      x - other container
      Returns:
      aggregated container
    • xor

      Description copied from class: MappeableContainer
      Computes the bitwise XOR of this container with another (symmetric difference). This container as well as the provided container are left unaffected.
      Specified by:
      xor in class MappeableContainer
      Parameters:
      value2 - other parameter
      Returns:
      aggregated container
    • xor

      protected MappeableContainer xor(CharIterator it)
    • forEach

      public void forEach(char msb, IntConsumer ic)
      Description copied from class: MappeableContainer
      Iterate through the values of this container and pass them along to the IntConsumer, using msb as the 16 most significant bits.
      Specified by:
      forEach in class MappeableContainer
      Parameters:
      msb - 16 most significant bits
      ic - consumer
    • andCardinality

      public int andCardinality(MappeableArrayContainer value2)
      Specified by:
      andCardinality in class MappeableContainer
    • andCardinality

      public int andCardinality(MappeableBitmapContainer x)
      Specified by:
      andCardinality in class MappeableContainer
    • andCardinality

      public int andCardinality(MappeableRunContainer x)
      Specified by:
      andCardinality in class MappeableContainer
    • contains

      protected boolean contains(MappeableRunContainer runContainer)
      Specified by:
      contains in class MappeableContainer
    • contains

      protected boolean contains(MappeableArrayContainer arrayContainer)
      Specified by:
      contains in class MappeableContainer
    • contains

      protected boolean contains(MappeableBitmapContainer bitmapContainer)
      Specified by:
      contains in class MappeableContainer
    • intersects

      public boolean intersects(int minimum, int supremum)
      Description copied from class: MappeableContainer
      Checks if the container intersects with a range
      Specified by:
      intersects in class MappeableContainer
      Parameters:
      minimum - the inclusive unsigned lower bound of the range
      supremum - the exclusive unsigned upper bound of the range
      Returns:
      true if the container intersects the range
    • contains

      public boolean contains(int minimum, int supremum)
      Description copied from class: MappeableContainer
      Checks whether the container contains the entire range
      Specified by:
      contains in class MappeableContainer
      Parameters:
      minimum - the inclusive lower bound of the range
      supremum - the exclusive upper bound of the range
      Returns:
      true if the container contains the range