Class CharSegmentedSortedMultiset

java.lang.Object
io.deephaven.engine.table.impl.ssms.CharSegmentedSortedMultiset
All Implemented Interfaces:
SegmentedSortedMultiSet<Character>, LongSizedDataStructure, CharVector, Vector<CharVector>, Serializable, Comparable<CharVector>, Iterable<Character>

public final class CharSegmentedSortedMultiset extends Object implements SegmentedSortedMultiSet<Character>, CharVector
See Also:
  • Constructor Details

    • CharSegmentedSortedMultiset

      public CharSegmentedSortedMultiset(int leafSize)
      Create a CharSegmentedSortedArray with the given leafSize.
      Parameters:
      leafSize - the maximumSize for any leaf
  • Method Details

    • insert

      public boolean insert(WritableChunk<? extends Values> valuesToInsert, WritableIntChunk<ChunkLengths> counts)
      Description copied from interface: SegmentedSortedMultiSet
      Insert new valuesToInsert into this SSMS. The valuesToInsert to insert must be sorted, without duplicates. The valuesToInsert and counts chunks will be modified during this call, and the resulting chunks are undefined.
      Specified by:
      insert in interface SegmentedSortedMultiSet<Character>
      Parameters:
      valuesToInsert - the valuesToInsert to insert
      counts - the number of times each value occurs
      Returns:
      true if any new values were inserted
    • insert

      public boolean insert(WritableChunk<? extends Values> valuesToInsert, WritableIntChunk<ChunkLengths> counts, int offset, int length)
      Description copied from interface: SegmentedSortedMultiSet
      Insert the length new valuesToInsert beginning at offset into this SSMS. The valuesToInsert to insert must be sorted, without duplicates, within the specified range. The valuesToInsert and counts chunks will be modified within the specified range during this call, and the resulting values within the range are undefined.
      Specified by:
      insert in interface SegmentedSortedMultiSet<Character>
      Parameters:
      valuesToInsert - the valuesToInsert to insert
      counts - the number of times each value occurs
      offset - the first position in valuesToInsert and counts to insert
      length - the number of positions in valuesToInsert and counts to insert
      Returns:
      true if any new values were inserted
    • insert

      public boolean insert(WritableCharChunk<? extends Values> valuesToInsert, WritableIntChunk<ChunkLengths> counts, int offset, int length)
      Insert the length values beginning at offset; accepts an already-typed chunk so callers that repeatedly insert from the same backing chunk can cast it once rather than per call.
    • insert

      public boolean insert(char value, long count)
      Insert count copies of a single value, returning whether a new distinct value was added (as opposed to merging into an existing one). This does the work of insert(WritableCharChunk, WritableIntChunk, int, int) for one value without requiring the caller to wrap it in a chunk, so seeding a freshly created set is allocation-free. Values at the boundaries reuse appendMaximum(char, long)/prependMinimum(char, long) (which handle leaf splitting); interior values are placed directly, splitting the target leaf only when it is full.
    • remove

      public boolean remove(SegmentedSortedMultiSet.RemoveContext removeContext, WritableChunk<? extends Values> valuesToRemove, WritableIntChunk<ChunkLengths> counts)
      Remove valuesToRemove from this SSA. The valuesToRemove to remove must be sorted.
      Specified by:
      remove in interface SegmentedSortedMultiSet<Character>
      Parameters:
      removeContext - removalContext
      valuesToRemove - the valuesToRemove to remove
      Returns:
      true if any values were removed.
    • remove

      public boolean remove(SegmentedSortedMultiSet.RemoveContext removeContext, WritableChunk<? extends Values> valuesToRemove, WritableIntChunk<ChunkLengths> counts, int offset, int length)
      Description copied from interface: SegmentedSortedMultiSet
      Remove the length valuesToRemove beginning at offset from this SSMS. The valuesToRemove to remove must be sorted within the specified range.
      Specified by:
      remove in interface SegmentedSortedMultiSet<Character>
      Parameters:
      removeContext - removalContext
      valuesToRemove - the valuesToRemove to remove
      offset - the first position in valuesToRemove and lengths to remove
      length - the number of positions in valuesToRemove and lengths to remove
      Returns:
      true if any values were removed.
    • remove

      public boolean remove(SegmentedSortedMultiSet.RemoveContext removeContext, WritableCharChunk<? extends Values> valuesToRemove, WritableIntChunk<ChunkLengths> counts, int offset, int length)
      Remove the length values beginning at offset; accepts an already-typed chunk so callers that repeatedly remove from the same backing chunk can cast it once rather than per call.
    • remove

      public boolean remove(char value, long count)
      Remove count copies of a single value, which must currently be present, returning whether the distinct value was fully removed (its count reached zero). This does the work of remove(RemoveContext, WritableCharChunk, WritableIntChunk, int, int) for one value without requiring the caller to wrap it in a chunk. Empty leaves are dropped and the set collapses back toward the directory and singleton representations, but non-empty leaves are not opportunistically merged.
    • validate

      @VisibleForTesting public void validate()
    • totalSize

      public long totalSize()
      Specified by:
      totalSize in interface SegmentedSortedMultiSet<Character>
      Returns:
      the total size of the set in elements (i.e. if A exists twice, 2 is returned not one)
    • getNodeSize

      public int getNodeSize()
      Specified by:
      getNodeSize in interface SegmentedSortedMultiSet<Character>
    • getMin

      public Character getMin()
      Specified by:
      getMin in interface SegmentedSortedMultiSet<Character>
    • getMax

      public Character getMax()
      Specified by:
      getMax in interface SegmentedSortedMultiSet<Character>
    • getMinChar

      public char getMinChar()
    • getMinCount

      public long getMinCount()
      Specified by:
      getMinCount in interface SegmentedSortedMultiSet<Character>
      Returns:
      the number of times the minimum value exists in this SSM.
    • getMaxChar

      public char getMaxChar()
    • getMaxCount

      public long getMaxCount()
      Specified by:
      getMaxCount in interface SegmentedSortedMultiSet<Character>
      Returns:
      the number of times the maximum value exists in this SSM.
    • moveFrontToBack

      public void moveFrontToBack(SegmentedSortedMultiSet untypedDestination, long count)
      Description copied from interface: SegmentedSortedMultiSet
      Remove count elements from the front of this SSM and add them to the back of the destination SSM.

      The minimum element of this SSM must be greater than or equal to the maximum of destination.

      Specified by:
      moveFrontToBack in interface SegmentedSortedMultiSet<Character>
      Parameters:
      untypedDestination - the SegmentedSortedMultiSet to append count elements to
      count - how many elements to move to the destination
    • moveBackToFront

      public void moveBackToFront(SegmentedSortedMultiSet untypedDestination, long count)
      Description copied from interface: SegmentedSortedMultiSet
      Remove count elements from the back of this SSM and add them to the front of the destination SSM.

      The minimum element of this SSM must be less than or equal to the maximum of destination.

      Specified by:
      moveBackToFront in interface SegmentedSortedMultiSet<Character>
      Parameters:
      untypedDestination - the SegmentedSortedMultiSet to prepend count elements to
      count - how many elements to move to the destination
    • keyChunk

      public WritableCharChunk<?> keyChunk()
      Specified by:
      keyChunk in interface SegmentedSortedMultiSet<Character>
    • fillKeyChunk

      public void fillKeyChunk(WritableChunk<?> keyChunk, int offset)
      Specified by:
      fillKeyChunk in interface SegmentedSortedMultiSet<Character>
    • countChunk

      public WritableLongChunk<?> countChunk()
      Specified by:
      countChunk in interface SegmentedSortedMultiSet<Character>
    • setTrackDeltas

      public void setTrackDeltas(boolean shouldTrackDeltas)
      Specified by:
      setTrackDeltas in interface SegmentedSortedMultiSet<Character>
    • clearDeltas

      public void clearDeltas()
      Specified by:
      clearDeltas in interface SegmentedSortedMultiSet<Character>
    • getAddedSize

      public int getAddedSize()
      Specified by:
      getAddedSize in interface SegmentedSortedMultiSet<Character>
    • getRemovedSize

      public int getRemovedSize()
      Specified by:
      getRemovedSize in interface SegmentedSortedMultiSet<Character>
    • fillRemovedChunk

      public void fillRemovedChunk(WritableCharChunk<? extends Values> chunk, int position)
    • fillAddedChunk

      public void fillAddedChunk(WritableCharChunk<? extends Values> chunk, int position)
    • getPrevValues

      public CharVector getPrevValues()
    • get

      public char get(long index)
      Description copied from interface: CharVector
      Get the element of this CharVector at offset index. If index is not within range [0, size()), will return the null char.
      Specified by:
      get in interface CharVector
      Parameters:
      index - An offset into this CharVector
      Returns:
      The element at the specified offset, or the null char
    • subVector

      public CharVector subVector(long fromIndexInclusive, long toIndexExclusive)
      Description copied from interface: Vector
      Get a Vector that represents a slice of this Vector.
      Specified by:
      subVector in interface CharVector
      Specified by:
      subVector in interface Vector<CharVector>
      Parameters:
      fromIndexInclusive - The first offset into this Vector to include in the result; if negative, the result will have a range of null values at offsets in [0, -fromIndexInclusive)
      toIndexExclusive - The first offset into this Vector to not include in the result; if larger than size(), the result will have a range of null values at the corresponding offsets
      Returns:
      The sub-Vector specified by [fromIndexInclusive, toIndexExclusive)
    • subVectorByPositions

      public CharVector subVectorByPositions(long[] positions)
      Description copied from interface: Vector
      Get a Vector that represents a set of offset positions in this Vector.
      Specified by:
      subVectorByPositions in interface CharVector
      Specified by:
      subVectorByPositions in interface Vector<CharVector>
      Parameters:
      positions - The offsets to include; if not within [0, size()), the corresponding offset in the result will contain the appropriate null value
      Returns:
      The sub-Vector specified by positions
    • toArray

      public char[] toArray()
      Description copied from interface: Vector
      Get an array representation of the elements of this Vector. Callers must not mutate the result, as implementations may choose to return their backing array in some cases.
      Specified by:
      toArray in interface CharVector
      Specified by:
      toArray in interface Vector<CharVector>
      Returns:
      An array representation of the elements of this Vector that must not be mutated
    • copyToArray

      public char[] copyToArray()
      Description copied from interface: Vector
      Get an array representation of the elements of this Vector. Callers may freely mutate the result, as it is guaranteed to be freshly-allocated and belongs to the caller upon return.
      Specified by:
      copyToArray in interface CharVector
      Specified by:
      copyToArray in interface Vector<CharVector>
      Returns:
      An array representation of the elements of this Vector that may be freely mutated
    • size

      public long size()
      Description copied from interface: LongSizedDataStructure
      The size of this data structure.
      Specified by:
      size in interface LongSizedDataStructure
      Specified by:
      size in interface SegmentedSortedMultiSet<Character>
      Returns:
      the size of the set (i.e. the number of unique elements).
    • getDirect

      public CharVector getDirect()
      Specified by:
      getDirect in interface CharVector
      Specified by:
      getDirect in interface Vector<CharVector>
      Returns:
      A version of this Vector that is flattened out to only reference memory
    • equals

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

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

      public String toString()
      Overrides:
      toString in class Object