Class CompactSketch

java.lang.Object
org.apache.datasketches.theta.Sketch
org.apache.datasketches.theta.CompactSketch

public abstract class CompactSketch
extends Sketch
The parent class of all the CompactSketches. CompactSketches are never created directly. They are created as a result of the compact() method of an UpdateSketch or as a result of a getResult() of a SetOperation.

A CompactSketch is the simplest form of a Theta Sketch. It consists of a compact list (i.e., no intervening spaces) of hash values, which may be ordered or not, a value for theta and a seed hash. A CompactSketch is read-only, and the space required when stored is only the space required for the hash values and 8 to 24 bytes of preamble. An empty CompactSketch consumes only 8 bytes.

Author:
Lee Rhodes
  • Constructor Details

  • Method Details

    • compact

      public abstract CompactSketch compact​(boolean dstOrdered, org.apache.datasketches.memory.WritableMemory dstMem)
      Description copied from class: Sketch
      Convert this sketch to a new CompactSketch of the chosen order and direct or on the heap.

      If this sketch is already in the proper form, this operation returns this, otherwise, this method returns a new CompactSketch of the proper form.

      If this sketch is a type of UpdateSketch, the compacting process converts the hash table of the UpdateSketch to a simple list of the valid hash values. Any hash values of zero or equal-to or greater than theta will be discarded. The number of valid values remaining in the CompactSketch depends on a number of factors, but may be larger or smaller than Nominal Entries (or k). It will never exceed 2k. If it is critical to always limit the size to no more than k, then rebuild() should be called on the UpdateSketch prior to calling this method.

      A CompactSketch is always immutable.

      Specified by:
      compact in class Sketch
      Parameters:
      dstOrdered - See Destination Ordered
      dstMem - See Destination Memory.
      Returns:
      this sketch as a CompactSketch in the chosen form
    • getCompactBytes

      public int getCompactBytes()
      Description copied from class: Sketch
      Returns the number of storage bytes required for this Sketch if its current state were compacted. It this sketch is already in the compact form this is equivalent to calling Sketch.getCurrentBytes().
      Specified by:
      getCompactBytes in class Sketch
      Returns:
      number of compact bytes
    • getFamily

      public Family getFamily()
      Description copied from class: Sketch
      Returns the Family that this sketch belongs to
      Specified by:
      getFamily in class Sketch
      Returns:
      the Family that this sketch belongs to
    • isCompact

      public boolean isCompact()
      Description copied from class: Sketch
      Returns true if this sketch is in compact form.
      Specified by:
      isCompact in class Sketch
      Returns:
      true if this sketch is in compact form.