Package org.apache.datasketches.theta

# Class Sketches

java.lang.Object
org.apache.datasketches.theta.Sketches

public final class Sketches extends Object
This class brings together the common sketch and set operation creation methods and the public static methods into one place.

Author:
  Lee Rhodes

## Method Summary

Modifier and Type
Method
Description
`static int`
`getCompactSketchMaxBytes(int lgNomEntries)`
Returns the maximum number of storage bytes required for a CompactSketch given the configured log_base2 of the number of nominal entries, which is a power of 2.
`static double`
`getEstimate(org.apache.datasketches.memory.Memory srcMem)`
Gets the unique count estimate from a valid memory image of a Sketch
`static double`
`getLowerBound(int numStdDev, org.apache.datasketches.memory.Memory srcMem)`
Gets the approximate lower error bound from a valid memory image of a Sketch given the specified number of Standard Deviations.
`static int`
`getMaxAnotBResultBytes(int maxNomEntries)`
Ref: `SetOperation.getMaxAnotBResultBytes(int)`.
`static int`
`getMaxCompactSketchBytes(int numberOfEntries)`
Returns the maximum number of storage bytes required for a CompactSketch with the given number of actual entries.
`static int`
`getMaxIntersectionBytes(int nomEntries)`
Ref: `SetOperation.getMaxIntersectionBytes(int)`
`static int`
`getMaxUnionBytes(int nomEntries)`
Ref: `SetOperation.getMaxUnionBytes(int)`
`static int`
`getMaxUpdateSketchBytes(int nomEntries)`
Ref: `Sketch.getMaxUpdateSketchBytes(int)`
`static int`
`getSerializationVersion(org.apache.datasketches.memory.Memory srcMem)`
Ref: `Sketch.getSerializationVersion(Memory)`
`static double`
`getUpperBound(int numStdDev, org.apache.datasketches.memory.Memory srcMem)`
Gets the approximate upper error bound from a valid memory image of a Sketch given the specified number of Standard Deviations.
`static CompactSketch`
`heapifyCompactSketch(org.apache.datasketches.memory.Memory srcMem)`
Ref: `CompactSketch.heapify(Memory)`
`static CompactSketch`
`heapifyCompactSketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)`
Ref: `CompactSketch.heapify(Memory, long)`
`static SetOperation`
`heapifySetOperation(org.apache.datasketches.memory.Memory srcMem)`
Ref: `SetOperation.heapify(Memory)`
`static SetOperation`
`heapifySetOperation(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)`
Ref: `SetOperation.heapify(Memory, long)`
`static Sketch`
`heapifySketch(org.apache.datasketches.memory.Memory srcMem)`
Ref: `Sketch.heapify(Memory)`
`static Sketch`
`heapifySketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)`
Ref: `Sketch.heapify(Memory, long)`
`static UpdateSketch`
`heapifyUpdateSketch(org.apache.datasketches.memory.Memory srcMem)`
Ref: `UpdateSketch.heapify(Memory)`
`static UpdateSketch`
`heapifyUpdateSketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)`
Ref: `UpdateSketch.heapify(Memory, long)`
`static SetOperationBuilder`
`setOperationBuilder()`
Ref: `SetOperationBuilder`
`static UpdateSketchBuilder`
`updateSketchBuilder()`
Ref: `UpdateSketchBuilder`
`static CompactSketch`
`wrapCompactSketch(org.apache.datasketches.memory.Memory srcMem)`
Ref: `CompactSketch.wrap(Memory)`
`static CompactSketch`
`wrapCompactSketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)`
Ref: `CompactSketch.wrap(Memory, long)`
`static Intersection`
`wrapIntersection(org.apache.datasketches.memory.Memory srcMem)`
Convenience method, calls `SetOperation.wrap(Memory)` and casts the result to a Intersection
`static Intersection`
`wrapIntersection(org.apache.datasketches.memory.WritableMemory srcMem)`
Convenience method, calls `SetOperation.wrap(Memory)` and casts the result to a Intersection
`static SetOperation`
`wrapSetOperation(org.apache.datasketches.memory.Memory srcMem)`
Ref: `SetOperation.wrap(Memory)`
`static SetOperation`
`wrapSetOperation(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)`
Ref: `SetOperation.wrap(Memory, long)`
`static SetOperation`
`wrapSetOperation(org.apache.datasketches.memory.WritableMemory srcMem)`
Ref: `SetOperation.wrap(Memory)`
`static SetOperation`
`wrapSetOperation(org.apache.datasketches.memory.WritableMemory srcMem, long expectedSeed)`
Ref: `SetOperation.wrap(Memory, long)`
`static Sketch`
`wrapSketch(org.apache.datasketches.memory.Memory srcMem)`
Ref: `Sketch.wrap(Memory)`
`static Sketch`
`wrapSketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)`
Ref: `Sketch.wrap(Memory, long)`
`static Union`
`wrapUnion(org.apache.datasketches.memory.Memory srcMem)`
Convenience method, calls `SetOperation.wrap(Memory)` and casts the result to a Union
`static Union`
`wrapUnion(org.apache.datasketches.memory.WritableMemory srcMem)`
Convenience method, calls `SetOperation.wrap(Memory)` and casts the result to a Union
`static UpdateSketch`
`wrapUpdateSketch(org.apache.datasketches.memory.WritableMemory srcMem)`
Ref: `UpdateSketch.wrap(Memory)`
`static UpdateSketch`
`wrapUpdateSketch(org.apache.datasketches.memory.WritableMemory srcMem, long expectedSeed)`
Ref: `UpdateSketch.wrap(Memory, long)`

