Class ArrayContainer

java.lang.Object
io.deephaven.engine.rowset.impl.rsp.container.Container
io.deephaven.engine.rowset.impl.rsp.container.ArrayContainer
Direct Known Subclasses:
RspArray.SpanView

public class ArrayContainer extends Container
Simple container made of an array of 16-bit integers
  • Field Details

    • SWITCH_CONTAINER_CARDINALITY_THRESHOLD

      public static final int SWITCH_CONTAINER_CARDINALITY_THRESHOLD
      See Also:
    • cardinality

      protected int cardinality
    • content

      protected short[] content
    • shared

      protected boolean shared
  • Constructor Details

    • ArrayContainer

      protected ArrayContainer(short[] content, int cardinality, boolean shared)
    • ArrayContainer

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

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

      public ArrayContainer(short[] arr, int sz)
    • ArrayContainer

      public ArrayContainer(short[] newContent)
  • Method Details

    • getContent

      public short[] getContent()
    • makeByCopying

      public static ArrayContainer makeByCopying(short[] arr, int offset, int sz)
      Construct a new ArrayContainer from values copied from the provided array.
      Parameters:
      arr - array with values in increasing unsigned short order.
      offset - index position for the first element to take.
      sz - number of elements to read from the array.
    • makeByCopying

      public static ArrayContainer makeByCopying(int newCapacity, short[] arr, int offset, int sz)
    • makeByWrapping

      public static ArrayContainer makeByWrapping(short[] arr, int sz)
      Construct a new ArrayContainer using the provided array. The container takes ownership of the array.
      Parameters:
      arr - array with values in increasing unsigned short order. The container takes ownership of this array.
      sz - number of elements in arr.
    • add

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

      public Container iset(short x)
      Description copied from class: Container
      Insert a short to the container. May generate a new container.
      Specified by:
      iset in class Container
      Parameters:
      x - short to be added
      Returns:
      the resulting container
    • set

      public Container set(short x)
      Description copied from class: Container
      Return a new container with the short given as parameter added.
      Specified by:
      set in class Container
      Parameters:
      x - a short to be added
      Returns:
      a new container with x added
    • and

      public Container and(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • and

      public Container and(BitmapContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • and

      public Container and(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • andNot

      public Container andNot(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • andNot

      public Container andNot(BitmapContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • andNot

      public Container andNot(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • deepCopy

      public ArrayContainer deepCopy()
      Description copied from class: Container
      Get a full deep copy of the container in a new container object.
      Specified by:
      deepCopy in class Container
      Returns:
      A copy of the container as a new object.
    • cowRef

      public ArrayContainer cowRef()
      Description copied from class: Container
      Get a shared, copy-on-write copy of an existing container. Mutations on the returned container will always return a copy and leave the original container unchanged.

      This operation allows for cheap read-only references to the same values, at the cost of an additional copy for any first mutation.

      Specified by:
      cowRef in class Container
      Returns:
      A copy-on-write reference to the container.
    • isEmpty

      public boolean isEmpty()
      Description copied from class: Container
      Checks whether the container is empty or not.
      Specified by:
      isEmpty in class Container
      Returns:
      true if the container is empty.
    • isAllOnes

      public boolean isAllOnes()
      Description copied from class: Container
      Checks whether the container spans the full 2^16 range (ie, contains every short value) This is an O(1) operation in all container types (some do not cache cardinality).
      Specified by:
      isAllOnes in class Container
      Returns:
      true if the container does not miss any single short value.
    • contains

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

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

      protected boolean contains(RunContainer runContainer)
      Specified by:
      contains in class Container
    • contains

      protected boolean contains(ArrayContainer arrayContainer)
      Specified by:
      contains in class Container
    • contains

      protected boolean contains(BitmapContainer bitmapContainer)
      Specified by:
      contains in class Container
    • iflip

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

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

      public ShortAdvanceIterator getReverseShortIterator()
      Description copied from class: Container
      Iterator to visit the short values in the container in descending order.
      Specified by:
      getReverseShortIterator in class Container
      Returns:
      iterator
    • getShortIterator

      public io.deephaven.engine.rowset.impl.rsp.container.ArrayContainer.ShortForwardIterator getShortIterator()
      Description copied from class: Container
      Iterator to visit the short values in the container in ascending order.
      Specified by:
      getShortIterator in class Container
      Returns:
      iterator
    • getShortBatchIterator

      public ContainerShortBatchIterator getShortBatchIterator(int skipCount)
      Description copied from class: Container
      Gets an iterator to visit the contents of the container in batches of short values
      Specified by:
      getShortBatchIterator in class Container
      Parameters:
      skipCount - number of elements to skip from the start of the container.
      Returns:
      iterator
    • getShortRangeIterator

      public SearchRangeIterator getShortRangeIterator(int initialSeek)
      Description copied from class: Container
      Iterator to visit the short values in container in [start, end) ranges, in increasing order of start values.
      Specified by:
      getShortRangeIterator in class Container
      Returns:
      iterator
    • iadd

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

      public Container iappend(int begin, int end)
      Description copied from class: Container
      Add all shorts in [begin,end) using an unsigned interpretation. May generate a new container. The beginning of the range should be strictly greater than the last value already present in the container, if there is one.
      Specified by:
      iappend in class Container
      Parameters:
      begin - start of range (inclusive)
      end - end of range (exclusive)
      Returns:
      the new container
    • iand

      public Container iand(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • iand

      public Container iand(BitmapContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • iand

      public Container iand(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • iandNot

      public Container iandNot(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • iandNot

      public Container iandNot(BitmapContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • iandNot

      public Container iandNot(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • inot

      public Container inot(int firstOfRange, int exclusiveEndOfRange)
      Description copied from class: Container
      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 Container
      Parameters:
      firstOfRange - beginning of range (inclusive); 0 is beginning of this container.
      exclusiveEndOfRange - ending of range (exclusive)
      Returns:
      (partially) complemented container
    • ior

      public Container ior(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • ior

      public Container ior(BitmapContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • ior

      public Container ior(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • remove

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

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

      public Container ixor(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • ixor

      public Container ixor(BitmapContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • ixor

      public Container ixor(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • loadData

      protected void loadData(BitmapContainer bitmapContainer)
    • loadDataWithSkipValue

      protected void loadDataWithSkipValue(BitmapContainer bitmapContainer, short valueToSkip, PositionHint positionHintOut)
    • not

      public Container not(int firstOfRange, int lastOfRange)
      Description copied from class: Container
      Computes the bitwise NOT of this container (complement). Only those bits within the range are affected. This is equivalent to an xor with a range of ones for the given range. The current container is left unaffected.
      Specified by:
      not in class Container
      Parameters:
      firstOfRange - beginning of range (inclusive); 0 is beginning of this container.
      lastOfRange - ending of range (exclusive)
      Returns:
      (partially) complemented container
    • or

      public Container or(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • or

      public Container or(BitmapContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • or

      public Container or(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • or

      protected Container or(ShortIterator it)
    • rank

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

      public Container iunset(short x)
      Description copied from class: Container
      Create a new container with the short removed.
      Specified by:
      iunset in class Container
      Parameters:
      x - to be removed
      Returns:
      New container without x.
    • unset

      public Container unset(short x)
      Description copied from class: Container
      Remove the short from this container. May create a new container.
      Specified by:
      unset in class Container
      Parameters:
      x - to be removed
      Returns:
      resulting container.
    • runOptimize

      public Container runOptimize()
      Description copied from class: Container
      Convert to RunContainers, when the result is smaller. Overridden by RunContainer to possibility switch from RunContainer to a smaller alternative. Overridden by BitmapContainer with a more efficient approach.
      Specified by:
      runOptimize in class Container
      Returns:
      the new container
    • select

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

      public Container select(int startRank, int endRank)
      Description copied from class: Container
      Returns a new container with all values between ranks startPos and endPos.
      Specified by:
      select in class Container
      Parameters:
      startRank - rank for the start of the range
      endRank - rank for the end of the range, exclusive
      Returns:
      a new Container with all the values between ranks [startPos, endPos)
    • find

      public int find(short x)
      Description copied from class: Container
      Searches for the specified short value
      Specified by:
      find in class Container
      Parameters:
      x - value to search for
      Returns:
      Relative position of the value in the sorted set of elements in this container, in the range [0 .. cardinality - 1]. If not present, (-(insertion point) - 1) similar to Array.binarySearch.

      For values of x that Container.contains(short) returns true, this method returns the same value as Container.rank(short).

    • selectRanges

      public void selectRanges(RangeConsumer outValues, RangeIterator inPositions)
      Description copied from class: Container
      As select but for all the positions in a range.
      Specified by:
      selectRanges in class Container
      Parameters:
      outValues - accept is called in this consumer for each resulting range.
      inPositions - input iterator that provides the position ranges.
    • iandRange

      public Container iandRange(int start, int end)
      Description copied from class: Container
      Calculate the intersection of this container and a range; may overwrite the existing container or return a new one.
      Specified by:
      iandRange in class Container
      Parameters:
      start - start of range
      end - end of range, exclusive.
      Returns:
      a Container containing the intersction of this container and the given range.
    • andRange

      public Container andRange(int start, int end)
      Description copied from class: Container
      Calculate the intersection of this container and a range, in a new container. The existing container is not modified.
      Specified by:
      andRange in class Container
      Parameters:
      start - start of range
      end - end of range, exclusive.
      Returns:
      a new Container containing the intersction of this container and the given range.
    • findRanges

      public boolean findRanges(RangeConsumer outPositions, RangeIterator inValues, int maxPos)
      Description copied from class: Container
      As find but for all the values in a range.
      Specified by:
      findRanges in class Container
      Parameters:
      outPositions - accept is called in this consumer for each resulting position range.
      inValues - input iterator that provides the key ranges; these must each exist in the container.
      maxPos - maximum position to add to outPositions; values of position > maxPos are not added.
      Returns:
      true if maxPos was reached, false otherwise.
    • toBitmapContainer

      public BitmapContainer toBitmapContainer()
      Copies the data in a bitmap container.
      Specified by:
      toBitmapContainer in class Container
      Returns:
      the bitmap container
    • nextValue

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

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

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

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

      public Container xor(ArrayContainer value2)
      Description copied from class: Container
      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 Container
      Parameters:
      value2 - Another container
      Returns:
      aggregated container
    • xor

      public Container xor(BitmapContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • xor

      public Container xor(RunContainer x)
      Description copied from class: Container
      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 Container
      Parameters:
      x - Another container
      Returns:
      aggregated container
    • xor

      protected Container xor(ShortIterator it)
    • forEach

      public boolean forEach(ShortConsumer sc)
      Description copied from class: Container
      Iterate through the values of this container in order and pass them along to the ShortConsumer.
      Specified by:
      forEach in class Container
      Parameters:
      sc - a shortConsumer
      Returns:
      false if the consumer returned false at some point, true otherwise.
    • forEach

      public boolean forEach(int rankOffset, ShortConsumer sc)
      Description copied from class: Container
      Like forEach, but skipping the first rankOffset elements.
      Specified by:
      forEach in class Container
      Parameters:
      rankOffset - the position (rank) offset of the element where to start
      sc - a ShortConsumer
      Returns:
      false if the consumer returned false at some point, true otherwise.
    • forEachRange

      public boolean forEachRange(int rankOffset, ShortRangeConsumer sc)
      Specified by:
      forEachRange in class Container
    • subsetOf

      public boolean subsetOf(ArrayContainer c)
      Specified by:
      subsetOf in class Container
      Parameters:
      c - Another container
      Returns:
      true if every key in this container is also a key in x.
    • subsetOf

      public boolean subsetOf(BitmapContainer c)
      Specified by:
      subsetOf in class Container
      Parameters:
      c - Another container
      Returns:
      true if every key in this container is also a key in x.
    • subsetOf

      public boolean subsetOf(RunContainer c)
      Specified by:
      subsetOf in class Container
      Parameters:
      c - Another container
      Returns:
      true if every key in this container is also a key in x.
    • overlapsRange

      public boolean overlapsRange(int rangeStart, int rangeEnd)
      Specified by:
      overlapsRange in class Container
      Parameters:
      rangeStart - the beginning of the range, as an int.
      rangeEnd - the end of the range (exclusive), as an int.
      Returns:
      true if there is any element in this container in the range provided.
    • overlaps

      public boolean overlaps(ArrayContainer c)
      Specified by:
      overlaps in class Container
      Parameters:
      c - Another container
      Returns:
      true if at least one key in this container is also a key in x.
    • overlaps

      public boolean overlaps(BitmapContainer c)
      Specified by:
      overlaps in class Container
      Parameters:
      c - Another container
      Returns:
      true if at least one key in this container is also a key in x.
    • overlaps

      public boolean overlaps(RunContainer c)
      Specified by:
      overlaps in class Container
      Parameters:
      c - Another container
      Returns:
      true if at least one key in this container is also a key in x.
    • setCopyOnWrite

      public final void setCopyOnWrite()
      Specified by:
      setCopyOnWrite in class Container
    • onCopyOnWrite

      protected void onCopyOnWrite()
    • bytesAllocated

      public int bytesAllocated()
      Specified by:
      bytesAllocated in class Container
      Returns:
      The allocated size in bytes of the underlying array backing store used by this container.
    • bytesUsed

      public int bytesUsed()
      Specified by:
      bytesUsed in class Container
      Returns:
      The size in bytes of the used portion out of the total allocated bytes for the underlying array backing store used by this container.
    • toLargeContainer

      public Container toLargeContainer()
    • validate

      public void validate()
      Specified by:
      validate in class Container
    • isShared

      public boolean isShared()
      Specified by:
      isShared in class Container