# Class ThetaIntersection

java.lang.Object
org.apache.datasketches.theta.ThetaSetOperation
org.apache.datasketches.theta.ThetaIntersection

All Implemented Interfaces:
  `MemorySegmentStatus`

public abstract class ThetaIntersection extends ThetaSetOperation
The API for intersection operations

Author:
  Lee Rhodes

## Constructor Summary

Constructors
Constructor
Description
`ThetaIntersection()`
No argument constructor.

## Method Summary

Modifier and Type
Method
Description
`Family`
`getFamily()`
Gets the Family of this ThetaSetOperation
`CompactThetaSketch`
`getResult()`
Gets the result of this operation as an ordered CompactThetaSketch on the Java heap.
`abstract CompactThetaSketch`
`getResult(boolean dstOrdered, MemorySegment dstSeg)`
Gets the result of this operation as a CompactThetaSketch in the given dstSeg.
`abstract boolean`
`hasResult()`
Returns true if there is a valid intersection result available
`abstract void`
`intersect(ThetaSketch sketchIn)`
Intersect the given sketch with the internal state.
`CompactThetaSketch`
`intersect(ThetaSketch a, ThetaSketch b)`
Perform intersect set operation on the two given sketch arguments and return the result as an ordered CompactThetaSketch on the heap.
`abstract CompactThetaSketch`
`intersect(ThetaSketch a, ThetaSketch b, boolean dstOrdered, MemorySegment dstSeg)`
Perform intersect set operation on the two given sketches and return the result as a CompactThetaSketch.
`abstract void`
`reset()`
Resets this ThetaIntersection for stateful operations only.
`abstract byte[]`
`toByteArray()`
Serialize this intersection to a byte array form.
`static ThetaIntersection`
`wrap(MemorySegment srcSeg)`
Factory: Wrap a ThetaIntersection target around the given source MemorySegment containing intersection data.
`static ThetaIntersection`
`wrap(MemorySegment srcSeg, long expectedSeed)`
Factory: Wrap a ThetaIntersection target around the given source MemorySegment containing intersection data.

### Methods inherited from class ThetaSetOperation

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

### Methods inherited from class Object

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

### Methods inherited from interface MemorySegmentStatus

`hasMemorySegment, isOffHeap, isSameResource`

## Constructor Details

### ThetaIntersection

public ThetaIntersection()
No argument constructor.

## Method Details

### getFamily

public Family getFamily()
Description copied from class: `ThetaSetOperation`
Gets the Family of this ThetaSetOperation

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

### getResult

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

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

### getResult

public abstract CompactThetaSketch getResult(boolean dstOrdered, MemorySegment dstSeg)
Gets the result of this operation as a CompactThetaSketch in the given dstSeg. This does not disturb the underlying data structure of this intersection. The `intersect(ThetaSketch)` method must have been called at least once, otherwise an exception will be thrown. This is because a virgin intersection 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
  `dstSeg` - the destination MemorySegment.
Returns:
  the result of this operation as a CompactThetaSketch stored in the given dstSeg, 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 ThetaIntersection 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(ThetaSketch 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 CompactThetaSketch intersect(ThetaSketch a, ThetaSketch b)
Perform intersect set operation on the two given sketch arguments and return the result as an ordered CompactThetaSketch on the heap.

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

### intersect

public abstract CompactThetaSketch intersect(ThetaSketch a, ThetaSketch b, boolean dstOrdered, MemorySegment dstSeg)
Perform intersect set operation on the two given sketches and return the result as a CompactThetaSketch.

Parameters:
  `a` - The first sketch argument
  `b` - The second sketch argument
  `dstOrdered` - See Destination Ordered.
  `dstSeg` - the destination MemorySegment.
Returns:
  the result as a CompactThetaSketch.

### wrap

public static ThetaIntersection wrap(MemorySegment srcSeg)
Factory: Wrap a ThetaIntersection target around the given source MemorySegment containing intersection data. This method assumes the Default Update Seed. If the given source MemorySegment is read-only, the returned object will also be read-only.

Parameters:
  `srcSeg` - The source MemorySegment image.
Returns:
  a ThetaIntersection that wraps a source MemorySegment that contains a ThetaIntersection image

### wrap

public static ThetaIntersection wrap(MemorySegment srcSeg, long expectedSeed)
Factory: Wrap a ThetaIntersection target around the given source MemorySegment containing intersection data. If the given source MemorySegment is read-only, the returned object will also be read-only.

Parameters:
  `srcSeg` - The source MemorySegment image.
  `expectedSeed` - See seed
Returns:
  a ThetaIntersection that wraps a source MemorySegment that contains a ThetaIntersection image