Class UpdateSketch
public abstract class UpdateSketch extends Sketch
- Author:
- Lee Rhodes
-
Method Summary
Modifier and Type Method Description static UpdateSketchBuilderbuilder()Returns a new builderCompactSketchcompact(boolean dstOrdered, org.apache.datasketches.memory.WritableMemory dstMem)Convert this sketch to a new CompactSketch of the chosen order and direct or on the heap.intgetCompactBytes()Returns the number of storage bytes required for this Sketch if its current state were compacted.abstract intgetLgNomLongs()Gets the Log base 2 of the configured nominal entriesabstract ResizeFactorgetResizeFactor()Returns the configured ResizeFactorstatic UpdateSketchheapify(org.apache.datasketches.memory.Memory srcMem)Instantiates an on-heap UpdateSketch from Memory.static UpdateSketchheapify(org.apache.datasketches.memory.Memory srcMem, long seed)Instantiates an on-heap UpdateSketch from Memory.booleanisCompact()Returns true if this sketch is in compact form.booleanisOrdered()Returns true if internal cache is orderedabstract UpdateSketchrebuild()Rebuilds the hash table to remove dirty values or to reduce the size to nominal entries.abstract voidreset()Resets this sketch back to a virgin empty state.UpdateReturnStateupdate(byte[] data)Present this sketch with the given byte array.UpdateReturnStateupdate(char[] data)Present this sketch with the given char array.UpdateReturnStateupdate(double datum)Present this sketch with the given double (or float) datum.UpdateReturnStateupdate(int[] data)Present this sketch with the given integer array.UpdateReturnStateupdate(long datum)Present this sketch with a long.UpdateReturnStateupdate(long[] data)Present this sketch with the given long array.UpdateReturnStateupdate(String datum)Present this sketch with the given String.static UpdateSketchwrap(org.apache.datasketches.memory.WritableMemory srcMem)Wrap takes the sketch image in Memory and refers to it directly.static UpdateSketchwrap(org.apache.datasketches.memory.WritableMemory srcMem, long seed)Wrap takes the sketch image in Memory and refers to it directly.Methods inherited from class org.apache.datasketches.theta.Sketch
compact, getCountLessThanThetaLong, getCurrentBytes, getEstimate, getFamily, getLowerBound, getMaxCompactSketchBytes, getMaxUpdateSketchBytes, getRetainedEntries, getRetainedEntries, getSerializationVersion, getTheta, getThetaLong, getUpperBound, hasMemory, isDirect, isEmpty, isEstimationMode, isSameResource, iterator, toByteArray, toString, toString, toString, toString, wrap, wrap
-
Method Details
-
wrap
Wrap takes the sketch image in Memory and refers to it directly. There is no data copying onto the java heap. Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have been explicitly stored as direct objects can be wrapped. This method assumes theUtil.DEFAULT_UPDATE_SEED. Default Update Seed.- Parameters:
srcMem- an image of a Sketch where the image seed hash matches the default seed hash. See Memory- Returns:
- a Sketch backed by the given Memory
-
wrap
Wrap takes the sketch image in Memory and refers to it directly. There is no data copying onto the java heap. Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have been explicitly stored as direct objects can be wrapped. An attempt to "wrap" earlier version sketches will result in a "heapified", normal Java Heap version of the sketch where all data will be copied to the heap.- Parameters:
srcMem- an image of a Sketch where the image seed hash matches the given seed hash. See Memoryseed- See Update Hash Seed. Compact sketches store a 16-bit hash of the seed, but not the seed itself.- Returns:
- a UpdateSketch backed by the given Memory
-
heapify
Instantiates an on-heap UpdateSketch from Memory. This method assumes theUtil.DEFAULT_UPDATE_SEED.- Parameters:
srcMem- See Memory- Returns:
- an UpdateSketch
-
heapify
Instantiates an on-heap UpdateSketch from Memory.- Parameters:
srcMem- See Memoryseed- See Update Hash Seed.- Returns:
- an UpdateSketch
-
compact
public CompactSketch compact(boolean dstOrdered, org.apache.datasketches.memory.WritableMemory dstMem)Description copied from class:SketchConvert 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:
compactin classSketch- Parameters:
dstOrdered- See Destination OrdereddstMem- See Destination Memory.- Returns:
- this sketch as a CompactSketch in the chosen form
-
getCompactBytes
public int getCompactBytes()Description copied from class:SketchReturns 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 callingSketch.getCurrentBytes().- Specified by:
getCompactBytesin classSketch- Returns:
- number of compact bytes
-
isCompact
public boolean isCompact()Description copied from class:SketchReturns true if this sketch is in compact form. -
isOrdered
public boolean isOrdered()Description copied from class:SketchReturns true if internal cache is ordered -
builder
Returns a new builder- Returns:
- a new builder
-
getResizeFactor
Returns the configured ResizeFactor- Returns:
- the configured ResizeFactor
-
reset
public abstract void reset()Resets this sketch back to a virgin empty state. -
rebuild
Rebuilds the hash table to remove dirty values or to reduce the size to nominal entries.- Returns:
- this sketch
-
update
Present this sketch with a long.- Parameters:
datum- The given long datum.- Returns:
- See Update Return State
-
update
Present this sketch with the given double (or float) datum. The double will be converted to a long using Double.doubleToLongBits(datum), which normalizes all NaN values to a single NaN representation. Plus and minus zero will be normalized to plus zero. The special floating-point values NaN and +/- Infinity are treated as distinct.- Parameters:
datum- The given double datum.- Returns:
- See Update Return State
-
update
Present this sketch with the given String. The string is converted to a byte array using UTF8 encoding. If the string is null or empty no update attempt is made and the method returns.Note: this will not produce the same output hash values as the
update(char[])method and will generally be a little slower depending on the complexity of the UTF8 encoding.- Parameters:
datum- The given String.- Returns:
- See Update Return State
-
update
Present this sketch with the given byte array. If the byte array is null or empty no update attempt is made and the method returns.- Parameters:
data- The given byte array.- Returns:
- See Update Return State
-
update
Present this sketch with the given char array. If the char array is null or empty no update attempt is made and the method returns.Note: this will not produce the same output hash values as the
update(String)method but will be a little faster as it avoids the complexity of the UTF8 encoding.- Parameters:
data- The given char array.- Returns:
- See Update Return State
-
update
Present this sketch with the given integer array. If the integer array is null or empty no update attempt is made and the method returns.- Parameters:
data- The given int array.- Returns:
- See Update Return State
-
update
Present this sketch with the given long array. If the long array is null or empty no update attempt is made and the method returns.- Parameters:
data- The given long array.- Returns:
- See Update Return State
-
getLgNomLongs
public abstract int getLgNomLongs()Gets the Log base 2 of the configured nominal entries- Returns:
- the Log base 2 of the configured nominal entries
-