org.apache.datasketches.theta

## Class Intersection

- java.lang.Object
- - org.apache.datasketches.theta.SetOperation
  - - org.apache.datasketches.theta.Intersection

All Implemented Interfaces:
  MemoryStatus

    public abstract class Intersection
    extends SetOperation

The API for intersection operations

Author:
  Lee Rhodes

### Constructor Summary

Constructors
Constructor and Description
`Intersection()`

### Method Summary

All Methods Static Methods Instance Methods Abstract Methods Concrete Methods
`protected static void` `checkMinSizeMemory(org.apache.datasketches.memory.Memory mem)`
`Family` `getFamily()` Gets the Family of this SetOperation
`protected static int` `getMaxLgArrLongs(org.apache.datasketches.memory.Memory dstMem)` Returns the maximum lgArrLongs given the capacity of the Memory.
`CompactSketch` `getResult()` Gets the result of this operation as an ordered CompactSketch on the Java heap.
`abstract CompactSketch` `getResult(boolean dstOrdered, org.apache.datasketches.memory.WritableMemory dstMem)` Gets the result of this operation as a CompactSketch in the given dstMem.
`abstract boolean` `hasResult()` Returns true if there is a valid intersection result available
`abstract void` `intersect(Sketch sketchIn)` Intersect the given sketch with the internal state.
`CompactSketch` `intersect(Sketch a, Sketch b)` Perform intersect set operation on the two given sketch arguments and return the result as an ordered CompactSketch on the heap.
`abstract CompactSketch` `intersect(Sketch a, Sketch b, boolean dstOrdered, org.apache.datasketches.memory.WritableMemory dstMem)` Perform intersect set operation on the two given sketches and return the result as a CompactSketch.
`protected static void` `memChecks(org.apache.datasketches.memory.Memory srcMem)`
`abstract void` `reset()` Resets this Intersection for stateful operations only.
`abstract byte[]` `toByteArray()` Serialize this intersection to a byte array form.

### Methods inherited from class org.apache.datasketches.theta.SetOperation

`builder, getMaxAnotBResultBytes, getMaxIntersectionBytes, getMaxUnionBytes, heapify, heapify, wrap, wrap, wrap, wrap`

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

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

### Methods inherited from interface org.apache.datasketches.common.MemoryStatus

`hasMemory, isDirect, isSameResource`

### Constructor Detail

#### Intersection

    public Intersection()

### Method Detail

#### getFamily

    public Family getFamily()

Description copied from class: `SetOperation`
Gets the Family of this SetOperation

Specified by:
  `getFamily` in class `SetOperation`
Returns:
  the Family of this SetOperation

#### getResult

    public CompactSketch getResult()

Gets the result of this operation as an ordered CompactSketch on the Java heap. This does not disturb the underlying data structure of this intersection. The `intersect(Sketch)` method must have been called at least once, otherwise an exception will be thrown. This is because a virgin Intersection object represents the Universal Set, which has an infinite number of values.

Returns:
  the result of this operation as an ordered CompactSketch on the Java heap

#### getResult

    public abstract CompactSketch getResult(boolean dstOrdered,
                                            org.apache.datasketches.memory.WritableMemory dstMem)

Gets the result of this operation as a CompactSketch in the given dstMem. This does not disturb the underlying data structure of this intersection. The `intersect(Sketch)` method must have been called at least once, otherwise an exception will be thrown. This is because a virgin Intersection object represents the Universal Set, which has an infinite number of values.

Note that presenting an intersection with an empty sketch sets the internal state of the intersection to empty = true, and current count = 0. This is consistent with the mathematical definition of the intersection of any set with the empty set is always empty.

Presenting an intersection with a null argument will throw an exception.

Parameters:
  `dstOrdered` - See Destination Ordered
  `dstMem` - See Destination Memory.
Returns:
  the result of this operation as a CompactSketch stored in the given dstMem, which can be either on or off-heap..

#### hasResult

    public abstract boolean hasResult()

Returns true if there is a valid intersection result available

Returns:
  true if there is a valid intersection result available

#### reset

    public abstract void reset()

Resets this Intersection for stateful operations only. The seed remains intact, otherwise reverts to the Universal Set: theta = 1.0, no retained data and empty = false.

#### toByteArray

    public abstract byte[] toByteArray()

Serialize this intersection to a byte array form.

Returns:
  byte array of this intersection

#### intersect

    public abstract void intersect(Sketch sketchIn)

Intersect the given sketch with the internal state. This method can be repeatedly called. If the given sketch is null the internal state becomes the empty sketch. Theta will become the minimum of thetas seen so far.

Parameters:
  `sketchIn` - the given sketch

#### intersect

    public CompactSketch intersect(Sketch a,
                                   Sketch b)

Perform intersect set operation on the two given sketch arguments and return the result as an ordered CompactSketch on the heap.

Parameters:
  `a` - The first sketch argument
  `b` - The second sketch argument
Returns:
  an ordered CompactSketch on the heap

#### intersect

    public abstract CompactSketch intersect(Sketch a,
                                            Sketch b,
                                            boolean dstOrdered,
                                            org.apache.datasketches.memory.WritableMemory dstMem)

Perform intersect set operation on the two given sketches and return the result as a CompactSketch.

Parameters:
  `a` - The first sketch argument
  `b` - The second sketch argument
  `dstOrdered` - See Destination Ordered.
  `dstMem` - See Destination Memory.
Returns:
  the result as a CompactSketch.

#### getMaxLgArrLongs

    protected static int getMaxLgArrLongs(org.apache.datasketches.memory.Memory dstMem)

Returns the maximum lgArrLongs given the capacity of the Memory.

Parameters:
  `dstMem` - the given Memory
Returns:
  the maximum lgArrLongs given the capacity of the Memory

#### checkMinSizeMemory

    protected static void checkMinSizeMemory(org.apache.datasketches.memory.Memory mem)

#### memChecks

    protected static void memChecks(org.apache.datasketches.memory.Memory srcMem)