### Methods inherited from class java.lang.Object

`equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## Method Details

### getEstimate

public static double getEstimate(org.apache.datasketches.memory.Memory srcMem)
Gets the unique count estimate from a valid memory image of a Sketch

Parameters:
  `srcMem` - See Memory
Returns:
  the sketch's best estimate of the cardinality of the input stream.

### getLowerBound

public static double getLowerBound(int numStdDev, org.apache.datasketches.memory.Memory srcMem)
Gets the approximate lower error bound from a valid memory image of a Sketch given the specified number of Standard Deviations. This will return getEstimate() if isEmpty() is true.

Parameters:
  `numStdDev` - See Number of Standard Deviations
  `srcMem` - See Memory
Returns:
  the lower bound.

### getMaxAnotBResultBytes

public static int getMaxAnotBResultBytes(int maxNomEntries)
Ref: `SetOperation.getMaxAnotBResultBytes(int)`. Returns the maximum number of bytes for the returned CompactSketch, given the maximum value of nomEntries of the first sketch A of AnotB.

Parameters:
  `maxNomEntries` - the given value
Returns:
  the maximum number of bytes.

### getMaxCompactSketchBytes

public static int getMaxCompactSketchBytes(int numberOfEntries)
Returns the maximum number of storage bytes required for a CompactSketch with the given number of actual entries.

Parameters:
  `numberOfEntries` - the actual number of retained entries stored in the sketch.
Returns:
  the maximum number of storage bytes required for a CompactSketch with the given number of retained entries.

### getCompactSketchMaxBytes

public static int getCompactSketchMaxBytes(int lgNomEntries)
Returns the maximum number of storage bytes required for a CompactSketch given the configured log_base2 of the number of nominal entries, which is a power of 2.

Parameters:
  `lgNomEntries` - Nominal Entries
Returns:
  the maximum number of storage bytes required for a CompactSketch with the given lgNomEntries.
See Also:
  - `Sketch.getCompactSketchMaxBytes(int)`

### getMaxIntersectionBytes

public static int getMaxIntersectionBytes(int nomEntries)
Ref: `SetOperation.getMaxIntersectionBytes(int)`

Parameters:
  `nomEntries` - Ref: `SetOperation.getMaxIntersectionBytes(int)`, `nomEntries`
Returns:
  Ref: `SetOperation.getMaxIntersectionBytes(int)`

### getMaxUnionBytes

public static int getMaxUnionBytes(int nomEntries)
Ref: `SetOperation.getMaxUnionBytes(int)`

Parameters:
  `nomEntries` - Ref: `SetOperation.getMaxUnionBytes(int)`, `nomEntries`
Returns:
  Ref: `SetOperation.getMaxUnionBytes(int)`

### getMaxUpdateSketchBytes

public static int getMaxUpdateSketchBytes(int nomEntries)
Ref: `Sketch.getMaxUpdateSketchBytes(int)`

Parameters:
  `nomEntries` - Ref: `Sketch.getMaxUpdateSketchBytes(int)`, `nomEntries`
Returns:
  Ref: `Sketch.getMaxUpdateSketchBytes(int)`

### getSerializationVersion

public static int getSerializationVersion(org.apache.datasketches.memory.Memory srcMem)
Ref: `Sketch.getSerializationVersion(Memory)`

Parameters:
  `srcMem` - Ref: `Sketch.getSerializationVersion(Memory)`, `srcMem`
Returns:
  Ref: `Sketch.getSerializationVersion(Memory)`

### getUpperBound

public static double getUpperBound(int numStdDev, org.apache.datasketches.memory.Memory srcMem)
Gets the approximate upper error bound from a valid memory image of a Sketch given the specified number of Standard Deviations. This will return getEstimate() if isEmpty() is true.

Parameters:
  `numStdDev` - See Number of Standard Deviations
  `srcMem` - See Memory
Returns:
  the upper bound.

### heapifyCompactSketch

public static CompactSketch heapifyCompactSketch(org.apache.datasketches.memory.Memory srcMem)
Ref: `CompactSketch.heapify(Memory)`

Parameters:
  `srcMem` - Ref: `CompactSketch.heapify(Memory)`, `srcMem`
Returns:
  `CompactSketch`

### heapifyCompactSketch

public static CompactSketch heapifyCompactSketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)
Ref: `CompactSketch.heapify(Memory, long)`

Parameters:
  `srcMem` - Ref: `CompactSketch.heapify(Memory, long)`, `srcMem`
  `expectedSeed` - Ref: `CompactSketch.heapify(Memory, long)`, `expectedSeed`
Returns:
  `CompactSketch`

### wrapCompactSketch

public static CompactSketch wrapCompactSketch(org.apache.datasketches.memory.Memory srcMem)
Ref: `CompactSketch.wrap(Memory)`

Parameters:
  `srcMem` - Ref: `CompactSketch.wrap(Memory)`, `srcMem`
Returns:
  `CompactSketch`

### wrapCompactSketch

public static CompactSketch wrapCompactSketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)
Ref: `CompactSketch.wrap(Memory, long)`

Parameters:
  `srcMem` - Ref: `CompactSketch.wrap(Memory, long)`, `srcMem`
  `expectedSeed` - Ref: `CompactSketch.wrap(Memory, long)`, `expectedSeed`
Returns:
  `CompactSketch`

### heapifySetOperation

public static SetOperation heapifySetOperation(org.apache.datasketches.memory.Memory srcMem)
Ref: `SetOperation.heapify(Memory)`

Parameters:
  `srcMem` - Ref: `SetOperation.heapify(Memory)`, `srcMem`
Returns:
  `SetOperation`

### heapifySetOperation

public static SetOperation heapifySetOperation(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)
Ref: `SetOperation.heapify(Memory, long)`

Parameters:
  `srcMem` - Ref: `SetOperation.heapify(Memory, long)`, `srcMem`
  `expectedSeed` - the seed used to validate the given Memory image. Ref: `SetOperation.heapify(Memory, long)`, `expectedSeed`
Returns:
  `SetOperation`

### heapifySketch

public static Sketch heapifySketch(org.apache.datasketches.memory.Memory srcMem)
Ref: `Sketch.heapify(Memory)`

Parameters:
  `srcMem` - Ref: `Sketch.heapify(Memory)`, `srcMem`
Returns:
  `Sketch`

### heapifySketch

public static Sketch heapifySketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)
Ref: `Sketch.heapify(Memory, long)`

Parameters:
  `srcMem` - Ref: `Sketch.heapify(Memory, long)`, `srcMem`
  `expectedSeed` - the seed used to validate the given Memory image. Ref: `Sketch.heapify(Memory, long)`, `expectedSeed`
Returns:
  `Sketch`

### heapifyUpdateSketch

public static UpdateSketch heapifyUpdateSketch(org.apache.datasketches.memory.Memory srcMem)
Ref: `UpdateSketch.heapify(Memory)`

Parameters:
  `srcMem` - Ref: `UpdateSketch.heapify(Memory)`, `srcMem`
Returns:
  `UpdateSketch`

### heapifyUpdateSketch

public static UpdateSketch heapifyUpdateSketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)
Ref: `UpdateSketch.heapify(Memory, long)`

Parameters:
  `srcMem` - Ref: `UpdateSketch.heapify(Memory, long)`, `srcMem`
  `expectedSeed` - the seed used to validate the given Memory image. Ref: `UpdateSketch.heapify(Memory, long)`, `expectedSeed`
Returns:
  `UpdateSketch`

### setOperationBuilder

public static SetOperationBuilder setOperationBuilder()
Ref: `SetOperationBuilder`

Returns:
  `SetOperationBuilder`

### updateSketchBuilder

public static UpdateSketchBuilder updateSketchBuilder()
Ref: `UpdateSketchBuilder`

Returns:
  `UpdateSketchBuilder`

### wrapIntersection

public static Intersection wrapIntersection(org.apache.datasketches.memory.Memory srcMem)
Convenience method, calls `SetOperation.wrap(Memory)` and casts the result to a Intersection

Parameters:
  `srcMem` - Ref: `SetOperation.wrap(Memory)`, `srcMem`
Returns:
  a Intersection backed by the given Memory

### wrapIntersection

public static Intersection wrapIntersection(org.apache.datasketches.memory.WritableMemory srcMem)
Convenience method, calls `SetOperation.wrap(Memory)` and casts the result to a Intersection

Parameters:
  `srcMem` - Ref: `SetOperation.wrap(Memory)`, `srcMem`
Returns:
  a Intersection backed by the given Memory

### wrapSetOperation

public static SetOperation wrapSetOperation(org.apache.datasketches.memory.Memory srcMem)
Ref: `SetOperation.wrap(Memory)`

Parameters:
  `srcMem` - Ref: `SetOperation.wrap(Memory)`, `srcMem`
Returns:
  `SetOperation`

### wrapSetOperation

public static SetOperation wrapSetOperation(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)
Ref: `SetOperation.wrap(Memory, long)`

Parameters:
  `srcMem` - Ref: `SetOperation.wrap(Memory, long)`, `srcMem`
  `expectedSeed` - the seed used to validate the given Memory image. Ref: `SetOperation.wrap(Memory, long)`, `expectedSeed`
Returns:
  `SetOperation`

### wrapSetOperation

public static SetOperation wrapSetOperation(org.apache.datasketches.memory.WritableMemory srcMem)
Ref: `SetOperation.wrap(Memory)`

Parameters:
  `srcMem` - Ref: `SetOperation.wrap(Memory)`, `srcMem`
Returns:
  `SetOperation`

### wrapSetOperation

public static SetOperation wrapSetOperation(org.apache.datasketches.memory.WritableMemory srcMem, long expectedSeed)
Ref: `SetOperation.wrap(Memory, long)`

Parameters:
  `srcMem` - Ref: `SetOperation.wrap(Memory, long)`, `srcMem`
  `expectedSeed` - the seed used to validate the given Memory image. Ref: `SetOperation.wrap(Memory, long)`, `expectedSeed`
Returns:
  `SetOperation`

### wrapSketch

public static Sketch wrapSketch(org.apache.datasketches.memory.Memory srcMem)
Ref: `Sketch.wrap(Memory)`

Parameters:
  `srcMem` - Ref: `Sketch.wrap(Memory)`, `srcMem`
Returns:
  `Sketch`

### wrapSketch

public static Sketch wrapSketch(org.apache.datasketches.memory.Memory srcMem, long expectedSeed)
Ref: `Sketch.wrap(Memory, long)`

Parameters:
  `srcMem` - Ref: `Sketch.wrap(Memory, long)`, `srcMem`
  `expectedSeed` - the expectedSeed used to validate the given Memory image. Ref: `Sketch.wrap(Memory, long)`, `expectedSeed`
Returns:
  `Sketch`

### wrapUnion

public static Union wrapUnion(org.apache.datasketches.memory.Memory srcMem)
Convenience method, calls `SetOperation.wrap(Memory)` and casts the result to a Union

Parameters:
  `srcMem` - Ref: `SetOperation.wrap(Memory)`, `srcMem`
Returns:
  a Union backed by the given Memory

### wrapUnion

public static Union wrapUnion(org.apache.datasketches.memory.WritableMemory srcMem)
Convenience method, calls `SetOperation.wrap(Memory)` and casts the result to a Union

Parameters:
  `srcMem` - Ref: `SetOperation.wrap(Memory)`, `srcMem`
Returns:
  a Union backed by the given Memory

### wrapUpdateSketch

public static UpdateSketch wrapUpdateSketch(org.apache.datasketches.memory.WritableMemory srcMem)
Ref: `UpdateSketch.wrap(Memory)`

Parameters:
  `srcMem` - Ref: `UpdateSketch.wrap(Memory)`, `srcMem`
Returns:
  `UpdateSketch`

### wrapUpdateSketch

public static UpdateSketch wrapUpdateSketch(org.apache.datasketches.memory.WritableMemory srcMem, long expectedSeed)
Ref: `UpdateSketch.wrap(Memory, long)`

Parameters:
  `srcMem` - Ref: `UpdateSketch.wrap(Memory, long)`, `srcMem`
  `expectedSeed` - the seed used to validate the given Memory image. Ref: `UpdateSketch.wrap(Memory, long)`, `expectedSeed`
Returns:
  `UpdateSketch`