repo
stringlengths
7
58
path
stringlengths
12
218
func_name
stringlengths
3
140
original_string
stringlengths
73
34.1k
language
stringclasses
1 value
code
stringlengths
73
34.1k
code_tokens
list
docstring
stringlengths
3
16k
docstring_tokens
list
sha
stringlengths
40
40
url
stringlengths
105
339
partition
stringclasses
1 value
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/fdt/FdtSketch.java
FdtSketch.computeLgK
static int computeLgK(final double threshold, final double rse) { final double v = Math.ceil(1.0 / (threshold * rse * rse)); final int lgK = (int) Math.ceil(Math.log(v) / Math.log(2)); if (lgK > MAX_LG_NOM_LONGS) { throw new SketchesArgumentException("Requested Sketch (LgK = " + lgK + " > 2^26), " + "either increase the threshold, the rse or both."); } return lgK; }
java
static int computeLgK(final double threshold, final double rse) { final double v = Math.ceil(1.0 / (threshold * rse * rse)); final int lgK = (int) Math.ceil(Math.log(v) / Math.log(2)); if (lgK > MAX_LG_NOM_LONGS) { throw new SketchesArgumentException("Requested Sketch (LgK = " + lgK + " > 2^26), " + "either increase the threshold, the rse or both."); } return lgK; }
[ "static", "int", "computeLgK", "(", "final", "double", "threshold", ",", "final", "double", "rse", ")", "{", "final", "double", "v", "=", "Math", ".", "ceil", "(", "1.0", "/", "(", "threshold", "*", "rse", "*", "rse", ")", ")", ";", "final", "int", ...
Computes LgK given the threshold and RSE. @param threshold the fraction, between zero and 1.0, of the total stream length that defines a "Frequent" (or heavy) tuple. @param rse the maximum Relative Standard Error for the estimate of the distinct population of a reported tuple (selected with a primary key) at the threshold. @return LgK
[ "Computes", "LgK", "given", "the", "threshold", "and", "RSE", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/FdtSketch.java#L164-L172
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/ItemsAuxiliary.java
ItemsAuxiliary.getQuantile
T getQuantile(final double fRank) { checkFractionalRankBounds(fRank); if (auxN_ <= 0) { return null; } final long pos = QuantilesHelper.posOfPhi(fRank, auxN_); return approximatelyAnswerPositionalQuery(pos); }
java
T getQuantile(final double fRank) { checkFractionalRankBounds(fRank); if (auxN_ <= 0) { return null; } final long pos = QuantilesHelper.posOfPhi(fRank, auxN_); return approximatelyAnswerPositionalQuery(pos); }
[ "T", "getQuantile", "(", "final", "double", "fRank", ")", "{", "checkFractionalRankBounds", "(", "fRank", ")", ";", "if", "(", "auxN_", "<=", "0", ")", "{", "return", "null", ";", "}", "final", "long", "pos", "=", "QuantilesHelper", ".", "posOfPhi", "(",...
Get the estimated quantile given a fractional rank. @param fRank the fractional rank where: 0 &le; fRank &le; 1.0. @return the estimated quantile
[ "Get", "the", "estimated", "quantile", "given", "a", "fractional", "rank", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsAuxiliary.java#L71-L76
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/ItemsAuxiliary.java
ItemsAuxiliary.approximatelyAnswerPositionalQuery
@SuppressWarnings("unchecked") private T approximatelyAnswerPositionalQuery(final long pos) { assert 0 <= pos; assert pos < auxN_; final int index = QuantilesHelper.chunkContainingPos(auxCumWtsArr_, pos); return (T) this.auxSamplesArr_[index]; }
java
@SuppressWarnings("unchecked") private T approximatelyAnswerPositionalQuery(final long pos) { assert 0 <= pos; assert pos < auxN_; final int index = QuantilesHelper.chunkContainingPos(auxCumWtsArr_, pos); return (T) this.auxSamplesArr_[index]; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "T", "approximatelyAnswerPositionalQuery", "(", "final", "long", "pos", ")", "{", "assert", "0", "<=", "pos", ";", "assert", "pos", "<", "auxN_", ";", "final", "int", "index", "=", "QuantilesHelper...
Assuming that there are n items in the true stream, this asks what item would appear in position 0 &le; pos &lt; n of a hypothetical sorted version of that stream. <p>Note that since that since the true stream is unavailable, we don't actually answer the question for that stream, but rather for a <i>different</i> stream of the same length, that could hypothetically be reconstructed from the weighted samples in our sketch. @param pos position @return approximate answer
[ "Assuming", "that", "there", "are", "n", "items", "in", "the", "true", "stream", "this", "asks", "what", "item", "would", "appear", "in", "position", "0", "&le", ";", "pos", "&lt", ";", "n", "of", "a", "hypothetical", "sorted", "version", "of", "that", ...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsAuxiliary.java#L90-L96
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/ItemsAuxiliary.java
ItemsAuxiliary.populateFromItemsSketch
private final static <T> void populateFromItemsSketch( final int k, final long n, final long bitPattern, final T[] combinedBuffer, final int baseBufferCount, final int numSamples, final T[] itemsArr, final long[] cumWtsArr, final Comparator<? super T> comparator) { long weight = 1; int nxt = 0; long bits = bitPattern; assert bits == (n / (2L * k)); // internal consistency check for (int lvl = 0; bits != 0L; lvl++, bits >>>= 1) { weight *= 2; if ((bits & 1L) > 0L) { final int offset = (2 + lvl) * k; for (int i = 0; i < k; i++) { itemsArr[nxt] = combinedBuffer[i + offset]; cumWtsArr[nxt] = weight; nxt++; } } } weight = 1; //NOT a mistake! We just copied the highest level; now we need to copy the base buffer final int startOfBaseBufferBlock = nxt; // Copy BaseBuffer over, along with weight = 1 for (int i = 0; i < baseBufferCount; i++) { itemsArr[nxt] = combinedBuffer[i]; cumWtsArr[nxt] = weight; nxt++; } assert nxt == numSamples; // Must sort the items that came from the base buffer. // Don't need to sort the corresponding weights because they are all the same. Arrays.sort(itemsArr, startOfBaseBufferBlock, numSamples, comparator); cumWtsArr[numSamples] = 0; }
java
private final static <T> void populateFromItemsSketch( final int k, final long n, final long bitPattern, final T[] combinedBuffer, final int baseBufferCount, final int numSamples, final T[] itemsArr, final long[] cumWtsArr, final Comparator<? super T> comparator) { long weight = 1; int nxt = 0; long bits = bitPattern; assert bits == (n / (2L * k)); // internal consistency check for (int lvl = 0; bits != 0L; lvl++, bits >>>= 1) { weight *= 2; if ((bits & 1L) > 0L) { final int offset = (2 + lvl) * k; for (int i = 0; i < k; i++) { itemsArr[nxt] = combinedBuffer[i + offset]; cumWtsArr[nxt] = weight; nxt++; } } } weight = 1; //NOT a mistake! We just copied the highest level; now we need to copy the base buffer final int startOfBaseBufferBlock = nxt; // Copy BaseBuffer over, along with weight = 1 for (int i = 0; i < baseBufferCount; i++) { itemsArr[nxt] = combinedBuffer[i]; cumWtsArr[nxt] = weight; nxt++; } assert nxt == numSamples; // Must sort the items that came from the base buffer. // Don't need to sort the corresponding weights because they are all the same. Arrays.sort(itemsArr, startOfBaseBufferBlock, numSamples, comparator); cumWtsArr[numSamples] = 0; }
[ "private", "final", "static", "<", "T", ">", "void", "populateFromItemsSketch", "(", "final", "int", "k", ",", "final", "long", "n", ",", "final", "long", "bitPattern", ",", "final", "T", "[", "]", "combinedBuffer", ",", "final", "int", "baseBufferCount", ...
Populate the arrays and registers from an ItemsSketch @param <T> the data type @param k K value of sketch @param n The current size of the stream @param bitPattern the bit pattern for valid log levels @param combinedBuffer the combined buffer reference @param baseBufferCount the count of the base buffer @param numSamples Total samples in the sketch @param itemsArr the consolidated array of all items from the sketch populated here @param cumWtsArr the cumulative weights for each item from the sketch populated here @param comparator the given comparator for data type T
[ "Populate", "the", "arrays", "and", "registers", "from", "an", "ItemsSketch" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsAuxiliary.java#L111-L146
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/DirectCompactUnorderedSketch.java
DirectCompactUnorderedSketch.wrapInstance
static DirectCompactUnorderedSketch wrapInstance(final Memory srcMem, final long seed) { final short memSeedHash = srcMem.getShort(SEED_HASH_SHORT); final short computedSeedHash = computeSeedHash(seed); checkSeedHashes(memSeedHash, computedSeedHash); return new DirectCompactUnorderedSketch(srcMem); }
java
static DirectCompactUnorderedSketch wrapInstance(final Memory srcMem, final long seed) { final short memSeedHash = srcMem.getShort(SEED_HASH_SHORT); final short computedSeedHash = computeSeedHash(seed); checkSeedHashes(memSeedHash, computedSeedHash); return new DirectCompactUnorderedSketch(srcMem); }
[ "static", "DirectCompactUnorderedSketch", "wrapInstance", "(", "final", "Memory", "srcMem", ",", "final", "long", "seed", ")", "{", "final", "short", "memSeedHash", "=", "srcMem", ".", "getShort", "(", "SEED_HASH_SHORT", ")", ";", "final", "short", "computedSeedHa...
Wraps the given Memory, which must be a SerVer 3, unordered, Compact Sketch image. Must check the validity of the Memory before calling. @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a> @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>. @return this sketch
[ "Wraps", "the", "given", "Memory", "which", "must", "be", "a", "SerVer", "3", "unordered", "Compact", "Sketch", "image", ".", "Must", "check", "the", "validity", "of", "the", "Memory", "before", "calling", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/DirectCompactUnorderedSketch.java#L41-L46
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/DirectCompactUnorderedSketch.java
DirectCompactUnorderedSketch.compact
static DirectCompactUnorderedSketch compact(final UpdateSketch sketch, final WritableMemory dstMem) { final int curCount = sketch.getRetainedEntries(true); long thetaLong = sketch.getThetaLong(); boolean empty = sketch.isEmpty(); thetaLong = thetaOnCompact(empty, curCount, thetaLong); empty = emptyOnCompact(curCount, thetaLong); final int preLongs = computeCompactPreLongs(thetaLong, empty, curCount); final short seedHash = sketch.getSeedHash(); final long[] cache = sketch.getCache(); final int requiredFlags = READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK; final byte flags = (byte) (requiredFlags | (empty ? EMPTY_FLAG_MASK : 0)); final boolean ordered = false; final long[] compactCache = CompactSketch.compactCache(cache, curCount, thetaLong, ordered); loadCompactMemory(compactCache, seedHash, curCount, thetaLong, dstMem, flags, preLongs); return new DirectCompactUnorderedSketch(dstMem); }
java
static DirectCompactUnorderedSketch compact(final UpdateSketch sketch, final WritableMemory dstMem) { final int curCount = sketch.getRetainedEntries(true); long thetaLong = sketch.getThetaLong(); boolean empty = sketch.isEmpty(); thetaLong = thetaOnCompact(empty, curCount, thetaLong); empty = emptyOnCompact(curCount, thetaLong); final int preLongs = computeCompactPreLongs(thetaLong, empty, curCount); final short seedHash = sketch.getSeedHash(); final long[] cache = sketch.getCache(); final int requiredFlags = READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK; final byte flags = (byte) (requiredFlags | (empty ? EMPTY_FLAG_MASK : 0)); final boolean ordered = false; final long[] compactCache = CompactSketch.compactCache(cache, curCount, thetaLong, ordered); loadCompactMemory(compactCache, seedHash, curCount, thetaLong, dstMem, flags, preLongs); return new DirectCompactUnorderedSketch(dstMem); }
[ "static", "DirectCompactUnorderedSketch", "compact", "(", "final", "UpdateSketch", "sketch", ",", "final", "WritableMemory", "dstMem", ")", "{", "final", "int", "curCount", "=", "sketch", ".", "getRetainedEntries", "(", "true", ")", ";", "long", "thetaLong", "=", ...
Constructs given an UpdateSketch. @param sketch the given UpdateSketch @param dstMem the given destination Memory. This clears it before use. @return a DirectCompactUnorderedSketch
[ "Constructs", "given", "an", "UpdateSketch", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/DirectCompactUnorderedSketch.java#L54-L70
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/DirectCompactUnorderedSketch.java
DirectCompactUnorderedSketch.compact
static DirectCompactUnorderedSketch compact(final long[] cache, final boolean empty, final short seedHash, final int curCount, final long thetaLong, final WritableMemory dstMem) { final int preLongs = computeCompactPreLongs(thetaLong, empty, curCount); final int requiredFlags = READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK; final byte flags = (byte) (requiredFlags | (empty ? EMPTY_FLAG_MASK : 0)); loadCompactMemory(cache, seedHash, curCount, thetaLong, dstMem, flags, preLongs); return new DirectCompactUnorderedSketch(dstMem); }
java
static DirectCompactUnorderedSketch compact(final long[] cache, final boolean empty, final short seedHash, final int curCount, final long thetaLong, final WritableMemory dstMem) { final int preLongs = computeCompactPreLongs(thetaLong, empty, curCount); final int requiredFlags = READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK; final byte flags = (byte) (requiredFlags | (empty ? EMPTY_FLAG_MASK : 0)); loadCompactMemory(cache, seedHash, curCount, thetaLong, dstMem, flags, preLongs); return new DirectCompactUnorderedSketch(dstMem); }
[ "static", "DirectCompactUnorderedSketch", "compact", "(", "final", "long", "[", "]", "cache", ",", "final", "boolean", "empty", ",", "final", "short", "seedHash", ",", "final", "int", "curCount", ",", "final", "long", "thetaLong", ",", "final", "WritableMemory",...
Constructs this sketch from correct, valid components. @param cache in compact, ordered form @param empty The correct <a href="{@docRoot}/resources/dictionary.html#empty">Empty</a>. @param seedHash The correct <a href="{@docRoot}/resources/dictionary.html#seedHash">Seed Hash</a>. @param curCount correct value @param thetaLong The correct <a href="{@docRoot}/resources/dictionary.html#thetaLong">thetaLong</a>. @param dstMem the given destination Memory. This clears it before use. @return a DirectCompactUnorderedSketch
[ "Constructs", "this", "sketch", "from", "correct", "valid", "components", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/DirectCompactUnorderedSketch.java#L84-L91
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/sampling/ReservoirLongsSketch.java
ReservoirLongsSketch.getSamples
public long[] getSamples() { if (itemsSeen_ == 0) { return null; } final int numSamples = (int) Math.min(reservoirSize_, itemsSeen_); return java.util.Arrays.copyOf(data_, numSamples); }
java
public long[] getSamples() { if (itemsSeen_ == 0) { return null; } final int numSamples = (int) Math.min(reservoirSize_, itemsSeen_); return java.util.Arrays.copyOf(data_, numSamples); }
[ "public", "long", "[", "]", "getSamples", "(", ")", "{", "if", "(", "itemsSeen_", "==", "0", ")", "{", "return", "null", ";", "}", "final", "int", "numSamples", "=", "(", "int", ")", "Math", ".", "min", "(", "reservoirSize_", ",", "itemsSeen_", ")", ...
Returns a copy of the items in the reservoir. The returned array length may be smaller than the reservoir capacity. @return A copy of the reservoir array
[ "Returns", "a", "copy", "of", "the", "items", "in", "the", "reservoir", ".", "The", "returned", "array", "length", "may", "be", "smaller", "than", "the", "reservoir", "capacity", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/ReservoirLongsSketch.java#L281-L287
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/adouble/DoubleSummary.java
DoubleSummary.fromMemory
public static DeserializeResult<DoubleSummary> fromMemory(final Memory mem) { return new DeserializeResult<>(new DoubleSummary(mem.getDouble(VALUE_DOUBLE), Mode.values()[mem.getByte(MODE_BYTE)]), SERIALIZED_SIZE_BYTES); }
java
public static DeserializeResult<DoubleSummary> fromMemory(final Memory mem) { return new DeserializeResult<>(new DoubleSummary(mem.getDouble(VALUE_DOUBLE), Mode.values()[mem.getByte(MODE_BYTE)]), SERIALIZED_SIZE_BYTES); }
[ "public", "static", "DeserializeResult", "<", "DoubleSummary", ">", "fromMemory", "(", "final", "Memory", "mem", ")", "{", "return", "new", "DeserializeResult", "<>", "(", "new", "DoubleSummary", "(", "mem", ".", "getDouble", "(", "VALUE_DOUBLE", ")", ",", "Mo...
Creates an instance of the DoubleSummary given a serialized representation @param mem Memory object with serialized DoubleSummary @return DeserializedResult object, which contains a DoubleSummary object and number of bytes read from the Memory
[ "Creates", "an", "instance", "of", "the", "DoubleSummary", "given", "a", "serialized", "representation" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/adouble/DoubleSummary.java#L125-L128
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/sampling/ReservoirLongsUnion.java
ReservoirLongsUnion.update
public void update(final long datum) { if (gadget_ == null) { gadget_ = ReservoirLongsSketch.newInstance(maxK_); } gadget_.update(datum); }
java
public void update(final long datum) { if (gadget_ == null) { gadget_ = ReservoirLongsSketch.newInstance(maxK_); } gadget_.update(datum); }
[ "public", "void", "update", "(", "final", "long", "datum", ")", "{", "if", "(", "gadget_", "==", "null", ")", "{", "gadget_", "=", "ReservoirLongsSketch", ".", "newInstance", "(", "maxK_", ")", ";", "}", "gadget_", ".", "update", "(", "datum", ")", ";"...
Present this union with a long. @param datum The given long datum.
[ "Present", "this", "union", "with", "a", "long", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/ReservoirLongsUnion.java#L176-L181
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/PreambleUtil.java
PreambleUtil.preambleToString
static String preambleToString(final byte[] byteArr) { final Memory mem = Memory.wrap(byteArr); return preambleToString(mem); }
java
static String preambleToString(final byte[] byteArr) { final Memory mem = Memory.wrap(byteArr); return preambleToString(mem); }
[ "static", "String", "preambleToString", "(", "final", "byte", "[", "]", "byteArr", ")", "{", "final", "Memory", "mem", "=", "Memory", ".", "wrap", "(", "byteArr", ")", ";", "return", "preambleToString", "(", "mem", ")", ";", "}" ]
Returns a human readable string summary of the preamble state of the given byte array. Used primarily in testing. @param byteArr the given byte array. @return the summary preamble string.
[ "Returns", "a", "human", "readable", "string", "summary", "of", "the", "preamble", "state", "of", "the", "given", "byte", "array", ".", "Used", "primarily", "in", "testing", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/PreambleUtil.java#L196-L199
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesAuxiliary.java
DoublesAuxiliary.populateFromDoublesSketch
private final static void populateFromDoublesSketch( final int k, final long n, final long bitPattern, final DoublesSketchAccessor sketchAccessor, final double[] itemsArr, final long[] cumWtsArr) { long weight = 1; int nxt = 0; long bits = bitPattern; assert bits == (n / (2L * k)); // internal consistency check for (int lvl = 0; bits != 0L; lvl++, bits >>>= 1) { weight *= 2; if ((bits & 1L) > 0L) { sketchAccessor.setLevel(lvl); for (int i = 0; i < sketchAccessor.numItems(); i++) { itemsArr[nxt] = sketchAccessor.get(i); cumWtsArr[nxt] = weight; nxt++; } } } weight = 1; //NOT a mistake! We just copied the highest level; now we need to copy the base buffer final int startOfBaseBufferBlock = nxt; // Copy BaseBuffer over, along with weight = 1 sketchAccessor.setLevel(BB_LVL_IDX); for (int i = 0; i < sketchAccessor.numItems(); i++) { itemsArr[nxt] = sketchAccessor.get(i); cumWtsArr[nxt] = weight; nxt++; } assert nxt == itemsArr.length; // Must sort the items that came from the base buffer. // Don't need to sort the corresponding weights because they are all the same. final int numSamples = nxt; Arrays.sort(itemsArr, startOfBaseBufferBlock, numSamples); cumWtsArr[numSamples] = 0; }
java
private final static void populateFromDoublesSketch( final int k, final long n, final long bitPattern, final DoublesSketchAccessor sketchAccessor, final double[] itemsArr, final long[] cumWtsArr) { long weight = 1; int nxt = 0; long bits = bitPattern; assert bits == (n / (2L * k)); // internal consistency check for (int lvl = 0; bits != 0L; lvl++, bits >>>= 1) { weight *= 2; if ((bits & 1L) > 0L) { sketchAccessor.setLevel(lvl); for (int i = 0; i < sketchAccessor.numItems(); i++) { itemsArr[nxt] = sketchAccessor.get(i); cumWtsArr[nxt] = weight; nxt++; } } } weight = 1; //NOT a mistake! We just copied the highest level; now we need to copy the base buffer final int startOfBaseBufferBlock = nxt; // Copy BaseBuffer over, along with weight = 1 sketchAccessor.setLevel(BB_LVL_IDX); for (int i = 0; i < sketchAccessor.numItems(); i++) { itemsArr[nxt] = sketchAccessor.get(i); cumWtsArr[nxt] = weight; nxt++; } assert nxt == itemsArr.length; // Must sort the items that came from the base buffer. // Don't need to sort the corresponding weights because they are all the same. final int numSamples = nxt; Arrays.sort(itemsArr, startOfBaseBufferBlock, numSamples); cumWtsArr[numSamples] = 0; }
[ "private", "final", "static", "void", "populateFromDoublesSketch", "(", "final", "int", "k", ",", "final", "long", "n", ",", "final", "long", "bitPattern", ",", "final", "DoublesSketchAccessor", "sketchAccessor", ",", "final", "double", "[", "]", "itemsArr", ","...
Populate the arrays and registers from a DoublesSketch @param k K value of sketch @param n The current size of the stream @param bitPattern the bit pattern for valid log levels @param sketchAccessor A DoublesSketchAccessor around the sketch @param itemsArr the consolidated array of all items from the sketch populated here @param cumWtsArr the cumulative weights for each item from the sketch populated here
[ "Populate", "the", "arrays", "and", "registers", "from", "a", "DoublesSketch" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesAuxiliary.java#L96-L133
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesAuxiliary.java
DoublesAuxiliary.blockyTandemMergeSort
static void blockyTandemMergeSort(final double[] keyArr, final long[] valArr, final int arrLen, final int blkSize) { assert blkSize >= 1; if (arrLen <= blkSize) { return; } int numblks = arrLen / blkSize; if ((numblks * blkSize) < arrLen) { numblks += 1; } assert ((numblks * blkSize) >= arrLen); // duplicate the input is preparation for the "ping-pong" copy reduction strategy. final double[] keyTmp = Arrays.copyOf(keyArr, arrLen); final long[] valTmp = Arrays.copyOf(valArr, arrLen); blockyTandemMergeSortRecursion(keyTmp, valTmp, keyArr, valArr, 0, numblks, blkSize, arrLen); }
java
static void blockyTandemMergeSort(final double[] keyArr, final long[] valArr, final int arrLen, final int blkSize) { assert blkSize >= 1; if (arrLen <= blkSize) { return; } int numblks = arrLen / blkSize; if ((numblks * blkSize) < arrLen) { numblks += 1; } assert ((numblks * blkSize) >= arrLen); // duplicate the input is preparation for the "ping-pong" copy reduction strategy. final double[] keyTmp = Arrays.copyOf(keyArr, arrLen); final long[] valTmp = Arrays.copyOf(valArr, arrLen); blockyTandemMergeSortRecursion(keyTmp, valTmp, keyArr, valArr, 0, numblks, blkSize, arrLen); }
[ "static", "void", "blockyTandemMergeSort", "(", "final", "double", "[", "]", "keyArr", ",", "final", "long", "[", "]", "valArr", ",", "final", "int", "arrLen", ",", "final", "int", "blkSize", ")", "{", "assert", "blkSize", ">=", "1", ";", "if", "(", "a...
used by DoublesAuxiliary and UtilTest
[ "used", "by", "DoublesAuxiliary", "and", "UtilTest" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesAuxiliary.java#L147-L163
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesAuxiliary.java
DoublesAuxiliary.tandemMerge
private static void tandemMerge(final double[] keySrc, final long[] valSrc, final int arrStart1, final int arrLen1, final int arrStart2, final int arrLen2, final double[] keyDst, final long[] valDst, final int arrStart3) { final int arrStop1 = arrStart1 + arrLen1; final int arrStop2 = arrStart2 + arrLen2; int i1 = arrStart1; int i2 = arrStart2; int i3 = arrStart3; while ((i1 < arrStop1) && (i2 < arrStop2)) { if (keySrc[i2] < keySrc[i1]) { keyDst[i3] = keySrc[i2]; valDst[i3] = valSrc[i2]; i2++; } else { keyDst[i3] = keySrc[i1]; valDst[i3] = valSrc[i1]; i1++; } i3++; } if (i1 < arrStop1) { arraycopy(keySrc, i1, keyDst, i3, arrStop1 - i1); arraycopy(valSrc, i1, valDst, i3, arrStop1 - i1); } else { assert i2 < arrStop2; arraycopy(keySrc, i2, keyDst, i3, arrStop2 - i2); arraycopy(valSrc, i2, valDst, i3, arrStop2 - i2); } }
java
private static void tandemMerge(final double[] keySrc, final long[] valSrc, final int arrStart1, final int arrLen1, final int arrStart2, final int arrLen2, final double[] keyDst, final long[] valDst, final int arrStart3) { final int arrStop1 = arrStart1 + arrLen1; final int arrStop2 = arrStart2 + arrLen2; int i1 = arrStart1; int i2 = arrStart2; int i3 = arrStart3; while ((i1 < arrStop1) && (i2 < arrStop2)) { if (keySrc[i2] < keySrc[i1]) { keyDst[i3] = keySrc[i2]; valDst[i3] = valSrc[i2]; i2++; } else { keyDst[i3] = keySrc[i1]; valDst[i3] = valSrc[i1]; i1++; } i3++; } if (i1 < arrStop1) { arraycopy(keySrc, i1, keyDst, i3, arrStop1 - i1); arraycopy(valSrc, i1, valDst, i3, arrStop1 - i1); } else { assert i2 < arrStop2; arraycopy(keySrc, i2, keyDst, i3, arrStop2 - i2); arraycopy(valSrc, i2, valDst, i3, arrStop2 - i2); } }
[ "private", "static", "void", "tandemMerge", "(", "final", "double", "[", "]", "keySrc", ",", "final", "long", "[", "]", "valSrc", ",", "final", "int", "arrStart1", ",", "final", "int", "arrLen1", ",", "final", "int", "arrStart2", ",", "final", "int", "ar...
Performs two merges in tandem. One of them provides the sort keys while the other one passively undergoes the same data motion. @param keySrc key source @param valSrc value source @param arrStart1 Array 1 start offset @param arrLen1 Array 1 length @param arrStart2 Array 2 start offset @param arrLen2 Array 2 length @param keyDst key destination @param valDst value destination @param arrStart3 Array 3 start offset
[ "Performs", "two", "merges", "in", "tandem", ".", "One", "of", "them", "provides", "the", "sort", "keys", "while", "the", "other", "one", "passively", "undergoes", "the", "same", "data", "motion", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesAuxiliary.java#L235-L267
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hash/MurmurHash3v2.java
MurmurHash3v2.hash
public static long[] hash(final long[] in, final long seed) { if ((in == null) || (in.length == 0)) { return emptyOrNull(seed, new long[2]); } return hash(Memory.wrap(in), 0L, in.length << 3, seed, new long[2]); }
java
public static long[] hash(final long[] in, final long seed) { if ((in == null) || (in.length == 0)) { return emptyOrNull(seed, new long[2]); } return hash(Memory.wrap(in), 0L, in.length << 3, seed, new long[2]); }
[ "public", "static", "long", "[", "]", "hash", "(", "final", "long", "[", "]", "in", ",", "final", "long", "seed", ")", "{", "if", "(", "(", "in", "==", "null", ")", "||", "(", "in", ".", "length", "==", "0", ")", ")", "{", "return", "emptyOrNul...
Returns a 128-bit hash of the input. Provided for compatibility with older version of MurmurHash3, but empty or null input now returns a hash. @param in long array @param seed A long valued seed. @return the hash
[ "Returns", "a", "128", "-", "bit", "hash", "of", "the", "input", ".", "Provided", "for", "compatibility", "with", "older", "version", "of", "MurmurHash3", "but", "empty", "or", "null", "input", "now", "returns", "a", "hash", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hash/MurmurHash3v2.java#L46-L51
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hash/MurmurHash3v2.java
MurmurHash3v2.hash
public static long[] hash(final String in, final long seed, final long[] hashOut) { if ((in == null) || (in.length() == 0)) { return emptyOrNull(seed, hashOut); } final byte[] byteArr = in.getBytes(UTF_8); return hash(Memory.wrap(byteArr), 0L, byteArr.length, seed, hashOut); }
java
public static long[] hash(final String in, final long seed, final long[] hashOut) { if ((in == null) || (in.length() == 0)) { return emptyOrNull(seed, hashOut); } final byte[] byteArr = in.getBytes(UTF_8); return hash(Memory.wrap(byteArr), 0L, byteArr.length, seed, hashOut); }
[ "public", "static", "long", "[", "]", "hash", "(", "final", "String", "in", ",", "final", "long", "seed", ",", "final", "long", "[", "]", "hashOut", ")", "{", "if", "(", "(", "in", "==", "null", ")", "||", "(", "in", ".", "length", "(", ")", "=...
Returns a 128-bit hash of the input. @param in a String @param seed A long valued seed. @param hashOut A long array of size 2 @return the hash
[ "Returns", "a", "128", "-", "bit", "hash", "of", "the", "input", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hash/MurmurHash3v2.java#L137-L143
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hash/MurmurHash3v2.java
MurmurHash3v2.mixK1
private static long mixK1(long k1) { k1 *= C1; k1 = Long.rotateLeft(k1, 31); k1 *= C2; return k1; }
java
private static long mixK1(long k1) { k1 *= C1; k1 = Long.rotateLeft(k1, 31); k1 *= C2; return k1; }
[ "private", "static", "long", "mixK1", "(", "long", "k1", ")", "{", "k1", "*=", "C1", ";", "k1", "=", "Long", ".", "rotateLeft", "(", "k1", ",", "31", ")", ";", "k1", "*=", "C2", ";", "return", "k1", ";", "}" ]
Self mix of k1 @param k1 input argument @return mix
[ "Self", "mix", "of", "k1" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hash/MurmurHash3v2.java#L282-L287
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hash/MurmurHash3v2.java
MurmurHash3v2.mixK2
private static long mixK2(long k2) { k2 *= C2; k2 = Long.rotateLeft(k2, 33); k2 *= C1; return k2; }
java
private static long mixK2(long k2) { k2 *= C2; k2 = Long.rotateLeft(k2, 33); k2 *= C1; return k2; }
[ "private", "static", "long", "mixK2", "(", "long", "k2", ")", "{", "k2", "*=", "C2", ";", "k2", "=", "Long", ".", "rotateLeft", "(", "k2", ",", "33", ")", ";", "k2", "*=", "C1", ";", "return", "k2", ";", "}" ]
Self mix of k2 @param k2 input argument @return mix
[ "Self", "mix", "of", "k2" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hash/MurmurHash3v2.java#L295-L300
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/ItemsByteArrayImpl.java
ItemsByteArrayImpl.combinedBufferToItemsArray
@SuppressWarnings("unchecked") private static <T> T[] combinedBufferToItemsArray(final ItemsSketch<T> sketch, final boolean ordered) { final int extra = 2; // extra space for min and max values final int outArrCap = sketch.getRetainedItems(); final T minValue = sketch.getMinValue(); final T[] outArr = (T[]) Array.newInstance(minValue.getClass(), outArrCap + extra); //Load min, max outArr[0] = minValue; outArr[1] = sketch.getMaxValue(); final int baseBufferCount = sketch.getBaseBufferCount(); final Object[] combinedBuffer = sketch.getCombinedBuffer(); //Load base buffer System.arraycopy(combinedBuffer, 0, outArr, extra, baseBufferCount); //Load levels long bitPattern = sketch.getBitPattern(); if (bitPattern > 0) { final int k = sketch.getK(); int index = extra + baseBufferCount; for (int level = 0; bitPattern != 0L; level++, bitPattern >>>= 1) { if ((bitPattern & 1L) > 0L) { System.arraycopy(combinedBuffer, (2 + level) * k, outArr, index, k); index += k; } } } if (ordered) { Arrays.sort(outArr, extra, baseBufferCount + extra, sketch.getComparator()); } return outArr; }
java
@SuppressWarnings("unchecked") private static <T> T[] combinedBufferToItemsArray(final ItemsSketch<T> sketch, final boolean ordered) { final int extra = 2; // extra space for min and max values final int outArrCap = sketch.getRetainedItems(); final T minValue = sketch.getMinValue(); final T[] outArr = (T[]) Array.newInstance(minValue.getClass(), outArrCap + extra); //Load min, max outArr[0] = minValue; outArr[1] = sketch.getMaxValue(); final int baseBufferCount = sketch.getBaseBufferCount(); final Object[] combinedBuffer = sketch.getCombinedBuffer(); //Load base buffer System.arraycopy(combinedBuffer, 0, outArr, extra, baseBufferCount); //Load levels long bitPattern = sketch.getBitPattern(); if (bitPattern > 0) { final int k = sketch.getK(); int index = extra + baseBufferCount; for (int level = 0; bitPattern != 0L; level++, bitPattern >>>= 1) { if ((bitPattern & 1L) > 0L) { System.arraycopy(combinedBuffer, (2 + level) * k, outArr, index, k); index += k; } } } if (ordered) { Arrays.sort(outArr, extra, baseBufferCount + extra, sketch.getComparator()); } return outArr; }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "private", "static", "<", "T", ">", "T", "[", "]", "combinedBufferToItemsArray", "(", "final", "ItemsSketch", "<", "T", ">", "sketch", ",", "final", "boolean", "ordered", ")", "{", "final", "int", "extra", ...
Returns an array of items in compact form, including min and max extracted from the Combined Buffer. @param <T> the data type @param sketch a type of ItemsSketch @param ordered true if the desired form of the resulting array has the base buffer sorted. @return an array of items, including min and max extracted from the Combined Buffer.
[ "Returns", "an", "array", "of", "items", "in", "compact", "form", "including", "min", "and", "max", "extracted", "from", "the", "Combined", "Buffer", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsByteArrayImpl.java#L77-L110
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/JaccardSimilarity.java
JaccardSimilarity.exactlyEqual
public static boolean exactlyEqual(final Sketch sketchA, final Sketch sketchB) { //Corner case checks if ((sketchA == null) || (sketchB == null)) { return false; } if (sketchA == sketchB) { return true; } if (sketchA.isEmpty() && sketchB.isEmpty()) { return true; } if (sketchA.isEmpty() || sketchB.isEmpty()) { return false; } final int countA = sketchA.getRetainedEntries(); final int countB = sketchB.getRetainedEntries(); //Create the Union final Union union = SetOperation.builder().setNominalEntries(ceilingPowerOf2(countA + countB)).buildUnion(); union.update(sketchA); union.update(sketchB); final Sketch unionAB = union.getResult(); final long thetaLongUAB = unionAB.getThetaLong(); final long thetaLongA = sketchA.getThetaLong(); final long thetaLongB = sketchB.getThetaLong(); final int countUAB = unionAB.getRetainedEntries(); //Check for identical counts and thetas if ((countUAB == countA) && (countUAB == countB) && (thetaLongUAB == thetaLongA) && (thetaLongUAB == thetaLongB)) { return true; } return false; }
java
public static boolean exactlyEqual(final Sketch sketchA, final Sketch sketchB) { //Corner case checks if ((sketchA == null) || (sketchB == null)) { return false; } if (sketchA == sketchB) { return true; } if (sketchA.isEmpty() && sketchB.isEmpty()) { return true; } if (sketchA.isEmpty() || sketchB.isEmpty()) { return false; } final int countA = sketchA.getRetainedEntries(); final int countB = sketchB.getRetainedEntries(); //Create the Union final Union union = SetOperation.builder().setNominalEntries(ceilingPowerOf2(countA + countB)).buildUnion(); union.update(sketchA); union.update(sketchB); final Sketch unionAB = union.getResult(); final long thetaLongUAB = unionAB.getThetaLong(); final long thetaLongA = sketchA.getThetaLong(); final long thetaLongB = sketchB.getThetaLong(); final int countUAB = unionAB.getRetainedEntries(); //Check for identical counts and thetas if ((countUAB == countA) && (countUAB == countB) && (thetaLongUAB == thetaLongA) && (thetaLongUAB == thetaLongB)) { return true; } return false; }
[ "public", "static", "boolean", "exactlyEqual", "(", "final", "Sketch", "sketchA", ",", "final", "Sketch", "sketchB", ")", "{", "//Corner case checks", "if", "(", "(", "sketchA", "==", "null", ")", "||", "(", "sketchB", "==", "null", ")", ")", "{", "return"...
Returns true if the two given sketches have exactly the same hash values and the same theta values. Thus, they are equivalent. @param sketchA the given sketch A @param sketchB the given sketch B @return true if the two given sketches have exactly the same hash values and the same theta values.
[ "Returns", "true", "if", "the", "two", "given", "sketches", "have", "exactly", "the", "same", "hash", "values", "and", "the", "same", "theta", "values", ".", "Thus", "they", "are", "equivalent", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/JaccardSimilarity.java#L92-L119
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/Union.java
Union.update
public void update(final Sketch<S> sketchIn) { if (sketchIn == null || sketchIn.isEmpty()) { return; } if (sketchIn.theta_ < theta_) { theta_ = sketchIn.theta_; } final SketchIterator<S> it = sketchIn.iterator(); while (it.next()) { sketch_.merge(it.getKey(), it.getSummary(), summarySetOps_); } }
java
public void update(final Sketch<S> sketchIn) { if (sketchIn == null || sketchIn.isEmpty()) { return; } if (sketchIn.theta_ < theta_) { theta_ = sketchIn.theta_; } final SketchIterator<S> it = sketchIn.iterator(); while (it.next()) { sketch_.merge(it.getKey(), it.getSummary(), summarySetOps_); } }
[ "public", "void", "update", "(", "final", "Sketch", "<", "S", ">", "sketchIn", ")", "{", "if", "(", "sketchIn", "==", "null", "||", "sketchIn", ".", "isEmpty", "(", ")", ")", "{", "return", ";", "}", "if", "(", "sketchIn", ".", "theta_", "<", "thet...
Updates the internal set by adding entries from the given sketch @param sketchIn input sketch to add to the internal set
[ "Updates", "the", "internal", "set", "by", "adding", "entries", "from", "the", "given", "sketch" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/Union.java#L48-L55
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/fdt/PostProcessor.java
PostProcessor.getGroupList
public List<Group> getGroupList(final int[] priKeyIndices, final int numStdDev, final int limit) { //allows subsequent queries with different priKeyIndices without rebuilding the map if (!mapValid) { populateMap(priKeyIndices); } return populateList(numStdDev, limit); }
java
public List<Group> getGroupList(final int[] priKeyIndices, final int numStdDev, final int limit) { //allows subsequent queries with different priKeyIndices without rebuilding the map if (!mapValid) { populateMap(priKeyIndices); } return populateList(numStdDev, limit); }
[ "public", "List", "<", "Group", ">", "getGroupList", "(", "final", "int", "[", "]", "priKeyIndices", ",", "final", "int", "numStdDev", ",", "final", "int", "limit", ")", "{", "//allows subsequent queries with different priKeyIndices without rebuilding the map", "if", ...
Return the most frequent Groups associated with Primary Keys based on the size of the groups. @param priKeyIndices the indices of the primary dimensions @param numStdDev the number of standard deviations for the error bounds, this value is an integer and must be one of 1, 2, or 3. <a href="{@docRoot}/resources/dictionary.html#numStdDev">See Number of Standard Deviations</a> @param limit the maximum number of rows to return. If &le; 0, all rows will be returned. @return the most frequent Groups associated with Primary Keys based on the size of the groups.
[ "Return", "the", "most", "frequent", "Groups", "associated", "with", "Primary", "Keys", "based", "on", "the", "size", "of", "the", "groups", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/PostProcessor.java#L73-L78
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/fdt/PostProcessor.java
PostProcessor.populateMap
private void populateMap(final int[] priKeyIndices) { final SketchIterator<ArrayOfStringsSummary> it = sketch.iterator(); Arrays.fill(hashArr, 0L); Arrays.fill(priKeyArr, null); Arrays.fill(counterArr, 0); groupCount = 0; final int lgMapArrSize = Integer.numberOfTrailingZeros(mapArrSize); while (it.next()) { final String[] arr = it.getSummary().getValue(); final String priKey = getPrimaryKey(arr, priKeyIndices, sep); final long hash = stringHash(priKey); final int index = hashSearchOrInsert(hashArr, lgMapArrSize, hash); if (index < 0) { //was empty, hash inserted final int idx = -(index + 1); //actual index counterArr[idx] = 1; groupCount++; priKeyArr[idx] = priKey; } else { //found, duplicate counterArr[index]++; //increment } } mapValid = true; }
java
private void populateMap(final int[] priKeyIndices) { final SketchIterator<ArrayOfStringsSummary> it = sketch.iterator(); Arrays.fill(hashArr, 0L); Arrays.fill(priKeyArr, null); Arrays.fill(counterArr, 0); groupCount = 0; final int lgMapArrSize = Integer.numberOfTrailingZeros(mapArrSize); while (it.next()) { final String[] arr = it.getSummary().getValue(); final String priKey = getPrimaryKey(arr, priKeyIndices, sep); final long hash = stringHash(priKey); final int index = hashSearchOrInsert(hashArr, lgMapArrSize, hash); if (index < 0) { //was empty, hash inserted final int idx = -(index + 1); //actual index counterArr[idx] = 1; groupCount++; priKeyArr[idx] = priKey; } else { //found, duplicate counterArr[index]++; //increment } } mapValid = true; }
[ "private", "void", "populateMap", "(", "final", "int", "[", "]", "priKeyIndices", ")", "{", "final", "SketchIterator", "<", "ArrayOfStringsSummary", ">", "it", "=", "sketch", ".", "iterator", "(", ")", ";", "Arrays", ".", "fill", "(", "hashArr", ",", "0L",...
Scan each entry in the sketch. Count the number of duplicate occurrences of each primary key in a hash map. @param priKeyIndices identifies the primary key indices
[ "Scan", "each", "entry", "in", "the", "sketch", ".", "Count", "the", "number", "of", "duplicate", "occurrences", "of", "each", "primary", "key", "in", "a", "hash", "map", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/PostProcessor.java#L85-L108
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/fdt/PostProcessor.java
PostProcessor.populateList
private List<Group> populateList(final int numStdDev, final int limit) { final List<Group> list = new ArrayList<>(); for (int i = 0; i < mapArrSize; i++) { if (hashArr[i] != 0) { final String priKey = priKeyArr[i]; final int count = counterArr[i]; final double est = sketch.getEstimate(count); final double ub = sketch.getUpperBound(numStdDev, count); final double lb = sketch.getLowerBound(numStdDev, count); final double thresh = (double) count / sketch.getRetainedEntries(); final double rse = (sketch.getUpperBound(1, count) / est) - 1.0; final Group gp = group.copy(); gp.init(priKey, count, est, ub, lb, thresh, rse); list.add(gp); } } list.sort(null); //Comparable implemented in Group final int totLen = list.size(); final List<Group> returnList; if ((limit > 0) && (limit < totLen)) { returnList = list.subList(0, limit); } else { returnList = list; } return returnList; }
java
private List<Group> populateList(final int numStdDev, final int limit) { final List<Group> list = new ArrayList<>(); for (int i = 0; i < mapArrSize; i++) { if (hashArr[i] != 0) { final String priKey = priKeyArr[i]; final int count = counterArr[i]; final double est = sketch.getEstimate(count); final double ub = sketch.getUpperBound(numStdDev, count); final double lb = sketch.getLowerBound(numStdDev, count); final double thresh = (double) count / sketch.getRetainedEntries(); final double rse = (sketch.getUpperBound(1, count) / est) - 1.0; final Group gp = group.copy(); gp.init(priKey, count, est, ub, lb, thresh, rse); list.add(gp); } } list.sort(null); //Comparable implemented in Group final int totLen = list.size(); final List<Group> returnList; if ((limit > 0) && (limit < totLen)) { returnList = list.subList(0, limit); } else { returnList = list; } return returnList; }
[ "private", "List", "<", "Group", ">", "populateList", "(", "final", "int", "numStdDev", ",", "final", "int", "limit", ")", "{", "final", "List", "<", "Group", ">", "list", "=", "new", "ArrayList", "<>", "(", ")", ";", "for", "(", "int", "i", "=", "...
Create the list of groups along with the error statistics @param numStdDev number of standard deviations @param limit the maximum size of the list to return @return the list of groups along with the error statistics
[ "Create", "the", "list", "of", "groups", "along", "with", "the", "error", "statistics" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/PostProcessor.java#L116-L142
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/fdt/PostProcessor.java
PostProcessor.getPrimaryKey
private static String getPrimaryKey(final String[] tuple, final int[] priKeyIndices, final char sep) { assert priKeyIndices.length < tuple.length; final StringBuilder sb = new StringBuilder(); final int keys = priKeyIndices.length; for (int i = 0; i < keys; i++) { final int idx = priKeyIndices[i]; sb.append(tuple[idx]); if ((i + 1) < keys) { sb.append(sep); } } return sb.toString(); }
java
private static String getPrimaryKey(final String[] tuple, final int[] priKeyIndices, final char sep) { assert priKeyIndices.length < tuple.length; final StringBuilder sb = new StringBuilder(); final int keys = priKeyIndices.length; for (int i = 0; i < keys; i++) { final int idx = priKeyIndices[i]; sb.append(tuple[idx]); if ((i + 1) < keys) { sb.append(sep); } } return sb.toString(); }
[ "private", "static", "String", "getPrimaryKey", "(", "final", "String", "[", "]", "tuple", ",", "final", "int", "[", "]", "priKeyIndices", ",", "final", "char", "sep", ")", "{", "assert", "priKeyIndices", ".", "length", "<", "tuple", ".", "length", ";", ...
also used by test
[ "also", "used", "by", "test" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/PostProcessor.java#L153-L164
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hll/ToByteArrayImpl.java
ToByteArrayImpl.toHllByteArray
static final byte[] toHllByteArray(final AbstractHllArray impl, final boolean compact) { int auxBytes = 0; if (impl.tgtHllType == TgtHllType.HLL_4) { final AuxHashMap auxHashMap = impl.getAuxHashMap(); if (auxHashMap != null) { auxBytes = (compact) ? auxHashMap.getCompactSizeBytes() : auxHashMap.getUpdatableSizeBytes(); } else { auxBytes = (compact) ? 0 : 4 << LG_AUX_ARR_INTS[impl.lgConfigK]; } } final int totBytes = HLL_BYTE_ARR_START + impl.getHllByteArrBytes() + auxBytes; final byte[] byteArr = new byte[totBytes]; final WritableMemory wmem = WritableMemory.wrap(byteArr); insertHll(impl, wmem, compact); return byteArr; }
java
static final byte[] toHllByteArray(final AbstractHllArray impl, final boolean compact) { int auxBytes = 0; if (impl.tgtHllType == TgtHllType.HLL_4) { final AuxHashMap auxHashMap = impl.getAuxHashMap(); if (auxHashMap != null) { auxBytes = (compact) ? auxHashMap.getCompactSizeBytes() : auxHashMap.getUpdatableSizeBytes(); } else { auxBytes = (compact) ? 0 : 4 << LG_AUX_ARR_INTS[impl.lgConfigK]; } } final int totBytes = HLL_BYTE_ARR_START + impl.getHllByteArrBytes() + auxBytes; final byte[] byteArr = new byte[totBytes]; final WritableMemory wmem = WritableMemory.wrap(byteArr); insertHll(impl, wmem, compact); return byteArr; }
[ "static", "final", "byte", "[", "]", "toHllByteArray", "(", "final", "AbstractHllArray", "impl", ",", "final", "boolean", "compact", ")", "{", "int", "auxBytes", "=", "0", ";", "if", "(", "impl", ".", "tgtHllType", "==", "TgtHllType", ".", "HLL_4", ")", ...
To byte array used by the heap HLL types.
[ "To", "byte", "array", "used", "by", "the", "heap", "HLL", "types", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/ToByteArrayImpl.java#L42-L59
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/sampling/PreambleUtil.java
PreambleUtil.getAndCheckPreLongs
static int getAndCheckPreLongs(final Memory mem) { final long cap = mem.getCapacity(); if (cap < 8) { throwNotBigEnough(cap, 8); } final int preLongs = mem.getByte(0) & 0x3F; final int required = Math.max(preLongs << 3, 8); if (cap < required) { throwNotBigEnough(cap, required); } return preLongs; }
java
static int getAndCheckPreLongs(final Memory mem) { final long cap = mem.getCapacity(); if (cap < 8) { throwNotBigEnough(cap, 8); } final int preLongs = mem.getByte(0) & 0x3F; final int required = Math.max(preLongs << 3, 8); if (cap < required) { throwNotBigEnough(cap, required); } return preLongs; }
[ "static", "int", "getAndCheckPreLongs", "(", "final", "Memory", "mem", ")", "{", "final", "long", "cap", "=", "mem", ".", "getCapacity", "(", ")", ";", "if", "(", "cap", "<", "8", ")", "{", "throwNotBigEnough", "(", "cap", ",", "8", ")", ";", "}", ...
Checks Memory for capacity to hold the preamble and returns the extracted preLongs. @param mem the given Memory @return the extracted prelongs value.
[ "Checks", "Memory", "for", "capacity", "to", "hold", "the", "preamble", "and", "returns", "the", "extracted", "preLongs", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/PreambleUtil.java#L430-L437
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesIntersection.java
ArrayOfDoublesIntersection.update
public void update(final ArrayOfDoublesSketch sketchIn, final ArrayOfDoublesCombiner combiner) { final boolean isFirstCall = isFirstCall_; isFirstCall_ = false; if (sketchIn == null) { isEmpty_ = true; sketch_ = null; return; } Util.checkSeedHashes(seedHash_, sketchIn.getSeedHash()); theta_ = min(theta_, sketchIn.getThetaLong()); isEmpty_ |= sketchIn.isEmpty(); if (isEmpty_ || sketchIn.getRetainedEntries() == 0) { sketch_ = null; return; } if (isFirstCall) { sketch_ = createSketch(sketchIn.getRetainedEntries(), numValues_, seed_); final ArrayOfDoublesSketchIterator it = sketchIn.iterator(); while (it.next()) { sketch_.insert(it.getKey(), it.getValues()); } } else { //not the first call final int matchSize = min(sketch_.getRetainedEntries(), sketchIn.getRetainedEntries()); final long[] matchKeys = new long[matchSize]; final double[][] matchValues = new double[matchSize][]; int matchCount = 0; final ArrayOfDoublesSketchIterator it = sketchIn.iterator(); while (it.next()) { final double[] values = sketch_.find(it.getKey()); if (values != null) { matchKeys[matchCount] = it.getKey(); matchValues[matchCount] = combiner.combine(values, it.getValues()); matchCount++; } } sketch_ = null; if (matchCount > 0) { sketch_ = createSketch(matchCount, numValues_, seed_); for (int i = 0; i < matchCount; i++) { sketch_.insert(matchKeys[i], matchValues[i]); } } if (sketch_ != null) { sketch_.setThetaLong(theta_); sketch_.setNotEmpty(); } } }
java
public void update(final ArrayOfDoublesSketch sketchIn, final ArrayOfDoublesCombiner combiner) { final boolean isFirstCall = isFirstCall_; isFirstCall_ = false; if (sketchIn == null) { isEmpty_ = true; sketch_ = null; return; } Util.checkSeedHashes(seedHash_, sketchIn.getSeedHash()); theta_ = min(theta_, sketchIn.getThetaLong()); isEmpty_ |= sketchIn.isEmpty(); if (isEmpty_ || sketchIn.getRetainedEntries() == 0) { sketch_ = null; return; } if (isFirstCall) { sketch_ = createSketch(sketchIn.getRetainedEntries(), numValues_, seed_); final ArrayOfDoublesSketchIterator it = sketchIn.iterator(); while (it.next()) { sketch_.insert(it.getKey(), it.getValues()); } } else { //not the first call final int matchSize = min(sketch_.getRetainedEntries(), sketchIn.getRetainedEntries()); final long[] matchKeys = new long[matchSize]; final double[][] matchValues = new double[matchSize][]; int matchCount = 0; final ArrayOfDoublesSketchIterator it = sketchIn.iterator(); while (it.next()) { final double[] values = sketch_.find(it.getKey()); if (values != null) { matchKeys[matchCount] = it.getKey(); matchValues[matchCount] = combiner.combine(values, it.getValues()); matchCount++; } } sketch_ = null; if (matchCount > 0) { sketch_ = createSketch(matchCount, numValues_, seed_); for (int i = 0; i < matchCount; i++) { sketch_.insert(matchKeys[i], matchValues[i]); } } if (sketch_ != null) { sketch_.setThetaLong(theta_); sketch_.setNotEmpty(); } } }
[ "public", "void", "update", "(", "final", "ArrayOfDoublesSketch", "sketchIn", ",", "final", "ArrayOfDoublesCombiner", "combiner", ")", "{", "final", "boolean", "isFirstCall", "=", "isFirstCall_", ";", "isFirstCall_", "=", "false", ";", "if", "(", "sketchIn", "==",...
Updates the internal set by intersecting it with the given sketch. @param sketchIn Input sketch to intersect with the internal set. @param combiner Method of combining two arrays of double values
[ "Updates", "the", "internal", "set", "by", "intersecting", "it", "with", "the", "given", "sketch", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesIntersection.java#L43-L90
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesIntersection.java
ArrayOfDoublesIntersection.getResult
public ArrayOfDoublesCompactSketch getResult(final WritableMemory dstMem) { if (isFirstCall_) { throw new SketchesStateException( "getResult() with no intervening intersections is not a legal result."); } if (sketch_ == null) { return new HeapArrayOfDoublesCompactSketch( null, null, Long.MAX_VALUE, true, numValues_, seedHash_); } return sketch_.compact(dstMem); }
java
public ArrayOfDoublesCompactSketch getResult(final WritableMemory dstMem) { if (isFirstCall_) { throw new SketchesStateException( "getResult() with no intervening intersections is not a legal result."); } if (sketch_ == null) { return new HeapArrayOfDoublesCompactSketch( null, null, Long.MAX_VALUE, true, numValues_, seedHash_); } return sketch_.compact(dstMem); }
[ "public", "ArrayOfDoublesCompactSketch", "getResult", "(", "final", "WritableMemory", "dstMem", ")", "{", "if", "(", "isFirstCall_", ")", "{", "throw", "new", "SketchesStateException", "(", "\"getResult() with no intervening intersections is not a legal result.\"", ")", ";", ...
Gets the internal set as an off-heap compact sketch using the given memory. @param dstMem Memory for the compact sketch (can be null). @return Result of the intersections so far as a compact sketch.
[ "Gets", "the", "internal", "set", "as", "an", "off", "-", "heap", "compact", "sketch", "using", "the", "given", "memory", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesIntersection.java#L97-L107
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesIntersection.java
ArrayOfDoublesIntersection.reset
public void reset() { isEmpty_ = false; theta_ = Long.MAX_VALUE; sketch_ = null; isFirstCall_ = true; }
java
public void reset() { isEmpty_ = false; theta_ = Long.MAX_VALUE; sketch_ = null; isFirstCall_ = true; }
[ "public", "void", "reset", "(", ")", "{", "isEmpty_", "=", "false", ";", "theta_", "=", "Long", ".", "MAX_VALUE", ";", "sketch_", "=", "null", ";", "isFirstCall_", "=", "true", ";", "}" ]
Resets the internal set to the initial state, which represents the Universal Set
[ "Resets", "the", "internal", "set", "to", "the", "initial", "state", "which", "represents", "the", "Universal", "Set" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesIntersection.java#L120-L125
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java
ArrayOfDoublesSketch.heapify
public static ArrayOfDoublesSketch heapify(final Memory mem, final long seed) { final SerializerDeserializer.SketchType sketchType = SerializerDeserializer.getSketchType(mem); if (sketchType == SerializerDeserializer.SketchType.ArrayOfDoublesQuickSelectSketch) { return new HeapArrayOfDoublesQuickSelectSketch(mem, seed); } return new HeapArrayOfDoublesCompactSketch(mem, seed); }
java
public static ArrayOfDoublesSketch heapify(final Memory mem, final long seed) { final SerializerDeserializer.SketchType sketchType = SerializerDeserializer.getSketchType(mem); if (sketchType == SerializerDeserializer.SketchType.ArrayOfDoublesQuickSelectSketch) { return new HeapArrayOfDoublesQuickSelectSketch(mem, seed); } return new HeapArrayOfDoublesCompactSketch(mem, seed); }
[ "public", "static", "ArrayOfDoublesSketch", "heapify", "(", "final", "Memory", "mem", ",", "final", "long", "seed", ")", "{", "final", "SerializerDeserializer", ".", "SketchType", "sketchType", "=", "SerializerDeserializer", ".", "getSketchType", "(", "mem", ")", ...
Heapify the given Memory and seed as a ArrayOfDoublesSketch @param mem the given Memory @param seed the given seed @return an ArrayOfDoublesSketch
[ "Heapify", "the", "given", "Memory", "and", "seed", "as", "a", "ArrayOfDoublesSketch" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java#L72-L78
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java
ArrayOfDoublesSketch.wrap
public static ArrayOfDoublesSketch wrap(final Memory mem, final long seed) { final SerializerDeserializer.SketchType sketchType = SerializerDeserializer.getSketchType(mem); if (sketchType == SerializerDeserializer.SketchType.ArrayOfDoublesQuickSelectSketch) { return new DirectArrayOfDoublesQuickSelectSketchR(mem, seed); } return new DirectArrayOfDoublesCompactSketch(mem, seed); }
java
public static ArrayOfDoublesSketch wrap(final Memory mem, final long seed) { final SerializerDeserializer.SketchType sketchType = SerializerDeserializer.getSketchType(mem); if (sketchType == SerializerDeserializer.SketchType.ArrayOfDoublesQuickSelectSketch) { return new DirectArrayOfDoublesQuickSelectSketchR(mem, seed); } return new DirectArrayOfDoublesCompactSketch(mem, seed); }
[ "public", "static", "ArrayOfDoublesSketch", "wrap", "(", "final", "Memory", "mem", ",", "final", "long", "seed", ")", "{", "final", "SerializerDeserializer", ".", "SketchType", "sketchType", "=", "SerializerDeserializer", ".", "getSketchType", "(", "mem", ")", ";"...
Wrap the given Memory and seed as a ArrayOfDoublesSketch @param mem the given Memory @param seed the given seed @return an ArrayOfDoublesSketch
[ "Wrap", "the", "given", "Memory", "and", "seed", "as", "a", "ArrayOfDoublesSketch" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesSketch.java#L95-L101
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/AnotB.java
AnotB.aNotB
public CompactSketch aNotB(final Sketch a, final Sketch b) { return aNotB(a, b, true, null); }
java
public CompactSketch aNotB(final Sketch a, final Sketch b) { return aNotB(a, b, true, null); }
[ "public", "CompactSketch", "aNotB", "(", "final", "Sketch", "a", ",", "final", "Sketch", "b", ")", "{", "return", "aNotB", "(", "a", ",", "b", ",", "true", ",", "null", ")", ";", "}" ]
Perform A-and-not-B set operation on the two given sketches and return the result as an ordered CompactSketch on the heap. @param a The incoming sketch for the first argument @param b The incoming sketch for the second argument @return an ordered CompactSketch on the heap
[ "Perform", "A", "-", "and", "-", "not", "-", "B", "set", "operation", "on", "the", "two", "given", "sketches", "and", "return", "the", "result", "as", "an", "ordered", "CompactSketch", "on", "the", "heap", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/AnotB.java#L69-L71
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hll/HllSketch.java
HllSketch.heapify
public static final HllSketch heapify(final Memory srcMem) { final CurMode curMode = checkPreamble(srcMem); final HllSketch heapSketch; if (curMode == CurMode.HLL) { final TgtHllType tgtHllType = extractTgtHllType(srcMem); if (tgtHllType == TgtHllType.HLL_4) { heapSketch = new HllSketch(Hll4Array.heapify(srcMem)); } else if (tgtHllType == TgtHllType.HLL_6) { heapSketch = new HllSketch(Hll6Array.heapify(srcMem)); } else { //Hll_8 heapSketch = new HllSketch(Hll8Array.heapify(srcMem)); } } else if (curMode == CurMode.LIST) { heapSketch = new HllSketch(CouponList.heapifyList(srcMem)); } else { heapSketch = new HllSketch(CouponHashSet.heapifySet(srcMem)); } return heapSketch; }
java
public static final HllSketch heapify(final Memory srcMem) { final CurMode curMode = checkPreamble(srcMem); final HllSketch heapSketch; if (curMode == CurMode.HLL) { final TgtHllType tgtHllType = extractTgtHllType(srcMem); if (tgtHllType == TgtHllType.HLL_4) { heapSketch = new HllSketch(Hll4Array.heapify(srcMem)); } else if (tgtHllType == TgtHllType.HLL_6) { heapSketch = new HllSketch(Hll6Array.heapify(srcMem)); } else { //Hll_8 heapSketch = new HllSketch(Hll8Array.heapify(srcMem)); } } else if (curMode == CurMode.LIST) { heapSketch = new HllSketch(CouponList.heapifyList(srcMem)); } else { heapSketch = new HllSketch(CouponHashSet.heapifySet(srcMem)); } return heapSketch; }
[ "public", "static", "final", "HllSketch", "heapify", "(", "final", "Memory", "srcMem", ")", "{", "final", "CurMode", "curMode", "=", "checkPreamble", "(", "srcMem", ")", ";", "final", "HllSketch", "heapSketch", ";", "if", "(", "curMode", "==", "CurMode", "."...
Heapify the given Memory, which must be a valid HllSketch image and may have data. @param srcMem the given Memory, which is read-only. @return an HllSketch on the java heap.
[ "Heapify", "the", "given", "Memory", "which", "must", "be", "a", "valid", "HllSketch", "image", "and", "may", "have", "data", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/HllSketch.java#L136-L154
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hll/HllSketch.java
HllSketch.writableWrap
public static final HllSketch writableWrap(final WritableMemory wmem) { final boolean compact = extractCompactFlag(wmem); if (compact) { throw new SketchesArgumentException( "Cannot perform a writableWrap of a writable sketch image that is in compact form."); } final int lgConfigK = extractLgK(wmem); final TgtHllType tgtHllType = extractTgtHllType(wmem); final long minBytes = getMaxUpdatableSerializationBytes(lgConfigK, tgtHllType); final long capBytes = wmem.getCapacity(); HllUtil.checkMemSize(minBytes, capBytes); final CurMode curMode = checkPreamble(wmem); final HllSketch directSketch; if (curMode == CurMode.HLL) { if (tgtHllType == TgtHllType.HLL_4) { directSketch = new HllSketch(new DirectHll4Array(lgConfigK, wmem)); } else if (tgtHllType == TgtHllType.HLL_6) { directSketch = new HllSketch(new DirectHll6Array(lgConfigK, wmem)); } else { //Hll_8 directSketch = new HllSketch(new DirectHll8Array(lgConfigK, wmem)); } } else if (curMode == CurMode.LIST) { directSketch = new HllSketch(new DirectCouponList(lgConfigK, tgtHllType, curMode, wmem)); } else { directSketch = new HllSketch(new DirectCouponHashSet(lgConfigK, tgtHllType, wmem)); } return directSketch; }
java
public static final HllSketch writableWrap(final WritableMemory wmem) { final boolean compact = extractCompactFlag(wmem); if (compact) { throw new SketchesArgumentException( "Cannot perform a writableWrap of a writable sketch image that is in compact form."); } final int lgConfigK = extractLgK(wmem); final TgtHllType tgtHllType = extractTgtHllType(wmem); final long minBytes = getMaxUpdatableSerializationBytes(lgConfigK, tgtHllType); final long capBytes = wmem.getCapacity(); HllUtil.checkMemSize(minBytes, capBytes); final CurMode curMode = checkPreamble(wmem); final HllSketch directSketch; if (curMode == CurMode.HLL) { if (tgtHllType == TgtHllType.HLL_4) { directSketch = new HllSketch(new DirectHll4Array(lgConfigK, wmem)); } else if (tgtHllType == TgtHllType.HLL_6) { directSketch = new HllSketch(new DirectHll6Array(lgConfigK, wmem)); } else { //Hll_8 directSketch = new HllSketch(new DirectHll8Array(lgConfigK, wmem)); } } else if (curMode == CurMode.LIST) { directSketch = new HllSketch(new DirectCouponList(lgConfigK, tgtHllType, curMode, wmem)); } else { directSketch = new HllSketch(new DirectCouponHashSet(lgConfigK, tgtHllType, wmem)); } return directSketch; }
[ "public", "static", "final", "HllSketch", "writableWrap", "(", "final", "WritableMemory", "wmem", ")", "{", "final", "boolean", "compact", "=", "extractCompactFlag", "(", "wmem", ")", ";", "if", "(", "compact", ")", "{", "throw", "new", "SketchesArgumentExceptio...
Wraps the given WritableMemory, which must be a image of a valid updatable sketch, and may have data. What remains on the java heap is a thin wrapper object that reads and writes to the given WritableMemory, which, depending on how the user configures the WritableMemory, may actually reside on the Java heap or off-heap. <p>The given <i>dstMem</i> is checked for the required capacity as determined by {@link #getMaxUpdatableSerializationBytes(int, TgtHllType)}. @param wmem an writable image of a valid sketch with data. @return an HllSketch where the sketch data is in the given dstMem.
[ "Wraps", "the", "given", "WritableMemory", "which", "must", "be", "a", "image", "of", "a", "valid", "updatable", "sketch", "and", "may", "have", "data", ".", "What", "remains", "on", "the", "java", "heap", "is", "a", "thin", "wrapper", "object", "that", ...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/HllSketch.java#L167-L197
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hll/HllSketch.java
HllSketch.getMaxUpdatableSerializationBytes
public static final int getMaxUpdatableSerializationBytes(final int lgConfigK, final TgtHllType tgtHllType) { final int arrBytes; if (tgtHllType == TgtHllType.HLL_4) { final int auxBytes = 4 << LG_AUX_ARR_INTS[lgConfigK]; arrBytes = AbstractHllArray.hll4ArrBytes(lgConfigK) + auxBytes; } else if (tgtHllType == TgtHllType.HLL_6) { arrBytes = AbstractHllArray.hll6ArrBytes(lgConfigK); } else { //HLL_8 arrBytes = AbstractHllArray.hll8ArrBytes(lgConfigK); } return HLL_BYTE_ARR_START + arrBytes; }
java
public static final int getMaxUpdatableSerializationBytes(final int lgConfigK, final TgtHllType tgtHllType) { final int arrBytes; if (tgtHllType == TgtHllType.HLL_4) { final int auxBytes = 4 << LG_AUX_ARR_INTS[lgConfigK]; arrBytes = AbstractHllArray.hll4ArrBytes(lgConfigK) + auxBytes; } else if (tgtHllType == TgtHllType.HLL_6) { arrBytes = AbstractHllArray.hll6ArrBytes(lgConfigK); } else { //HLL_8 arrBytes = AbstractHllArray.hll8ArrBytes(lgConfigK); } return HLL_BYTE_ARR_START + arrBytes; }
[ "public", "static", "final", "int", "getMaxUpdatableSerializationBytes", "(", "final", "int", "lgConfigK", ",", "final", "TgtHllType", "tgtHllType", ")", "{", "final", "int", "arrBytes", ";", "if", "(", "tgtHllType", "==", "TgtHllType", ".", "HLL_4", ")", "{", ...
Returns the maximum size in bytes that this sketch can grow to given lgConfigK. However, for the HLL_4 sketch type, this value can be exceeded in extremely rare cases. If exceeded, it will be larger by only a few percent. @param lgConfigK The Log2 of K for the target HLL sketch. This value must be between 4 and 21 inclusively. @param tgtHllType the desired Hll type @return the maximum size in bytes that this sketch can grow to.
[ "Returns", "the", "maximum", "size", "in", "bytes", "that", "this", "sketch", "can", "grow", "to", "given", "lgConfigK", ".", "However", "for", "the", "HLL_4", "sketch", "type", "this", "value", "can", "be", "exceeded", "in", "extremely", "rare", "cases", ...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/HllSketch.java#L283-L297
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesByteArrayImpl.java
DoublesByteArrayImpl.convertToByteArray
private static byte[] convertToByteArray(final DoublesSketch sketch, final int flags, final boolean ordered, final boolean compact) { final int preLongs = 2; final int extra = 2; // extra space for min and max values final int prePlusExtraBytes = (preLongs + extra) << 3; final int k = sketch.getK(); final long n = sketch.getN(); // If not-compact, have accessor always report full levels. Then use level size to determine // whether to copy data out. final DoublesSketchAccessor dsa = DoublesSketchAccessor.wrap(sketch, !compact); final int outBytes = (compact ? sketch.getCompactStorageBytes() : sketch.getUpdatableStorageBytes()); final byte[] outByteArr = new byte[outBytes]; final WritableMemory memOut = WritableMemory.wrap(outByteArr); //insert preamble-0, N, min, max insertPre0(memOut, preLongs, flags, k); if (sketch.isEmpty()) { return outByteArr; } insertN(memOut, n); insertMinDouble(memOut, sketch.getMinValue()); insertMaxDouble(memOut, sketch.getMaxValue()); long memOffsetBytes = prePlusExtraBytes; // might need to sort base buffer but don't want to change input sketch final int bbCnt = Util.computeBaseBufferItems(k, n); if (bbCnt > 0) { //Base buffer items only final double[] bbItemsArr = dsa.getArray(0, bbCnt); if (ordered) { Arrays.sort(bbItemsArr); } memOut.putDoubleArray(memOffsetBytes, bbItemsArr, 0, bbCnt); } // If n < 2k, totalLevels == 0 so ok to overshoot the offset update memOffsetBytes += (compact ? bbCnt : 2 * k) << 3; // If serializing from a compact sketch to a non-compact form, we may end up copying data for a // higher level one or more times into an unused level. A bit wasteful, but not incorrect. final int totalLevels = Util.computeTotalLevels(sketch.getBitPattern()); for (int lvl = 0; lvl < totalLevels; ++lvl) { dsa.setLevel(lvl); if (dsa.numItems() > 0) { assert dsa.numItems() == k; memOut.putDoubleArray(memOffsetBytes, dsa.getArray(0, k), 0, k); memOffsetBytes += (k << 3); } } return outByteArr; }
java
private static byte[] convertToByteArray(final DoublesSketch sketch, final int flags, final boolean ordered, final boolean compact) { final int preLongs = 2; final int extra = 2; // extra space for min and max values final int prePlusExtraBytes = (preLongs + extra) << 3; final int k = sketch.getK(); final long n = sketch.getN(); // If not-compact, have accessor always report full levels. Then use level size to determine // whether to copy data out. final DoublesSketchAccessor dsa = DoublesSketchAccessor.wrap(sketch, !compact); final int outBytes = (compact ? sketch.getCompactStorageBytes() : sketch.getUpdatableStorageBytes()); final byte[] outByteArr = new byte[outBytes]; final WritableMemory memOut = WritableMemory.wrap(outByteArr); //insert preamble-0, N, min, max insertPre0(memOut, preLongs, flags, k); if (sketch.isEmpty()) { return outByteArr; } insertN(memOut, n); insertMinDouble(memOut, sketch.getMinValue()); insertMaxDouble(memOut, sketch.getMaxValue()); long memOffsetBytes = prePlusExtraBytes; // might need to sort base buffer but don't want to change input sketch final int bbCnt = Util.computeBaseBufferItems(k, n); if (bbCnt > 0) { //Base buffer items only final double[] bbItemsArr = dsa.getArray(0, bbCnt); if (ordered) { Arrays.sort(bbItemsArr); } memOut.putDoubleArray(memOffsetBytes, bbItemsArr, 0, bbCnt); } // If n < 2k, totalLevels == 0 so ok to overshoot the offset update memOffsetBytes += (compact ? bbCnt : 2 * k) << 3; // If serializing from a compact sketch to a non-compact form, we may end up copying data for a // higher level one or more times into an unused level. A bit wasteful, but not incorrect. final int totalLevels = Util.computeTotalLevels(sketch.getBitPattern()); for (int lvl = 0; lvl < totalLevels; ++lvl) { dsa.setLevel(lvl); if (dsa.numItems() > 0) { assert dsa.numItems() == k; memOut.putDoubleArray(memOffsetBytes, dsa.getArray(0, k), 0, k); memOffsetBytes += (k << 3); } } return outByteArr; }
[ "private", "static", "byte", "[", "]", "convertToByteArray", "(", "final", "DoublesSketch", "sketch", ",", "final", "int", "flags", ",", "final", "boolean", "ordered", ",", "final", "boolean", "compact", ")", "{", "final", "int", "preLongs", "=", "2", ";", ...
Returns a byte array, including preamble, min, max and data extracted from the sketch. @param sketch the given DoublesSketch @param flags the Flags field @param ordered true if the desired form of the resulting array has the base buffer sorted. @param compact true if the desired form of the resulting array is in compact form. @return a byte array, including preamble, min, max and data extracted from the Combined Buffer.
[ "Returns", "a", "byte", "array", "including", "preamble", "min", "max", "and", "data", "extracted", "from", "the", "sketch", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesByteArrayImpl.java#L64-L114
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/frequencies/ItemsSketch.java
ItemsSketch.update
public void update(final T item, final long count) { if ((item == null) || (count == 0)) { return; } if (count < 0) { throw new SketchesArgumentException("Count may not be negative"); } this.streamWeight += count; hashMap.adjustOrPutValue(item, count); if (getNumActiveItems() > curMapCap) { //over the threshold, we need to do something if (hashMap.getLgLength() < lgMaxMapSize) { //below tgt size, we can grow hashMap.resize(2 * hashMap.getLength()); curMapCap = hashMap.getCapacity(); } else { //At tgt size, must purge offset += hashMap.purge(sampleSize); if (getNumActiveItems() > getMaximumMapCapacity()) { throw new SketchesStateException("Purge did not reduce active items."); } } } }
java
public void update(final T item, final long count) { if ((item == null) || (count == 0)) { return; } if (count < 0) { throw new SketchesArgumentException("Count may not be negative"); } this.streamWeight += count; hashMap.adjustOrPutValue(item, count); if (getNumActiveItems() > curMapCap) { //over the threshold, we need to do something if (hashMap.getLgLength() < lgMaxMapSize) { //below tgt size, we can grow hashMap.resize(2 * hashMap.getLength()); curMapCap = hashMap.getCapacity(); } else { //At tgt size, must purge offset += hashMap.purge(sampleSize); if (getNumActiveItems() > getMaximumMapCapacity()) { throw new SketchesStateException("Purge did not reduce active items."); } } } }
[ "public", "void", "update", "(", "final", "T", "item", ",", "final", "long", "count", ")", "{", "if", "(", "(", "item", "==", "null", ")", "||", "(", "count", "==", "0", ")", ")", "{", "return", ";", "}", "if", "(", "count", "<", "0", ")", "{...
Update this sketch with a item and a positive frequency count. @param item for which the frequency should be increased. The item can be any long value and is only used by the sketch to determine uniqueness. @param count the amount by which the frequency of the item should be increased. An count of zero is a no-op, and a negative count will throw an exception.
[ "Update", "this", "sketch", "with", "a", "item", "and", "a", "positive", "frequency", "count", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/frequencies/ItemsSketch.java#L562-L583
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/frequencies/ReversePurgeItemHashMap.java
ReversePurgeItemHashMap.adjustOrPutValue
void adjustOrPutValue(final T key, final long adjustAmount) { final int arrayMask = keys.length - 1; int probe = (int) hash(key.hashCode()) & arrayMask; int drift = 1; while (states[probe] != 0 && !keys[probe].equals(key)) { probe = (probe + 1) & arrayMask; drift++; //only used for theoretical analysis assert (drift < DRIFT_LIMIT) : "drift: " + drift + " >= DRIFT_LIMIT"; } if (states[probe] == 0) { // adding the key to the table the value assert (numActive <= loadThreshold) : "numActive: " + numActive + " > loadThreshold: " + loadThreshold; keys[probe] = key; values[probe] = adjustAmount; states[probe] = (short) drift; numActive++; } else { // adjusting the value of an existing key assert (keys[probe].equals(key)); values[probe] += adjustAmount; } }
java
void adjustOrPutValue(final T key, final long adjustAmount) { final int arrayMask = keys.length - 1; int probe = (int) hash(key.hashCode()) & arrayMask; int drift = 1; while (states[probe] != 0 && !keys[probe].equals(key)) { probe = (probe + 1) & arrayMask; drift++; //only used for theoretical analysis assert (drift < DRIFT_LIMIT) : "drift: " + drift + " >= DRIFT_LIMIT"; } if (states[probe] == 0) { // adding the key to the table the value assert (numActive <= loadThreshold) : "numActive: " + numActive + " > loadThreshold: " + loadThreshold; keys[probe] = key; values[probe] = adjustAmount; states[probe] = (short) drift; numActive++; } else { // adjusting the value of an existing key assert (keys[probe].equals(key)); values[probe] += adjustAmount; } }
[ "void", "adjustOrPutValue", "(", "final", "T", "key", ",", "final", "long", "adjustAmount", ")", "{", "final", "int", "arrayMask", "=", "keys", ".", "length", "-", "1", ";", "int", "probe", "=", "(", "int", ")", "hash", "(", "key", ".", "hashCode", "...
Increments the value mapped to the key if the key is present in the map. Otherwise, the key is inserted with the putAmount. @param key the key of the value to increment @param adjustAmount the amount by which to increment the value
[ "Increments", "the", "value", "mapped", "to", "the", "key", "if", "the", "key", "is", "present", "in", "the", "map", ".", "Otherwise", "the", "key", "is", "inserted", "with", "the", "putAmount", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/frequencies/ReversePurgeItemHashMap.java#L86-L110
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/frequencies/ReversePurgeItemHashMap.java
ReversePurgeItemHashMap.resize
@SuppressWarnings("unchecked") void resize(final int newSize) { final Object[] oldKeys = keys; final long[] oldValues = values; final short[] oldStates = states; keys = new Object[newSize]; values = new long[newSize]; states = new short[newSize]; loadThreshold = (int) (newSize * LOAD_FACTOR); lgLength = Integer.numberOfTrailingZeros(newSize); numActive = 0; for (int i = 0; i < oldKeys.length; i++) { if (oldStates[i] > 0) { adjustOrPutValue((T) oldKeys[i], oldValues[i]); } } }
java
@SuppressWarnings("unchecked") void resize(final int newSize) { final Object[] oldKeys = keys; final long[] oldValues = values; final short[] oldStates = states; keys = new Object[newSize]; values = new long[newSize]; states = new short[newSize]; loadThreshold = (int) (newSize * LOAD_FACTOR); lgLength = Integer.numberOfTrailingZeros(newSize); numActive = 0; for (int i = 0; i < oldKeys.length; i++) { if (oldStates[i] > 0) { adjustOrPutValue((T) oldKeys[i], oldValues[i]); } } }
[ "@", "SuppressWarnings", "(", "\"unchecked\"", ")", "void", "resize", "(", "final", "int", "newSize", ")", "{", "final", "Object", "[", "]", "oldKeys", "=", "keys", ";", "final", "long", "[", "]", "oldValues", "=", "values", ";", "final", "short", "[", ...
assume newSize is power of 2
[ "assume", "newSize", "is", "power", "of", "2" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/frequencies/ReversePurgeItemHashMap.java#L189-L205
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/frequencies/ReversePurgeItemHashMap.java
ReversePurgeItemHashMap.purge
long purge(final int sampleSize) { final int limit = Math.min(sampleSize, getNumActive()); int numSamples = 0; int i = 0; final long[] samples = new long[limit]; while (numSamples < limit) { if (isActive(i)) { samples[numSamples] = values[i]; numSamples++; } i++; } final long val = QuickSelect.select(samples, 0, numSamples - 1, limit / 2); adjustAllValuesBy(-1 * val); keepOnlyPositiveCounts(); return val; }
java
long purge(final int sampleSize) { final int limit = Math.min(sampleSize, getNumActive()); int numSamples = 0; int i = 0; final long[] samples = new long[limit]; while (numSamples < limit) { if (isActive(i)) { samples[numSamples] = values[i]; numSamples++; } i++; } final long val = QuickSelect.select(samples, 0, numSamples - 1, limit / 2); adjustAllValuesBy(-1 * val); keepOnlyPositiveCounts(); return val; }
[ "long", "purge", "(", "final", "int", "sampleSize", ")", "{", "final", "int", "limit", "=", "Math", ".", "min", "(", "sampleSize", ",", "getNumActive", "(", ")", ")", ";", "int", "numSamples", "=", "0", ";", "int", "i", "=", "0", ";", "final", "lon...
This function is called when a key is processed that is not currently assigned a counter, and all the counters are in use. This function estimates the median of the counters in the sketch via sampling, decrements all counts by this estimate, throws out all counters that are no longer positive, and increments offset accordingly. @param sampleSize number of samples @return the median value
[ "This", "function", "is", "called", "when", "a", "key", "is", "processed", "that", "is", "not", "currently", "assigned", "a", "counter", "and", "all", "the", "counters", "are", "in", "use", ".", "This", "function", "estimates", "the", "median", "of", "the"...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/frequencies/ReversePurgeItemHashMap.java#L267-L286
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesUnionImplR.java
DoublesUnionImplR.wrapInstance
static DoublesUnionImplR wrapInstance(final Memory mem) { final DirectUpdateDoublesSketchR sketch = DirectUpdateDoublesSketchR.wrapInstance(mem); final int k = sketch.getK(); final DoublesUnionImplR union = new DoublesUnionImplR(k); union.maxK_ = k; union.gadget_ = sketch; return union; }
java
static DoublesUnionImplR wrapInstance(final Memory mem) { final DirectUpdateDoublesSketchR sketch = DirectUpdateDoublesSketchR.wrapInstance(mem); final int k = sketch.getK(); final DoublesUnionImplR union = new DoublesUnionImplR(k); union.maxK_ = k; union.gadget_ = sketch; return union; }
[ "static", "DoublesUnionImplR", "wrapInstance", "(", "final", "Memory", "mem", ")", "{", "final", "DirectUpdateDoublesSketchR", "sketch", "=", "DirectUpdateDoublesSketchR", ".", "wrapInstance", "(", "mem", ")", ";", "final", "int", "k", "=", "sketch", ".", "getK", ...
Returns a read-only Union object that wraps off-heap data structure of the given memory image of a non-compact DoublesSketch. The data structures of the Union remain off-heap. @param mem A memory image of a non-compact DoublesSketch to be used as the data structure for the union and will be modified. @return a Union object
[ "Returns", "a", "read", "-", "only", "Union", "object", "that", "wraps", "off", "-", "heap", "data", "structure", "of", "the", "given", "memory", "image", "of", "a", "non", "-", "compact", "DoublesSketch", ".", "The", "data", "structures", "of", "the", "...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesUnionImplR.java#L37-L44
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hll/DirectHllArray.java
DirectHllArray.updateMemory
final void updateMemory(final WritableMemory newWmem) { wmem = newWmem; mem = newWmem; memObj = wmem.getArray(); memAdd = wmem.getCumulativeOffset(0L); }
java
final void updateMemory(final WritableMemory newWmem) { wmem = newWmem; mem = newWmem; memObj = wmem.getArray(); memAdd = wmem.getCumulativeOffset(0L); }
[ "final", "void", "updateMemory", "(", "final", "WritableMemory", "newWmem", ")", "{", "wmem", "=", "newWmem", ";", "mem", "=", "newWmem", ";", "memObj", "=", "wmem", ".", "getArray", "(", ")", ";", "memAdd", "=", "wmem", ".", "getCumulativeOffset", "(", ...
only called by DirectAuxHashMap
[ "only", "called", "by", "DirectAuxHashMap" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/DirectHllArray.java#L67-L72
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesUtil.java
DoublesUtil.copyToHeap
static HeapUpdateDoublesSketch copyToHeap(final DoublesSketch sketch) { final HeapUpdateDoublesSketch qsCopy; qsCopy = HeapUpdateDoublesSketch.newInstance(sketch.getK()); qsCopy.putN(sketch.getN()); qsCopy.putMinValue(sketch.getMinValue()); qsCopy.putMaxValue(sketch.getMaxValue()); qsCopy.putBaseBufferCount(sketch.getBaseBufferCount()); qsCopy.putBitPattern(sketch.getBitPattern()); if (sketch.isCompact()) { final int combBufItems = Util.computeCombinedBufferItemCapacity(sketch.getK(), sketch.getN()); final double[] combBuf = new double[combBufItems]; qsCopy.putCombinedBuffer(combBuf); final DoublesSketchAccessor sketchAccessor = DoublesSketchAccessor.wrap(sketch); final DoublesSketchAccessor copyAccessor = DoublesSketchAccessor.wrap(qsCopy); // start with BB copyAccessor.putArray(sketchAccessor.getArray(0, sketchAccessor.numItems()), 0, 0, sketchAccessor.numItems()); long bitPattern = sketch.getBitPattern(); for (int lvl = 0; bitPattern != 0L; ++lvl, bitPattern >>>= 1) { if ((bitPattern & 1L) > 0L) { sketchAccessor.setLevel(lvl); copyAccessor.setLevel(lvl); copyAccessor.putArray(sketchAccessor.getArray(0, sketchAccessor.numItems()), 0, 0, sketchAccessor.numItems()); } } } else { final double[] combBuf = sketch.getCombinedBuffer(); qsCopy.putCombinedBuffer(Arrays.copyOf(combBuf, combBuf.length)); } return qsCopy; }
java
static HeapUpdateDoublesSketch copyToHeap(final DoublesSketch sketch) { final HeapUpdateDoublesSketch qsCopy; qsCopy = HeapUpdateDoublesSketch.newInstance(sketch.getK()); qsCopy.putN(sketch.getN()); qsCopy.putMinValue(sketch.getMinValue()); qsCopy.putMaxValue(sketch.getMaxValue()); qsCopy.putBaseBufferCount(sketch.getBaseBufferCount()); qsCopy.putBitPattern(sketch.getBitPattern()); if (sketch.isCompact()) { final int combBufItems = Util.computeCombinedBufferItemCapacity(sketch.getK(), sketch.getN()); final double[] combBuf = new double[combBufItems]; qsCopy.putCombinedBuffer(combBuf); final DoublesSketchAccessor sketchAccessor = DoublesSketchAccessor.wrap(sketch); final DoublesSketchAccessor copyAccessor = DoublesSketchAccessor.wrap(qsCopy); // start with BB copyAccessor.putArray(sketchAccessor.getArray(0, sketchAccessor.numItems()), 0, 0, sketchAccessor.numItems()); long bitPattern = sketch.getBitPattern(); for (int lvl = 0; bitPattern != 0L; ++lvl, bitPattern >>>= 1) { if ((bitPattern & 1L) > 0L) { sketchAccessor.setLevel(lvl); copyAccessor.setLevel(lvl); copyAccessor.putArray(sketchAccessor.getArray(0, sketchAccessor.numItems()), 0, 0, sketchAccessor.numItems()); } } } else { final double[] combBuf = sketch.getCombinedBuffer(); qsCopy.putCombinedBuffer(Arrays.copyOf(combBuf, combBuf.length)); } return qsCopy; }
[ "static", "HeapUpdateDoublesSketch", "copyToHeap", "(", "final", "DoublesSketch", "sketch", ")", "{", "final", "HeapUpdateDoublesSketch", "qsCopy", ";", "qsCopy", "=", "HeapUpdateDoublesSketch", ".", "newInstance", "(", "sketch", ".", "getK", "(", ")", ")", ";", "...
Returns an on-heap copy of the given sketch @param sketch the given sketch @return a copy of the given sketch
[ "Returns", "an", "on", "-", "heap", "copy", "of", "the", "given", "sketch" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesUtil.java#L33-L66
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesUtil.java
DoublesUtil.checkDoublesSerVer
static void checkDoublesSerVer(final int serVer, final int minSupportedSerVer) { final int max = DoublesSketch.DOUBLES_SER_VER; if ((serVer > max) || (serVer < minSupportedSerVer)) { throw new SketchesArgumentException( "Possible corruption: Unsupported Serialization Version: " + serVer); } }
java
static void checkDoublesSerVer(final int serVer, final int minSupportedSerVer) { final int max = DoublesSketch.DOUBLES_SER_VER; if ((serVer > max) || (serVer < minSupportedSerVer)) { throw new SketchesArgumentException( "Possible corruption: Unsupported Serialization Version: " + serVer); } }
[ "static", "void", "checkDoublesSerVer", "(", "final", "int", "serVer", ",", "final", "int", "minSupportedSerVer", ")", "{", "final", "int", "max", "=", "DoublesSketch", ".", "DOUBLES_SER_VER", ";", "if", "(", "(", "serVer", ">", "max", ")", "||", "(", "ser...
Check the validity of the given serialization version @param serVer the given serialization version @param minSupportedSerVer the oldest serialization version supported
[ "Check", "the", "validity", "of", "the", "given", "serialization", "version" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesUtil.java#L73-L79
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DirectCompactDoublesSketch.java
DirectCompactDoublesSketch.wrapInstance
static DirectCompactDoublesSketch wrapInstance(final Memory srcMem) { final long memCap = srcMem.getCapacity(); final int preLongs = extractPreLongs(srcMem); final int serVer = extractSerVer(srcMem); final int familyID = extractFamilyID(srcMem); final int flags = extractFlags(srcMem); final int k = extractK(srcMem); final boolean empty = (flags & EMPTY_FLAG_MASK) > 0; final long n = empty ? 0 : extractN(srcMem); //VALIDITY CHECKS DirectUpdateDoublesSketchR.checkPreLongs(preLongs); Util.checkFamilyID(familyID); DoublesUtil.checkDoublesSerVer(serVer, MIN_DIRECT_DOUBLES_SER_VER); checkCompact(serVer, flags); Util.checkK(k); checkDirectMemCapacity(k, n, memCap); DirectUpdateDoublesSketchR.checkEmptyAndN(empty, n); final DirectCompactDoublesSketch dds = new DirectCompactDoublesSketch(k); dds.mem_ = (WritableMemory) srcMem; return dds; }
java
static DirectCompactDoublesSketch wrapInstance(final Memory srcMem) { final long memCap = srcMem.getCapacity(); final int preLongs = extractPreLongs(srcMem); final int serVer = extractSerVer(srcMem); final int familyID = extractFamilyID(srcMem); final int flags = extractFlags(srcMem); final int k = extractK(srcMem); final boolean empty = (flags & EMPTY_FLAG_MASK) > 0; final long n = empty ? 0 : extractN(srcMem); //VALIDITY CHECKS DirectUpdateDoublesSketchR.checkPreLongs(preLongs); Util.checkFamilyID(familyID); DoublesUtil.checkDoublesSerVer(serVer, MIN_DIRECT_DOUBLES_SER_VER); checkCompact(serVer, flags); Util.checkK(k); checkDirectMemCapacity(k, n, memCap); DirectUpdateDoublesSketchR.checkEmptyAndN(empty, n); final DirectCompactDoublesSketch dds = new DirectCompactDoublesSketch(k); dds.mem_ = (WritableMemory) srcMem; return dds; }
[ "static", "DirectCompactDoublesSketch", "wrapInstance", "(", "final", "Memory", "srcMem", ")", "{", "final", "long", "memCap", "=", "srcMem", ".", "getCapacity", "(", ")", ";", "final", "int", "preLongs", "=", "extractPreLongs", "(", "srcMem", ")", ";", "final...
Wrap this sketch around the given compact Memory image of a DoublesSketch. @param srcMem the given compact Memory image of a DoublesSketch that may have data, @return a sketch that wraps the given srcMem
[ "Wrap", "this", "sketch", "around", "the", "given", "compact", "Memory", "image", "of", "a", "DoublesSketch", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DirectCompactDoublesSketch.java#L123-L147
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DirectCompactDoublesSketch.java
DirectCompactDoublesSketch.checkCompact
static void checkCompact(final int serVer, final int flags) { final int compactFlagMask = COMPACT_FLAG_MASK | ORDERED_FLAG_MASK; if ((serVer != 2) && ((flags & EMPTY_FLAG_MASK) == 0) && ((flags & compactFlagMask) != compactFlagMask)) { throw new SketchesArgumentException( "Possible corruption: Must be v2, empty, or compact and ordered. Flags field: " + Integer.toBinaryString(flags) + ", SerVer: " + serVer); } }
java
static void checkCompact(final int serVer, final int flags) { final int compactFlagMask = COMPACT_FLAG_MASK | ORDERED_FLAG_MASK; if ((serVer != 2) && ((flags & EMPTY_FLAG_MASK) == 0) && ((flags & compactFlagMask) != compactFlagMask)) { throw new SketchesArgumentException( "Possible corruption: Must be v2, empty, or compact and ordered. Flags field: " + Integer.toBinaryString(flags) + ", SerVer: " + serVer); } }
[ "static", "void", "checkCompact", "(", "final", "int", "serVer", ",", "final", "int", "flags", ")", "{", "final", "int", "compactFlagMask", "=", "COMPACT_FLAG_MASK", "|", "ORDERED_FLAG_MASK", ";", "if", "(", "(", "serVer", "!=", "2", ")", "&&", "(", "(", ...
Checks a sketch's serial version and flags to see if the sketch can be wrapped as a DirectCompactDoubleSketch. Throws an exception if the sketch is neither empty nor compact and ordered, unles the sketch uses serialization version 2. @param serVer the serialization version @param flags Flags from the sketch to evaluate
[ "Checks", "a", "sketch", "s", "serial", "version", "and", "flags", "to", "see", "if", "the", "sketch", "can", "be", "wrapped", "as", "a", "DirectCompactDoubleSketch", ".", "Throws", "an", "exception", "if", "the", "sketch", "is", "neither", "empty", "nor", ...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DirectCompactDoublesSketch.java#L234-L243
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/HashOperations.java
HashOperations.countPart
public static int countPart(final long[] srcArr, final int lgArrLongs, final long thetaLong) { int cnt = 0; final int len = 1 << lgArrLongs; for (int i = len; i-- > 0;) { final long hash = srcArr[i]; if (continueCondition(thetaLong, hash) ) { continue; } cnt++ ; } return cnt; }
java
public static int countPart(final long[] srcArr, final int lgArrLongs, final long thetaLong) { int cnt = 0; final int len = 1 << lgArrLongs; for (int i = len; i-- > 0;) { final long hash = srcArr[i]; if (continueCondition(thetaLong, hash) ) { continue; } cnt++ ; } return cnt; }
[ "public", "static", "int", "countPart", "(", "final", "long", "[", "]", "srcArr", ",", "final", "int", "lgArrLongs", ",", "final", "long", "thetaLong", ")", "{", "int", "cnt", "=", "0", ";", "final", "int", "len", "=", "1", "<<", "lgArrLongs", ";", "...
Counts the cardinality of the first Log2 values of the given source array. @param srcArr the given source array @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a> @param thetaLong <a href="{@docRoot}/resources/dictionary.html#thetaLong">See Theta Long</a> @return the cardinality
[ "Counts", "the", "cardinality", "of", "the", "first", "Log2", "values", "of", "the", "given", "source", "array", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/HashOperations.java#L36-L47
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/HashOperations.java
HashOperations.count
public static int count(final long[] srcArr, final long thetaLong) { int cnt = 0; final int len = srcArr.length; for (int i = len; i-- > 0;) { final long hash = srcArr[i]; if (continueCondition(thetaLong, hash) ) { continue; } cnt++ ; } return cnt; }
java
public static int count(final long[] srcArr, final long thetaLong) { int cnt = 0; final int len = srcArr.length; for (int i = len; i-- > 0;) { final long hash = srcArr[i]; if (continueCondition(thetaLong, hash) ) { continue; } cnt++ ; } return cnt; }
[ "public", "static", "int", "count", "(", "final", "long", "[", "]", "srcArr", ",", "final", "long", "thetaLong", ")", "{", "int", "cnt", "=", "0", ";", "final", "int", "len", "=", "srcArr", ".", "length", ";", "for", "(", "int", "i", "=", "len", ...
Counts the cardinality of the given source array. @param srcArr the given source array @param thetaLong <a href="{@docRoot}/resources/dictionary.html#thetaLong">See Theta Long</a> @return the cardinality
[ "Counts", "the", "cardinality", "of", "the", "given", "source", "array", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/HashOperations.java#L55-L66
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/HashOperations.java
HashOperations.hashSearch
public static int hashSearch(final long[] hashTable, final int lgArrLongs, final long hash) { if (hash == 0) { throw new SketchesArgumentException("Given hash cannot be zero: " + hash); } final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1 final int stride = getStride(hash, lgArrLongs); int curProbe = (int) (hash & arrayMask); // search for duplicate or empty slot final int loopIndex = curProbe; do { final long arrVal = hashTable[curProbe]; if (arrVal == EMPTY) { return -1; // not found } else if (arrVal == hash) { return curProbe; // found } curProbe = (curProbe + stride) & arrayMask; } while (curProbe != loopIndex); return -1; }
java
public static int hashSearch(final long[] hashTable, final int lgArrLongs, final long hash) { if (hash == 0) { throw new SketchesArgumentException("Given hash cannot be zero: " + hash); } final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1 final int stride = getStride(hash, lgArrLongs); int curProbe = (int) (hash & arrayMask); // search for duplicate or empty slot final int loopIndex = curProbe; do { final long arrVal = hashTable[curProbe]; if (arrVal == EMPTY) { return -1; // not found } else if (arrVal == hash) { return curProbe; // found } curProbe = (curProbe + stride) & arrayMask; } while (curProbe != loopIndex); return -1; }
[ "public", "static", "int", "hashSearch", "(", "final", "long", "[", "]", "hashTable", ",", "final", "int", "lgArrLongs", ",", "final", "long", "hash", ")", "{", "if", "(", "hash", "==", "0", ")", "{", "throw", "new", "SketchesArgumentException", "(", "\"...
This is a classical Knuth-style Open Addressing, Double Hash search scheme for on-heap. Returns the index if found, -1 if not found. @param hashTable The hash table to search. Must be a power of 2 in size. @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>. lgArrLongs &le; log2(hashTable.length). @param hash A hash value to search for. Must not be zero. @return Current probe index if found, -1 if not found.
[ "This", "is", "a", "classical", "Knuth", "-", "style", "Open", "Addressing", "Double", "Hash", "search", "scheme", "for", "on", "-", "heap", ".", "Returns", "the", "index", "if", "found", "-", "1", "if", "not", "found", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/HashOperations.java#L86-L106
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/HashOperations.java
HashOperations.hashArrayInsert
public static int hashArrayInsert(final long[] srcArr, final long[] hashTable, final int lgArrLongs, final long thetaLong) { int count = 0; final int arrLen = srcArr.length; checkThetaCorruption(thetaLong); for (int i = 0; i < arrLen; i++ ) { // scan source array, build target array final long hash = srcArr[i]; checkHashCorruption(hash); if (continueCondition(thetaLong, hash) ) { continue; } if (hashSearchOrInsert(hashTable, lgArrLongs, hash) < 0) { count++ ; } } return count; }
java
public static int hashArrayInsert(final long[] srcArr, final long[] hashTable, final int lgArrLongs, final long thetaLong) { int count = 0; final int arrLen = srcArr.length; checkThetaCorruption(thetaLong); for (int i = 0; i < arrLen; i++ ) { // scan source array, build target array final long hash = srcArr[i]; checkHashCorruption(hash); if (continueCondition(thetaLong, hash) ) { continue; } if (hashSearchOrInsert(hashTable, lgArrLongs, hash) < 0) { count++ ; } } return count; }
[ "public", "static", "int", "hashArrayInsert", "(", "final", "long", "[", "]", "srcArr", ",", "final", "long", "[", "]", "hashTable", ",", "final", "int", "lgArrLongs", ",", "final", "long", "thetaLong", ")", "{", "int", "count", "=", "0", ";", "final", ...
Inserts the given long array into the given hash table array of the target size, removes any negative input values, ignores duplicates and counts the values inserted. The given hash table may have values, but they must have been inserted by this method or one of the other OADH insert methods in this class and they may not be dirty. This method performs additional checks against potentially invalid hash values or theta values. Returns the count of values actually inserted. @param srcArr the source hash array to be potentially inserted @param hashTable The correctly sized target hash table that must be a power of two. @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>. lgArrLongs &le; log2(hashTable.length). @param thetaLong must greater than zero <a href="{@docRoot}/resources/dictionary.html#thetaLong">See Theta Long</a> @return the count of values actually inserted
[ "Inserts", "the", "given", "long", "array", "into", "the", "given", "hash", "table", "array", "of", "the", "target", "size", "removes", "any", "negative", "input", "values", "ignores", "duplicates", "and", "counts", "the", "values", "inserted", ".", "The", "...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/HashOperations.java#L188-L204
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/HashOperations.java
HashOperations.hashSearch
public static int hashSearch(final Memory mem, final int lgArrLongs, final long hash, final int memOffsetBytes) { final int arrayMask = (1 << lgArrLongs) - 1; final int stride = getStride(hash, lgArrLongs); int curProbe = (int) (hash & arrayMask); final int loopIndex = curProbe; do { final int curProbeOffsetBytes = (curProbe << 3) + memOffsetBytes; final long curArrayHash = mem.getLong(curProbeOffsetBytes); if (curArrayHash == EMPTY) { return -1; } else if (curArrayHash == hash) { return curProbe; } curProbe = (curProbe + stride) & arrayMask; } while (curProbe != loopIndex); return -1; }
java
public static int hashSearch(final Memory mem, final int lgArrLongs, final long hash, final int memOffsetBytes) { final int arrayMask = (1 << lgArrLongs) - 1; final int stride = getStride(hash, lgArrLongs); int curProbe = (int) (hash & arrayMask); final int loopIndex = curProbe; do { final int curProbeOffsetBytes = (curProbe << 3) + memOffsetBytes; final long curArrayHash = mem.getLong(curProbeOffsetBytes); if (curArrayHash == EMPTY) { return -1; } else if (curArrayHash == hash) { return curProbe; } curProbe = (curProbe + stride) & arrayMask; } while (curProbe != loopIndex); return -1; }
[ "public", "static", "int", "hashSearch", "(", "final", "Memory", "mem", ",", "final", "int", "lgArrLongs", ",", "final", "long", "hash", ",", "final", "int", "memOffsetBytes", ")", "{", "final", "int", "arrayMask", "=", "(", "1", "<<", "lgArrLongs", ")", ...
This is a classical Knuth-style Open Addressing, Double Hash search scheme for off-heap. Returns the index if found, -1 if not found. @param mem The Memory hash table to search. @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>. lgArrLongs &le; log2(hashTable.length). @param hash A hash value to search for. Must not be zero. @param memOffsetBytes offset in the memory where the hash array starts @return index if found, -1 if not found.
[ "This", "is", "a", "classical", "Knuth", "-", "style", "Open", "Addressing", "Double", "Hash", "search", "scheme", "for", "off", "-", "heap", ".", "Returns", "the", "index", "if", "found", "-", "1", "if", "not", "found", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/HashOperations.java#L219-L233
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/HashOperations.java
HashOperations.fastHashInsertOnly
public static int fastHashInsertOnly(final WritableMemory wmem, final int lgArrLongs, final long hash, final int memOffsetBytes) { final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1 final int stride = getStride(hash, lgArrLongs); int curProbe = (int) (hash & arrayMask); // search for duplicate or zero final int loopIndex = curProbe; do { final int curProbeOffsetBytes = (curProbe << 3) + memOffsetBytes; final long curArrayHash = wmem.getLong(curProbeOffsetBytes); if (curArrayHash == EMPTY) { wmem.putLong(curProbeOffsetBytes, hash); return curProbe; } curProbe = (curProbe + stride) & arrayMask; } while (curProbe != loopIndex); throw new SketchesArgumentException("No empty slot in table!"); }
java
public static int fastHashInsertOnly(final WritableMemory wmem, final int lgArrLongs, final long hash, final int memOffsetBytes) { final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1 final int stride = getStride(hash, lgArrLongs); int curProbe = (int) (hash & arrayMask); // search for duplicate or zero final int loopIndex = curProbe; do { final int curProbeOffsetBytes = (curProbe << 3) + memOffsetBytes; final long curArrayHash = wmem.getLong(curProbeOffsetBytes); if (curArrayHash == EMPTY) { wmem.putLong(curProbeOffsetBytes, hash); return curProbe; } curProbe = (curProbe + stride) & arrayMask; } while (curProbe != loopIndex); throw new SketchesArgumentException("No empty slot in table!"); }
[ "public", "static", "int", "fastHashInsertOnly", "(", "final", "WritableMemory", "wmem", ",", "final", "int", "lgArrLongs", ",", "final", "long", "hash", ",", "final", "int", "memOffsetBytes", ")", "{", "final", "int", "arrayMask", "=", "(", "1", "<<", "lgAr...
This is a classical Knuth-style Open Addressing, Double Hash insert scheme, but inserts values directly into a Memory. This method assumes that the input hash is not a duplicate. Useful for rebuilding tables to avoid unnecessary comparisons. Returns the index of insertion, which is always positive or zero. Throws an exception if table has no empty slot. @param wmem The writable memory @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>. lgArrLongs &le; log2(hashTable.length). @param hash value that must not be zero and will be inserted into the array into an empty slot. @param memOffsetBytes offset in the memory where the hash array starts @return index of insertion. Always positive or zero.
[ "This", "is", "a", "classical", "Knuth", "-", "style", "Open", "Addressing", "Double", "Hash", "insert", "scheme", "but", "inserts", "values", "directly", "into", "a", "Memory", ".", "This", "method", "assumes", "that", "the", "input", "hash", "is", "not", ...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/HashOperations.java#L250-L267
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/ConcurrentHeapQuickSelectSketch.java
ConcurrentHeapQuickSelectSketch.advanceEpoch
@SuppressFBWarnings(value = "VO_VOLATILE_INCREMENT", justification = "False Positive") private void advanceEpoch() { awaitBgPropagationTermination(); startEagerPropagation(); ConcurrentPropagationService.resetExecutorService(Thread.currentThread().getId()); //noinspection NonAtomicOperationOnVolatileField // this increment of a volatile field is done within the scope of the propagation // synchronization and hence is done by a single thread // Ignore a FindBugs warning epoch_++; endPropagation(null, true); initBgPropagationService(); }
java
@SuppressFBWarnings(value = "VO_VOLATILE_INCREMENT", justification = "False Positive") private void advanceEpoch() { awaitBgPropagationTermination(); startEagerPropagation(); ConcurrentPropagationService.resetExecutorService(Thread.currentThread().getId()); //noinspection NonAtomicOperationOnVolatileField // this increment of a volatile field is done within the scope of the propagation // synchronization and hence is done by a single thread // Ignore a FindBugs warning epoch_++; endPropagation(null, true); initBgPropagationService(); }
[ "@", "SuppressFBWarnings", "(", "value", "=", "\"VO_VOLATILE_INCREMENT\"", ",", "justification", "=", "\"False Positive\"", ")", "private", "void", "advanceEpoch", "(", ")", "{", "awaitBgPropagationTermination", "(", ")", ";", "startEagerPropagation", "(", ")", ";", ...
Advances the epoch while there is no background propagation This ensures a propagation invoked before the reset cannot affect the sketch after the reset is completed.
[ "Advances", "the", "epoch", "while", "there", "is", "no", "background", "propagation", "This", "ensures", "a", "propagation", "invoked", "before", "the", "reset", "cannot", "affect", "the", "sketch", "after", "the", "reset", "is", "completed", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/ConcurrentHeapQuickSelectSketch.java#L236-L249
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/HeapUpdateDoublesSketch.java
HeapUpdateDoublesSketch.newInstance
static HeapUpdateDoublesSketch newInstance(final int k) { final HeapUpdateDoublesSketch hqs = new HeapUpdateDoublesSketch(k); final int baseBufAlloc = 2 * Math.min(DoublesSketch.MIN_K, k); //the min is important hqs.n_ = 0; hqs.combinedBuffer_ = new double[baseBufAlloc]; hqs.baseBufferCount_ = 0; hqs.bitPattern_ = 0; hqs.minValue_ = Double.NaN; hqs.maxValue_ = Double.NaN; return hqs; }
java
static HeapUpdateDoublesSketch newInstance(final int k) { final HeapUpdateDoublesSketch hqs = new HeapUpdateDoublesSketch(k); final int baseBufAlloc = 2 * Math.min(DoublesSketch.MIN_K, k); //the min is important hqs.n_ = 0; hqs.combinedBuffer_ = new double[baseBufAlloc]; hqs.baseBufferCount_ = 0; hqs.bitPattern_ = 0; hqs.minValue_ = Double.NaN; hqs.maxValue_ = Double.NaN; return hqs; }
[ "static", "HeapUpdateDoublesSketch", "newInstance", "(", "final", "int", "k", ")", "{", "final", "HeapUpdateDoublesSketch", "hqs", "=", "new", "HeapUpdateDoublesSketch", "(", "k", ")", ";", "final", "int", "baseBufAlloc", "=", "2", "*", "Math", ".", "min", "("...
Obtains a new on-heap instance of a DoublesSketch. @param k Parameter that controls space usage of sketch and accuracy of estimates. Must be greater than 1 and less than 65536 and a power of 2. @return a HeapUpdateDoublesSketch
[ "Obtains", "a", "new", "on", "-", "heap", "instance", "of", "a", "DoublesSketch", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/HeapUpdateDoublesSketch.java#L92-L102
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/HeapUpdateDoublesSketch.java
HeapUpdateDoublesSketch.srcMemoryToCombinedBuffer
private void srcMemoryToCombinedBuffer(final Memory srcMem, final int serVer, final boolean srcIsCompact, final int combBufCap) { final int preLongs = 2; final int extra = (serVer == 1) ? 3 : 2; // space for min and max values, buf alloc (SerVer 1) final int preBytes = (preLongs + extra) << 3; final int bbCnt = baseBufferCount_; final int k = getK(); final long n = getN(); final double[] combinedBuffer = new double[combBufCap]; //always non-compact //Load min, max putMinValue(srcMem.getDouble(MIN_DOUBLE)); putMaxValue(srcMem.getDouble(MAX_DOUBLE)); if (srcIsCompact) { //Load base buffer srcMem.getDoubleArray(preBytes, combinedBuffer, 0, bbCnt); //Load levels from compact srcMem long bitPattern = bitPattern_; if (bitPattern != 0) { long memOffset = preBytes + (bbCnt << 3); int combBufOffset = 2 * k; while (bitPattern != 0L) { if ((bitPattern & 1L) > 0L) { srcMem.getDoubleArray(memOffset, combinedBuffer, combBufOffset, k); memOffset += (k << 3); //bytes, increment compactly } combBufOffset += k; //doubles, increment every level bitPattern >>>= 1; } } } else { //srcMem not compact final int levels = Util.computeNumLevelsNeeded(k, n); final int totItems = (levels == 0) ? bbCnt : (2 + levels) * k; srcMem.getDoubleArray(preBytes, combinedBuffer, 0, totItems); } putCombinedBuffer(combinedBuffer); }
java
private void srcMemoryToCombinedBuffer(final Memory srcMem, final int serVer, final boolean srcIsCompact, final int combBufCap) { final int preLongs = 2; final int extra = (serVer == 1) ? 3 : 2; // space for min and max values, buf alloc (SerVer 1) final int preBytes = (preLongs + extra) << 3; final int bbCnt = baseBufferCount_; final int k = getK(); final long n = getN(); final double[] combinedBuffer = new double[combBufCap]; //always non-compact //Load min, max putMinValue(srcMem.getDouble(MIN_DOUBLE)); putMaxValue(srcMem.getDouble(MAX_DOUBLE)); if (srcIsCompact) { //Load base buffer srcMem.getDoubleArray(preBytes, combinedBuffer, 0, bbCnt); //Load levels from compact srcMem long bitPattern = bitPattern_; if (bitPattern != 0) { long memOffset = preBytes + (bbCnt << 3); int combBufOffset = 2 * k; while (bitPattern != 0L) { if ((bitPattern & 1L) > 0L) { srcMem.getDoubleArray(memOffset, combinedBuffer, combBufOffset, k); memOffset += (k << 3); //bytes, increment compactly } combBufOffset += k; //doubles, increment every level bitPattern >>>= 1; } } } else { //srcMem not compact final int levels = Util.computeNumLevelsNeeded(k, n); final int totItems = (levels == 0) ? bbCnt : (2 + levels) * k; srcMem.getDoubleArray(preBytes, combinedBuffer, 0, totItems); } putCombinedBuffer(combinedBuffer); }
[ "private", "void", "srcMemoryToCombinedBuffer", "(", "final", "Memory", "srcMem", ",", "final", "int", "serVer", ",", "final", "boolean", "srcIsCompact", ",", "final", "int", "combBufCap", ")", "{", "final", "int", "preLongs", "=", "2", ";", "final", "int", ...
Loads the Combined Buffer, min and max from the given source Memory. The resulting Combined Buffer is always in non-compact form and must be pre-allocated. @param srcMem the given source Memory @param serVer the serialization version of the source @param srcIsCompact true if the given source Memory is in compact form @param combBufCap total items for the combined buffer (size in doubles)
[ "Loads", "the", "Combined", "Buffer", "min", "and", "max", "from", "the", "given", "source", "Memory", ".", "The", "resulting", "Combined", "Buffer", "is", "always", "in", "non", "-", "compact", "form", "and", "must", "be", "pre", "-", "allocated", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/HeapUpdateDoublesSketch.java#L252-L290
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/HeapUpdateDoublesSketch.java
HeapUpdateDoublesSketch.checkHeapMemCapacity
static void checkHeapMemCapacity(final int k, final long n, final boolean compact, final int serVer, final long memCapBytes) { final int metaPre = Family.QUANTILES.getMaxPreLongs() + ((serVer == 1) ? 3 : 2); final int retainedItems = computeRetainedItems(k, n); final int reqBufBytes; if (compact) { reqBufBytes = (metaPre + retainedItems) << 3; } else { //not compact final int totLevels = Util.computeNumLevelsNeeded(k, n); reqBufBytes = (totLevels == 0) ? (metaPre + retainedItems) << 3 : (metaPre + ((2 + totLevels) * k)) << 3; } if (memCapBytes < reqBufBytes) { throw new SketchesArgumentException("Possible corruption: Memory capacity too small: " + memCapBytes + " < " + reqBufBytes); } }
java
static void checkHeapMemCapacity(final int k, final long n, final boolean compact, final int serVer, final long memCapBytes) { final int metaPre = Family.QUANTILES.getMaxPreLongs() + ((serVer == 1) ? 3 : 2); final int retainedItems = computeRetainedItems(k, n); final int reqBufBytes; if (compact) { reqBufBytes = (metaPre + retainedItems) << 3; } else { //not compact final int totLevels = Util.computeNumLevelsNeeded(k, n); reqBufBytes = (totLevels == 0) ? (metaPre + retainedItems) << 3 : (metaPre + ((2 + totLevels) * k)) << 3; } if (memCapBytes < reqBufBytes) { throw new SketchesArgumentException("Possible corruption: Memory capacity too small: " + memCapBytes + " < " + reqBufBytes); } }
[ "static", "void", "checkHeapMemCapacity", "(", "final", "int", "k", ",", "final", "long", "n", ",", "final", "boolean", "compact", ",", "final", "int", "serVer", ",", "final", "long", "memCapBytes", ")", "{", "final", "int", "metaPre", "=", "Family", ".", ...
Checks the validity of the heap memory capacity assuming n, k and the compact state. @param k the given value of k @param n the given value of n @param compact true if memory is in compact form @param serVer serialization version of the source @param memCapBytes the current memory capacity in bytes
[ "Checks", "the", "validity", "of", "the", "heap", "memory", "capacity", "assuming", "n", "k", "and", "the", "compact", "state", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/HeapUpdateDoublesSketch.java#L409-L426
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/cpc/PreambleUtil.java
PreambleUtil.getNumCoupons
static int getNumCoupons(final Memory mem) { final Format format = getFormat(mem); final HiField hiField = HiField.NUM_COUPONS; final long offset = getHiFieldOffset(format, hiField); return mem.getInt(offset); }
java
static int getNumCoupons(final Memory mem) { final Format format = getFormat(mem); final HiField hiField = HiField.NUM_COUPONS; final long offset = getHiFieldOffset(format, hiField); return mem.getInt(offset); }
[ "static", "int", "getNumCoupons", "(", "final", "Memory", "mem", ")", "{", "final", "Format", "format", "=", "getFormat", "(", "mem", ")", ";", "final", "HiField", "hiField", "=", "HiField", ".", "NUM_COUPONS", ";", "final", "long", "offset", "=", "getHiFi...
PREAMBLE HI_FIELD GETS
[ "PREAMBLE", "HI_FIELD", "GETS" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/PreambleUtil.java#L288-L293
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/cpc/PreambleUtil.java
PreambleUtil.putEmptyMerged
static void putEmptyMerged(final WritableMemory wmem, final int lgK, final short seedHash) { final Format format = Format.EMPTY_MERGED; final byte preInts = getDefinedPreInts(format); final byte fiCol = (byte) 0; final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK); checkCapacity(wmem.getCapacity(), 8); putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash); }
java
static void putEmptyMerged(final WritableMemory wmem, final int lgK, final short seedHash) { final Format format = Format.EMPTY_MERGED; final byte preInts = getDefinedPreInts(format); final byte fiCol = (byte) 0; final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK); checkCapacity(wmem.getCapacity(), 8); putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash); }
[ "static", "void", "putEmptyMerged", "(", "final", "WritableMemory", "wmem", ",", "final", "int", "lgK", ",", "final", "short", "seedHash", ")", "{", "final", "Format", "format", "=", "Format", ".", "EMPTY_MERGED", ";", "final", "byte", "preInts", "=", "getDe...
PUT INTO MEMORY
[ "PUT", "INTO", "MEMORY" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/PreambleUtil.java#L380-L389
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/cpc/PreambleUtil.java
PreambleUtil.checkLoPreamble
static void checkLoPreamble(final Memory mem) { rtAssertEquals(getSerVer(mem), SER_VER & 0XFF); final Format fmt = getFormat(mem); final int preIntsDef = getDefinedPreInts(fmt) & 0XFF; rtAssertEquals(getPreInts(mem), preIntsDef); final Family fam = getFamily(mem); rtAssert(fam == Family.CPC); final int lgK = getLgK(mem); rtAssert((lgK >= 4) && (lgK <= 26)); final int fiCol = getFiCol(mem); rtAssert((fiCol <= 63) && (fiCol >= 0)); }
java
static void checkLoPreamble(final Memory mem) { rtAssertEquals(getSerVer(mem), SER_VER & 0XFF); final Format fmt = getFormat(mem); final int preIntsDef = getDefinedPreInts(fmt) & 0XFF; rtAssertEquals(getPreInts(mem), preIntsDef); final Family fam = getFamily(mem); rtAssert(fam == Family.CPC); final int lgK = getLgK(mem); rtAssert((lgK >= 4) && (lgK <= 26)); final int fiCol = getFiCol(mem); rtAssert((fiCol <= 63) && (fiCol >= 0)); }
[ "static", "void", "checkLoPreamble", "(", "final", "Memory", "mem", ")", "{", "rtAssertEquals", "(", "getSerVer", "(", "mem", ")", ",", "SER_VER", "&", "0XFF", ")", ";", "final", "Format", "fmt", "=", "getFormat", "(", "mem", ")", ";", "final", "int", ...
basic checks of SerVer, Format, preInts, Family, fiCol, lgK.
[ "basic", "checks", "of", "SerVer", "Format", "preInts", "Family", "fiCol", "lgK", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/PreambleUtil.java#L795-L806
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/kll/KllHelper.java
KllHelper.validateValues
static final void validateValues(final float[] values) { for (int i = 0; i < values.length ; i++) { if (Float.isNaN(values[i])) { throw new SketchesArgumentException("Values must not be NaN"); } if ((i < (values.length - 1)) && (values[i] >= values[i + 1])) { throw new SketchesArgumentException( "Values must be unique and monotonically increasing"); } } }
java
static final void validateValues(final float[] values) { for (int i = 0; i < values.length ; i++) { if (Float.isNaN(values[i])) { throw new SketchesArgumentException("Values must not be NaN"); } if ((i < (values.length - 1)) && (values[i] >= values[i + 1])) { throw new SketchesArgumentException( "Values must be unique and monotonically increasing"); } } }
[ "static", "final", "void", "validateValues", "(", "final", "float", "[", "]", "values", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "values", ".", "length", ";", "i", "++", ")", "{", "if", "(", "Float", ".", "isNaN", "(", "values",...
Checks the sequential validity of the given array of float values. They must be unique, monotonically increasing and not NaN. @param values the given array of values
[ "Checks", "the", "sequential", "validity", "of", "the", "given", "array", "of", "float", "values", ".", "They", "must", "be", "unique", "monotonically", "increasing", "and", "not", "NaN", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/kll/KllHelper.java#L45-L55
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/HeapCompactUnorderedSketch.java
HeapCompactUnorderedSketch.compact
static CompactSketch compact(final long[] cache, final boolean empty, final short seedHash, final int curCount, final long thetaLong) { if ((curCount == 1) && (thetaLong == Long.MAX_VALUE)) { return new SingleItemSketch(cache[0], seedHash); } return new HeapCompactUnorderedSketch(cache, empty, seedHash, curCount, thetaLong); }
java
static CompactSketch compact(final long[] cache, final boolean empty, final short seedHash, final int curCount, final long thetaLong) { if ((curCount == 1) && (thetaLong == Long.MAX_VALUE)) { return new SingleItemSketch(cache[0], seedHash); } return new HeapCompactUnorderedSketch(cache, empty, seedHash, curCount, thetaLong); }
[ "static", "CompactSketch", "compact", "(", "final", "long", "[", "]", "cache", ",", "final", "boolean", "empty", ",", "final", "short", "seedHash", ",", "final", "int", "curCount", ",", "final", "long", "thetaLong", ")", "{", "if", "(", "(", "curCount", ...
Constructs this sketch from correct, valid arguments. @param cache in compact form @param empty The correct <a href="{@docRoot}/resources/dictionary.html#empty">Empty</a>. @param seedHash The correct <a href="{@docRoot}/resources/dictionary.html#seedHash">Seed Hash</a>. @param curCount correct value @param thetaLong The correct <a href="{@docRoot}/resources/dictionary.html#thetaLong">thetaLong</a>. @return a CompactSketch
[ "Constructs", "this", "sketch", "from", "correct", "valid", "arguments", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/HeapCompactUnorderedSketch.java#L106-L112
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DirectUpdateDoublesSketch.java
DirectUpdateDoublesSketch.newInstance
static DirectUpdateDoublesSketch newInstance(final int k, final WritableMemory dstMem) { // must be able to hold at least an empty sketch final long memCap = dstMem.getCapacity(); checkDirectMemCapacity(k, 0, memCap); //initialize dstMem dstMem.putLong(0, 0L); //clear pre0 insertPreLongs(dstMem, 2); insertSerVer(dstMem, DoublesSketch.DOUBLES_SER_VER); insertFamilyID(dstMem, Family.QUANTILES.getID()); insertFlags(dstMem, EMPTY_FLAG_MASK); insertK(dstMem, k); if (memCap >= COMBINED_BUFFER) { insertN(dstMem, 0L); insertMinDouble(dstMem, Double.NaN); insertMaxDouble(dstMem, Double.NaN); } final DirectUpdateDoublesSketch dds = new DirectUpdateDoublesSketch(k); dds.mem_ = dstMem; return dds; }
java
static DirectUpdateDoublesSketch newInstance(final int k, final WritableMemory dstMem) { // must be able to hold at least an empty sketch final long memCap = dstMem.getCapacity(); checkDirectMemCapacity(k, 0, memCap); //initialize dstMem dstMem.putLong(0, 0L); //clear pre0 insertPreLongs(dstMem, 2); insertSerVer(dstMem, DoublesSketch.DOUBLES_SER_VER); insertFamilyID(dstMem, Family.QUANTILES.getID()); insertFlags(dstMem, EMPTY_FLAG_MASK); insertK(dstMem, k); if (memCap >= COMBINED_BUFFER) { insertN(dstMem, 0L); insertMinDouble(dstMem, Double.NaN); insertMaxDouble(dstMem, Double.NaN); } final DirectUpdateDoublesSketch dds = new DirectUpdateDoublesSketch(k); dds.mem_ = dstMem; return dds; }
[ "static", "DirectUpdateDoublesSketch", "newInstance", "(", "final", "int", "k", ",", "final", "WritableMemory", "dstMem", ")", "{", "// must be able to hold at least an empty sketch", "final", "long", "memCap", "=", "dstMem", ".", "getCapacity", "(", ")", ";", "checkD...
Obtains a new Direct instance of a DoublesSketch, which may be off-heap. @param k Parameter that controls space usage of sketch and accuracy of estimates. Must be greater than 1 and less than 65536 and a power of 2. @param dstMem the destination Memory that will be initialized to hold the data for this sketch. It must initially be at least (16 * MIN_K + 32) bytes, where MIN_K defaults to 2. As it grows it will request more memory using the MemoryRequest callback. @return a DirectUpdateDoublesSketch
[ "Obtains", "a", "new", "Direct", "instance", "of", "a", "DoublesSketch", "which", "may", "be", "off", "-", "heap", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DirectUpdateDoublesSketch.java#L59-L81
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DirectUpdateDoublesSketch.java
DirectUpdateDoublesSketch.growCombinedMemBuffer
private WritableMemory growCombinedMemBuffer(final int itemSpaceNeeded) { final long memBytes = mem_.getCapacity(); final int needBytes = (itemSpaceNeeded << 3) + COMBINED_BUFFER; //+ preamble + min & max assert needBytes > memBytes; memReqSvr = (memReqSvr == null) ? mem_.getMemoryRequestServer() : memReqSvr; final WritableMemory newMem = memReqSvr.request(needBytes); mem_.copyTo(0, newMem, 0, memBytes); memReqSvr.requestClose(mem_, newMem); return newMem; }
java
private WritableMemory growCombinedMemBuffer(final int itemSpaceNeeded) { final long memBytes = mem_.getCapacity(); final int needBytes = (itemSpaceNeeded << 3) + COMBINED_BUFFER; //+ preamble + min & max assert needBytes > memBytes; memReqSvr = (memReqSvr == null) ? mem_.getMemoryRequestServer() : memReqSvr; final WritableMemory newMem = memReqSvr.request(needBytes); mem_.copyTo(0, newMem, 0, memBytes); memReqSvr.requestClose(mem_, newMem); return newMem; }
[ "private", "WritableMemory", "growCombinedMemBuffer", "(", "final", "int", "itemSpaceNeeded", ")", "{", "final", "long", "memBytes", "=", "mem_", ".", "getCapacity", "(", ")", ";", "final", "int", "needBytes", "=", "(", "itemSpaceNeeded", "<<", "3", ")", "+", ...
Direct supporting methods
[ "Direct", "supporting", "methods" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DirectUpdateDoublesSketch.java#L233-L247
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/sampling/VarOptItemsSketch.java
VarOptItemsSketch.newInstance
public static <T> VarOptItemsSketch<T> newInstance(final int k, final ResizeFactor rf) { return new VarOptItemsSketch<>(k, rf); }
java
public static <T> VarOptItemsSketch<T> newInstance(final int k, final ResizeFactor rf) { return new VarOptItemsSketch<>(k, rf); }
[ "public", "static", "<", "T", ">", "VarOptItemsSketch", "<", "T", ">", "newInstance", "(", "final", "int", "k", ",", "final", "ResizeFactor", "rf", ")", "{", "return", "new", "VarOptItemsSketch", "<>", "(", "k", ",", "rf", ")", ";", "}" ]
Construct a varopt sampling sketch with up to k samples using the specified resize factor. @param k Maximum size of sampling. Allocated size may be smaller until sketch fills. Unlike many sketches in this package, this value does <em>not</em> need to be a power of 2. @param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a> @param <T> The type of object held in the sketch. @return A VarOptItemsSketch initialized with maximum size k and resize factor rf.
[ "Construct", "a", "varopt", "sampling", "sketch", "with", "up", "to", "k", "samples", "using", "the", "specified", "resize", "factor", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/VarOptItemsSketch.java#L192-L194
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/sampling/VarOptItemsSketch.java
VarOptItemsSketch.newInstanceAsGadget
static <T> VarOptItemsSketch<T> newInstanceAsGadget(final int k) { final VarOptItemsSketch<T> sketch = new VarOptItemsSketch<>(k, DEFAULT_RESIZE_FACTOR); sketch.marks_ = new ArrayList<>(sketch.currItemsAlloc_); return sketch; }
java
static <T> VarOptItemsSketch<T> newInstanceAsGadget(final int k) { final VarOptItemsSketch<T> sketch = new VarOptItemsSketch<>(k, DEFAULT_RESIZE_FACTOR); sketch.marks_ = new ArrayList<>(sketch.currItemsAlloc_); return sketch; }
[ "static", "<", "T", ">", "VarOptItemsSketch", "<", "T", ">", "newInstanceAsGadget", "(", "final", "int", "k", ")", "{", "final", "VarOptItemsSketch", "<", "T", ">", "sketch", "=", "new", "VarOptItemsSketch", "<>", "(", "k", ",", "DEFAULT_RESIZE_FACTOR", ")",...
Construct a varopt sketch for use as a unioning gadget, meaning the array of marked elements is also initialized. @param k Maximum size of sampling. Allocated size may be smaller until sketch fills. Unlike many sketches in this package, this value does <em>not</em> need to be a power of 2. @param <T> The type of object held in the sketch. @return A VarOptItemsSketch initialized with maximum size k and a valid array of marks.
[ "Construct", "a", "varopt", "sketch", "for", "use", "as", "a", "unioning", "gadget", "meaning", "the", "array", "of", "marked", "elements", "is", "also", "initialized", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/VarOptItemsSketch.java#L206-L210
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/sampling/VarOptItemsSketch.java
VarOptItemsSketch.copyAndSetN
VarOptItemsSketch<T> copyAndSetN(final boolean asSketch, final long adjustedN) { final VarOptItemsSketch<T> sketch; sketch = new VarOptItemsSketch<>(data_, weights_, k_,n_, currItemsAlloc_, rf_, h_, r_, totalWtR_); if (!asSketch) { sketch.marks_ = this.marks_; sketch.numMarksInH_ = this.numMarksInH_; } if (adjustedN >= 0) { sketch.n_ = adjustedN; } return sketch; }
java
VarOptItemsSketch<T> copyAndSetN(final boolean asSketch, final long adjustedN) { final VarOptItemsSketch<T> sketch; sketch = new VarOptItemsSketch<>(data_, weights_, k_,n_, currItemsAlloc_, rf_, h_, r_, totalWtR_); if (!asSketch) { sketch.marks_ = this.marks_; sketch.numMarksInH_ = this.numMarksInH_; } if (adjustedN >= 0) { sketch.n_ = adjustedN; } return sketch; }
[ "VarOptItemsSketch", "<", "T", ">", "copyAndSetN", "(", "final", "boolean", "asSketch", ",", "final", "long", "adjustedN", ")", "{", "final", "VarOptItemsSketch", "<", "T", ">", "sketch", ";", "sketch", "=", "new", "VarOptItemsSketch", "<>", "(", "data_", ",...
Creates a copy of the sketch, optionally discarding any information about marks that would indicate the class's use as a union gadget as opposed to a valid sketch. @param asSketch If true, copies as a sketch; if false, copies as a union gadget @param adjustedN Target value of n for the resulting sketch. Ignored if negative. @return A copy of the sketch.
[ "Creates", "a", "copy", "of", "the", "sketch", "optionally", "discarding", "any", "information", "about", "marks", "that", "would", "indicate", "the", "class", "s", "use", "as", "a", "union", "gadget", "as", "opposed", "to", "a", "valid", "sketch", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/VarOptItemsSketch.java#L682-L697
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/sampling/VarOptItemsSketch.java
VarOptItemsSketch.decreaseKBy1
void decreaseKBy1() { if (k_ <= 1) { throw new SketchesStateException("Cannot decrease k below 1 in union"); } if ((h_ == 0) && (r_ == 0)) { // exact mode, but no data yet; this reduction is somewhat gratuitous --k_; } else if ((h_ > 0) && (r_ == 0)) { // exact mode, but we have some data --k_; if (h_ > k_) { transitionFromWarmup(); } } else if ((h_ > 0) && (r_ > 0)) { // reservoir mode, but we have some exact samples. // Our strategy will be to pull an item out of H (which we are allowed to do since it's // still just data), reduce k, and then re-insert the item // first, slide the R zone to the left by 1, temporarily filling the gap final int oldGapIdx = h_; final int oldFinalRIdx = (h_ + 1 + r_) - 1; assert oldFinalRIdx == k_; swapValues(oldFinalRIdx, oldGapIdx); // now we pull an item out of H; any item is ok, but if we grab the rightmost and then // reduce h_, the heap invariant will be preserved (and the gap will be restored), plus // the push() of the item that will probably happen later will be cheap. final int pulledIdx = h_ - 1; final T pulledItem = data_.get(pulledIdx); final double pulledWeight = weights_.get(pulledIdx); final boolean pulledMark = marks_.get(pulledIdx); if (pulledMark) { --numMarksInH_; } weights_.set(pulledIdx, -1.0); // to make bugs easier to spot --h_; --k_; --n_; // will be re-incremented with the update update(pulledItem, pulledWeight, pulledMark); } else if ((h_ == 0) && (r_ > 0)) { // pure reservoir mode, so can simply eject a randomly chosen sample from the reservoir assert r_ >= 2; final int rIdxToDelete = 1 + SamplingUtil.rand.nextInt(r_); // 1 for the gap final int rightmostRIdx = (1 + r_) - 1; swapValues(rIdxToDelete, rightmostRIdx); weights_.set(rightmostRIdx, -1.0); --k_; --r_; } }
java
void decreaseKBy1() { if (k_ <= 1) { throw new SketchesStateException("Cannot decrease k below 1 in union"); } if ((h_ == 0) && (r_ == 0)) { // exact mode, but no data yet; this reduction is somewhat gratuitous --k_; } else if ((h_ > 0) && (r_ == 0)) { // exact mode, but we have some data --k_; if (h_ > k_) { transitionFromWarmup(); } } else if ((h_ > 0) && (r_ > 0)) { // reservoir mode, but we have some exact samples. // Our strategy will be to pull an item out of H (which we are allowed to do since it's // still just data), reduce k, and then re-insert the item // first, slide the R zone to the left by 1, temporarily filling the gap final int oldGapIdx = h_; final int oldFinalRIdx = (h_ + 1 + r_) - 1; assert oldFinalRIdx == k_; swapValues(oldFinalRIdx, oldGapIdx); // now we pull an item out of H; any item is ok, but if we grab the rightmost and then // reduce h_, the heap invariant will be preserved (and the gap will be restored), plus // the push() of the item that will probably happen later will be cheap. final int pulledIdx = h_ - 1; final T pulledItem = data_.get(pulledIdx); final double pulledWeight = weights_.get(pulledIdx); final boolean pulledMark = marks_.get(pulledIdx); if (pulledMark) { --numMarksInH_; } weights_.set(pulledIdx, -1.0); // to make bugs easier to spot --h_; --k_; --n_; // will be re-incremented with the update update(pulledItem, pulledWeight, pulledMark); } else if ((h_ == 0) && (r_ > 0)) { // pure reservoir mode, so can simply eject a randomly chosen sample from the reservoir assert r_ >= 2; final int rIdxToDelete = 1 + SamplingUtil.rand.nextInt(r_); // 1 for the gap final int rightmostRIdx = (1 + r_) - 1; swapValues(rIdxToDelete, rightmostRIdx); weights_.set(rightmostRIdx, -1.0); --k_; --r_; } }
[ "void", "decreaseKBy1", "(", ")", "{", "if", "(", "k_", "<=", "1", ")", "{", "throw", "new", "SketchesStateException", "(", "\"Cannot decrease k below 1 in union\"", ")", ";", "}", "if", "(", "(", "h_", "==", "0", ")", "&&", "(", "r_", "==", "0", ")", ...
Decreases sketch's value of k by 1, updating stored values as needed. <p>Subject to certain pre-conditions, decreasing k causes tau to increase. This fact is used by the unioning algorithm to force "marked" items out of H and into the reservoir region.</p>
[ "Decreases", "sketch", "s", "value", "of", "k", "by", "1", "updating", "stored", "values", "as", "needed", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/VarOptItemsSketch.java#L841-L896
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUpdatableSketchBuilder.java
ArrayOfDoublesUpdatableSketchBuilder.build
public ArrayOfDoublesUpdatableSketch build(final WritableMemory dstMem) { return new DirectArrayOfDoublesQuickSelectSketch(nomEntries_, resizeFactor_.lg(), samplingProbability_, numValues_, seed_, dstMem); }
java
public ArrayOfDoublesUpdatableSketch build(final WritableMemory dstMem) { return new DirectArrayOfDoublesQuickSelectSketch(nomEntries_, resizeFactor_.lg(), samplingProbability_, numValues_, seed_, dstMem); }
[ "public", "ArrayOfDoublesUpdatableSketch", "build", "(", "final", "WritableMemory", "dstMem", ")", "{", "return", "new", "DirectArrayOfDoublesQuickSelectSketch", "(", "nomEntries_", ",", "resizeFactor_", ".", "lg", "(", ")", ",", "samplingProbability_", ",", "numValues_...
Returns an ArrayOfDoublesUpdatableSketch with the current configuration of this Builder. @param dstMem instance of Memory to be used by the sketch @return an ArrayOfDoublesUpdatableSketch
[ "Returns", "an", "ArrayOfDoublesUpdatableSketch", "with", "the", "current", "configuration", "of", "this", "Builder", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUpdatableSketchBuilder.java#L113-L116
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.bytesToInt
public static int bytesToInt(final byte[] arr) { int v = 0; for (int i = 0; i < 4; i++) { v |= (arr[i] & 0XFF) << (i * 8); } return v; }
java
public static int bytesToInt(final byte[] arr) { int v = 0; for (int i = 0; i < 4; i++) { v |= (arr[i] & 0XFF) << (i * 8); } return v; }
[ "public", "static", "int", "bytesToInt", "(", "final", "byte", "[", "]", "arr", ")", "{", "int", "v", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "4", ";", "i", "++", ")", "{", "v", "|=", "(", "arr", "[", "i", "]", "&"...
Returns an int extracted from a Little-Endian byte array. @param arr the given byte array @return an int extracted from a Little-Endian byte array.
[ "Returns", "an", "int", "extracted", "from", "a", "Little", "-", "Endian", "byte", "array", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L113-L119
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.bytesToLong
public static long bytesToLong(final byte[] arr) { long v = 0; for (int i = 0; i < 8; i++) { v |= (arr[i] & 0XFFL) << (i * 8); } return v; }
java
public static long bytesToLong(final byte[] arr) { long v = 0; for (int i = 0; i < 8; i++) { v |= (arr[i] & 0XFFL) << (i * 8); } return v; }
[ "public", "static", "long", "bytesToLong", "(", "final", "byte", "[", "]", "arr", ")", "{", "long", "v", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "v", "|=", "(", "arr", "[", "i", "]", ...
Returns a long extracted from a Little-Endian byte array. @param arr the given byte array @return a long extracted from a Little-Endian byte array.
[ "Returns", "a", "long", "extracted", "from", "a", "Little", "-", "Endian", "byte", "array", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L126-L132
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.intToBytes
public static byte[] intToBytes(int v, final byte[] arr) { for (int i = 0; i < 4; i++) { arr[i] = (byte) (v & 0XFF); v >>>= 8; } return arr; }
java
public static byte[] intToBytes(int v, final byte[] arr) { for (int i = 0; i < 4; i++) { arr[i] = (byte) (v & 0XFF); v >>>= 8; } return arr; }
[ "public", "static", "byte", "[", "]", "intToBytes", "(", "int", "v", ",", "final", "byte", "[", "]", "arr", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "4", ";", "i", "++", ")", "{", "arr", "[", "i", "]", "=", "(", "byte", ...
Returns a Little-Endian byte array extracted from the given int. @param v the given int @param arr a given array of 4 bytes that will be returned with the data @return a Little-Endian byte array extracted from the given int.
[ "Returns", "a", "Little", "-", "Endian", "byte", "array", "extracted", "from", "the", "given", "int", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L140-L146
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.longToBytes
public static byte[] longToBytes(long v, final byte[] arr) { for (int i = 0; i < 8; i++) { arr[i] = (byte) (v & 0XFFL); v >>>= 8; } return arr; }
java
public static byte[] longToBytes(long v, final byte[] arr) { for (int i = 0; i < 8; i++) { arr[i] = (byte) (v & 0XFFL); v >>>= 8; } return arr; }
[ "public", "static", "byte", "[", "]", "longToBytes", "(", "long", "v", ",", "final", "byte", "[", "]", "arr", ")", "{", "for", "(", "int", "i", "=", "0", ";", "i", "<", "8", ";", "i", "++", ")", "{", "arr", "[", "i", "]", "=", "(", "byte", ...
Returns a Little-Endian byte array extracted from the given long. @param v the given long @param arr a given array of 8 bytes that will be returned with the data @return a Little-Endian byte array extracted from the given long.
[ "Returns", "a", "Little", "-", "Endian", "byte", "array", "extracted", "from", "the", "given", "long", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L154-L160
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.longToHexBytes
public static String longToHexBytes(final long v) { final long mask = 0XFFL; final StringBuilder sb = new StringBuilder(); for (int i = 8; i-- > 0; ) { final String s = Long.toHexString((v >>> (i * 8)) & mask); sb.append(zeroPad(s, 2)).append(" "); } return sb.toString(); }
java
public static String longToHexBytes(final long v) { final long mask = 0XFFL; final StringBuilder sb = new StringBuilder(); for (int i = 8; i-- > 0; ) { final String s = Long.toHexString((v >>> (i * 8)) & mask); sb.append(zeroPad(s, 2)).append(" "); } return sb.toString(); }
[ "public", "static", "String", "longToHexBytes", "(", "final", "long", "v", ")", "{", "final", "long", "mask", "=", "0XFF", "L", ";", "final", "StringBuilder", "sb", "=", "new", "StringBuilder", "(", ")", ";", "for", "(", "int", "i", "=", "8", ";", "i...
Returns a string of spaced hex bytes in Big-Endian order. @param v the given long @return string of spaced hex bytes in Big-Endian order.
[ "Returns", "a", "string", "of", "spaced", "hex", "bytes", "in", "Big", "-", "Endian", "order", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L169-L177
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.bytesToString
public static String bytesToString( final byte[] arr, final boolean signed, final boolean littleEndian, final String sep) { final StringBuilder sb = new StringBuilder(); final int mask = (signed) ? 0XFFFFFFFF : 0XFF; final int arrLen = arr.length; if (littleEndian) { for (int i = 0; i < (arrLen - 1); i++) { sb.append(arr[i] & mask).append(sep); } sb.append(arr[arrLen - 1] & mask); } else { for (int i = arrLen; i-- > 1; ) { sb.append(arr[i] & mask).append(sep); } sb.append(arr[0] & mask); } return sb.toString(); }
java
public static String bytesToString( final byte[] arr, final boolean signed, final boolean littleEndian, final String sep) { final StringBuilder sb = new StringBuilder(); final int mask = (signed) ? 0XFFFFFFFF : 0XFF; final int arrLen = arr.length; if (littleEndian) { for (int i = 0; i < (arrLen - 1); i++) { sb.append(arr[i] & mask).append(sep); } sb.append(arr[arrLen - 1] & mask); } else { for (int i = arrLen; i-- > 1; ) { sb.append(arr[i] & mask).append(sep); } sb.append(arr[0] & mask); } return sb.toString(); }
[ "public", "static", "String", "bytesToString", "(", "final", "byte", "[", "]", "arr", ",", "final", "boolean", "signed", ",", "final", "boolean", "littleEndian", ",", "final", "String", "sep", ")", "{", "final", "StringBuilder", "sb", "=", "new", "StringBuil...
Returns a string view of a byte array @param arr the given byte array @param signed set true if you want the byte values signed. @param littleEndian set true if you want Little-Endian order @param sep the separator string between bytes @return a string view of a byte array
[ "Returns", "a", "string", "view", "of", "a", "byte", "array" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L187-L204
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.nanoSecToString
public static String nanoSecToString(final long nS) { final long rem_nS = (long)(nS % 1000.0); final long rem_uS = (long)((nS / 1000.0) % 1000.0); final long rem_mS = (long)((nS / 1000000.0) % 1000.0); final long sec = (long)(nS / 1000000000.0); final String nSstr = zeroPad(Long.toString(rem_nS), 3); final String uSstr = zeroPad(Long.toString(rem_uS), 3); final String mSstr = zeroPad(Long.toString(rem_mS), 3); return String.format("%d.%3s_%3s_%3s", sec, mSstr, uSstr, nSstr); }
java
public static String nanoSecToString(final long nS) { final long rem_nS = (long)(nS % 1000.0); final long rem_uS = (long)((nS / 1000.0) % 1000.0); final long rem_mS = (long)((nS / 1000000.0) % 1000.0); final long sec = (long)(nS / 1000000000.0); final String nSstr = zeroPad(Long.toString(rem_nS), 3); final String uSstr = zeroPad(Long.toString(rem_uS), 3); final String mSstr = zeroPad(Long.toString(rem_mS), 3); return String.format("%d.%3s_%3s_%3s", sec, mSstr, uSstr, nSstr); }
[ "public", "static", "String", "nanoSecToString", "(", "final", "long", "nS", ")", "{", "final", "long", "rem_nS", "=", "(", "long", ")", "(", "nS", "%", "1000.0", ")", ";", "final", "long", "rem_uS", "=", "(", "long", ")", "(", "(", "nS", "/", "100...
Returns the given time in nanoseconds formatted as Sec.mSec uSec nSec @param nS the given nanoseconds @return the given time in nanoseconds formatted as Sec.mSec uSec nSec
[ "Returns", "the", "given", "time", "in", "nanoseconds", "formatted", "as", "Sec", ".", "mSec", "uSec", "nSec" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L211-L220
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.characterPad
public static final String characterPad(final String s, final int fieldLength, final char padChar, final boolean postpend) { final char[] chArr = s.toCharArray(); final int sLen = chArr.length; if (sLen < fieldLength) { final char[] out = new char[fieldLength]; final int blanks = fieldLength - sLen; if (postpend) { for (int i = 0; i < sLen; i++) { out[i] = chArr[i]; } for (int i = sLen; i < fieldLength; i++) { out[i] = padChar; } } else { //prepend for (int i = 0; i < blanks; i++) { out[i] = padChar; } for (int i = blanks; i < fieldLength; i++) { out[i] = chArr[i - blanks]; } } return String.valueOf(out); } return s; }
java
public static final String characterPad(final String s, final int fieldLength, final char padChar, final boolean postpend) { final char[] chArr = s.toCharArray(); final int sLen = chArr.length; if (sLen < fieldLength) { final char[] out = new char[fieldLength]; final int blanks = fieldLength - sLen; if (postpend) { for (int i = 0; i < sLen; i++) { out[i] = chArr[i]; } for (int i = sLen; i < fieldLength; i++) { out[i] = padChar; } } else { //prepend for (int i = 0; i < blanks; i++) { out[i] = padChar; } for (int i = blanks; i < fieldLength; i++) { out[i] = chArr[i - blanks]; } } return String.valueOf(out); } return s; }
[ "public", "static", "final", "String", "characterPad", "(", "final", "String", "s", ",", "final", "int", "fieldLength", ",", "final", "char", "padChar", ",", "final", "boolean", "postpend", ")", "{", "final", "char", "[", "]", "chArr", "=", "s", ".", "to...
Prepend or postpend the given string with the given character to fill the given field length. If the given string is equal or greater than the given field length, it will be returned without modification. @param s the given string @param fieldLength the desired field length @param padChar the desired pad character @param postpend if true append the pacCharacters to the end of the string. @return prepended or postpended given string with the given character to fill the given field length.
[ "Prepend", "or", "postpend", "the", "given", "string", "with", "the", "given", "character", "to", "fill", "the", "given", "field", "length", ".", "If", "the", "given", "string", "is", "equal", "or", "greater", "than", "the", "given", "field", "length", "it...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L260-L287
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.computeSeedHash
public static short computeSeedHash(final long seed) { final long[] seedArr = {seed}; final short seedHash = (short)((hash(seedArr, 0L)[0]) & 0xFFFFL); if (seedHash == 0) { throw new SketchesArgumentException( "The given seed: " + seed + " produced a seedHash of zero. " + "You must choose a different seed."); } return seedHash; }
java
public static short computeSeedHash(final long seed) { final long[] seedArr = {seed}; final short seedHash = (short)((hash(seedArr, 0L)[0]) & 0xFFFFL); if (seedHash == 0) { throw new SketchesArgumentException( "The given seed: " + seed + " produced a seedHash of zero. " + "You must choose a different seed."); } return seedHash; }
[ "public", "static", "short", "computeSeedHash", "(", "final", "long", "seed", ")", "{", "final", "long", "[", "]", "seedArr", "=", "{", "seed", "}", ";", "final", "short", "seedHash", "=", "(", "short", ")", "(", "(", "hash", "(", "seedArr", ",", "0L...
Computes and checks the 16-bit seed hash from the given long seed. The seed hash may not be zero in order to maintain compatibility with older serialized versions that did not have this concept. @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a> @return the seed hash.
[ "Computes", "and", "checks", "the", "16", "-", "bit", "seed", "hash", "from", "the", "given", "long", "seed", ".", "The", "seed", "hash", "may", "not", "be", "zero", "in", "order", "to", "maintain", "compatibility", "with", "older", "serialized", "versions...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L312-L321
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.checkIfMultipleOf8AndGT0
public static void checkIfMultipleOf8AndGT0(final long v, final String argName) { if (((v & 0X7L) == 0L) && (v > 0L)) { return; } throw new SketchesArgumentException("The value of the parameter \"" + argName + "\" must be a positive multiple of 8 and greater than zero: " + v); }
java
public static void checkIfMultipleOf8AndGT0(final long v, final String argName) { if (((v & 0X7L) == 0L) && (v > 0L)) { return; } throw new SketchesArgumentException("The value of the parameter \"" + argName + "\" must be a positive multiple of 8 and greater than zero: " + v); }
[ "public", "static", "void", "checkIfMultipleOf8AndGT0", "(", "final", "long", "v", ",", "final", "String", "argName", ")", "{", "if", "(", "(", "(", "v", "&", "0X7", "L", ")", "==", "0L", ")", "&&", "(", "v", ">", "0L", ")", ")", "{", "return", "...
Checks if parameter v is a multiple of 8 and greater than zero. @param v The parameter to check @param argName This name will be part of the error message if the check fails.
[ "Checks", "if", "parameter", "v", "is", "a", "multiple", "of", "8", "and", "greater", "than", "zero", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L330-L336
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.checkIfPowerOf2
public static void checkIfPowerOf2(final int v, final String argName) { if ((v > 0) && ((v & (v - 1)) == 0)) { return; } throw new SketchesArgumentException("The value of the parameter \"" + argName + "\" must be a positive integer-power of 2" + " and greater than 0: " + v); }
java
public static void checkIfPowerOf2(final int v, final String argName) { if ((v > 0) && ((v & (v - 1)) == 0)) { return; } throw new SketchesArgumentException("The value of the parameter \"" + argName + "\" must be a positive integer-power of 2" + " and greater than 0: " + v); }
[ "public", "static", "void", "checkIfPowerOf2", "(", "final", "int", "v", ",", "final", "String", "argName", ")", "{", "if", "(", "(", "v", ">", "0", ")", "&&", "(", "(", "v", "&", "(", "v", "-", "1", ")", ")", "==", "0", ")", ")", "{", "retur...
Checks the given parameter to make sure it is positive, an integer-power of 2 and greater than zero. @param v The input argument. @param argName Used in the thrown exception.
[ "Checks", "the", "given", "parameter", "to", "make", "sure", "it", "is", "positive", "an", "integer", "-", "power", "of", "2", "and", "greater", "than", "zero", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L366-L372
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.toLog2
public static int toLog2(final int value, final String argName) { checkIfPowerOf2(value, argName); return Integer.numberOfTrailingZeros(value); }
java
public static int toLog2(final int value, final String argName) { checkIfPowerOf2(value, argName); return Integer.numberOfTrailingZeros(value); }
[ "public", "static", "int", "toLog2", "(", "final", "int", "value", ",", "final", "String", "argName", ")", "{", "checkIfPowerOf2", "(", "value", ",", "argName", ")", ";", "return", "Integer", ".", "numberOfTrailingZeros", "(", "value", ")", ";", "}" ]
Checks the given value if it is a power of 2. If not, it throws an exception. Otherwise, returns the log-base2 of the given value. @param value must be a power of 2 and greater than zero. @param argName the argument name used in the exception if thrown. @return the log-base2 of the given value
[ "Checks", "the", "given", "value", "if", "it", "is", "a", "power", "of", "2", ".", "If", "not", "it", "throws", "an", "exception", ".", "Otherwise", "returns", "the", "log", "-", "base2", "of", "the", "given", "value", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L381-L384
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.evenlyLgSpaced
public static int[] evenlyLgSpaced(final int lgStart, final int lgEnd, final int points) { if (points <= 0) { throw new SketchesArgumentException("points must be > 0"); } if ((lgEnd < 0) || (lgStart < 0)) { throw new SketchesArgumentException("lgStart and lgEnd must be >= 0."); } final int[] out = new int[points]; out[0] = 1 << lgStart; if (points == 1) { return out; } final double delta = (lgEnd - lgStart) / (points - 1.0); for (int i = 1; i < points; i++) { final double mXpY = (delta * i) + lgStart; out[i] = (int)round(pow(2, mXpY)); } return out; }
java
public static int[] evenlyLgSpaced(final int lgStart, final int lgEnd, final int points) { if (points <= 0) { throw new SketchesArgumentException("points must be > 0"); } if ((lgEnd < 0) || (lgStart < 0)) { throw new SketchesArgumentException("lgStart and lgEnd must be >= 0."); } final int[] out = new int[points]; out[0] = 1 << lgStart; if (points == 1) { return out; } final double delta = (lgEnd - lgStart) / (points - 1.0); for (int i = 1; i < points; i++) { final double mXpY = (delta * i) + lgStart; out[i] = (int)round(pow(2, mXpY)); } return out; }
[ "public", "static", "int", "[", "]", "evenlyLgSpaced", "(", "final", "int", "lgStart", ",", "final", "int", "lgEnd", ",", "final", "int", "points", ")", "{", "if", "(", "points", "<=", "0", ")", "{", "throw", "new", "SketchesArgumentException", "(", "\"p...
Returns an int array of points that will be evenly spaced on a log axis. This is designed for Log_base2 numbers. @param lgStart the Log_base2 of the starting value. E.g., for 1 lgStart = 0. @param lgEnd the Log_base2 of the ending value. E.g. for 1024 lgEnd = 10. @param points the total number of points including the starting and ending values. @return an int array of points that will be evenly spaced on a log axis.
[ "Returns", "an", "int", "array", "of", "points", "that", "will", "be", "evenly", "spaced", "on", "a", "log", "axis", ".", "This", "is", "designed", "for", "Log_base2", "numbers", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L447-L463
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.simpleIntLog2
public static int simpleIntLog2(final int x) { final int exp = Integer.numberOfTrailingZeros(x); if (x != (1 << exp)) { throw new SketchesArgumentException("Argument x cannot be negative or zero."); } return exp; }
java
public static int simpleIntLog2(final int x) { final int exp = Integer.numberOfTrailingZeros(x); if (x != (1 << exp)) { throw new SketchesArgumentException("Argument x cannot be negative or zero."); } return exp; }
[ "public", "static", "int", "simpleIntLog2", "(", "final", "int", "x", ")", "{", "final", "int", "exp", "=", "Integer", ".", "numberOfTrailingZeros", "(", "x", ")", ";", "if", "(", "x", "!=", "(", "1", "<<", "exp", ")", ")", "{", "throw", "new", "Sk...
Gives the log2 of an integer that is known to be a power of 2. @param x number that is greater than zero @return the log2 of an integer that is known to be a power of 2.
[ "Gives", "the", "log2", "of", "an", "integer", "that", "is", "known", "to", "be", "a", "power", "of", "2", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L544-L550
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/Util.java
Util.startingSubMultiple
public static final int startingSubMultiple(final int lgTarget, final ResizeFactor rf, final int lgMin) { final int lgRF = rf.lg(); return (lgTarget <= lgMin) ? lgMin : (lgRF == 0) ? lgTarget : ((lgTarget - lgMin) % lgRF) + lgMin; }
java
public static final int startingSubMultiple(final int lgTarget, final ResizeFactor rf, final int lgMin) { final int lgRF = rf.lg(); return (lgTarget <= lgMin) ? lgMin : (lgRF == 0) ? lgTarget : ((lgTarget - lgMin) % lgRF) + lgMin; }
[ "public", "static", "final", "int", "startingSubMultiple", "(", "final", "int", "lgTarget", ",", "final", "ResizeFactor", "rf", ",", "final", "int", "lgMin", ")", "{", "final", "int", "lgRF", "=", "rf", ".", "lg", "(", ")", ";", "return", "(", "lgTarget"...
Gets the smallest allowed exponent of 2 that it is a sub-multiple of the target by zero, one or more resize factors. @param lgTarget Log2 of the target size @param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a> @param lgMin Log2 of the minimum allowed starting size @return The Log2 of the starting size
[ "Gets", "the", "smallest", "allowed", "exponent", "of", "2", "that", "it", "is", "a", "sub", "-", "multiple", "of", "the", "target", "by", "zero", "one", "or", "more", "resize", "factors", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/Util.java#L561-L565
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/UpdateSketch.java
UpdateSketch.heapify
public static UpdateSketch heapify(final Memory srcMem, final long seed) { final Family family = Family.idToFamily(srcMem.getByte(FAMILY_BYTE)); if (family.equals(Family.ALPHA)) { return HeapAlphaSketch.heapifyInstance(srcMem, seed); } return HeapQuickSelectSketch.heapifyInstance(srcMem, seed); }
java
public static UpdateSketch heapify(final Memory srcMem, final long seed) { final Family family = Family.idToFamily(srcMem.getByte(FAMILY_BYTE)); if (family.equals(Family.ALPHA)) { return HeapAlphaSketch.heapifyInstance(srcMem, seed); } return HeapQuickSelectSketch.heapifyInstance(srcMem, seed); }
[ "public", "static", "UpdateSketch", "heapify", "(", "final", "Memory", "srcMem", ",", "final", "long", "seed", ")", "{", "final", "Family", "family", "=", "Family", ".", "idToFamily", "(", "srcMem", ".", "getByte", "(", "FAMILY_BYTE", ")", ")", ";", "if", ...
Instantiates an on-heap UpdateSketch from Memory. @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a> @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>. @return an UpdateSketch
[ "Instantiates", "an", "on", "-", "heap", "UpdateSketch", "from", "Memory", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UpdateSketch.java#L107-L113
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/UpdateSketch.java
UpdateSketch.update
public UpdateReturnState update(final String datum) { if ((datum == null) || datum.isEmpty()) { return RejectedNullOrEmpty; } final byte[] data = datum.getBytes(UTF_8); return hashUpdate(hash(data, getSeed())[0] >>> 1); }
java
public UpdateReturnState update(final String datum) { if ((datum == null) || datum.isEmpty()) { return RejectedNullOrEmpty; } final byte[] data = datum.getBytes(UTF_8); return hashUpdate(hash(data, getSeed())[0] >>> 1); }
[ "public", "UpdateReturnState", "update", "(", "final", "String", "datum", ")", "{", "if", "(", "(", "datum", "==", "null", ")", "||", "datum", ".", "isEmpty", "(", ")", ")", "{", "return", "RejectedNullOrEmpty", ";", "}", "final", "byte", "[", "]", "da...
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. <p>Note: this will not produce the same output hash values as the {@link #update(char[])} method and will generally be a little slower depending on the complexity of the UTF8 encoding. </p> @param datum The given String. @return <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
[ "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", "ma...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UpdateSketch.java#L229-L235
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/theta/UpdateSketch.java
UpdateSketch.update
public UpdateReturnState update(final byte[] data) { if ((data == null) || (data.length == 0)) { return RejectedNullOrEmpty; } return hashUpdate(hash(data, getSeed())[0] >>> 1); }
java
public UpdateReturnState update(final byte[] data) { if ((data == null) || (data.length == 0)) { return RejectedNullOrEmpty; } return hashUpdate(hash(data, getSeed())[0] >>> 1); }
[ "public", "UpdateReturnState", "update", "(", "final", "byte", "[", "]", "data", ")", "{", "if", "(", "(", "data", "==", "null", ")", "||", "(", "data", ".", "length", "==", "0", ")", ")", "{", "return", "RejectedNullOrEmpty", ";", "}", "return", "ha...
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. @param data The given byte array. @return <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
[ "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", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UpdateSketch.java#L245-L250
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java
DoublesSketch.heapify
public static DoublesSketch heapify(final Memory srcMem) { if (checkIsCompactMemory(srcMem)) { return CompactDoublesSketch.heapify(srcMem); } return UpdateDoublesSketch.heapify(srcMem); }
java
public static DoublesSketch heapify(final Memory srcMem) { if (checkIsCompactMemory(srcMem)) { return CompactDoublesSketch.heapify(srcMem); } return UpdateDoublesSketch.heapify(srcMem); }
[ "public", "static", "DoublesSketch", "heapify", "(", "final", "Memory", "srcMem", ")", "{", "if", "(", "checkIsCompactMemory", "(", "srcMem", ")", ")", "{", "return", "CompactDoublesSketch", ".", "heapify", "(", "srcMem", ")", ";", "}", "return", "UpdateDouble...
Heapify takes the sketch image in Memory and instantiates an on-heap Sketch. The resulting sketch will not retain any link to the source Memory. @param srcMem a Memory image of a Sketch. <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a> @return a heap-based Sketch based on the given Memory
[ "Heapify", "takes", "the", "sketch", "image", "in", "Memory", "and", "instantiates", "an", "on", "-", "heap", "Sketch", ".", "The", "resulting", "sketch", "will", "not", "retain", "any", "link", "to", "the", "source", "Memory", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java#L167-L172
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java
DoublesSketch.wrap
public static DoublesSketch wrap(final Memory srcMem) { if (checkIsCompactMemory(srcMem)) { return DirectCompactDoublesSketch.wrapInstance(srcMem); } return DirectUpdateDoublesSketchR.wrapInstance(srcMem); }
java
public static DoublesSketch wrap(final Memory srcMem) { if (checkIsCompactMemory(srcMem)) { return DirectCompactDoublesSketch.wrapInstance(srcMem); } return DirectUpdateDoublesSketchR.wrapInstance(srcMem); }
[ "public", "static", "DoublesSketch", "wrap", "(", "final", "Memory", "srcMem", ")", "{", "if", "(", "checkIsCompactMemory", "(", "srcMem", ")", ")", "{", "return", "DirectCompactDoublesSketch", ".", "wrapInstance", "(", "srcMem", ")", ";", "}", "return", "Dire...
Wrap this sketch around the given Memory image of a DoublesSketch, compact or non-compact. @param srcMem the given Memory image of a DoublesSketch that may have data, @return a sketch that wraps the given srcMem
[ "Wrap", "this", "sketch", "around", "the", "given", "Memory", "image", "of", "a", "DoublesSketch", "compact", "or", "non", "-", "compact", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java#L180-L185
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java
DoublesSketch.downSample
public DoublesSketch downSample(final DoublesSketch srcSketch, final int smallerK, final WritableMemory dstMem) { return downSampleInternal(srcSketch, smallerK, dstMem); }
java
public DoublesSketch downSample(final DoublesSketch srcSketch, final int smallerK, final WritableMemory dstMem) { return downSampleInternal(srcSketch, smallerK, dstMem); }
[ "public", "DoublesSketch", "downSample", "(", "final", "DoublesSketch", "srcSketch", ",", "final", "int", "smallerK", ",", "final", "WritableMemory", "dstMem", ")", "{", "return", "downSampleInternal", "(", "srcSketch", ",", "smallerK", ",", "dstMem", ")", ";", ...
From an source sketch, create a new sketch that must have a smaller value of K. The original sketch is not modified. @param srcSketch the sourcing sketch @param smallerK the new sketch's value of K that must be smaller than this value of K. It is required that this.getK() = smallerK * 2^(nonnegative integer). @param dstMem the destination Memory. It must not overlap the Memory of this sketch. If null, a heap sketch will be returned, otherwise it will be off-heap. @return the new sketch.
[ "From", "an", "source", "sketch", "create", "a", "new", "sketch", "that", "must", "have", "a", "smaller", "value", "of", "K", ".", "The", "original", "sketch", "is", "not", "modified", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java#L601-L604
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java
DoublesSketch.putMemory
public void putMemory(final WritableMemory dstMem, final boolean compact) { if (isDirect() && (isCompact() == compact)) { final Memory srcMem = getMemory(); srcMem.copyTo(0, dstMem, 0, getStorageBytes()); } else { final byte[] byteArr = toByteArray(compact); final int arrLen = byteArr.length; final long memCap = dstMem.getCapacity(); if (memCap < arrLen) { throw new SketchesArgumentException( "Destination Memory not large enough: " + memCap + " < " + arrLen); } dstMem.putByteArray(0, byteArr, 0, arrLen); } }
java
public void putMemory(final WritableMemory dstMem, final boolean compact) { if (isDirect() && (isCompact() == compact)) { final Memory srcMem = getMemory(); srcMem.copyTo(0, dstMem, 0, getStorageBytes()); } else { final byte[] byteArr = toByteArray(compact); final int arrLen = byteArr.length; final long memCap = dstMem.getCapacity(); if (memCap < arrLen) { throw new SketchesArgumentException( "Destination Memory not large enough: " + memCap + " < " + arrLen); } dstMem.putByteArray(0, byteArr, 0, arrLen); } }
[ "public", "void", "putMemory", "(", "final", "WritableMemory", "dstMem", ",", "final", "boolean", "compact", ")", "{", "if", "(", "isDirect", "(", ")", "&&", "(", "isCompact", "(", ")", "==", "compact", ")", ")", "{", "final", "Memory", "srcMem", "=", ...
Puts the current sketch into the given Memory if there is sufficient space, otherwise, throws an error. @param dstMem the given memory. @param compact if true, compacts and sorts the base buffer, which optimizes merge performance at the cost of slightly increased serialization time.
[ "Puts", "the", "current", "sketch", "into", "the", "given", "Memory", "if", "there", "is", "sufficient", "space", "otherwise", "throws", "an", "error", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesSketch.java#L693-L707
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/QuantilesHelper.java
QuantilesHelper.convertToPrecedingCummulative
public static long convertToPrecedingCummulative(final long[] array) { long subtotal = 0; for (int i = 0; i < array.length; i++) { final long newSubtotal = subtotal + array[i]; array[i] = subtotal; subtotal = newSubtotal; } return subtotal; }
java
public static long convertToPrecedingCummulative(final long[] array) { long subtotal = 0; for (int i = 0; i < array.length; i++) { final long newSubtotal = subtotal + array[i]; array[i] = subtotal; subtotal = newSubtotal; } return subtotal; }
[ "public", "static", "long", "convertToPrecedingCummulative", "(", "final", "long", "[", "]", "array", ")", "{", "long", "subtotal", "=", "0", ";", "for", "(", "int", "i", "=", "0", ";", "i", "<", "array", ".", "length", ";", "i", "++", ")", "{", "f...
Convert the weights into totals of the weights preceding each item @param array of weights @return total weight
[ "Convert", "the", "weights", "into", "totals", "of", "the", "weights", "preceding", "each", "item" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/QuantilesHelper.java#L18-L26
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/QuantilesHelper.java
QuantilesHelper.chunkContainingPos
public static int chunkContainingPos(final long[] arr, final long pos) { final int nominalLength = arr.length - 1; /* remember, arr contains an "extra" position */ assert nominalLength > 0; final long n = arr[nominalLength]; assert 0 <= pos; assert pos < n; final int l = 0; final int r = nominalLength; // the following three asserts should probably be retained since they ensure // that the necessary invariants hold at the beginning of the search assert l < r; assert arr[l] <= pos; assert pos < arr[r]; return searchForChunkContainingPos(arr, pos, l, r); }
java
public static int chunkContainingPos(final long[] arr, final long pos) { final int nominalLength = arr.length - 1; /* remember, arr contains an "extra" position */ assert nominalLength > 0; final long n = arr[nominalLength]; assert 0 <= pos; assert pos < n; final int l = 0; final int r = nominalLength; // the following three asserts should probably be retained since they ensure // that the necessary invariants hold at the beginning of the search assert l < r; assert arr[l] <= pos; assert pos < arr[r]; return searchForChunkContainingPos(arr, pos, l, r); }
[ "public", "static", "int", "chunkContainingPos", "(", "final", "long", "[", "]", "arr", ",", "final", "long", "pos", ")", "{", "final", "int", "nominalLength", "=", "arr", ".", "length", "-", "1", ";", "/* remember, arr contains an \"extra\" position */", "asser...
This is written in terms of a plain array to facilitate testing. @param arr the chunk containing the position @param pos the position @return the index of the chunk containing the position
[ "This", "is", "written", "in", "terms", "of", "a", "plain", "array", "to", "facilitate", "testing", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/QuantilesHelper.java#L46-L60
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/tuple/AnotB.java
AnotB.getResult
public CompactSketch<S> getResult() { if (count_ == 0) { return new CompactSketch<S>(null, null, theta_, isEmpty_); } final CompactSketch<S> result = new CompactSketch<S>(Arrays.copyOfRange(keys_, 0, count_), Arrays.copyOfRange(summaries_, 0, count_), theta_, isEmpty_); reset(); return result; }
java
public CompactSketch<S> getResult() { if (count_ == 0) { return new CompactSketch<S>(null, null, theta_, isEmpty_); } final CompactSketch<S> result = new CompactSketch<S>(Arrays.copyOfRange(keys_, 0, count_), Arrays.copyOfRange(summaries_, 0, count_), theta_, isEmpty_); reset(); return result; }
[ "public", "CompactSketch", "<", "S", ">", "getResult", "(", ")", "{", "if", "(", "count_", "==", "0", ")", "{", "return", "new", "CompactSketch", "<", "S", ">", "(", "null", ",", "null", ",", "theta_", ",", "isEmpty_", ")", ";", "}", "final", "Comp...
Gets the result of this operation @return the result of this operation as a CompactSketch
[ "Gets", "the", "result", "of", "this", "operation" ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/AnotB.java#L74-L83
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/quantiles/ItemsUtil.java
ItemsUtil.validateValues
static final <T> void validateValues(final T[] values, final Comparator<? super T> comparator) { final int lenM1 = values.length - 1; for (int j = 0; j < lenM1; j++) { if ((values[j] != null) && (values[j + 1] != null) && (comparator.compare(values[j], values[j + 1]) < 0)) { continue; } throw new SketchesArgumentException( "Values must be unique, monotonically increasing and not null."); } }
java
static final <T> void validateValues(final T[] values, final Comparator<? super T> comparator) { final int lenM1 = values.length - 1; for (int j = 0; j < lenM1; j++) { if ((values[j] != null) && (values[j + 1] != null) && (comparator.compare(values[j], values[j + 1]) < 0)) { continue; } throw new SketchesArgumentException( "Values must be unique, monotonically increasing and not null."); } }
[ "static", "final", "<", "T", ">", "void", "validateValues", "(", "final", "T", "[", "]", "values", ",", "final", "Comparator", "<", "?", "super", "T", ">", "comparator", ")", "{", "final", "int", "lenM1", "=", "values", ".", "length", "-", "1", ";", ...
Checks the sequential validity of the given array of values. They must be unique, monotonically increasing and not null. @param <T> the data type @param values given array of values @param comparator the comparator for data type T
[ "Checks", "the", "sequential", "validity", "of", "the", "given", "array", "of", "values", ".", "They", "must", "be", "unique", "monotonically", "increasing", "and", "not", "null", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsUtil.java#L49-L59
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/cpc/PairTable.java
PairTable.rebuild
PairTable rebuild(final int newLgSizeInts) { checkLgSizeInts(newLgSizeInts); final int newSize = 1 << newLgSizeInts; final int oldSize = 1 << lgSizeInts; rtAssert(newSize > numPairs); final int[] oldSlotsArr = slotsArr; slotsArr = new int[newSize]; Arrays.fill(slotsArr, -1); lgSizeInts = newLgSizeInts; for (int i = 0; i < oldSize; i++) { final int item = oldSlotsArr[i]; if (item != -1) { mustInsert(this, item); } } return this; }
java
PairTable rebuild(final int newLgSizeInts) { checkLgSizeInts(newLgSizeInts); final int newSize = 1 << newLgSizeInts; final int oldSize = 1 << lgSizeInts; rtAssert(newSize > numPairs); final int[] oldSlotsArr = slotsArr; slotsArr = new int[newSize]; Arrays.fill(slotsArr, -1); lgSizeInts = newLgSizeInts; for (int i = 0; i < oldSize; i++) { final int item = oldSlotsArr[i]; if (item != -1) { mustInsert(this, item); } } return this; }
[ "PairTable", "rebuild", "(", "final", "int", "newLgSizeInts", ")", "{", "checkLgSizeInts", "(", "newLgSizeInts", ")", ";", "final", "int", "newSize", "=", "1", "<<", "newLgSizeInts", ";", "final", "int", "oldSize", "=", "1", "<<", "lgSizeInts", ";", "rtAsser...
Rebuilds to a larger size. NumItems and validBits remain unchanged. @param newLgSizeInts the new size @return a larger PairTable
[ "Rebuilds", "to", "a", "larger", "size", ".", "NumItems", "and", "validBits", "remain", "unchanged", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/PairTable.java#L99-L113
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/cpc/PairTable.java
PairTable.unwrappingGetItems
static int[] unwrappingGetItems(final PairTable table, final int numPairs) { if (numPairs < 1) { return null; } final int[] slotsArr = table.slotsArr; final int tableSize = 1 << table.lgSizeInts; final int[] result = new int[numPairs]; int i = 0; int l = 0; int r = numPairs - 1; // Special rules for the region before the first empty slot. final int hiBit = 1 << (table.validBits - 1); while ((i < tableSize) && (slotsArr[i] != -1)) { final int item = slotsArr[i++]; if ((item & hiBit) != 0) { result[r--] = item; } // This item was probably wrapped, so move to end. else { result[l++] = item; } } // The rest of the table is processed normally. while (i < tableSize) { final int look = slotsArr[i++]; if (look != -1) { result[l++] = look; } } assert l == (r + 1); return result; }
java
static int[] unwrappingGetItems(final PairTable table, final int numPairs) { if (numPairs < 1) { return null; } final int[] slotsArr = table.slotsArr; final int tableSize = 1 << table.lgSizeInts; final int[] result = new int[numPairs]; int i = 0; int l = 0; int r = numPairs - 1; // Special rules for the region before the first empty slot. final int hiBit = 1 << (table.validBits - 1); while ((i < tableSize) && (slotsArr[i] != -1)) { final int item = slotsArr[i++]; if ((item & hiBit) != 0) { result[r--] = item; } // This item was probably wrapped, so move to end. else { result[l++] = item; } } // The rest of the table is processed normally. while (i < tableSize) { final int look = slotsArr[i++]; if (look != -1) { result[l++] = look; } } assert l == (r + 1); return result; }
[ "static", "int", "[", "]", "unwrappingGetItems", "(", "final", "PairTable", "table", ",", "final", "int", "numPairs", ")", "{", "if", "(", "numPairs", "<", "1", ")", "{", "return", "null", ";", "}", "final", "int", "[", "]", "slotsArr", "=", "table", ...
While extracting the items from a linear probing hashtable, this will usually undo the wrap-around provided that the table isn't too full. Experiments suggest that for sufficiently large tables the load factor would have to be over 90 percent before this would fail frequently, and even then the subsequent sort would fix things up. @param table the given table to unwrap @param numPairs the number of valid pairs in the table @return the unwrapped table
[ "While", "extracting", "the", "items", "from", "a", "linear", "probing", "hashtable", "this", "will", "usually", "undo", "the", "wrap", "-", "around", "provided", "that", "the", "table", "isn", "t", "too", "full", ".", "Experiments", "suggest", "that", "for"...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/PairTable.java#L222-L246
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/cpc/PairTable.java
PairTable.introspectiveInsertionSort
static void introspectiveInsertionSort(final int[] a, final int l, final int r) { final int length = (r - l) + 1; long cost = 0; final long costLimit = 8L * length; for (int i = l + 1; i <= r; i++) { int j = i; final long v = a[i] & 0XFFFF_FFFFL; //v must be long while ((j >= (l + 1)) && (v < ((a[j - 1]) & 0XFFFF_FFFFL))) { a[j] = a[j - 1]; j -= 1; } a[j] = (int) v; cost += (i - j); // distance moved is a measure of work if (cost > costLimit) { //we need an unsigned sort, but it is linear time and very rarely occurs final long[] b = new long[a.length]; for (int m = 0; m < a.length; m++) { b[m] = a[m] & 0XFFFF_FFFFL; } Arrays.sort(b, l, r + 1); for (int m = 0; m < a.length; m++) { a[m] = (int) b[m]; } // The following sanity check can be used during development //int bad = 0; //for (int m = l; m < (r - 1); m++) { // final long b1 = a[m] & 0XFFFF_FFFFL; // final long b2 = a[m + 1] & 0XFFFF_FFFFL; // if (b1 > b2) { bad++; } //} //assert (bad == 0); return; } } // The following sanity check can be used during development // int bad = 0; // for (int m = l; m < (r - 1); m++) { // final long b1 = a[m] & 0XFFFF_FFFFL; // final long b2 = a[m + 1] & 0XFFFF_FFFFL; // if (b1 > b2) { bad++; } // } // assert (bad == 0); }
java
static void introspectiveInsertionSort(final int[] a, final int l, final int r) { final int length = (r - l) + 1; long cost = 0; final long costLimit = 8L * length; for (int i = l + 1; i <= r; i++) { int j = i; final long v = a[i] & 0XFFFF_FFFFL; //v must be long while ((j >= (l + 1)) && (v < ((a[j - 1]) & 0XFFFF_FFFFL))) { a[j] = a[j - 1]; j -= 1; } a[j] = (int) v; cost += (i - j); // distance moved is a measure of work if (cost > costLimit) { //we need an unsigned sort, but it is linear time and very rarely occurs final long[] b = new long[a.length]; for (int m = 0; m < a.length; m++) { b[m] = a[m] & 0XFFFF_FFFFL; } Arrays.sort(b, l, r + 1); for (int m = 0; m < a.length; m++) { a[m] = (int) b[m]; } // The following sanity check can be used during development //int bad = 0; //for (int m = l; m < (r - 1); m++) { // final long b1 = a[m] & 0XFFFF_FFFFL; // final long b2 = a[m + 1] & 0XFFFF_FFFFL; // if (b1 > b2) { bad++; } //} //assert (bad == 0); return; } } // The following sanity check can be used during development // int bad = 0; // for (int m = l; m < (r - 1); m++) { // final long b1 = a[m] & 0XFFFF_FFFFL; // final long b2 = a[m + 1] & 0XFFFF_FFFFL; // if (b1 > b2) { bad++; } // } // assert (bad == 0); }
[ "static", "void", "introspectiveInsertionSort", "(", "final", "int", "[", "]", "a", ",", "final", "int", "l", ",", "final", "int", "r", ")", "{", "final", "int", "length", "=", "(", "r", "-", "l", ")", "+", "1", ";", "long", "cost", "=", "0", ";"...
In applications where the input array is already nearly sorted, insertion sort runs in linear time with a very small constant. This introspective version of insertion sort protects against the quadratic cost of sorting bad input arrays. It keeps track of how much work has been done, and if that exceeds a constant times the array length, it switches to a different sorting algorithm. @param a the array to sort @param l points AT the leftmost element, i.e., inclusive. @param r points AT the rightmost element, i.e., inclusive.
[ "In", "applications", "where", "the", "input", "array", "is", "already", "nearly", "sorted", "insertion", "sort", "runs", "in", "linear", "time", "with", "a", "very", "small", "constant", ".", "This", "introspective", "version", "of", "insertion", "sort", "pro...
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/PairTable.java#L259-L298
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hllmap/UniqueCountMap.java
UniqueCountMap.update
public double update(final byte[] key, final byte[] identifier) { if (key == null) { return Double.NaN; } checkMethodKeySize(key); if (identifier == null) { return getEstimate(key); } final short coupon = (short) Map.coupon16(identifier); final int baseMapIndex = maps_[0].findOrInsertKey(key); final double baseMapEstimate = maps_[0].update(baseMapIndex, coupon); if (baseMapEstimate > 0) { return baseMapEstimate; } final int level = -(int) baseMapEstimate; // base map is level 0 if (level == 0) { return promote(key, coupon, maps_[0], baseMapIndex, level, baseMapIndex, 0); } final Map map = maps_[level]; final int index = map.findOrInsertKey(key); final double estimate = map.update(index, coupon); if (estimate > 0) { return estimate; } return promote(key, coupon, map, index, level, baseMapIndex, -estimate); }
java
public double update(final byte[] key, final byte[] identifier) { if (key == null) { return Double.NaN; } checkMethodKeySize(key); if (identifier == null) { return getEstimate(key); } final short coupon = (short) Map.coupon16(identifier); final int baseMapIndex = maps_[0].findOrInsertKey(key); final double baseMapEstimate = maps_[0].update(baseMapIndex, coupon); if (baseMapEstimate > 0) { return baseMapEstimate; } final int level = -(int) baseMapEstimate; // base map is level 0 if (level == 0) { return promote(key, coupon, maps_[0], baseMapIndex, level, baseMapIndex, 0); } final Map map = maps_[level]; final int index = map.findOrInsertKey(key); final double estimate = map.update(index, coupon); if (estimate > 0) { return estimate; } return promote(key, coupon, map, index, level, baseMapIndex, -estimate); }
[ "public", "double", "update", "(", "final", "byte", "[", "]", "key", ",", "final", "byte", "[", "]", "identifier", ")", "{", "if", "(", "key", "==", "null", ")", "{", "return", "Double", ".", "NaN", ";", "}", "checkMethodKeySize", "(", "key", ")", ...
Updates the map with a given key and identifier and returns the estimate of the number of unique identifiers encountered so far for the given key. @param key the given key @param identifier the given identifier for unique counting associated with the key @return the estimate of the number of unique identifiers encountered so far for the given key.
[ "Updates", "the", "map", "with", "a", "given", "key", "and", "identifier", "and", "returns", "the", "estimate", "of", "the", "number", "of", "unique", "identifiers", "encountered", "so", "far", "for", "the", "given", "key", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hllmap/UniqueCountMap.java#L111-L130
train
DataSketches/sketches-core
src/main/java/com/yahoo/sketches/hllmap/UniqueCountMap.java
UniqueCountMap.getEstimate
public double getEstimate(final byte[] key) { if (key == null) { return Double.NaN; } checkMethodKeySize(key); final double est = maps_[0].getEstimate(key); if (est >= 0.0) { return est; } //key has been promoted final int level = -(int)est; final Map map = maps_[level]; return map.getEstimate(key); }
java
public double getEstimate(final byte[] key) { if (key == null) { return Double.NaN; } checkMethodKeySize(key); final double est = maps_[0].getEstimate(key); if (est >= 0.0) { return est; } //key has been promoted final int level = -(int)est; final Map map = maps_[level]; return map.getEstimate(key); }
[ "public", "double", "getEstimate", "(", "final", "byte", "[", "]", "key", ")", "{", "if", "(", "key", "==", "null", ")", "{", "return", "Double", ".", "NaN", ";", "}", "checkMethodKeySize", "(", "key", ")", ";", "final", "double", "est", "=", "maps_"...
Retrieves the current estimate of unique count for a given key. @param key given key @return estimate of unique count so far
[ "Retrieves", "the", "current", "estimate", "of", "unique", "count", "for", "a", "given", "key", "." ]
900c8c9668a1e2f1d54d453e956caad54702e540
https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hllmap/UniqueCountMap.java#L137-L146
train