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/theta/SingleItemSketch.java | SingleItemSketch.create | public static SingleItemSketch create(final long datum, final long seed) {
final long[] data = { datum };
return new SingleItemSketch(hash(data, seed)[0] >>> 1);
} | java | public static SingleItemSketch create(final long datum, final long seed) {
final long[] data = { datum };
return new SingleItemSketch(hash(data, seed)[0] >>> 1);
} | [
"public",
"static",
"SingleItemSketch",
"create",
"(",
"final",
"long",
"datum",
",",
"final",
"long",
"seed",
")",
"{",
"final",
"long",
"[",
"]",
"data",
"=",
"{",
"datum",
"}",
";",
"return",
"new",
"SingleItemSketch",
"(",
"hash",
"(",
"data",
",",
... | Create this sketch with a long and a seed.
@param datum The given long datum.
@param seed used to hash the given value.
@return a SingleItemSketch | [
"Create",
"this",
"sketch",
"with",
"a",
"long",
"and",
"a",
"seed",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/SingleItemSketch.java#L184-L187 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/SingleItemSketch.java | SingleItemSketch.create | public static SingleItemSketch create(final String datum, final long seed) {
if ((datum == null) || datum.isEmpty()) { return null; }
final byte[] data = datum.getBytes(UTF_8);
return new SingleItemSketch(hash(data, seed)[0] >>> 1, seed);
} | java | public static SingleItemSketch create(final String datum, final long seed) {
if ((datum == null) || datum.isEmpty()) { return null; }
final byte[] data = datum.getBytes(UTF_8);
return new SingleItemSketch(hash(data, seed)[0] >>> 1, seed);
} | [
"public",
"static",
"SingleItemSketch",
"create",
"(",
"final",
"String",
"datum",
",",
"final",
"long",
"seed",
")",
"{",
"if",
"(",
"(",
"datum",
"==",
"null",
")",
"||",
"datum",
".",
"isEmpty",
"(",
")",
")",
"{",
"return",
"null",
";",
"}",
"fin... | Create this sketch with the given String and a seed.
The string is converted to a byte array using UTF8 encoding.
If the string is null or empty no create attempt is made and the method returns null.
<p>Note: this will not produce the same output hash values as the {@link #create(char[])}
method and will generally be a little slower depending on the complexity of the UTF8 encoding.
</p>
@param datum The given String.
@param seed used to hash the given value.
@return a SingleItemSketch or null | [
"Create",
"this",
"sketch",
"with",
"the",
"given",
"String",
"and",
"a",
"seed",
".",
"The",
"string",
"is",
"converted",
"to",
"a",
"byte",
"array",
"using",
"UTF8",
"encoding",
".",
"If",
"the",
"string",
"is",
"null",
"or",
"empty",
"no",
"create",
... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/SingleItemSketch.java#L219-L223 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/SingleItemSketch.java | SingleItemSketch.create | public static SingleItemSketch create(final byte[] data, final long seed) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, seed)[0] >>> 1, seed);
} | java | public static SingleItemSketch create(final byte[] data, final long seed) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, seed)[0] >>> 1, seed);
} | [
"public",
"static",
"SingleItemSketch",
"create",
"(",
"final",
"byte",
"[",
"]",
"data",
",",
"final",
"long",
"seed",
")",
"{",
"if",
"(",
"(",
"data",
"==",
"null",
")",
"||",
"(",
"data",
".",
"length",
"==",
"0",
")",
")",
"{",
"return",
"null... | Create this sketch with the given byte array and a seed.
If the byte array is null or empty no create attempt is made and the method returns null.
@param data The given byte array.
@param seed used to hash the given value.
@return a SingleItemSketch or null | [
"Create",
"this",
"sketch",
"with",
"the",
"given",
"byte",
"array",
"and",
"a",
"seed",
".",
"If",
"the",
"byte",
"array",
"is",
"null",
"or",
"empty",
"no",
"create",
"attempt",
"is",
"made",
"and",
"the",
"method",
"returns",
"null",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/SingleItemSketch.java#L233-L236 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/QuickSelectSketch.java | QuickSelectSketch.reset | public void reset() {
isEmpty_ = true;
count_ = 0;
theta_ = (long) (Long.MAX_VALUE * (double) samplingProbability_);
final int startingCapacity = Util.getStartingCapacity(nomEntries_, lgResizeFactor_);
lgCurrentCapacity_ = Integer.numberOfTrailingZeros(startingCapacity);
keys_ = new long[startingCapacity];
summaries_ = null; // wait for the first summary to call Array.newInstance()
setRebuildThreshold();
} | java | public void reset() {
isEmpty_ = true;
count_ = 0;
theta_ = (long) (Long.MAX_VALUE * (double) samplingProbability_);
final int startingCapacity = Util.getStartingCapacity(nomEntries_, lgResizeFactor_);
lgCurrentCapacity_ = Integer.numberOfTrailingZeros(startingCapacity);
keys_ = new long[startingCapacity];
summaries_ = null; // wait for the first summary to call Array.newInstance()
setRebuildThreshold();
} | [
"public",
"void",
"reset",
"(",
")",
"{",
"isEmpty_",
"=",
"true",
";",
"count_",
"=",
"0",
";",
"theta_",
"=",
"(",
"long",
")",
"(",
"Long",
".",
"MAX_VALUE",
"*",
"(",
"double",
")",
"samplingProbability_",
")",
";",
"final",
"int",
"startingCapacit... | Resets this sketch an empty state. | [
"Resets",
"this",
"sketch",
"an",
"empty",
"state",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/QuickSelectSketch.java#L239-L248 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/QuickSelectSketch.java | QuickSelectSketch.compact | @SuppressWarnings("unchecked")
public CompactSketch<S> compact() {
if (getRetainedEntries() == 0) {
return new CompactSketch<>(null, null, theta_, isEmpty_);
}
final long[] keys = new long[getRetainedEntries()];
final S[] summaries = (S[])
Array.newInstance(summaries_.getClass().getComponentType(), getRetainedEntries());
int i = 0;
for (int j = 0; j < keys_.length; j++) {
if (summaries_[j] != null) {
keys[i] = keys_[j];
summaries[i] = (S)summaries_[j].copy();
i++;
}
}
return new CompactSketch<>(keys, summaries, theta_, isEmpty_);
} | java | @SuppressWarnings("unchecked")
public CompactSketch<S> compact() {
if (getRetainedEntries() == 0) {
return new CompactSketch<>(null, null, theta_, isEmpty_);
}
final long[] keys = new long[getRetainedEntries()];
final S[] summaries = (S[])
Array.newInstance(summaries_.getClass().getComponentType(), getRetainedEntries());
int i = 0;
for (int j = 0; j < keys_.length; j++) {
if (summaries_[j] != null) {
keys[i] = keys_[j];
summaries[i] = (S)summaries_[j].copy();
i++;
}
}
return new CompactSketch<>(keys, summaries, theta_, isEmpty_);
} | [
"@",
"SuppressWarnings",
"(",
"\"unchecked\"",
")",
"public",
"CompactSketch",
"<",
"S",
">",
"compact",
"(",
")",
"{",
"if",
"(",
"getRetainedEntries",
"(",
")",
"==",
"0",
")",
"{",
"return",
"new",
"CompactSketch",
"<>",
"(",
"null",
",",
"null",
",",... | Converts the current state of the sketch into a compact sketch
@return compact sketch | [
"Converts",
"the",
"current",
"state",
"of",
"the",
"sketch",
"into",
"a",
"compact",
"sketch"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/QuickSelectSketch.java#L254-L271 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/sampling/VarOptItemsUnion.java | VarOptItemsUnion.getResult | public VarOptItemsSketch<T> getResult() {
// If no marked items in H, gadget is already valid mathematically. We can return what is
// basically just a copy of the gadget.
if (gadget_.getNumMarksInH() == 0) {
return simpleGadgetCoercer();
} else {
// At this point, we know that marked items are present in H. So:
// 1. Result will necessarily be in estimation mode
// 2. Marked items currently in H need to be absorbed into reservoir (R)
final VarOptItemsSketch<T> tmp = detectAndHandleSubcaseOfPseudoExact();
if (tmp != null) {
// sub-case detected and handled, so return the result
return tmp;
} else {
// continue with main logic
return migrateMarkedItemsByDecreasingK();
}
}
} | java | public VarOptItemsSketch<T> getResult() {
// If no marked items in H, gadget is already valid mathematically. We can return what is
// basically just a copy of the gadget.
if (gadget_.getNumMarksInH() == 0) {
return simpleGadgetCoercer();
} else {
// At this point, we know that marked items are present in H. So:
// 1. Result will necessarily be in estimation mode
// 2. Marked items currently in H need to be absorbed into reservoir (R)
final VarOptItemsSketch<T> tmp = detectAndHandleSubcaseOfPseudoExact();
if (tmp != null) {
// sub-case detected and handled, so return the result
return tmp;
} else {
// continue with main logic
return migrateMarkedItemsByDecreasingK();
}
}
} | [
"public",
"VarOptItemsSketch",
"<",
"T",
">",
"getResult",
"(",
")",
"{",
"// If no marked items in H, gadget is already valid mathematically. We can return what is",
"// basically just a copy of the gadget.",
"if",
"(",
"gadget_",
".",
"getNumMarksInH",
"(",
")",
"==",
"0",
... | Gets the varopt sketch resulting from the union of any input sketches.
@return A varopt sketch | [
"Gets",
"the",
"varopt",
"sketch",
"resulting",
"from",
"the",
"union",
"of",
"any",
"input",
"sketches",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/VarOptItemsUnion.java#L229-L247 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/sampling/VarOptItemsUnion.java | VarOptItemsUnion.markMovingGadgetCoercer | private VarOptItemsSketch<T> markMovingGadgetCoercer() {
final int resultK = gadget_.getHRegionCount() + gadget_.getRRegionCount();
int resultH = 0;
int resultR = 0;
int nextRPos = resultK; // = (resultK+1)-1, to fill R region from back to front
final ArrayList<T> data = new ArrayList<>(resultK + 1);
final ArrayList<Double> weights = new ArrayList<>(resultK + 1);
// Need arrays filled to use set() and be able to fill from end forward.
// Ideally would create as arrays but trying to avoid forcing user to pass a Class<?>
for (int i = 0; i < (resultK + 1); ++i) {
data.add(null);
weights.add(null);
}
final VarOptItemsSamples<T> sketchSamples = gadget_.getSketchSamples();
// insert R region items, ignoring weights
// Currently (May 2017) this next block is unreachable; this coercer is used only in the
// pseudo-exact case in which case there are no items natively in R, only marked items in H
// that will be moved into R as part of the coercion process.
Iterator<VarOptItemsSamples<T>.WeightedSample> sketchIterator;
sketchIterator = sketchSamples.getRIterator();
while (sketchIterator.hasNext()) {
final VarOptItemsSamples<T>.WeightedSample ws = sketchIterator.next();
data.set(nextRPos, ws.getItem());
weights.set(nextRPos, -1.0);
++resultR;
--nextRPos;
}
double transferredWeight = 0;
// insert H region items
sketchIterator = sketchSamples.getHIterator();
while (sketchIterator.hasNext()) {
final VarOptItemsSamples<T>.WeightedSample ws = sketchIterator.next();
if (ws.getMark()) {
data.set(nextRPos, ws.getItem());
weights.set(nextRPos, -1.0);
transferredWeight += ws.getWeight();
++resultR;
--nextRPos;
} else {
data.set(resultH, ws.getItem());
weights.set(resultH, ws.getWeight());
++resultH;
}
}
assert (resultH + resultR) == resultK;
assert Math.abs(transferredWeight - outerTauNumer) < 1e-10;
final double resultRWeight = gadget_.getTotalWtR() + transferredWeight;
final long resultN = n_;
// explicitly set values for the gap
data.set(resultH, null);
weights.set(resultH, -1.0);
// create sketch with the new values
return newInstanceFromUnionResult(data, weights, resultK, resultN, resultH, resultR, resultRWeight);
} | java | private VarOptItemsSketch<T> markMovingGadgetCoercer() {
final int resultK = gadget_.getHRegionCount() + gadget_.getRRegionCount();
int resultH = 0;
int resultR = 0;
int nextRPos = resultK; // = (resultK+1)-1, to fill R region from back to front
final ArrayList<T> data = new ArrayList<>(resultK + 1);
final ArrayList<Double> weights = new ArrayList<>(resultK + 1);
// Need arrays filled to use set() and be able to fill from end forward.
// Ideally would create as arrays but trying to avoid forcing user to pass a Class<?>
for (int i = 0; i < (resultK + 1); ++i) {
data.add(null);
weights.add(null);
}
final VarOptItemsSamples<T> sketchSamples = gadget_.getSketchSamples();
// insert R region items, ignoring weights
// Currently (May 2017) this next block is unreachable; this coercer is used only in the
// pseudo-exact case in which case there are no items natively in R, only marked items in H
// that will be moved into R as part of the coercion process.
Iterator<VarOptItemsSamples<T>.WeightedSample> sketchIterator;
sketchIterator = sketchSamples.getRIterator();
while (sketchIterator.hasNext()) {
final VarOptItemsSamples<T>.WeightedSample ws = sketchIterator.next();
data.set(nextRPos, ws.getItem());
weights.set(nextRPos, -1.0);
++resultR;
--nextRPos;
}
double transferredWeight = 0;
// insert H region items
sketchIterator = sketchSamples.getHIterator();
while (sketchIterator.hasNext()) {
final VarOptItemsSamples<T>.WeightedSample ws = sketchIterator.next();
if (ws.getMark()) {
data.set(nextRPos, ws.getItem());
weights.set(nextRPos, -1.0);
transferredWeight += ws.getWeight();
++resultR;
--nextRPos;
} else {
data.set(resultH, ws.getItem());
weights.set(resultH, ws.getWeight());
++resultH;
}
}
assert (resultH + resultR) == resultK;
assert Math.abs(transferredWeight - outerTauNumer) < 1e-10;
final double resultRWeight = gadget_.getTotalWtR() + transferredWeight;
final long resultN = n_;
// explicitly set values for the gap
data.set(resultH, null);
weights.set(resultH, -1.0);
// create sketch with the new values
return newInstanceFromUnionResult(data, weights, resultK, resultN, resultH, resultR, resultRWeight);
} | [
"private",
"VarOptItemsSketch",
"<",
"T",
">",
"markMovingGadgetCoercer",
"(",
")",
"{",
"final",
"int",
"resultK",
"=",
"gadget_",
".",
"getHRegionCount",
"(",
")",
"+",
"gadget_",
".",
"getRRegionCount",
"(",
")",
";",
"int",
"resultH",
"=",
"0",
";",
"i... | This coercer directly transfers marked items from the gadget's H into the result's R.
Deciding whether that is a valid thing to do is the responsibility of the caller. Currently,
this is only used for a subcase of pseudo-exact, but later it might be used by other
subcases as well.
@return A sketch derived from the gadget, with marked items moved to the reservoir | [
"This",
"coercer",
"directly",
"transfers",
"marked",
"items",
"from",
"the",
"gadget",
"s",
"H",
"into",
"the",
"result",
"s",
"R",
".",
"Deciding",
"whether",
"that",
"is",
"a",
"valid",
"thing",
"to",
"do",
"is",
"the",
"responsibility",
"of",
"the",
... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/sampling/VarOptItemsUnion.java#L476-L538 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/CompactSketch.java | CompactSketch.compactCache | static final long[] compactCache(final long[] srcCache, final int curCount,
final long thetaLong, final boolean dstOrdered) {
if (curCount == 0) {
return new long[0];
}
final long[] cacheOut = new long[curCount];
final int len = srcCache.length;
int j = 0;
for (int i = 0; i < len; i++) { //scan the full srcCache
final long v = srcCache[i];
if ((v <= 0L) || (v >= thetaLong) ) { continue; } //ignoring zeros or dirty values
cacheOut[j++] = v;
}
assert curCount == j;
if (dstOrdered && (curCount > 1)) {
Arrays.sort(cacheOut);
}
return cacheOut;
} | java | static final long[] compactCache(final long[] srcCache, final int curCount,
final long thetaLong, final boolean dstOrdered) {
if (curCount == 0) {
return new long[0];
}
final long[] cacheOut = new long[curCount];
final int len = srcCache.length;
int j = 0;
for (int i = 0; i < len; i++) { //scan the full srcCache
final long v = srcCache[i];
if ((v <= 0L) || (v >= thetaLong) ) { continue; } //ignoring zeros or dirty values
cacheOut[j++] = v;
}
assert curCount == j;
if (dstOrdered && (curCount > 1)) {
Arrays.sort(cacheOut);
}
return cacheOut;
} | [
"static",
"final",
"long",
"[",
"]",
"compactCache",
"(",
"final",
"long",
"[",
"]",
"srcCache",
",",
"final",
"int",
"curCount",
",",
"final",
"long",
"thetaLong",
",",
"final",
"boolean",
"dstOrdered",
")",
"{",
"if",
"(",
"curCount",
"==",
"0",
")",
... | Compact the given array. The source cache can be a hash table with interstitial zeros or
"dirty" values.
@param srcCache anything
@param curCount must be correct
@param thetaLong The correct
<a href="{@docRoot}/resources/dictionary.html#thetaLong">thetaLong</a>.
@param dstOrdered true if output array must be sorted
@return the compacted array | [
"Compact",
"the",
"given",
"array",
".",
"The",
"source",
"cache",
"can",
"be",
"a",
"hash",
"table",
"with",
"interstitial",
"zeros",
"or",
"dirty",
"values",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/CompactSketch.java#L72-L90 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/CompactSketch.java | CompactSketch.compactCachePart | static final long[] compactCachePart(final long[] srcCache, final int lgArrLongs,
final int curCount, final long thetaLong, final boolean dstOrdered) {
if (curCount == 0) {
return new long[0];
}
final long[] cacheOut = new long[curCount];
final int len = 1 << lgArrLongs;
int j = 0;
for (int i = 0; i < len; i++) {
final long v = srcCache[i];
if ((v <= 0L) || (v >= thetaLong) ) { continue; }
cacheOut[j++] = v;
}
assert curCount == j;
if (dstOrdered) {
Arrays.sort(cacheOut);
}
return cacheOut;
} | java | static final long[] compactCachePart(final long[] srcCache, final int lgArrLongs,
final int curCount, final long thetaLong, final boolean dstOrdered) {
if (curCount == 0) {
return new long[0];
}
final long[] cacheOut = new long[curCount];
final int len = 1 << lgArrLongs;
int j = 0;
for (int i = 0; i < len; i++) {
final long v = srcCache[i];
if ((v <= 0L) || (v >= thetaLong) ) { continue; }
cacheOut[j++] = v;
}
assert curCount == j;
if (dstOrdered) {
Arrays.sort(cacheOut);
}
return cacheOut;
} | [
"static",
"final",
"long",
"[",
"]",
"compactCachePart",
"(",
"final",
"long",
"[",
"]",
"srcCache",
",",
"final",
"int",
"lgArrLongs",
",",
"final",
"int",
"curCount",
",",
"final",
"long",
"thetaLong",
",",
"final",
"boolean",
"dstOrdered",
")",
"{",
"if... | Compact first 2^lgArrLongs of given array
@param srcCache anything
@param lgArrLongs The correct
<a href="{@docRoot}/resources/dictionary.html#lgArrLongs">lgArrLongs</a>.
@param curCount must be correct
@param thetaLong The correct
<a href="{@docRoot}/resources/dictionary.html#thetaLong">thetaLong</a>.
@param dstOrdered true if output array must be sorted
@return the compacted array | [
"Compact",
"first",
"2^lgArrLongs",
"of",
"given",
"array"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/CompactSketch.java#L103-L121 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/CompactSketch.java | CompactSketch.loadCompactMemory | static final Memory loadCompactMemory(final long[] compactCache, final short seedHash,
final int curCount, final long thetaLong, final WritableMemory dstMem,
final byte flags, final int preLongs) {
assert (dstMem != null) && (compactCache != null);
final int outLongs = preLongs + curCount;
final int outBytes = outLongs << 3;
final int dstBytes = (int) dstMem.getCapacity();
if (outBytes > dstBytes) {
throw new SketchesArgumentException("Insufficient Memory: " + dstBytes
+ ", Need: " + outBytes);
}
final byte famID = (byte) Family.COMPACT.getID();
insertPreLongs(dstMem, preLongs); //RF not used = 0
insertSerVer(dstMem, SER_VER);
insertFamilyID(dstMem, famID);
//ignore lgNomLongs, lgArrLongs bytes for compact sketches
insertFlags(dstMem, flags);
insertSeedHash(dstMem, seedHash);
if ((preLongs == 1) && (curCount == 1)) { //singleItem
dstMem.putLong(8, compactCache[0]);
return dstMem;
}
if (preLongs > 1) {
insertCurCount(dstMem, curCount);
insertP(dstMem, (float) 1.0);
}
if (preLongs > 2) {
insertThetaLong(dstMem, thetaLong);
}
if (curCount > 0) {
dstMem.putLongArray(preLongs << 3, compactCache, 0, curCount);
}
return dstMem;
} | java | static final Memory loadCompactMemory(final long[] compactCache, final short seedHash,
final int curCount, final long thetaLong, final WritableMemory dstMem,
final byte flags, final int preLongs) {
assert (dstMem != null) && (compactCache != null);
final int outLongs = preLongs + curCount;
final int outBytes = outLongs << 3;
final int dstBytes = (int) dstMem.getCapacity();
if (outBytes > dstBytes) {
throw new SketchesArgumentException("Insufficient Memory: " + dstBytes
+ ", Need: " + outBytes);
}
final byte famID = (byte) Family.COMPACT.getID();
insertPreLongs(dstMem, preLongs); //RF not used = 0
insertSerVer(dstMem, SER_VER);
insertFamilyID(dstMem, famID);
//ignore lgNomLongs, lgArrLongs bytes for compact sketches
insertFlags(dstMem, flags);
insertSeedHash(dstMem, seedHash);
if ((preLongs == 1) && (curCount == 1)) { //singleItem
dstMem.putLong(8, compactCache[0]);
return dstMem;
}
if (preLongs > 1) {
insertCurCount(dstMem, curCount);
insertP(dstMem, (float) 1.0);
}
if (preLongs > 2) {
insertThetaLong(dstMem, thetaLong);
}
if (curCount > 0) {
dstMem.putLongArray(preLongs << 3, compactCache, 0, curCount);
}
return dstMem;
} | [
"static",
"final",
"Memory",
"loadCompactMemory",
"(",
"final",
"long",
"[",
"]",
"compactCache",
",",
"final",
"short",
"seedHash",
",",
"final",
"int",
"curCount",
",",
"final",
"long",
"thetaLong",
",",
"final",
"WritableMemory",
"dstMem",
",",
"final",
"by... | compactCache and dstMem must be valid | [
"compactCache",
"and",
"dstMem",
"must",
"be",
"valid"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/CompactSketch.java#L124-L160 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/frequencies/LongsSketch.java | LongsSketch.getInstance | public static LongsSketch getInstance(final String string) {
final String[] tokens = string.split(",");
if (tokens.length < (STR_PREAMBLE_TOKENS + 2)) {
throw new SketchesArgumentException(
"String not long enough: " + tokens.length);
}
final int serVer = Integer.parseInt(tokens[0]);
final int famID = Integer.parseInt(tokens[1]);
final int lgMax = Integer.parseInt(tokens[2]);
final int flags = Integer.parseInt(tokens[3]);
final long streamWt = Long.parseLong(tokens[4]);
final long offset = Long.parseLong(tokens[5]); //error offset
//should always get at least the next 2 from the map
final int numActive = Integer.parseInt(tokens[6]);
final int lgCur = Integer.numberOfTrailingZeros(Integer.parseInt(tokens[7]));
//checks
if (serVer != SER_VER) {
throw new SketchesArgumentException("Possible Corruption: Bad SerVer: " + serVer);
}
Family.FREQUENCY.checkFamilyID(famID);
final boolean empty = flags > 0;
if (!empty && (numActive == 0)) {
throw new SketchesArgumentException(
"Possible Corruption: !Empty && NumActive=0; strLen: " + numActive);
}
final int numTokens = tokens.length;
if ((2 * numActive) != (numTokens - STR_PREAMBLE_TOKENS - 2)) {
throw new SketchesArgumentException(
"Possible Corruption: Incorrect # of tokens: " + numTokens
+ ", numActive: " + numActive);
}
final LongsSketch sketch = new LongsSketch(lgMax, lgCur);
sketch.streamWeight = streamWt;
sketch.offset = offset;
sketch.hashMap = deserializeFromStringArray(tokens);
return sketch;
} | java | public static LongsSketch getInstance(final String string) {
final String[] tokens = string.split(",");
if (tokens.length < (STR_PREAMBLE_TOKENS + 2)) {
throw new SketchesArgumentException(
"String not long enough: " + tokens.length);
}
final int serVer = Integer.parseInt(tokens[0]);
final int famID = Integer.parseInt(tokens[1]);
final int lgMax = Integer.parseInt(tokens[2]);
final int flags = Integer.parseInt(tokens[3]);
final long streamWt = Long.parseLong(tokens[4]);
final long offset = Long.parseLong(tokens[5]); //error offset
//should always get at least the next 2 from the map
final int numActive = Integer.parseInt(tokens[6]);
final int lgCur = Integer.numberOfTrailingZeros(Integer.parseInt(tokens[7]));
//checks
if (serVer != SER_VER) {
throw new SketchesArgumentException("Possible Corruption: Bad SerVer: " + serVer);
}
Family.FREQUENCY.checkFamilyID(famID);
final boolean empty = flags > 0;
if (!empty && (numActive == 0)) {
throw new SketchesArgumentException(
"Possible Corruption: !Empty && NumActive=0; strLen: " + numActive);
}
final int numTokens = tokens.length;
if ((2 * numActive) != (numTokens - STR_PREAMBLE_TOKENS - 2)) {
throw new SketchesArgumentException(
"Possible Corruption: Incorrect # of tokens: " + numTokens
+ ", numActive: " + numActive);
}
final LongsSketch sketch = new LongsSketch(lgMax, lgCur);
sketch.streamWeight = streamWt;
sketch.offset = offset;
sketch.hashMap = deserializeFromStringArray(tokens);
return sketch;
} | [
"public",
"static",
"LongsSketch",
"getInstance",
"(",
"final",
"String",
"string",
")",
"{",
"final",
"String",
"[",
"]",
"tokens",
"=",
"string",
".",
"split",
"(",
"\",\"",
")",
";",
"if",
"(",
"tokens",
".",
"length",
"<",
"(",
"STR_PREAMBLE_TOKENS",
... | Returns a sketch instance of this class from the given String,
which must be a String representation of this sketch class.
@param string a String representation of a sketch of this class.
@return a sketch instance of this class. | [
"Returns",
"a",
"sketch",
"instance",
"of",
"this",
"class",
"from",
"the",
"given",
"String",
"which",
"must",
"be",
"a",
"String",
"representation",
"of",
"this",
"sketch",
"class",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/frequencies/LongsSketch.java#L275-L313 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/frequencies/LongsSketch.java | LongsSketch.serializeToString | public String serializeToString() {
final StringBuilder sb = new StringBuilder();
//start the string with parameters of the sketch
final int serVer = SER_VER; //0
final int famID = Family.FREQUENCY.getID(); //1
final int lgMaxMapSz = lgMaxMapSize; //2
final int flags = (hashMap.getNumActive() == 0) ? EMPTY_FLAG_MASK : 0; //3
final String fmt = "%d,%d,%d,%d,%d,%d,";
final String s =
String.format(fmt, serVer, famID, lgMaxMapSz, flags, streamWeight, offset);
sb.append(s);
sb.append(hashMap.serializeToString()); //numActive, curMaplen, key[i], value[i], ...
// maxMapCap, samplesize are deterministic functions of maxMapSize,
// so we don't need them in the serialization
return sb.toString();
} | java | public String serializeToString() {
final StringBuilder sb = new StringBuilder();
//start the string with parameters of the sketch
final int serVer = SER_VER; //0
final int famID = Family.FREQUENCY.getID(); //1
final int lgMaxMapSz = lgMaxMapSize; //2
final int flags = (hashMap.getNumActive() == 0) ? EMPTY_FLAG_MASK : 0; //3
final String fmt = "%d,%d,%d,%d,%d,%d,";
final String s =
String.format(fmt, serVer, famID, lgMaxMapSz, flags, streamWeight, offset);
sb.append(s);
sb.append(hashMap.serializeToString()); //numActive, curMaplen, key[i], value[i], ...
// maxMapCap, samplesize are deterministic functions of maxMapSize,
// so we don't need them in the serialization
return sb.toString();
} | [
"public",
"String",
"serializeToString",
"(",
")",
"{",
"final",
"StringBuilder",
"sb",
"=",
"new",
"StringBuilder",
"(",
")",
";",
"//start the string with parameters of the sketch",
"final",
"int",
"serVer",
"=",
"SER_VER",
";",
"//0",
"final",
"int",
"famID",
"... | Returns a String representation of this sketch
@return a String representation of this sketch | [
"Returns",
"a",
"String",
"representation",
"of",
"this",
"sketch"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/frequencies/LongsSketch.java#L522-L537 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/frequencies/LongsSketch.java | LongsSketch.deserializeFromStringArray | static ReversePurgeLongHashMap deserializeFromStringArray(final String[] tokens) {
final int ignore = STR_PREAMBLE_TOKENS;
final int numActive = Integer.parseInt(tokens[ignore]);
final int length = Integer.parseInt(tokens[ignore + 1]);
final ReversePurgeLongHashMap hashMap = new ReversePurgeLongHashMap(length);
int j = 2 + ignore;
for (int i = 0; i < numActive; i++) {
final long key = Long.parseLong(tokens[j++]);
final long value = Long.parseLong(tokens[j++]);
hashMap.adjustOrPutValue(key, value);
}
return hashMap;
} | java | static ReversePurgeLongHashMap deserializeFromStringArray(final String[] tokens) {
final int ignore = STR_PREAMBLE_TOKENS;
final int numActive = Integer.parseInt(tokens[ignore]);
final int length = Integer.parseInt(tokens[ignore + 1]);
final ReversePurgeLongHashMap hashMap = new ReversePurgeLongHashMap(length);
int j = 2 + ignore;
for (int i = 0; i < numActive; i++) {
final long key = Long.parseLong(tokens[j++]);
final long value = Long.parseLong(tokens[j++]);
hashMap.adjustOrPutValue(key, value);
}
return hashMap;
} | [
"static",
"ReversePurgeLongHashMap",
"deserializeFromStringArray",
"(",
"final",
"String",
"[",
"]",
"tokens",
")",
"{",
"final",
"int",
"ignore",
"=",
"STR_PREAMBLE_TOKENS",
";",
"final",
"int",
"numActive",
"=",
"Integer",
".",
"parseInt",
"(",
"tokens",
"[",
... | Deserializes an array of String tokens into a hash map object of this class.
@param tokens the given array of Strings tokens.
@return a hash map object of this class | [
"Deserializes",
"an",
"array",
"of",
"String",
"tokens",
"into",
"a",
"hash",
"map",
"object",
"of",
"this",
"class",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/frequencies/LongsSketch.java#L793-L805 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hllmap/HllMap.java | HllMap.findKey | @Override
final int findKey(final byte[] key) {
final int keyLen = key.length;
final long[] hash = MurmurHash3.hash(key, SEED);
int entryIndex = getIndex(hash[0], tableEntries_);
final int stride = getStride(hash[1], tableEntries_);
final int loopIndex = entryIndex;
do {
if (isBitClear(stateArr_, entryIndex)) { //check if slot is empty
return ~entryIndex;
}
if (arraysEqual(key, 0, keysArr_, entryIndex * keyLen, keyLen)) { //check for key match
return entryIndex;
}
entryIndex = (entryIndex + stride) % tableEntries_;
} while (entryIndex != loopIndex);
throw new SketchesArgumentException("Key not found and no empty slots!");
} | java | @Override
final int findKey(final byte[] key) {
final int keyLen = key.length;
final long[] hash = MurmurHash3.hash(key, SEED);
int entryIndex = getIndex(hash[0], tableEntries_);
final int stride = getStride(hash[1], tableEntries_);
final int loopIndex = entryIndex;
do {
if (isBitClear(stateArr_, entryIndex)) { //check if slot is empty
return ~entryIndex;
}
if (arraysEqual(key, 0, keysArr_, entryIndex * keyLen, keyLen)) { //check for key match
return entryIndex;
}
entryIndex = (entryIndex + stride) % tableEntries_;
} while (entryIndex != loopIndex);
throw new SketchesArgumentException("Key not found and no empty slots!");
} | [
"@",
"Override",
"final",
"int",
"findKey",
"(",
"final",
"byte",
"[",
"]",
"key",
")",
"{",
"final",
"int",
"keyLen",
"=",
"key",
".",
"length",
";",
"final",
"long",
"[",
"]",
"hash",
"=",
"MurmurHash3",
".",
"hash",
"(",
"key",
",",
"SEED",
")",... | Returns the entry index for the given key given the array of keys, if found.
Otherwise, returns the one's complement of first empty entry found;
@param key the key to search for
@return the entry index of the given key, or the one's complement of the index if not found. | [
"Returns",
"the",
"entry",
"index",
"for",
"the",
"given",
"key",
"given",
"the",
"array",
"of",
"keys",
"if",
"found",
".",
"Otherwise",
"returns",
"the",
"one",
"s",
"complement",
"of",
"first",
"empty",
"entry",
"found",
";"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hllmap/HllMap.java#L127-L145 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hllmap/HllMap.java | HllMap.findEmpty | private static final int findEmpty(final byte[] key, final int tableEntries, final byte[] stateArr) {
final long[] hash = MurmurHash3.hash(key, SEED);
int entryIndex = getIndex(hash[0], tableEntries);
final int stride = getStride(hash[1], tableEntries);
final int loopIndex = entryIndex;
do {
if (isBitClear(stateArr, entryIndex)) { //check if slot is empty
return entryIndex;
}
entryIndex = (entryIndex + stride) % tableEntries;
} while (entryIndex != loopIndex);
throw new SketchesArgumentException("No empty slots.");
} | java | private static final int findEmpty(final byte[] key, final int tableEntries, final byte[] stateArr) {
final long[] hash = MurmurHash3.hash(key, SEED);
int entryIndex = getIndex(hash[0], tableEntries);
final int stride = getStride(hash[1], tableEntries);
final int loopIndex = entryIndex;
do {
if (isBitClear(stateArr, entryIndex)) { //check if slot is empty
return entryIndex;
}
entryIndex = (entryIndex + stride) % tableEntries;
} while (entryIndex != loopIndex);
throw new SketchesArgumentException("No empty slots.");
} | [
"private",
"static",
"final",
"int",
"findEmpty",
"(",
"final",
"byte",
"[",
"]",
"key",
",",
"final",
"int",
"tableEntries",
",",
"final",
"byte",
"[",
"]",
"stateArr",
")",
"{",
"final",
"long",
"[",
"]",
"hash",
"=",
"MurmurHash3",
".",
"hash",
"(",... | Find the first empty slot for the given key.
Only used by resize, where it is known that the key does not exist in the table.
Throws an exception if no empty slots.
@param key the given key
@param tableEntries prime size of table
@param stateArr the valid bit array
@return the first empty slot for the given key | [
"Find",
"the",
"first",
"empty",
"slot",
"for",
"the",
"given",
"key",
".",
"Only",
"used",
"by",
"resize",
"where",
"it",
"is",
"known",
"that",
"the",
"key",
"does",
"not",
"exist",
"in",
"the",
"table",
".",
"Throws",
"an",
"exception",
"if",
"no",
... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hllmap/HllMap.java#L236-L249 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hllmap/HllMap.java | HllMap.updateHll | private final boolean updateHll(final int entryIndex, final int coupon) {
final int newValue = coupon16Value(coupon);
final int hllIdx = coupon & (k_ - 1); //lower lgK bits
final int longIdx = hllIdx / 10;
final int shift = ((hllIdx % 10) * 6) & SIX_BIT_MASK;
long hllLong = arrOfHllArr_[(entryIndex * hllArrLongs_) + longIdx];
final int oldValue = (int)(hllLong >>> shift) & SIX_BIT_MASK;
if (newValue <= oldValue) { return false; }
// newValue > oldValue
//update hipEstAccum BEFORE updating invPow2Sum
final double invPow2Sum = invPow2SumHiArr_[entryIndex] + invPow2SumLoArr_[entryIndex];
final double oneOverQ = k_ / invPow2Sum;
hipEstAccumArr_[entryIndex] += oneOverQ;
//update invPow2Sum
if (oldValue < 32) { invPow2SumHiArr_[entryIndex] -= invPow2(oldValue); }
else { invPow2SumLoArr_[entryIndex] -= invPow2(oldValue); }
if (newValue < 32) { invPow2SumHiArr_[entryIndex] += invPow2(newValue); }
else { invPow2SumLoArr_[entryIndex] += invPow2(newValue); }
//insert the new value
hllLong &= ~(0X3FL << shift); //zero out the 6-bit field
hllLong |= ((long)newValue) << shift; //insert
arrOfHllArr_[(entryIndex * hllArrLongs_) + longIdx] = hllLong;
return true;
} | java | private final boolean updateHll(final int entryIndex, final int coupon) {
final int newValue = coupon16Value(coupon);
final int hllIdx = coupon & (k_ - 1); //lower lgK bits
final int longIdx = hllIdx / 10;
final int shift = ((hllIdx % 10) * 6) & SIX_BIT_MASK;
long hllLong = arrOfHllArr_[(entryIndex * hllArrLongs_) + longIdx];
final int oldValue = (int)(hllLong >>> shift) & SIX_BIT_MASK;
if (newValue <= oldValue) { return false; }
// newValue > oldValue
//update hipEstAccum BEFORE updating invPow2Sum
final double invPow2Sum = invPow2SumHiArr_[entryIndex] + invPow2SumLoArr_[entryIndex];
final double oneOverQ = k_ / invPow2Sum;
hipEstAccumArr_[entryIndex] += oneOverQ;
//update invPow2Sum
if (oldValue < 32) { invPow2SumHiArr_[entryIndex] -= invPow2(oldValue); }
else { invPow2SumLoArr_[entryIndex] -= invPow2(oldValue); }
if (newValue < 32) { invPow2SumHiArr_[entryIndex] += invPow2(newValue); }
else { invPow2SumLoArr_[entryIndex] += invPow2(newValue); }
//insert the new value
hllLong &= ~(0X3FL << shift); //zero out the 6-bit field
hllLong |= ((long)newValue) << shift; //insert
arrOfHllArr_[(entryIndex * hllArrLongs_) + longIdx] = hllLong;
return true;
} | [
"private",
"final",
"boolean",
"updateHll",
"(",
"final",
"int",
"entryIndex",
",",
"final",
"int",
"coupon",
")",
"{",
"final",
"int",
"newValue",
"=",
"coupon16Value",
"(",
"coupon",
")",
";",
"final",
"int",
"hllIdx",
"=",
"coupon",
"&",
"(",
"k_",
"-... | This method is specifically tied to the HLL array layout | [
"This",
"method",
"is",
"specifically",
"tied",
"to",
"the",
"HLL",
"array",
"layout"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hllmap/HllMap.java#L252-L280 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CompressionData.java | CompressionData.makeDecodingTable | private static short[] makeDecodingTable(final short[] encodingTable, final int numByteValues) {
final short[] decodingTable = new short[4096];
for (int byteValue = 0; byteValue < numByteValues; byteValue++) {
final int encodingEntry = encodingTable[byteValue] & 0xFFFF;
final int codeValue = encodingEntry & 0xfff;
final int codeLength = encodingEntry >> 12;
final int decodingEntry = (codeLength << 8) | byteValue;
final int garbageLength = 12 - codeLength;
final int numCopies = 1 << garbageLength;
for (int garbageBits = 0; garbageBits < numCopies; garbageBits++) {
final int extendedCodeValue = codeValue | (garbageBits << codeLength);
decodingTable[extendedCodeValue & 0xfff] = (short) decodingEntry;
}
}
return (decodingTable);
} | java | private static short[] makeDecodingTable(final short[] encodingTable, final int numByteValues) {
final short[] decodingTable = new short[4096];
for (int byteValue = 0; byteValue < numByteValues; byteValue++) {
final int encodingEntry = encodingTable[byteValue] & 0xFFFF;
final int codeValue = encodingEntry & 0xfff;
final int codeLength = encodingEntry >> 12;
final int decodingEntry = (codeLength << 8) | byteValue;
final int garbageLength = 12 - codeLength;
final int numCopies = 1 << garbageLength;
for (int garbageBits = 0; garbageBits < numCopies; garbageBits++) {
final int extendedCodeValue = codeValue | (garbageBits << codeLength);
decodingTable[extendedCodeValue & 0xfff] = (short) decodingEntry;
}
}
return (decodingTable);
} | [
"private",
"static",
"short",
"[",
"]",
"makeDecodingTable",
"(",
"final",
"short",
"[",
"]",
"encodingTable",
",",
"final",
"int",
"numByteValues",
")",
"{",
"final",
"short",
"[",
"]",
"decodingTable",
"=",
"new",
"short",
"[",
"4096",
"]",
";",
"for",
... | Given an encoding table that maps unsigned bytes to codewords
of length at most 12, this builds a size-4096 decoding table.
<p>The second argument is typically 256, but can be other values such as 65.
@param encodingTable unsigned
@param numByteValues size of encoding table
@return one segment of the decoding table | [
"Given",
"an",
"encoding",
"table",
"that",
"maps",
"unsigned",
"bytes",
"to",
"codewords",
"of",
"length",
"at",
"most",
"12",
"this",
"builds",
"a",
"size",
"-",
"4096",
"decoding",
"table",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CompressionData.java#L50-L67 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CompressionData.java | CompressionData.validateDecodingTable | static void validateDecodingTable(final short[] decodingTable, final short[] encodingTable) {
for (int decodeThis = 0; decodeThis < 4096; decodeThis++) {
final int tmpD = decodingTable[decodeThis] & 0xFFFF;
final int decodedByte = tmpD & 0xff;
final int decodedLength = tmpD >> 8;
final int tmpE = encodingTable[decodedByte] & 0xFFFF;
final int encodedBitpattern = tmpE & 0xfff;
final int encodedLength = tmpE >> 12;
// encodedBitpattern++; // uncomment this line to force failure when testing this method
// encodedLength++; // uncomment this line to force failure when testing this method
assert (decodedLength == encodedLength)
: "deLen: " + decodedLength + ", enLen: " + encodedLength;
assert (encodedBitpattern == (decodeThis & ((1 << decodedLength) - 1)));
}
} | java | static void validateDecodingTable(final short[] decodingTable, final short[] encodingTable) {
for (int decodeThis = 0; decodeThis < 4096; decodeThis++) {
final int tmpD = decodingTable[decodeThis] & 0xFFFF;
final int decodedByte = tmpD & 0xff;
final int decodedLength = tmpD >> 8;
final int tmpE = encodingTable[decodedByte] & 0xFFFF;
final int encodedBitpattern = tmpE & 0xfff;
final int encodedLength = tmpE >> 12;
// encodedBitpattern++; // uncomment this line to force failure when testing this method
// encodedLength++; // uncomment this line to force failure when testing this method
assert (decodedLength == encodedLength)
: "deLen: " + decodedLength + ", enLen: " + encodedLength;
assert (encodedBitpattern == (decodeThis & ((1 << decodedLength) - 1)));
}
} | [
"static",
"void",
"validateDecodingTable",
"(",
"final",
"short",
"[",
"]",
"decodingTable",
",",
"final",
"short",
"[",
"]",
"encodingTable",
")",
"{",
"for",
"(",
"int",
"decodeThis",
"=",
"0",
";",
"decodeThis",
"<",
"4096",
";",
"decodeThis",
"++",
")"... | These short arrays are being treated as unsigned
@param decodingTable unsigned
@param encodingTable unsigned | [
"These",
"short",
"arrays",
"are",
"being",
"treated",
"as",
"unsigned"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CompressionData.java#L74-L91 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/DoublesUnionImpl.java | DoublesUnionImpl.directInstance | static DoublesUnionImpl directInstance(final int maxK, final WritableMemory dstMem) {
final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.newInstance(maxK, dstMem);
final DoublesUnionImpl union = new DoublesUnionImpl(maxK);
union.maxK_ = maxK;
union.gadget_ = sketch;
return union;
} | java | static DoublesUnionImpl directInstance(final int maxK, final WritableMemory dstMem) {
final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.newInstance(maxK, dstMem);
final DoublesUnionImpl union = new DoublesUnionImpl(maxK);
union.maxK_ = maxK;
union.gadget_ = sketch;
return union;
} | [
"static",
"DoublesUnionImpl",
"directInstance",
"(",
"final",
"int",
"maxK",
",",
"final",
"WritableMemory",
"dstMem",
")",
"{",
"final",
"DirectUpdateDoublesSketch",
"sketch",
"=",
"DirectUpdateDoublesSketch",
".",
"newInstance",
"(",
"maxK",
",",
"dstMem",
")",
";... | Returns a empty DoublesUnion object that refers to the given direct, off-heap Memory,
which will be initialized to the empty state.
@param maxK determines the accuracy and size of the union and is a maximum value.
The effective <i>k</i> can be smaller due to unions with smaller <i>k</i> sketches.
It is recommended that <i>maxK</i> be a power of 2 to enable unioning of sketches with
different values of <i>k</i>.
@param dstMem the Memory to be used by the sketch
@return a DoublesUnion object | [
"Returns",
"a",
"empty",
"DoublesUnion",
"object",
"that",
"refers",
"to",
"the",
"given",
"direct",
"off",
"-",
"heap",
"Memory",
"which",
"will",
"be",
"initialized",
"to",
"the",
"empty",
"state",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesUnionImpl.java#L48-L54 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/DoublesUnionImpl.java | DoublesUnionImpl.heapifyInstance | static DoublesUnionImpl heapifyInstance(final DoublesSketch sketch) {
final int k = sketch.getK();
final DoublesUnionImpl union = new DoublesUnionImpl(k);
union.maxK_ = k;
union.gadget_ = copyToHeap(sketch);
return union;
} | java | static DoublesUnionImpl heapifyInstance(final DoublesSketch sketch) {
final int k = sketch.getK();
final DoublesUnionImpl union = new DoublesUnionImpl(k);
union.maxK_ = k;
union.gadget_ = copyToHeap(sketch);
return union;
} | [
"static",
"DoublesUnionImpl",
"heapifyInstance",
"(",
"final",
"DoublesSketch",
"sketch",
")",
"{",
"final",
"int",
"k",
"=",
"sketch",
".",
"getK",
"(",
")",
";",
"final",
"DoublesUnionImpl",
"union",
"=",
"new",
"DoublesUnionImpl",
"(",
"k",
")",
";",
"uni... | Returns a Heap DoublesUnion object that has been initialized with the data from the given
sketch.
@param sketch A DoublesSketch to be used as a source of data only and will not be modified.
@return a DoublesUnion object | [
"Returns",
"a",
"Heap",
"DoublesUnion",
"object",
"that",
"has",
"been",
"initialized",
"with",
"the",
"data",
"from",
"the",
"given",
"sketch",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesUnionImpl.java#L63-L69 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/DoublesUnionImpl.java | DoublesUnionImpl.wrapInstance | static DoublesUnionImpl wrapInstance(final WritableMemory mem) {
final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.wrapInstance(mem);
final DoublesUnionImpl union = new DoublesUnionImpl(sketch.getK());
union.gadget_ = sketch;
return union;
} | java | static DoublesUnionImpl wrapInstance(final WritableMemory mem) {
final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.wrapInstance(mem);
final DoublesUnionImpl union = new DoublesUnionImpl(sketch.getK());
union.gadget_ = sketch;
return union;
} | [
"static",
"DoublesUnionImpl",
"wrapInstance",
"(",
"final",
"WritableMemory",
"mem",
")",
"{",
"final",
"DirectUpdateDoublesSketch",
"sketch",
"=",
"DirectUpdateDoublesSketch",
".",
"wrapInstance",
"(",
"mem",
")",
";",
"final",
"DoublesUnionImpl",
"union",
"=",
"new"... | Returns an updatable 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",
"an",
"updatable",
"Union",
"object",
"that",
"wraps",
"off",
"-",
"heap",
"data",
"structure",
"of",
"the",
"given",
"memory",
"image",
"of",
"a",
"non",
"-",
"compact",
"DoublesSketch",
".",
"The",
"data",
"structures",
"of",
"the",
"Union",
"... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/DoublesUnionImpl.java#L95-L100 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/Sketch.java | Sketch.heapify | public static Sketch heapify(final Memory srcMem, final long seed) {
final int serVer = srcMem.getByte(SER_VER_BYTE);
if (serVer == 3) {
final byte famID = srcMem.getByte(FAMILY_BYTE);
final boolean ordered = (srcMem.getByte(FLAGS_BYTE) & ORDERED_FLAG_MASK) != 0;
return constructHeapSketch(famID, ordered, srcMem, seed);
}
if (serVer == 1) {
return ForwardCompatibility.heapify1to3(srcMem, seed);
}
if (serVer == 2) {
return ForwardCompatibility.heapify2to3(srcMem, seed);
}
throw new SketchesArgumentException("Unknown Serialization Version: " + serVer);
} | java | public static Sketch heapify(final Memory srcMem, final long seed) {
final int serVer = srcMem.getByte(SER_VER_BYTE);
if (serVer == 3) {
final byte famID = srcMem.getByte(FAMILY_BYTE);
final boolean ordered = (srcMem.getByte(FLAGS_BYTE) & ORDERED_FLAG_MASK) != 0;
return constructHeapSketch(famID, ordered, srcMem, seed);
}
if (serVer == 1) {
return ForwardCompatibility.heapify1to3(srcMem, seed);
}
if (serVer == 2) {
return ForwardCompatibility.heapify2to3(srcMem, seed);
}
throw new SketchesArgumentException("Unknown Serialization Version: " + serVer);
} | [
"public",
"static",
"Sketch",
"heapify",
"(",
"final",
"Memory",
"srcMem",
",",
"final",
"long",
"seed",
")",
"{",
"final",
"int",
"serVer",
"=",
"srcMem",
".",
"getByte",
"(",
"SER_VER_BYTE",
")",
";",
"if",
"(",
"serVer",
"==",
"3",
")",
"{",
"final"... | Heapify takes the sketch image in Memory and instantiates an on-heap
Sketch using the given seed.
The resulting sketch will not retain any link to the source Memory.
@param srcMem an image of a Sketch where the image seed hash matches the given seed hash.
<a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
Compact sketches store a 16-bit hash of the seed, but not the seed itself.
@return a Heap-based Sketch from the given Memory | [
"Heapify",
"takes",
"the",
"sketch",
"image",
"in",
"Memory",
"and",
"instantiates",
"an",
"on",
"-",
"heap",
"Sketch",
"using",
"the",
"given",
"seed",
".",
"The",
"resulting",
"sketch",
"will",
"not",
"retain",
"any",
"link",
"to",
"the",
"source",
"Memo... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/Sketch.java#L66-L80 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/Sketch.java | Sketch.isValidSketchID | static final boolean isValidSketchID(final int id) {
return (id == Family.ALPHA.getID())
|| (id == Family.QUICKSELECT.getID())
|| (id == Family.COMPACT.getID());
} | java | static final boolean isValidSketchID(final int id) {
return (id == Family.ALPHA.getID())
|| (id == Family.QUICKSELECT.getID())
|| (id == Family.COMPACT.getID());
} | [
"static",
"final",
"boolean",
"isValidSketchID",
"(",
"final",
"int",
"id",
")",
"{",
"return",
"(",
"id",
"==",
"Family",
".",
"ALPHA",
".",
"getID",
"(",
")",
")",
"||",
"(",
"id",
"==",
"Family",
".",
"QUICKSELECT",
".",
"getID",
"(",
")",
")",
... | Returns true if given Family id is one of the theta sketches
@param id the given Family id
@return true if given Family id is one of the theta sketches | [
"Returns",
"true",
"if",
"given",
"Family",
"id",
"is",
"one",
"of",
"the",
"theta",
"sketches"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/Sketch.java#L536-L540 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/Sketch.java | Sketch.checkSketchAndMemoryFlags | static final void checkSketchAndMemoryFlags(final Sketch sketch) {
final Memory mem = sketch.getMemory();
if (mem == null) { return; }
final int flags = PreambleUtil.extractFlags(mem);
if (((flags & COMPACT_FLAG_MASK) > 0) ^ sketch.isCompact()) {
throw new SketchesArgumentException("Possible corruption: "
+ "Memory Compact Flag inconsistent with Sketch");
}
if (((flags & ORDERED_FLAG_MASK) > 0) ^ sketch.isOrdered()) {
throw new SketchesArgumentException("Possible corruption: "
+ "Memory Ordered Flag inconsistent with Sketch");
}
} | java | static final void checkSketchAndMemoryFlags(final Sketch sketch) {
final Memory mem = sketch.getMemory();
if (mem == null) { return; }
final int flags = PreambleUtil.extractFlags(mem);
if (((flags & COMPACT_FLAG_MASK) > 0) ^ sketch.isCompact()) {
throw new SketchesArgumentException("Possible corruption: "
+ "Memory Compact Flag inconsistent with Sketch");
}
if (((flags & ORDERED_FLAG_MASK) > 0) ^ sketch.isOrdered()) {
throw new SketchesArgumentException("Possible corruption: "
+ "Memory Ordered Flag inconsistent with Sketch");
}
} | [
"static",
"final",
"void",
"checkSketchAndMemoryFlags",
"(",
"final",
"Sketch",
"sketch",
")",
"{",
"final",
"Memory",
"mem",
"=",
"sketch",
".",
"getMemory",
"(",
")",
";",
"if",
"(",
"mem",
"==",
"null",
")",
"{",
"return",
";",
"}",
"final",
"int",
... | Checks Ordered and Compact flags for integrity between sketch and Memory
@param sketch the given sketch | [
"Checks",
"Ordered",
"and",
"Compact",
"flags",
"for",
"integrity",
"between",
"sketch",
"and",
"Memory"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/Sketch.java#L546-L558 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/Sketch.java | Sketch.constructHeapSketch | private static final Sketch constructHeapSketch(final byte famID, final boolean ordered,
final Memory srcMem, final long seed) {
final boolean compact = (srcMem.getByte(FLAGS_BYTE) & COMPACT_FLAG_MASK) != 0;
final Family family = idToFamily(famID);
switch (family) {
case ALPHA: {
if (compact) {
throw new SketchesArgumentException("Possibly Corrupted " + family
+ " image: cannot be compact");
}
return HeapAlphaSketch.heapifyInstance(srcMem, seed);
}
case QUICKSELECT: {
return HeapQuickSelectSketch.heapifyInstance(srcMem, seed);
}
case COMPACT: {
if (!compact) {
throw new SketchesArgumentException("Possibly Corrupted " + family
+ " image: must be compact");
}
return ordered ? HeapCompactOrderedSketch.heapifyInstance(srcMem, seed)
: HeapCompactUnorderedSketch.heapifyInstance(srcMem, seed);
}
default: {
throw new SketchesArgumentException("Sketch cannot heapify family: " + family
+ " as a Sketch");
}
}
} | java | private static final Sketch constructHeapSketch(final byte famID, final boolean ordered,
final Memory srcMem, final long seed) {
final boolean compact = (srcMem.getByte(FLAGS_BYTE) & COMPACT_FLAG_MASK) != 0;
final Family family = idToFamily(famID);
switch (family) {
case ALPHA: {
if (compact) {
throw new SketchesArgumentException("Possibly Corrupted " + family
+ " image: cannot be compact");
}
return HeapAlphaSketch.heapifyInstance(srcMem, seed);
}
case QUICKSELECT: {
return HeapQuickSelectSketch.heapifyInstance(srcMem, seed);
}
case COMPACT: {
if (!compact) {
throw new SketchesArgumentException("Possibly Corrupted " + family
+ " image: must be compact");
}
return ordered ? HeapCompactOrderedSketch.heapifyInstance(srcMem, seed)
: HeapCompactUnorderedSketch.heapifyInstance(srcMem, seed);
}
default: {
throw new SketchesArgumentException("Sketch cannot heapify family: " + family
+ " as a Sketch");
}
}
} | [
"private",
"static",
"final",
"Sketch",
"constructHeapSketch",
"(",
"final",
"byte",
"famID",
",",
"final",
"boolean",
"ordered",
",",
"final",
"Memory",
"srcMem",
",",
"final",
"long",
"seed",
")",
"{",
"final",
"boolean",
"compact",
"=",
"(",
"srcMem",
"."... | Instantiates a Heap Sketch from Memory.
@param famID the Family ID
@param ordered true if the sketch is of the Compact family and ordered
@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>.
The seed required to instantiate a non-compact sketch.
@return a Sketch | [
"Instantiates",
"a",
"Heap",
"Sketch",
"from",
"Memory",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/Sketch.java#L619-L647 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java | ItemsUnion.getInstance | public static <T> ItemsUnion<T> getInstance(final Comparator<? super T> comparator) {
return new ItemsUnion<T>(PreambleUtil.DEFAULT_K, comparator, null);
} | java | public static <T> ItemsUnion<T> getInstance(final Comparator<? super T> comparator) {
return new ItemsUnion<T>(PreambleUtil.DEFAULT_K, comparator, null);
} | [
"public",
"static",
"<",
"T",
">",
"ItemsUnion",
"<",
"T",
">",
"getInstance",
"(",
"final",
"Comparator",
"<",
"?",
"super",
"T",
">",
"comparator",
")",
"{",
"return",
"new",
"ItemsUnion",
"<",
"T",
">",
"(",
"PreambleUtil",
".",
"DEFAULT_K",
",",
"c... | Create an instance of ItemsUnion with the default k
@param <T> type of item
@param comparator to compare items
@return an instance of ItemsUnion | [
"Create",
"an",
"instance",
"of",
"ItemsUnion",
"with",
"the",
"default",
"k"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java#L42-L44 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java | ItemsUnion.getInstance | public static <T> ItemsUnion<T> getInstance(final int maxK, final Comparator<? super T> comparator) {
return new ItemsUnion<>(maxK, comparator, null);
} | java | public static <T> ItemsUnion<T> getInstance(final int maxK, final Comparator<? super T> comparator) {
return new ItemsUnion<>(maxK, comparator, null);
} | [
"public",
"static",
"<",
"T",
">",
"ItemsUnion",
"<",
"T",
">",
"getInstance",
"(",
"final",
"int",
"maxK",
",",
"final",
"Comparator",
"<",
"?",
"super",
"T",
">",
"comparator",
")",
"{",
"return",
"new",
"ItemsUnion",
"<>",
"(",
"maxK",
",",
"compara... | Create an instance of ItemsUnion
@param <T> type of item
@param maxK determines the accuracy and size of the union and is a maximum value.
The effective <i>k</i> can be smaller due to unions with smaller <i>k</i> sketches.
It is recommended that <i>maxK</i> be a power of 2 to enable unioning of sketches with
different values of <i>k</i>.
@param comparator to compare items
@return an instance of ItemsUnion | [
"Create",
"an",
"instance",
"of",
"ItemsUnion"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java#L56-L58 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java | ItemsUnion.getInstance | public static <T> ItemsUnion<T> getInstance(final Memory srcMem,
final Comparator<? super T> comparator, final ArrayOfItemsSerDe<T> serDe) {
final ItemsSketch<T> gadget = ItemsSketch.getInstance(srcMem, comparator, serDe);
return new ItemsUnion<>(gadget.getK(), gadget.getComparator(), gadget);
} | java | public static <T> ItemsUnion<T> getInstance(final Memory srcMem,
final Comparator<? super T> comparator, final ArrayOfItemsSerDe<T> serDe) {
final ItemsSketch<T> gadget = ItemsSketch.getInstance(srcMem, comparator, serDe);
return new ItemsUnion<>(gadget.getK(), gadget.getComparator(), gadget);
} | [
"public",
"static",
"<",
"T",
">",
"ItemsUnion",
"<",
"T",
">",
"getInstance",
"(",
"final",
"Memory",
"srcMem",
",",
"final",
"Comparator",
"<",
"?",
"super",
"T",
">",
"comparator",
",",
"final",
"ArrayOfItemsSerDe",
"<",
"T",
">",
"serDe",
")",
"{",
... | Heapify the given srcMem into a Union object.
@param <T> type of item
@param srcMem the given srcMem.
A reference to srcMem will not be maintained internally.
@param comparator to compare items
@param serDe an instance of ArrayOfItemsSerDe
@return an instance of ItemsUnion | [
"Heapify",
"the",
"given",
"srcMem",
"into",
"a",
"Union",
"object",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java#L69-L73 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java | ItemsUnion.getInstance | public static <T> ItemsUnion<T> getInstance(final ItemsSketch<T> sketch) {
return new ItemsUnion<>(sketch.getK(), sketch.getComparator(), ItemsSketch.copy(sketch));
} | java | public static <T> ItemsUnion<T> getInstance(final ItemsSketch<T> sketch) {
return new ItemsUnion<>(sketch.getK(), sketch.getComparator(), ItemsSketch.copy(sketch));
} | [
"public",
"static",
"<",
"T",
">",
"ItemsUnion",
"<",
"T",
">",
"getInstance",
"(",
"final",
"ItemsSketch",
"<",
"T",
">",
"sketch",
")",
"{",
"return",
"new",
"ItemsUnion",
"<>",
"(",
"sketch",
".",
"getK",
"(",
")",
",",
"sketch",
".",
"getComparator... | Create an instance of ItemsUnion based on ItemsSketch
@param <T> type of item
@param sketch the basis of the union
@return an instance of ItemsUnion | [
"Create",
"an",
"instance",
"of",
"ItemsUnion",
"based",
"on",
"ItemsSketch"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java#L81-L83 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java | ItemsUnion.update | public void update(final ItemsSketch<T> sketchIn) {
gadget_ = updateLogic(maxK_, comparator_, gadget_, sketchIn);
} | java | public void update(final ItemsSketch<T> sketchIn) {
gadget_ = updateLogic(maxK_, comparator_, gadget_, sketchIn);
} | [
"public",
"void",
"update",
"(",
"final",
"ItemsSketch",
"<",
"T",
">",
"sketchIn",
")",
"{",
"gadget_",
"=",
"updateLogic",
"(",
"maxK_",
",",
"comparator_",
",",
"gadget_",
",",
"sketchIn",
")",
";",
"}"
] | Iterative union operation, which means this method can be repeatedly called.
Merges the given sketch into this union object.
The given sketch is not modified.
It is required that the ratio of the two K values be a power of 2.
This is easily satisfied if each of the K values is already a power of 2.
If the given sketch is null or empty it is ignored.
<p>It is required that the results of the union operation, which can be obtained at any time,
is obtained from {@link #getResult() }.</p>
@param sketchIn the sketch to be merged into this one. | [
"Iterative",
"union",
"operation",
"which",
"means",
"this",
"method",
"can",
"be",
"repeatedly",
"called",
".",
"Merges",
"the",
"given",
"sketch",
"into",
"this",
"union",
"object",
".",
"The",
"given",
"sketch",
"is",
"not",
"modified",
".",
"It",
"is",
... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java#L98-L100 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java | ItemsUnion.update | public void update(final Memory srcMem, final ArrayOfItemsSerDe<T> serDe) {
final ItemsSketch<T> that = ItemsSketch.getInstance(srcMem, comparator_, serDe);
gadget_ = updateLogic(maxK_, comparator_, gadget_, that);
} | java | public void update(final Memory srcMem, final ArrayOfItemsSerDe<T> serDe) {
final ItemsSketch<T> that = ItemsSketch.getInstance(srcMem, comparator_, serDe);
gadget_ = updateLogic(maxK_, comparator_, gadget_, that);
} | [
"public",
"void",
"update",
"(",
"final",
"Memory",
"srcMem",
",",
"final",
"ArrayOfItemsSerDe",
"<",
"T",
">",
"serDe",
")",
"{",
"final",
"ItemsSketch",
"<",
"T",
">",
"that",
"=",
"ItemsSketch",
".",
"getInstance",
"(",
"srcMem",
",",
"comparator_",
","... | Iterative union operation, which means this method can be repeatedly called.
Merges the given Memory image of a ItemsSketch into this union object.
The given Memory object is not modified and a link to it is not retained.
It is required that the ratio of the two K values be a power of 2.
This is easily satisfied if each of the K values is already a power of 2.
If the given sketch is null or empty it is ignored.
<p>It is required that the results of the union operation, which can be obtained at any time,
is obtained from {@link #getResult() }.</p>
@param srcMem Memory image of sketch to be merged
@param serDe an instance of ArrayOfItemsSerDe | [
"Iterative",
"union",
"operation",
"which",
"means",
"this",
"method",
"can",
"be",
"repeatedly",
"called",
".",
"Merges",
"the",
"given",
"Memory",
"image",
"of",
"a",
"ItemsSketch",
"into",
"this",
"union",
"object",
".",
"The",
"given",
"Memory",
"object",
... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java#L115-L118 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java | ItemsUnion.getResult | public ItemsSketch<T> getResult() {
if (gadget_ == null) {
return ItemsSketch.getInstance(maxK_, comparator_);
}
return ItemsSketch.copy(gadget_); //can't have any externally owned handles.
} | java | public ItemsSketch<T> getResult() {
if (gadget_ == null) {
return ItemsSketch.getInstance(maxK_, comparator_);
}
return ItemsSketch.copy(gadget_); //can't have any externally owned handles.
} | [
"public",
"ItemsSketch",
"<",
"T",
">",
"getResult",
"(",
")",
"{",
"if",
"(",
"gadget_",
"==",
"null",
")",
"{",
"return",
"ItemsSketch",
".",
"getInstance",
"(",
"maxK_",
",",
"comparator_",
")",
";",
"}",
"return",
"ItemsSketch",
".",
"copy",
"(",
"... | Gets the result of this Union operation as a copy of the internal state.
This enables further union update operations on this state.
@return the result of this Union operation | [
"Gets",
"the",
"result",
"of",
"this",
"Union",
"operation",
"as",
"a",
"copy",
"of",
"the",
"internal",
"state",
".",
"This",
"enables",
"further",
"union",
"update",
"operations",
"on",
"this",
"state",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/ItemsUnion.java#L138-L143 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/frequencies/PreambleUtil.java | PreambleUtil.checkPreambleSize | static long checkPreambleSize(final Memory mem) {
final long cap = mem.getCapacity();
if (cap < 8) { throwNotBigEnough(cap, 8); }
final long pre0 = mem.getLong(0);
final int preLongs = (int) (pre0 & 0X3FL); //lower 6 bits
final int required = Math.max(preLongs << 3, 8);
if (cap < required) { throwNotBigEnough(cap, required); }
return pre0;
} | java | static long checkPreambleSize(final Memory mem) {
final long cap = mem.getCapacity();
if (cap < 8) { throwNotBigEnough(cap, 8); }
final long pre0 = mem.getLong(0);
final int preLongs = (int) (pre0 & 0X3FL); //lower 6 bits
final int required = Math.max(preLongs << 3, 8);
if (cap < required) { throwNotBigEnough(cap, required); }
return pre0;
} | [
"static",
"long",
"checkPreambleSize",
"(",
"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 first 8 bytes.
@param mem the given Memory
@return the first 8 bytes of preamble as a long. | [
"Checks",
"Memory",
"for",
"capacity",
"to",
"hold",
"the",
"preamble",
"and",
"returns",
"the",
"first",
"8",
"bytes",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/frequencies/PreambleUtil.java#L244-L252 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UnionImpl.java | UnionImpl.initNewHeapInstance | static UnionImpl initNewHeapInstance(final int lgNomLongs, final long seed, final float p,
final ResizeFactor rf) {
final UpdateSketch gadget = new HeapQuickSelectSketch(
lgNomLongs, seed, p, rf, true); //create with UNION family
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = gadget.getThetaLong();
unionImpl.unionEmpty_ = gadget.isEmpty();
return unionImpl;
} | java | static UnionImpl initNewHeapInstance(final int lgNomLongs, final long seed, final float p,
final ResizeFactor rf) {
final UpdateSketch gadget = new HeapQuickSelectSketch(
lgNomLongs, seed, p, rf, true); //create with UNION family
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = gadget.getThetaLong();
unionImpl.unionEmpty_ = gadget.isEmpty();
return unionImpl;
} | [
"static",
"UnionImpl",
"initNewHeapInstance",
"(",
"final",
"int",
"lgNomLongs",
",",
"final",
"long",
"seed",
",",
"final",
"float",
"p",
",",
"final",
"ResizeFactor",
"rf",
")",
"{",
"final",
"UpdateSketch",
"gadget",
"=",
"new",
"HeapQuickSelectSketch",
"(",
... | Construct a new Union SetOperation on the java heap.
Called by SetOperationBuilder.
@param lgNomLongs <a href="{@docRoot}/resources/dictionary.html#lgNomLogs">See lgNomLongs</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
@param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>
@param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
@return instance of this sketch | [
"Construct",
"a",
"new",
"Union",
"SetOperation",
"on",
"the",
"java",
"heap",
".",
"Called",
"by",
"SetOperationBuilder",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UnionImpl.java#L74-L82 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UnionImpl.java | UnionImpl.initNewDirectInstance | static UnionImpl initNewDirectInstance(
final int lgNomLongs,
final long seed,
final float p,
final ResizeFactor rf,
final MemoryRequestServer memReqSvr,
final WritableMemory dstMem) {
final UpdateSketch gadget = new DirectQuickSelectSketch(
lgNomLongs, seed, p, rf, memReqSvr, dstMem, true); //create with UNION family
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = gadget.getThetaLong();
unionImpl.unionEmpty_ = gadget.isEmpty();
return unionImpl;
} | java | static UnionImpl initNewDirectInstance(
final int lgNomLongs,
final long seed,
final float p,
final ResizeFactor rf,
final MemoryRequestServer memReqSvr,
final WritableMemory dstMem) {
final UpdateSketch gadget = new DirectQuickSelectSketch(
lgNomLongs, seed, p, rf, memReqSvr, dstMem, true); //create with UNION family
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = gadget.getThetaLong();
unionImpl.unionEmpty_ = gadget.isEmpty();
return unionImpl;
} | [
"static",
"UnionImpl",
"initNewDirectInstance",
"(",
"final",
"int",
"lgNomLongs",
",",
"final",
"long",
"seed",
",",
"final",
"float",
"p",
",",
"final",
"ResizeFactor",
"rf",
",",
"final",
"MemoryRequestServer",
"memReqSvr",
",",
"final",
"WritableMemory",
"dstM... | Construct a new Direct Union in the off-heap destination Memory.
Called by SetOperationBuilder.
@param lgNomLongs <a href="{@docRoot}/resources/dictionary.html#lgNomLogs">See lgNomLongs</a>.
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
@param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>
@param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
@param memReqSvr a given instance of a MemoryRequestServer
@param dstMem the given Memory object destination. It will be cleared prior to use.
@return this class | [
"Construct",
"a",
"new",
"Direct",
"Union",
"in",
"the",
"off",
"-",
"heap",
"destination",
"Memory",
".",
"Called",
"by",
"SetOperationBuilder",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UnionImpl.java#L96-L109 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UnionImpl.java | UnionImpl.heapifyInstance | static UnionImpl heapifyInstance(final Memory srcMem, final long seed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = HeapQuickSelectSketch.heapifyInstance(srcMem, seed);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmpty(srcMem);
return unionImpl;
} | java | static UnionImpl heapifyInstance(final Memory srcMem, final long seed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = HeapQuickSelectSketch.heapifyInstance(srcMem, seed);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmpty(srcMem);
return unionImpl;
} | [
"static",
"UnionImpl",
"heapifyInstance",
"(",
"final",
"Memory",
"srcMem",
",",
"final",
"long",
"seed",
")",
"{",
"Family",
".",
"UNION",
".",
"checkFamilyID",
"(",
"extractFamilyID",
"(",
"srcMem",
")",
")",
";",
"final",
"UpdateSketch",
"gadget",
"=",
"H... | Heapify a Union from a Memory Union object containing data.
Called by SetOperation.
@param srcMem The source Memory Union object.
<a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
@return this class | [
"Heapify",
"a",
"Union",
"from",
"a",
"Memory",
"Union",
"object",
"containing",
"data",
".",
"Called",
"by",
"SetOperation",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UnionImpl.java#L119-L126 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UnionImpl.java | UnionImpl.fastWrap | static UnionImpl fastWrap(final WritableMemory srcMem, final long seed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = DirectQuickSelectSketch.fastWritableWrap(srcMem, seed);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmpty(srcMem);
return unionImpl;
} | java | static UnionImpl fastWrap(final WritableMemory srcMem, final long seed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = DirectQuickSelectSketch.fastWritableWrap(srcMem, seed);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmpty(srcMem);
return unionImpl;
} | [
"static",
"UnionImpl",
"fastWrap",
"(",
"final",
"WritableMemory",
"srcMem",
",",
"final",
"long",
"seed",
")",
"{",
"Family",
".",
"UNION",
".",
"checkFamilyID",
"(",
"extractFamilyID",
"(",
"srcMem",
")",
")",
";",
"final",
"UpdateSketch",
"gadget",
"=",
"... | Fast-wrap a Union object around a Union Memory object containing data.
This does NO validity checking of the given Memory.
@param srcMem The source Memory object.
<a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
@return this class | [
"Fast",
"-",
"wrap",
"a",
"Union",
"object",
"around",
"a",
"Union",
"Memory",
"object",
"containing",
"data",
".",
"This",
"does",
"NO",
"validity",
"checking",
"of",
"the",
"given",
"Memory",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UnionImpl.java#L153-L160 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UnionImpl.java | UnionImpl.wrapInstance | static UnionImpl wrapInstance(final Memory srcMem, final long seed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = DirectQuickSelectSketchR.readOnlyWrap(srcMem, seed);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmpty(srcMem);
return unionImpl;
} | java | static UnionImpl wrapInstance(final Memory srcMem, final long seed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = DirectQuickSelectSketchR.readOnlyWrap(srcMem, seed);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmpty(srcMem);
return unionImpl;
} | [
"static",
"UnionImpl",
"wrapInstance",
"(",
"final",
"Memory",
"srcMem",
",",
"final",
"long",
"seed",
")",
"{",
"Family",
".",
"UNION",
".",
"checkFamilyID",
"(",
"extractFamilyID",
"(",
"srcMem",
")",
")",
";",
"final",
"UpdateSketch",
"gadget",
"=",
"Dire... | Wrap a Union object around a Union Memory object containing data.
Called by SetOperation.
@param srcMem The source Memory object.
<a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
@return this class | [
"Wrap",
"a",
"Union",
"object",
"around",
"a",
"Union",
"Memory",
"object",
"containing",
"data",
".",
"Called",
"by",
"SetOperation",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UnionImpl.java#L170-L177 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UnionImpl.java | UnionImpl.processVer1 | private void processVer1(final Memory skMem) {
final long thetaLongIn = skMem.getLong(THETA_LONG);
unionThetaLong_ = min(unionThetaLong_, thetaLongIn); //Theta rule
final int curCount = skMem.getInt(RETAINED_ENTRIES_INT);
final int preLongs = 3;
for (int i = 0; i < curCount; i++ ) {
final int offsetBytes = (preLongs + i) << 3;
final long hashIn = skMem.getLong(offsetBytes);
if (hashIn >= unionThetaLong_) { break; } // "early stop"
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong()); //Theta rule
unionEmpty_ = unionEmpty_ && gadget_.isEmpty();
} | java | private void processVer1(final Memory skMem) {
final long thetaLongIn = skMem.getLong(THETA_LONG);
unionThetaLong_ = min(unionThetaLong_, thetaLongIn); //Theta rule
final int curCount = skMem.getInt(RETAINED_ENTRIES_INT);
final int preLongs = 3;
for (int i = 0; i < curCount; i++ ) {
final int offsetBytes = (preLongs + i) << 3;
final long hashIn = skMem.getLong(offsetBytes);
if (hashIn >= unionThetaLong_) { break; } // "early stop"
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong()); //Theta rule
unionEmpty_ = unionEmpty_ && gadget_.isEmpty();
} | [
"private",
"void",
"processVer1",
"(",
"final",
"Memory",
"skMem",
")",
"{",
"final",
"long",
"thetaLongIn",
"=",
"skMem",
".",
"getLong",
"(",
"THETA_LONG",
")",
";",
"unionThetaLong_",
"=",
"min",
"(",
"unionThetaLong_",
",",
"thetaLongIn",
")",
";",
"//Th... | can only be compact, ordered, size > 24 | [
"can",
"only",
"be",
"compact",
"ordered",
"size",
">",
"24"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UnionImpl.java#L406-L419 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UnionImpl.java | UnionImpl.processVer2 | private void processVer2(final Memory skMem) {
Util.checkSeedHashes(seedHash_, skMem.getShort(SEED_HASH_SHORT));
final int preLongs = skMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int curCount = skMem.getInt(RETAINED_ENTRIES_INT);
final long thetaLongIn;
if (preLongs == 1) { //does not change anything {1.0, 0, T}
return;
}
if (preLongs == 2) { //exact mode
assert curCount > 0;
thetaLongIn = Long.MAX_VALUE;
} else { //prelongs == 3, curCount may be 0 (e.g., from intersection)
thetaLongIn = skMem.getLong(THETA_LONG);
}
unionThetaLong_ = min(unionThetaLong_, thetaLongIn); //Theta rule
for (int i = 0; i < curCount; i++ ) {
final int offsetBytes = (preLongs + i) << 3;
final long hashIn = skMem.getLong(offsetBytes);
if (hashIn >= unionThetaLong_) { break; } // "early stop"
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong());
unionEmpty_ = unionEmpty_ && gadget_.isEmpty();
} | java | private void processVer2(final Memory skMem) {
Util.checkSeedHashes(seedHash_, skMem.getShort(SEED_HASH_SHORT));
final int preLongs = skMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int curCount = skMem.getInt(RETAINED_ENTRIES_INT);
final long thetaLongIn;
if (preLongs == 1) { //does not change anything {1.0, 0, T}
return;
}
if (preLongs == 2) { //exact mode
assert curCount > 0;
thetaLongIn = Long.MAX_VALUE;
} else { //prelongs == 3, curCount may be 0 (e.g., from intersection)
thetaLongIn = skMem.getLong(THETA_LONG);
}
unionThetaLong_ = min(unionThetaLong_, thetaLongIn); //Theta rule
for (int i = 0; i < curCount; i++ ) {
final int offsetBytes = (preLongs + i) << 3;
final long hashIn = skMem.getLong(offsetBytes);
if (hashIn >= unionThetaLong_) { break; } // "early stop"
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong());
unionEmpty_ = unionEmpty_ && gadget_.isEmpty();
} | [
"private",
"void",
"processVer2",
"(",
"final",
"Memory",
"skMem",
")",
"{",
"Util",
".",
"checkSeedHashes",
"(",
"seedHash_",
",",
"skMem",
".",
"getShort",
"(",
"SEED_HASH_SHORT",
")",
")",
";",
"final",
"int",
"preLongs",
"=",
"skMem",
".",
"getByte",
"... | can only be compact, ordered, size >= 8 | [
"can",
"only",
"be",
"compact",
"ordered",
"size",
">",
"=",
"8"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UnionImpl.java#L423-L446 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UnionImpl.java | UnionImpl.processVer3 | private void processVer3(final Memory skMem) {
Util.checkSeedHashes(seedHash_, skMem.getShort(SEED_HASH_SHORT));
final int preLongs = skMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int curCount;
final long thetaLongIn;
if (preLongs == 1) { //SingleItemSketch if not empty, Read-Only, Compact and Ordered
final int flags = skMem.getByte(FLAGS_BYTE);
if (flags == (READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK | ORDERED_FLAG_MASK)) {
curCount = 1;
thetaLongIn = Long.MAX_VALUE;
} else {
return; //otherwise an empty sketch {1.0, 0, T}
}
}
else if (preLongs == 2) { //curCount has to be > 0 and exact mode. Cannot be from intersection.
curCount = skMem.getInt(RETAINED_ENTRIES_INT);
assert curCount > 0;
thetaLongIn = Long.MAX_VALUE;
}
else { //prelongs == 3, curCount may be 0 (e.g., from intersection).
curCount = skMem.getInt(RETAINED_ENTRIES_INT);
assert curCount > 0;
thetaLongIn = skMem.getLong(THETA_LONG);
}
unionThetaLong_ = min(unionThetaLong_, thetaLongIn); //theta rule
final boolean ordered = (skMem.getByte(FLAGS_BYTE) & ORDERED_FLAG_MASK) != 0;
if (ordered) { //must be compact
for (int i = 0; i < curCount; i++ ) {
final int offsetBytes = (preLongs + i) << 3;
final long hashIn = skMem.getLong(offsetBytes);
if (hashIn >= unionThetaLong_) { break; } // "early stop"
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
}
else { //not-ordered, could be compact or hash-table form
final boolean compact = (skMem.getByte(FLAGS_BYTE) & COMPACT_FLAG_MASK) != 0;
final int size = (compact) ? curCount : 1 << skMem.getByte(LG_ARR_LONGS_BYTE);
for (int i = 0; i < size; i++ ) {
final int offsetBytes = (preLongs + i) << 3;
final long hashIn = skMem.getLong(offsetBytes);
if ((hashIn <= 0L) || (hashIn >= unionThetaLong_)) { continue; }
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
}
unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong()); //sync thetaLongs
unionEmpty_ = unionEmpty_ && gadget_.isEmpty();
} | java | private void processVer3(final Memory skMem) {
Util.checkSeedHashes(seedHash_, skMem.getShort(SEED_HASH_SHORT));
final int preLongs = skMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int curCount;
final long thetaLongIn;
if (preLongs == 1) { //SingleItemSketch if not empty, Read-Only, Compact and Ordered
final int flags = skMem.getByte(FLAGS_BYTE);
if (flags == (READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK | ORDERED_FLAG_MASK)) {
curCount = 1;
thetaLongIn = Long.MAX_VALUE;
} else {
return; //otherwise an empty sketch {1.0, 0, T}
}
}
else if (preLongs == 2) { //curCount has to be > 0 and exact mode. Cannot be from intersection.
curCount = skMem.getInt(RETAINED_ENTRIES_INT);
assert curCount > 0;
thetaLongIn = Long.MAX_VALUE;
}
else { //prelongs == 3, curCount may be 0 (e.g., from intersection).
curCount = skMem.getInt(RETAINED_ENTRIES_INT);
assert curCount > 0;
thetaLongIn = skMem.getLong(THETA_LONG);
}
unionThetaLong_ = min(unionThetaLong_, thetaLongIn); //theta rule
final boolean ordered = (skMem.getByte(FLAGS_BYTE) & ORDERED_FLAG_MASK) != 0;
if (ordered) { //must be compact
for (int i = 0; i < curCount; i++ ) {
final int offsetBytes = (preLongs + i) << 3;
final long hashIn = skMem.getLong(offsetBytes);
if (hashIn >= unionThetaLong_) { break; } // "early stop"
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
}
else { //not-ordered, could be compact or hash-table form
final boolean compact = (skMem.getByte(FLAGS_BYTE) & COMPACT_FLAG_MASK) != 0;
final int size = (compact) ? curCount : 1 << skMem.getByte(LG_ARR_LONGS_BYTE);
for (int i = 0; i < size; i++ ) {
final int offsetBytes = (preLongs + i) << 3;
final long hashIn = skMem.getLong(offsetBytes);
if ((hashIn <= 0L) || (hashIn >= unionThetaLong_)) { continue; }
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
}
unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong()); //sync thetaLongs
unionEmpty_ = unionEmpty_ && gadget_.isEmpty();
} | [
"private",
"void",
"processVer3",
"(",
"final",
"Memory",
"skMem",
")",
"{",
"Util",
".",
"checkSeedHashes",
"(",
"seedHash_",
",",
"skMem",
".",
"getShort",
"(",
"SEED_HASH_SHORT",
")",
")",
";",
"final",
"int",
"preLongs",
"=",
"skMem",
".",
"getByte",
"... | could be unordered, ordered, compact, or not, size >= 8 | [
"could",
"be",
"unordered",
"ordered",
"compact",
"or",
"not",
"size",
">",
"=",
"8"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UnionImpl.java#L450-L496 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hll/CubicInterpolation.java | CubicInterpolation.usingXArrAndYStride | static double usingXArrAndYStride(
final double[] xArr, final double yStride, final double x) {
final int xArrLen = xArr.length;
final int xArrLenM1 = xArrLen - 1;
final int offset;
assert ((xArrLen >= 4) && (x >= xArr[0]) && (x <= xArr[xArrLenM1]));
if (x == xArr[xArrLenM1]) { /* corner case */
return (yStride * (xArrLenM1));
}
offset = findStraddle(xArr, x); //uses recursion
final int xArrLenM2 = xArrLen - 2;
assert ((offset >= 0) && (offset <= (xArrLenM2)));
if (offset == 0) { /* corner case */
return (interpolateUsingXArrAndYStride(xArr, yStride, (offset - 0), x));
}
else if (offset == xArrLenM2) { /* corner case */
return (interpolateUsingXArrAndYStride(xArr, yStride, (offset - 2), x));
}
/* main case */
return (interpolateUsingXArrAndYStride(xArr, yStride, (offset - 1), x));
} | java | static double usingXArrAndYStride(
final double[] xArr, final double yStride, final double x) {
final int xArrLen = xArr.length;
final int xArrLenM1 = xArrLen - 1;
final int offset;
assert ((xArrLen >= 4) && (x >= xArr[0]) && (x <= xArr[xArrLenM1]));
if (x == xArr[xArrLenM1]) { /* corner case */
return (yStride * (xArrLenM1));
}
offset = findStraddle(xArr, x); //uses recursion
final int xArrLenM2 = xArrLen - 2;
assert ((offset >= 0) && (offset <= (xArrLenM2)));
if (offset == 0) { /* corner case */
return (interpolateUsingXArrAndYStride(xArr, yStride, (offset - 0), x));
}
else if (offset == xArrLenM2) { /* corner case */
return (interpolateUsingXArrAndYStride(xArr, yStride, (offset - 2), x));
}
/* main case */
return (interpolateUsingXArrAndYStride(xArr, yStride, (offset - 1), x));
} | [
"static",
"double",
"usingXArrAndYStride",
"(",
"final",
"double",
"[",
"]",
"xArr",
",",
"final",
"double",
"yStride",
",",
"final",
"double",
"x",
")",
"{",
"final",
"int",
"xArrLen",
"=",
"xArr",
".",
"length",
";",
"final",
"int",
"xArrLenM1",
"=",
"... | Used by HllEstimators | [
"Used",
"by",
"HllEstimators"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/CubicInterpolation.java#L60-L84 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hll/Union.java | Union.heapify | public static final Union heapify(final Memory mem) {
final int lgK = HllUtil.checkLgK(mem.getByte(PreambleUtil.LG_K_BYTE));
final HllSketch sk = HllSketch.heapify(mem);
final Union union = new Union(lgK);
union.update(sk);
return union;
} | java | public static final Union heapify(final Memory mem) {
final int lgK = HllUtil.checkLgK(mem.getByte(PreambleUtil.LG_K_BYTE));
final HllSketch sk = HllSketch.heapify(mem);
final Union union = new Union(lgK);
union.update(sk);
return union;
} | [
"public",
"static",
"final",
"Union",
"heapify",
"(",
"final",
"Memory",
"mem",
")",
"{",
"final",
"int",
"lgK",
"=",
"HllUtil",
".",
"checkLgK",
"(",
"mem",
".",
"getByte",
"(",
"PreambleUtil",
".",
"LG_K_BYTE",
")",
")",
";",
"final",
"HllSketch",
"sk"... | Construct a union operator populated with the given Memory image of an HllSketch.
@param mem the given Memory
@return a union operator populated with the given Memory image of an HllSketch. | [
"Construct",
"a",
"union",
"operator",
"populated",
"with",
"the",
"given",
"Memory",
"image",
"of",
"an",
"HllSketch",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/Union.java#L103-L109 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hll/Union.java | Union.update | public void update(final HllSketch sketch) {
gadget.hllSketchImpl = unionImpl(sketch.hllSketchImpl, gadget.hllSketchImpl, lgMaxK);
} | java | public void update(final HllSketch sketch) {
gadget.hllSketchImpl = unionImpl(sketch.hllSketchImpl, gadget.hllSketchImpl, lgMaxK);
} | [
"public",
"void",
"update",
"(",
"final",
"HllSketch",
"sketch",
")",
"{",
"gadget",
".",
"hllSketchImpl",
"=",
"unionImpl",
"(",
"sketch",
".",
"hllSketchImpl",
",",
"gadget",
".",
"hllSketchImpl",
",",
"lgMaxK",
")",
";",
"}"
] | Update this union operator with the given sketch.
@param sketch the given sketch. | [
"Update",
"this",
"union",
"operator",
"with",
"the",
"given",
"sketch",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/Union.java#L270-L272 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hll/Union.java | Union.copyOrDownsampleHll | private static final HllSketchImpl copyOrDownsampleHll(
final HllSketchImpl srcImpl, final int tgtLgK) {
assert srcImpl.getCurMode() == HLL;
final AbstractHllArray src = (AbstractHllArray) srcImpl;
final int srcLgK = src.getLgConfigK();
if ((srcLgK <= tgtLgK) && (src.getTgtHllType() == TgtHllType.HLL_8)) {
return src.copy();
}
final int minLgK = Math.min(srcLgK, tgtLgK);
final HllArray tgtHllArr = HllArray.newHeapHll(minLgK, TgtHllType.HLL_8);
final PairIterator srcItr = src.iterator();
while (srcItr.nextValid()) {
tgtHllArr.couponUpdate(srcItr.getPair());
}
//both of these are required for isomorphism
tgtHllArr.putHipAccum(src.getHipAccum());
tgtHllArr.putOutOfOrderFlag(src.isOutOfOrderFlag());
return tgtHllArr;
} | java | private static final HllSketchImpl copyOrDownsampleHll(
final HllSketchImpl srcImpl, final int tgtLgK) {
assert srcImpl.getCurMode() == HLL;
final AbstractHllArray src = (AbstractHllArray) srcImpl;
final int srcLgK = src.getLgConfigK();
if ((srcLgK <= tgtLgK) && (src.getTgtHllType() == TgtHllType.HLL_8)) {
return src.copy();
}
final int minLgK = Math.min(srcLgK, tgtLgK);
final HllArray tgtHllArr = HllArray.newHeapHll(minLgK, TgtHllType.HLL_8);
final PairIterator srcItr = src.iterator();
while (srcItr.nextValid()) {
tgtHllArr.couponUpdate(srcItr.getPair());
}
//both of these are required for isomorphism
tgtHllArr.putHipAccum(src.getHipAccum());
tgtHllArr.putOutOfOrderFlag(src.isOutOfOrderFlag());
return tgtHllArr;
} | [
"private",
"static",
"final",
"HllSketchImpl",
"copyOrDownsampleHll",
"(",
"final",
"HllSketchImpl",
"srcImpl",
",",
"final",
"int",
"tgtLgK",
")",
"{",
"assert",
"srcImpl",
".",
"getCurMode",
"(",
")",
"==",
"HLL",
";",
"final",
"AbstractHllArray",
"src",
"=",
... | Caller must ultimately manage oooFlag, as caller has more info | [
"Caller",
"must",
"ultimately",
"manage",
"oooFlag",
"as",
"caller",
"has",
"more",
"info"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/Union.java#L438-L456 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/fdt/Group.java | Group.init | public Group init(final String priKey, final int count, final double estimate, final double ub,
final double lb, final double fraction, final double rse) {
this.count = count;
est = estimate;
this.ub = ub;
this.lb = lb;
this.fraction = fraction;
this.rse = rse;
this.priKey = priKey;
return this;
} | java | public Group init(final String priKey, final int count, final double estimate, final double ub,
final double lb, final double fraction, final double rse) {
this.count = count;
est = estimate;
this.ub = ub;
this.lb = lb;
this.fraction = fraction;
this.rse = rse;
this.priKey = priKey;
return this;
} | [
"public",
"Group",
"init",
"(",
"final",
"String",
"priKey",
",",
"final",
"int",
"count",
",",
"final",
"double",
"estimate",
",",
"final",
"double",
"ub",
",",
"final",
"double",
"lb",
",",
"final",
"double",
"fraction",
",",
"final",
"double",
"rse",
... | Specifies the parameters to be listed as columns
@param priKey the primary key of the FDT sketch
@param count the number of retained rows associated with this group
@param estimate the estimate of the original population associated with this group
@param ub the upper bound of the estimate
@param lb the lower bound of the extimate
@param fraction the fraction of all retained rows of the sketch associated with this group
@param rse the estimated Relative Standard Error for this group.
@return return this | [
"Specifies",
"the",
"parameters",
"to",
"be",
"listed",
"as",
"columns"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/Group.java#L47-L57 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/Sketches.java | Sketches.getEstimate | public static double getEstimate(final Memory srcMem) {
checkIfValidThetaSketch(srcMem);
return Sketch.estimate(getThetaLong(srcMem), getRetainedEntries(srcMem), getEmpty(srcMem));
} | java | public static double getEstimate(final Memory srcMem) {
checkIfValidThetaSketch(srcMem);
return Sketch.estimate(getThetaLong(srcMem), getRetainedEntries(srcMem), getEmpty(srcMem));
} | [
"public",
"static",
"double",
"getEstimate",
"(",
"final",
"Memory",
"srcMem",
")",
"{",
"checkIfValidThetaSketch",
"(",
"srcMem",
")",
";",
"return",
"Sketch",
".",
"estimate",
"(",
"getThetaLong",
"(",
"srcMem",
")",
",",
"getRetainedEntries",
"(",
"srcMem",
... | Gets the unique count estimate from a valid memory image of a Sketch
@param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
@return the sketch's best estimate of the cardinality of the input stream. | [
"Gets",
"the",
"unique",
"count",
"estimate",
"from",
"a",
"valid",
"memory",
"image",
"of",
"a",
"Sketch"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/Sketches.java#L280-L283 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/DirectArrayOfDoublesQuickSelectSketch.java | DirectArrayOfDoublesQuickSelectSketch.rebuild | @Override
protected void rebuild(final int newCapacity) {
final int numValues = getNumValues();
checkIfEnoughMemory(mem_, newCapacity, numValues);
final int currCapacity = getCurrentCapacity();
final long[] keys = new long[currCapacity];
final double[] values = new double[currCapacity * numValues];
mem_.getLongArray(keysOffset_, keys, 0, currCapacity);
mem_.getDoubleArray(valuesOffset_, values, 0, currCapacity * numValues);
mem_.clear(keysOffset_,
((long) SIZE_OF_KEY_BYTES * newCapacity) + ((long) SIZE_OF_VALUE_BYTES * newCapacity * numValues));
mem_.putInt(RETAINED_ENTRIES_INT, 0);
mem_.putByte(LG_CUR_CAPACITY_BYTE, (byte)Integer.numberOfTrailingZeros(newCapacity));
valuesOffset_ = keysOffset_ + (SIZE_OF_KEY_BYTES * newCapacity);
lgCurrentCapacity_ = Integer.numberOfTrailingZeros(newCapacity);
for (int i = 0; i < keys.length; i++) {
if ((keys[i] != 0) && (keys[i] < theta_)) {
insert(keys[i], Arrays.copyOfRange(values, i * numValues, (i + 1) * numValues));
}
}
setRebuildThreshold();
} | java | @Override
protected void rebuild(final int newCapacity) {
final int numValues = getNumValues();
checkIfEnoughMemory(mem_, newCapacity, numValues);
final int currCapacity = getCurrentCapacity();
final long[] keys = new long[currCapacity];
final double[] values = new double[currCapacity * numValues];
mem_.getLongArray(keysOffset_, keys, 0, currCapacity);
mem_.getDoubleArray(valuesOffset_, values, 0, currCapacity * numValues);
mem_.clear(keysOffset_,
((long) SIZE_OF_KEY_BYTES * newCapacity) + ((long) SIZE_OF_VALUE_BYTES * newCapacity * numValues));
mem_.putInt(RETAINED_ENTRIES_INT, 0);
mem_.putByte(LG_CUR_CAPACITY_BYTE, (byte)Integer.numberOfTrailingZeros(newCapacity));
valuesOffset_ = keysOffset_ + (SIZE_OF_KEY_BYTES * newCapacity);
lgCurrentCapacity_ = Integer.numberOfTrailingZeros(newCapacity);
for (int i = 0; i < keys.length; i++) {
if ((keys[i] != 0) && (keys[i] < theta_)) {
insert(keys[i], Arrays.copyOfRange(values, i * numValues, (i + 1) * numValues));
}
}
setRebuildThreshold();
} | [
"@",
"Override",
"protected",
"void",
"rebuild",
"(",
"final",
"int",
"newCapacity",
")",
"{",
"final",
"int",
"numValues",
"=",
"getNumValues",
"(",
")",
";",
"checkIfEnoughMemory",
"(",
"mem_",
",",
"newCapacity",
",",
"numValues",
")",
";",
"final",
"int"... | rebuild in the same memory | [
"rebuild",
"in",
"the",
"same",
"memory"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/DirectArrayOfDoublesQuickSelectSketch.java#L256-L277 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/HeapAlphaSketch.java | HeapAlphaSketch.newHeapInstance | static HeapAlphaSketch newHeapInstance(final int lgNomLongs, final long seed, final float p,
final ResizeFactor rf) {
if (lgNomLongs < ALPHA_MIN_LG_NOM_LONGS) {
throw new SketchesArgumentException(
"This sketch requires a minimum nominal entries of " + (1 << ALPHA_MIN_LG_NOM_LONGS));
}
final double nomLongs = (1L << lgNomLongs);
final double alpha = nomLongs / (nomLongs + 1.0);
final long split1 = (long) (((p * (alpha + 1.0)) / 2.0) * MAX_THETA_LONG_AS_DOUBLE);
final HeapAlphaSketch has = new HeapAlphaSketch(lgNomLongs, seed, p, rf, alpha, split1);
final int lgArrLongs = Util.startingSubMultiple(lgNomLongs + 1, rf, MIN_LG_ARR_LONGS);
has.lgArrLongs_ = lgArrLongs;
has.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
has.curCount_ = 0;
has.thetaLong_ = (long)(p * MAX_THETA_LONG_AS_DOUBLE);
has.empty_ = true; //other flags: bigEndian = readOnly = compact = ordered = false;
has.cache_ = new long[1 << lgArrLongs];
return has;
} | java | static HeapAlphaSketch newHeapInstance(final int lgNomLongs, final long seed, final float p,
final ResizeFactor rf) {
if (lgNomLongs < ALPHA_MIN_LG_NOM_LONGS) {
throw new SketchesArgumentException(
"This sketch requires a minimum nominal entries of " + (1 << ALPHA_MIN_LG_NOM_LONGS));
}
final double nomLongs = (1L << lgNomLongs);
final double alpha = nomLongs / (nomLongs + 1.0);
final long split1 = (long) (((p * (alpha + 1.0)) / 2.0) * MAX_THETA_LONG_AS_DOUBLE);
final HeapAlphaSketch has = new HeapAlphaSketch(lgNomLongs, seed, p, rf, alpha, split1);
final int lgArrLongs = Util.startingSubMultiple(lgNomLongs + 1, rf, MIN_LG_ARR_LONGS);
has.lgArrLongs_ = lgArrLongs;
has.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
has.curCount_ = 0;
has.thetaLong_ = (long)(p * MAX_THETA_LONG_AS_DOUBLE);
has.empty_ = true; //other flags: bigEndian = readOnly = compact = ordered = false;
has.cache_ = new long[1 << lgArrLongs];
return has;
} | [
"static",
"HeapAlphaSketch",
"newHeapInstance",
"(",
"final",
"int",
"lgNomLongs",
",",
"final",
"long",
"seed",
",",
"final",
"float",
"p",
",",
"final",
"ResizeFactor",
"rf",
")",
"{",
"if",
"(",
"lgNomLongs",
"<",
"ALPHA_MIN_LG_NOM_LONGS",
")",
"{",
"throw"... | Get a new sketch instance on the java heap.
@param lgNomLongs <a href="{@docRoot}/resources/dictionary.html#lgNomLongs">See lgNomLongs</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>
@param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>
@param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
@return instance of this sketch | [
"Get",
"a",
"new",
"sketch",
"instance",
"on",
"the",
"java",
"heap",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/HeapAlphaSketch.java#L77-L99 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/HeapAlphaSketch.java | HeapAlphaSketch.heapifyInstance | static HeapAlphaSketch heapifyInstance(final Memory srcMem, final long seed) {
final int preambleLongs = extractPreLongs(srcMem); //byte 0
final int lgNomLongs = extractLgNomLongs(srcMem); //byte 3
final int lgArrLongs = extractLgArrLongs(srcMem); //byte 4
checkAlphaFamily(srcMem, preambleLongs, lgNomLongs);
checkMemIntegrity(srcMem, seed, preambleLongs, lgNomLongs, lgArrLongs);
final float p = extractP(srcMem); //bytes 12-15
final int lgRF = extractLgResizeFactor(srcMem); //byte 0
final ResizeFactor myRF = ResizeFactor.getRF(lgRF);
final double nomLongs = (1L << lgNomLongs);
final double alpha = nomLongs / (nomLongs + 1.0);
final long split1 = (long) (((p * (alpha + 1.0)) / 2.0) * MAX_THETA_LONG_AS_DOUBLE);
if ((myRF == ResizeFactor.X1)
&& (lgArrLongs != Util.startingSubMultiple(lgNomLongs + 1, myRF, MIN_LG_ARR_LONGS))) {
throw new SketchesArgumentException("Possible corruption: ResizeFactor X1, but provided "
+ "array too small for sketch size");
}
final HeapAlphaSketch has = new HeapAlphaSketch(lgNomLongs, seed, p, myRF, alpha, split1);
has.lgArrLongs_ = lgArrLongs;
has.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
has.curCount_ = extractCurCount(srcMem);
has.thetaLong_ = extractThetaLong(srcMem);
has.empty_ = PreambleUtil.isEmpty(srcMem);
has.cache_ = new long[1 << lgArrLongs];
srcMem.getLongArray(preambleLongs << 3, has.cache_, 0, 1 << lgArrLongs); //read in as hash table
return has;
} | java | static HeapAlphaSketch heapifyInstance(final Memory srcMem, final long seed) {
final int preambleLongs = extractPreLongs(srcMem); //byte 0
final int lgNomLongs = extractLgNomLongs(srcMem); //byte 3
final int lgArrLongs = extractLgArrLongs(srcMem); //byte 4
checkAlphaFamily(srcMem, preambleLongs, lgNomLongs);
checkMemIntegrity(srcMem, seed, preambleLongs, lgNomLongs, lgArrLongs);
final float p = extractP(srcMem); //bytes 12-15
final int lgRF = extractLgResizeFactor(srcMem); //byte 0
final ResizeFactor myRF = ResizeFactor.getRF(lgRF);
final double nomLongs = (1L << lgNomLongs);
final double alpha = nomLongs / (nomLongs + 1.0);
final long split1 = (long) (((p * (alpha + 1.0)) / 2.0) * MAX_THETA_LONG_AS_DOUBLE);
if ((myRF == ResizeFactor.X1)
&& (lgArrLongs != Util.startingSubMultiple(lgNomLongs + 1, myRF, MIN_LG_ARR_LONGS))) {
throw new SketchesArgumentException("Possible corruption: ResizeFactor X1, but provided "
+ "array too small for sketch size");
}
final HeapAlphaSketch has = new HeapAlphaSketch(lgNomLongs, seed, p, myRF, alpha, split1);
has.lgArrLongs_ = lgArrLongs;
has.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
has.curCount_ = extractCurCount(srcMem);
has.thetaLong_ = extractThetaLong(srcMem);
has.empty_ = PreambleUtil.isEmpty(srcMem);
has.cache_ = new long[1 << lgArrLongs];
srcMem.getLongArray(preambleLongs << 3, has.cache_, 0, 1 << lgArrLongs); //read in as hash table
return has;
} | [
"static",
"HeapAlphaSketch",
"heapifyInstance",
"(",
"final",
"Memory",
"srcMem",
",",
"final",
"long",
"seed",
")",
"{",
"final",
"int",
"preambleLongs",
"=",
"extractPreLongs",
"(",
"srcMem",
")",
";",
"//byte 0",
"final",
"int",
"lgNomLongs",
"=",
"extractLgN... | Heapify a sketch from a Memory object containing sketch data.
@param srcMem The source Memory object.
<a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
@return instance of this sketch | [
"Heapify",
"a",
"sketch",
"from",
"a",
"Memory",
"object",
"containing",
"sketch",
"data",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/HeapAlphaSketch.java#L108-L139 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/HeapAlphaSketch.java | HeapAlphaSketch.getR | private static final int getR(final double theta, final double alpha, final double p) {
final double split1 = (p * (alpha + 1.0)) / 2.0;
if (theta > split1) { return 0; }
if (theta > (alpha * split1)) { return 1; }
return 2;
} | java | private static final int getR(final double theta, final double alpha, final double p) {
final double split1 = (p * (alpha + 1.0)) / 2.0;
if (theta > split1) { return 0; }
if (theta > (alpha * split1)) { return 1; }
return 2;
} | [
"private",
"static",
"final",
"int",
"getR",
"(",
"final",
"double",
"theta",
",",
"final",
"double",
"alpha",
",",
"final",
"double",
"p",
")",
"{",
"final",
"double",
"split1",
"=",
"(",
"p",
"*",
"(",
"alpha",
"+",
"1.0",
")",
")",
"/",
"2.0",
"... | Computes whether there have been 0, 1, or 2 or more actual insertions into the cache in a
numerically safe way.
@param theta <a href="{@docRoot}/resources/dictionary.html#theta">See Theta</a>.
@param alpha internal computed value alpha.
@param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>.
@return R. | [
"Computes",
"whether",
"there",
"have",
"been",
"0",
"1",
"or",
"2",
"or",
"more",
"actual",
"insertions",
"into",
"the",
"cache",
"in",
"a",
"numerically",
"safe",
"way",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/HeapAlphaSketch.java#L528-L533 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUnion.java | ArrayOfDoublesUnion.wrap | public static ArrayOfDoublesUnion wrap(final Memory mem, final long seed) {
return wrapUnionImpl((WritableMemory) mem, seed, false);
} | java | public static ArrayOfDoublesUnion wrap(final Memory mem, final long seed) {
return wrapUnionImpl((WritableMemory) mem, seed, false);
} | [
"public",
"static",
"ArrayOfDoublesUnion",
"wrap",
"(",
"final",
"Memory",
"mem",
",",
"final",
"long",
"seed",
")",
"{",
"return",
"wrapUnionImpl",
"(",
"(",
"WritableMemory",
")",
"mem",
",",
"seed",
",",
"false",
")",
";",
"}"
] | Wrap the given Memory and seed as an ArrayOfDoublesUnion
@param mem the given Memory
@param seed the given seed
@return an ArrayOfDoublesUnion | [
"Wrap",
"the",
"given",
"Memory",
"and",
"seed",
"as",
"an",
"ArrayOfDoublesUnion"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUnion.java#L90-L92 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUnion.java | ArrayOfDoublesUnion.update | public void update(final ArrayOfDoublesSketch sketchIn) {
if (sketchIn == null) { return; }
Util.checkSeedHashes(seedHash_, sketchIn.getSeedHash());
if (sketch_.getNumValues() != sketchIn.getNumValues()) {
throw new SketchesArgumentException("Incompatible sketches: number of values mismatch "
+ sketch_.getNumValues() + " and " + sketchIn.getNumValues());
}
if (sketchIn.isEmpty()) { return; }
if (sketchIn.getThetaLong() < theta_) { theta_ = sketchIn.getThetaLong(); }
final ArrayOfDoublesSketchIterator it = sketchIn.iterator();
while (it.next()) {
sketch_.merge(it.getKey(), it.getValues());
}
} | java | public void update(final ArrayOfDoublesSketch sketchIn) {
if (sketchIn == null) { return; }
Util.checkSeedHashes(seedHash_, sketchIn.getSeedHash());
if (sketch_.getNumValues() != sketchIn.getNumValues()) {
throw new SketchesArgumentException("Incompatible sketches: number of values mismatch "
+ sketch_.getNumValues() + " and " + sketchIn.getNumValues());
}
if (sketchIn.isEmpty()) { return; }
if (sketchIn.getThetaLong() < theta_) { theta_ = sketchIn.getThetaLong(); }
final ArrayOfDoublesSketchIterator it = sketchIn.iterator();
while (it.next()) {
sketch_.merge(it.getKey(), it.getValues());
}
} | [
"public",
"void",
"update",
"(",
"final",
"ArrayOfDoublesSketch",
"sketchIn",
")",
"{",
"if",
"(",
"sketchIn",
"==",
"null",
")",
"{",
"return",
";",
"}",
"Util",
".",
"checkSeedHashes",
"(",
"seedHash_",
",",
"sketchIn",
".",
"getSeedHash",
"(",
")",
")",... | Updates the union by adding a set of entries from a given sketch
@param sketchIn sketch to add to the union | [
"Updates",
"the",
"union",
"by",
"adding",
"a",
"set",
"of",
"entries",
"from",
"a",
"given",
"sketch"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUnion.java#L117-L130 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUnion.java | ArrayOfDoublesUnion.getResult | public ArrayOfDoublesCompactSketch getResult(final WritableMemory dstMem) {
if (sketch_.getRetainedEntries() > sketch_.getNominalEntries()) {
theta_ = Math.min(theta_, sketch_.getNewTheta());
}
if (dstMem == null) {
return new HeapArrayOfDoublesCompactSketch(sketch_, theta_);
}
return new DirectArrayOfDoublesCompactSketch(sketch_, theta_, dstMem);
} | java | public ArrayOfDoublesCompactSketch getResult(final WritableMemory dstMem) {
if (sketch_.getRetainedEntries() > sketch_.getNominalEntries()) {
theta_ = Math.min(theta_, sketch_.getNewTheta());
}
if (dstMem == null) {
return new HeapArrayOfDoublesCompactSketch(sketch_, theta_);
}
return new DirectArrayOfDoublesCompactSketch(sketch_, theta_, dstMem);
} | [
"public",
"ArrayOfDoublesCompactSketch",
"getResult",
"(",
"final",
"WritableMemory",
"dstMem",
")",
"{",
"if",
"(",
"sketch_",
".",
"getRetainedEntries",
"(",
")",
">",
"sketch_",
".",
"getNominalEntries",
"(",
")",
")",
"{",
"theta_",
"=",
"Math",
".",
"min"... | Returns the resulting union in the form of a compact sketch
@param dstMem memory for the result (can be null)
@return compact sketch representing the union (off-heap if memory is provided) | [
"Returns",
"the",
"resulting",
"union",
"in",
"the",
"form",
"of",
"a",
"compact",
"sketch"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/ArrayOfDoublesUnion.java#L137-L145 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hll/HllArray.java | HllArray.extractCommonHll | static final void extractCommonHll(final Memory srcMem, final HllArray hllArray) {
hllArray.putOutOfOrderFlag(extractOooFlag(srcMem));
hllArray.putCurMin(extractCurMin(srcMem));
hllArray.putHipAccum(extractHipAccum(srcMem));
hllArray.putKxQ0(extractKxQ0(srcMem));
hllArray.putKxQ1(extractKxQ1(srcMem));
hllArray.putNumAtCurMin(extractNumAtCurMin(srcMem));
//load Hll array
srcMem.getByteArray(HLL_BYTE_ARR_START, hllArray.hllByteArr, 0, hllArray.hllByteArr.length);
} | java | static final void extractCommonHll(final Memory srcMem, final HllArray hllArray) {
hllArray.putOutOfOrderFlag(extractOooFlag(srcMem));
hllArray.putCurMin(extractCurMin(srcMem));
hllArray.putHipAccum(extractHipAccum(srcMem));
hllArray.putKxQ0(extractKxQ0(srcMem));
hllArray.putKxQ1(extractKxQ1(srcMem));
hllArray.putNumAtCurMin(extractNumAtCurMin(srcMem));
//load Hll array
srcMem.getByteArray(HLL_BYTE_ARR_START, hllArray.hllByteArr, 0, hllArray.hllByteArr.length);
} | [
"static",
"final",
"void",
"extractCommonHll",
"(",
"final",
"Memory",
"srcMem",
",",
"final",
"HllArray",
"hllArray",
")",
"{",
"hllArray",
".",
"putOutOfOrderFlag",
"(",
"extractOooFlag",
"(",
"srcMem",
")",
")",
";",
"hllArray",
".",
"putCurMin",
"(",
"extr... | used by heapify by all Heap HLL | [
"used",
"by",
"heapify",
"by",
"all",
"Heap",
"HLL"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/HllArray.java#L238-L248 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/DirectCompactSketch.java | DirectCompactSketch.compactMemoryToByteArray | static byte[] compactMemoryToByteArray(final Memory srcMem, final int preLongs,
final int curCount) {
final int outBytes = (curCount + preLongs) << 3;
final byte[] byteArrOut = new byte[outBytes];
srcMem.getByteArray(0, byteArrOut, 0, outBytes); //copies the whole thing
return byteArrOut;
} | java | static byte[] compactMemoryToByteArray(final Memory srcMem, final int preLongs,
final int curCount) {
final int outBytes = (curCount + preLongs) << 3;
final byte[] byteArrOut = new byte[outBytes];
srcMem.getByteArray(0, byteArrOut, 0, outBytes); //copies the whole thing
return byteArrOut;
} | [
"static",
"byte",
"[",
"]",
"compactMemoryToByteArray",
"(",
"final",
"Memory",
"srcMem",
",",
"final",
"int",
"preLongs",
",",
"final",
"int",
"curCount",
")",
"{",
"final",
"int",
"outBytes",
"=",
"(",
"curCount",
"+",
"preLongs",
")",
"<<",
"3",
";",
... | Serializes a Memory based compact sketch to a byte array
@param srcMem the source Memory
@param preLongs current preamble longs
@param curCount the current valid count
@return this Direct, Compact sketch as a byte array | [
"Serializes",
"a",
"Memory",
"based",
"compact",
"sketch",
"to",
"a",
"byte",
"array"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/DirectCompactSketch.java#L126-L132 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/Rebuilder.java | Rebuilder.quickSelectAndRebuild | static final void quickSelectAndRebuild(final WritableMemory mem, final int preambleLongs,
final int lgNomLongs) {
//Note: This copies the Memory data onto the heap and then at the end copies the result
// back to Memory. Even if we tried to do this directly into Memory it would require pre-clearing,
// and the internal loops would be slower. The bulk copies are performed at a low level and
// are quite fast. Measurements reveal that we are not paying much of a penalty.
//Pull data into tmp arr for QS algo
final int lgArrLongs = extractLgArrLongs(mem);
final int curCount = extractCurCount(mem);
final int arrLongs = 1 << lgArrLongs;
final long[] tmpArr = new long[arrLongs];
final int preBytes = preambleLongs << 3;
mem.getLongArray(preBytes, tmpArr, 0, arrLongs); //copy mem data to tmpArr
//Do the QuickSelect on a tmp arr to create new thetaLong
final int pivot = (1 << lgNomLongs) + 1; // (K+1) pivot for QS
final long newThetaLong = selectExcludingZeros(tmpArr, curCount, pivot);
insertThetaLong(mem, newThetaLong); //UPDATE thetalong
//Rebuild to clean up dirty data, update count
final long[] tgtArr = new long[arrLongs];
final int newCurCount =
HashOperations.hashArrayInsert(tmpArr, tgtArr, lgArrLongs, newThetaLong);
insertCurCount(mem, newCurCount); //UPDATE curCount
//put the rebuilt array back into memory
mem.putLongArray(preBytes, tgtArr, 0, arrLongs);
} | java | static final void quickSelectAndRebuild(final WritableMemory mem, final int preambleLongs,
final int lgNomLongs) {
//Note: This copies the Memory data onto the heap and then at the end copies the result
// back to Memory. Even if we tried to do this directly into Memory it would require pre-clearing,
// and the internal loops would be slower. The bulk copies are performed at a low level and
// are quite fast. Measurements reveal that we are not paying much of a penalty.
//Pull data into tmp arr for QS algo
final int lgArrLongs = extractLgArrLongs(mem);
final int curCount = extractCurCount(mem);
final int arrLongs = 1 << lgArrLongs;
final long[] tmpArr = new long[arrLongs];
final int preBytes = preambleLongs << 3;
mem.getLongArray(preBytes, tmpArr, 0, arrLongs); //copy mem data to tmpArr
//Do the QuickSelect on a tmp arr to create new thetaLong
final int pivot = (1 << lgNomLongs) + 1; // (K+1) pivot for QS
final long newThetaLong = selectExcludingZeros(tmpArr, curCount, pivot);
insertThetaLong(mem, newThetaLong); //UPDATE thetalong
//Rebuild to clean up dirty data, update count
final long[] tgtArr = new long[arrLongs];
final int newCurCount =
HashOperations.hashArrayInsert(tmpArr, tgtArr, lgArrLongs, newThetaLong);
insertCurCount(mem, newCurCount); //UPDATE curCount
//put the rebuilt array back into memory
mem.putLongArray(preBytes, tgtArr, 0, arrLongs);
} | [
"static",
"final",
"void",
"quickSelectAndRebuild",
"(",
"final",
"WritableMemory",
"mem",
",",
"final",
"int",
"preambleLongs",
",",
"final",
"int",
"lgNomLongs",
")",
"{",
"//Note: This copies the Memory data onto the heap and then at the end copies the result",
"// back to M... | Rebuild the hashTable in the given Memory at its current size. Changes theta and thus count.
This assumes a Memory preamble of standard form with correct values of curCount and thetaLong.
ThetaLong and curCount will change.
Afterwards, caller must update local class members curCount and thetaLong from Memory.
@param mem the Memory the given Memory
@param preambleLongs size of preamble in longs
@param lgNomLongs the log_base2 of k, the configuration parameter of the sketch | [
"Rebuild",
"the",
"hashTable",
"in",
"the",
"given",
"Memory",
"at",
"its",
"current",
"size",
".",
"Changes",
"theta",
"and",
"thus",
"count",
".",
"This",
"assumes",
"a",
"Memory",
"preamble",
"of",
"standard",
"form",
"with",
"correct",
"values",
"of",
... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/Rebuilder.java#L42-L70 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/Rebuilder.java | Rebuilder.resize | static final void resize(final WritableMemory mem, final int preambleLongs,
final int srcLgArrLongs, final int tgtLgArrLongs) {
//Note: This copies the Memory data onto the heap and then at the end copies the result
// back to Memory. Even if we tried to do this directly into Memory it would require pre-clearing,
// and the internal loops would be slower. The bulk copies are performed at a low level and
// are quite fast. Measurements reveal that we are not paying much of a penalty.
//Preamble stays in place
final int preBytes = preambleLongs << 3;
//Bulk copy source to on-heap buffer
final int srcHTLen = 1 << srcLgArrLongs; //current value
final long[] srcHTArr = new long[srcHTLen]; //on-heap src buffer
mem.getLongArray(preBytes, srcHTArr, 0, srcHTLen);
//Create destination on-heap buffer
final int dstHTLen = 1 << tgtLgArrLongs;
final long[] dstHTArr = new long[dstHTLen]; //on-heap dst buffer
//Rebuild hash table in destination buffer
final long thetaLong = extractThetaLong(mem);
HashOperations.hashArrayInsert(srcHTArr, dstHTArr, tgtLgArrLongs, thetaLong);
//Bulk copy to destination memory
mem.putLongArray(preBytes, dstHTArr, 0, dstHTLen); //put it back, no need to clear
insertLgArrLongs(mem, tgtLgArrLongs); //update in mem
} | java | static final void resize(final WritableMemory mem, final int preambleLongs,
final int srcLgArrLongs, final int tgtLgArrLongs) {
//Note: This copies the Memory data onto the heap and then at the end copies the result
// back to Memory. Even if we tried to do this directly into Memory it would require pre-clearing,
// and the internal loops would be slower. The bulk copies are performed at a low level and
// are quite fast. Measurements reveal that we are not paying much of a penalty.
//Preamble stays in place
final int preBytes = preambleLongs << 3;
//Bulk copy source to on-heap buffer
final int srcHTLen = 1 << srcLgArrLongs; //current value
final long[] srcHTArr = new long[srcHTLen]; //on-heap src buffer
mem.getLongArray(preBytes, srcHTArr, 0, srcHTLen);
//Create destination on-heap buffer
final int dstHTLen = 1 << tgtLgArrLongs;
final long[] dstHTArr = new long[dstHTLen]; //on-heap dst buffer
//Rebuild hash table in destination buffer
final long thetaLong = extractThetaLong(mem);
HashOperations.hashArrayInsert(srcHTArr, dstHTArr, tgtLgArrLongs, thetaLong);
//Bulk copy to destination memory
mem.putLongArray(preBytes, dstHTArr, 0, dstHTLen); //put it back, no need to clear
insertLgArrLongs(mem, tgtLgArrLongs); //update in mem
} | [
"static",
"final",
"void",
"resize",
"(",
"final",
"WritableMemory",
"mem",
",",
"final",
"int",
"preambleLongs",
",",
"final",
"int",
"srcLgArrLongs",
",",
"final",
"int",
"tgtLgArrLongs",
")",
"{",
"//Note: This copies the Memory data onto the heap and then at the end c... | Resizes existing hash array into a larger one within a single Memory assuming enough space.
This assumes a Memory preamble of standard form with the correct value of thetaLong.
The Memory lgArrLongs will change.
Afterwards, the caller must update local copies of lgArrLongs and hashTableThreshold from
Memory.
@param mem the Memory
@param preambleLongs the size of the preamble in longs
@param srcLgArrLongs the size of the source hash table
@param tgtLgArrLongs the LgArrLongs value for the new hash table | [
"Resizes",
"existing",
"hash",
"array",
"into",
"a",
"larger",
"one",
"within",
"a",
"single",
"Memory",
"assuming",
"enough",
"space",
".",
"This",
"assumes",
"a",
"Memory",
"preamble",
"of",
"standard",
"form",
"with",
"the",
"correct",
"value",
"of",
"the... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/Rebuilder.java#L125-L147 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/Rebuilder.java | Rebuilder.actLgResizeFactor | static final int actLgResizeFactor(final long capBytes, final int lgArrLongs, final int preLongs,
final int lgRF) {
final int maxHTLongs = Util.floorPowerOf2(((int)(capBytes >>> 3) - preLongs));
final int lgFactor = Math.max(Integer.numberOfTrailingZeros(maxHTLongs) - lgArrLongs, 0);
return (lgFactor >= lgRF) ? lgRF : lgFactor;
} | java | static final int actLgResizeFactor(final long capBytes, final int lgArrLongs, final int preLongs,
final int lgRF) {
final int maxHTLongs = Util.floorPowerOf2(((int)(capBytes >>> 3) - preLongs));
final int lgFactor = Math.max(Integer.numberOfTrailingZeros(maxHTLongs) - lgArrLongs, 0);
return (lgFactor >= lgRF) ? lgRF : lgFactor;
} | [
"static",
"final",
"int",
"actLgResizeFactor",
"(",
"final",
"long",
"capBytes",
",",
"final",
"int",
"lgArrLongs",
",",
"final",
"int",
"preLongs",
",",
"final",
"int",
"lgRF",
")",
"{",
"final",
"int",
"maxHTLongs",
"=",
"Util",
".",
"floorPowerOf2",
"(",
... | Returns the actual log2 Resize Factor that can be used to grow the hash table. This will be
an integer value between zero and the given lgRF, inclusive;
@param capBytes the current memory capacity in bytes
@param lgArrLongs the current lg hash table size in longs
@param preLongs the current preamble size in longs
@param lgRF the configured lg Resize Factor
@return the actual log2 Resize Factor that can be used to grow the hash table | [
"Returns",
"the",
"actual",
"log2",
"Resize",
"Factor",
"that",
"can",
"be",
"used",
"to",
"grow",
"the",
"hash",
"table",
".",
"This",
"will",
"be",
"an",
"integer",
"value",
"between",
"zero",
"and",
"the",
"given",
"lgRF",
"inclusive",
";"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/Rebuilder.java#L158-L163 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UpdateSketchBuilder.java | UpdateSketchBuilder.setLogNominalEntries | public UpdateSketchBuilder setLogNominalEntries(final int lgNomEntries) {
bLgNomLongs = lgNomEntries;
if ((bLgNomLongs > MAX_LG_NOM_LONGS) || (bLgNomLongs < MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException(
"Log Nominal Entries must be >= 4 and <= 26: " + lgNomEntries);
}
return this;
} | java | public UpdateSketchBuilder setLogNominalEntries(final int lgNomEntries) {
bLgNomLongs = lgNomEntries;
if ((bLgNomLongs > MAX_LG_NOM_LONGS) || (bLgNomLongs < MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException(
"Log Nominal Entries must be >= 4 and <= 26: " + lgNomEntries);
}
return this;
} | [
"public",
"UpdateSketchBuilder",
"setLogNominalEntries",
"(",
"final",
"int",
"lgNomEntries",
")",
"{",
"bLgNomLongs",
"=",
"lgNomEntries",
";",
"if",
"(",
"(",
"bLgNomLongs",
">",
"MAX_LG_NOM_LONGS",
")",
"||",
"(",
"bLgNomLongs",
"<",
"MIN_LG_NOM_LONGS",
")",
")... | Alternative method of setting the Nominal Entries for this sketch from the log_base2 value.
This value is also used for building a shared concurrent sketch.
The minimum value is 4 and the maximum value is 26.
Be aware that sketches as large as this maximum value may not have been
thoroughly tested or characterized for performance.
@param lgNomEntries the Log Nominal Entries for the concurrent shared sketch
@return this UpdateSketchBuilder | [
"Alternative",
"method",
"of",
"setting",
"the",
"Nominal",
"Entries",
"for",
"this",
"sketch",
"from",
"the",
"log_base2",
"value",
".",
"This",
"value",
"is",
"also",
"used",
"for",
"building",
"a",
"shared",
"concurrent",
"sketch",
".",
"The",
"minimum",
... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UpdateSketchBuilder.java#L109-L116 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UpdateSketchBuilder.java | UpdateSketchBuilder.setLocalNominalEntries | public UpdateSketchBuilder setLocalNominalEntries(final int nomEntries) {
bLocalLgNomLongs = Integer.numberOfTrailingZeros(ceilingPowerOf2(nomEntries));
if ((bLocalLgNomLongs > MAX_LG_NOM_LONGS) || (bLocalLgNomLongs < MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException(
"Nominal Entries must be >= 16 and <= 67108864: " + nomEntries);
}
return this;
} | java | public UpdateSketchBuilder setLocalNominalEntries(final int nomEntries) {
bLocalLgNomLongs = Integer.numberOfTrailingZeros(ceilingPowerOf2(nomEntries));
if ((bLocalLgNomLongs > MAX_LG_NOM_LONGS) || (bLocalLgNomLongs < MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException(
"Nominal Entries must be >= 16 and <= 67108864: " + nomEntries);
}
return this;
} | [
"public",
"UpdateSketchBuilder",
"setLocalNominalEntries",
"(",
"final",
"int",
"nomEntries",
")",
"{",
"bLocalLgNomLongs",
"=",
"Integer",
".",
"numberOfTrailingZeros",
"(",
"ceilingPowerOf2",
"(",
"nomEntries",
")",
")",
";",
"if",
"(",
"(",
"bLocalLgNomLongs",
">... | Sets the Nominal Entries for the concurrent local sketch. The minimum value is 16 and the
maximum value is 67,108,864, which is 2^26.
Be aware that sketches as large as this maximum
value have not been thoroughly tested or characterized for performance.
@param nomEntries <a href="{@docRoot}/resources/dictionary.html#nomEntries">Nominal Entries</a>
This will become the ceiling power of 2 if it is not.
@return this ConcurrentThetaBuilder | [
"Sets",
"the",
"Nominal",
"Entries",
"for",
"the",
"concurrent",
"local",
"sketch",
".",
"The",
"minimum",
"value",
"is",
"16",
"and",
"the",
"maximum",
"value",
"is",
"67",
"108",
"864",
"which",
"is",
"2^26",
".",
"Be",
"aware",
"that",
"sketches",
"as... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UpdateSketchBuilder.java#L136-L143 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UpdateSketchBuilder.java | UpdateSketchBuilder.setLocalLogNominalEntries | public UpdateSketchBuilder setLocalLogNominalEntries(final int lgNomEntries) {
bLocalLgNomLongs = lgNomEntries;
if ((bLocalLgNomLongs > MAX_LG_NOM_LONGS) || (bLocalLgNomLongs < MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException(
"Log Nominal Entries must be >= 4 and <= 26: " + lgNomEntries);
}
return this;
} | java | public UpdateSketchBuilder setLocalLogNominalEntries(final int lgNomEntries) {
bLocalLgNomLongs = lgNomEntries;
if ((bLocalLgNomLongs > MAX_LG_NOM_LONGS) || (bLocalLgNomLongs < MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException(
"Log Nominal Entries must be >= 4 and <= 26: " + lgNomEntries);
}
return this;
} | [
"public",
"UpdateSketchBuilder",
"setLocalLogNominalEntries",
"(",
"final",
"int",
"lgNomEntries",
")",
"{",
"bLocalLgNomLongs",
"=",
"lgNomEntries",
";",
"if",
"(",
"(",
"bLocalLgNomLongs",
">",
"MAX_LG_NOM_LONGS",
")",
"||",
"(",
"bLocalLgNomLongs",
"<",
"MIN_LG_NOM... | Alternative method of setting the Nominal Entries for a local concurrent sketch from the
log_base2 value.
The minimum value is 4 and the maximum value is 26.
Be aware that sketches as large as this maximum
value have not been thoroughly tested or characterized for performance.
@param lgNomEntries the Log Nominal Entries for a concurrent local sketch
@return this ConcurrentThetaBuilder | [
"Alternative",
"method",
"of",
"setting",
"the",
"Nominal",
"Entries",
"for",
"a",
"local",
"concurrent",
"sketch",
"from",
"the",
"log_base2",
"value",
".",
"The",
"minimum",
"value",
"is",
"4",
"and",
"the",
"maximum",
"value",
"is",
"26",
".",
"Be",
"aw... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UpdateSketchBuilder.java#L155-L162 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/theta/UpdateSketchBuilder.java | UpdateSketchBuilder.buildLocal | public UpdateSketch buildLocal(final UpdateSketch shared) {
if ((shared == null) || !(shared instanceof ConcurrentSharedThetaSketch)) {
throw new SketchesStateException("The concurrent shared sketch must be built first.");
}
return new ConcurrentHeapThetaBuffer(bLocalLgNomLongs, bSeed,
(ConcurrentSharedThetaSketch) shared, bPropagateOrderedCompact, bMaxNumLocalThreads);
} | java | public UpdateSketch buildLocal(final UpdateSketch shared) {
if ((shared == null) || !(shared instanceof ConcurrentSharedThetaSketch)) {
throw new SketchesStateException("The concurrent shared sketch must be built first.");
}
return new ConcurrentHeapThetaBuffer(bLocalLgNomLongs, bSeed,
(ConcurrentSharedThetaSketch) shared, bPropagateOrderedCompact, bMaxNumLocalThreads);
} | [
"public",
"UpdateSketch",
"buildLocal",
"(",
"final",
"UpdateSketch",
"shared",
")",
"{",
"if",
"(",
"(",
"shared",
"==",
"null",
")",
"||",
"!",
"(",
"shared",
"instanceof",
"ConcurrentSharedThetaSketch",
")",
")",
"{",
"throw",
"new",
"SketchesStateException",... | Returns a local concurrent UpdateSketch to be used as a per-thread local buffer along with the
given concurrent shared UpdateSketch and the current configuration of this Builder
<p>The parameters unique to the local concurrent sketch are:
<ul>
<li>Local Nominal Entries or Local Log Nominal Entries</li>
<li>Propagate Ordered Compact flag</li>
</ul>
@param shared the concurrent shared sketch to be accessed via the concurrent local sketch.
@return an UpdateSketch to be used as a per-thread local buffer. | [
"Returns",
"a",
"local",
"concurrent",
"UpdateSketch",
"to",
"be",
"used",
"as",
"a",
"per",
"-",
"thread",
"local",
"buffer",
"along",
"with",
"the",
"given",
"concurrent",
"shared",
"UpdateSketch",
"and",
"the",
"current",
"configuration",
"of",
"this",
"Bui... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/theta/UpdateSketchBuilder.java#L465-L471 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.copy | CpcSketch copy() {
final CpcSketch copy = new CpcSketch(lgK, seed);
copy.numCoupons = numCoupons;
copy.mergeFlag = mergeFlag;
copy.fiCol = fiCol;
copy.windowOffset = windowOffset;
copy.slidingWindow = (slidingWindow == null) ? null : slidingWindow.clone();
copy.pairTable = (pairTable == null) ? null : pairTable.copy();
copy.kxp = kxp;
copy.hipEstAccum = hipEstAccum;
return copy;
} | java | CpcSketch copy() {
final CpcSketch copy = new CpcSketch(lgK, seed);
copy.numCoupons = numCoupons;
copy.mergeFlag = mergeFlag;
copy.fiCol = fiCol;
copy.windowOffset = windowOffset;
copy.slidingWindow = (slidingWindow == null) ? null : slidingWindow.clone();
copy.pairTable = (pairTable == null) ? null : pairTable.copy();
copy.kxp = kxp;
copy.hipEstAccum = hipEstAccum;
return copy;
} | [
"CpcSketch",
"copy",
"(",
")",
"{",
"final",
"CpcSketch",
"copy",
"=",
"new",
"CpcSketch",
"(",
"lgK",
",",
"seed",
")",
";",
"copy",
".",
"numCoupons",
"=",
"numCoupons",
";",
"copy",
".",
"mergeFlag",
"=",
"mergeFlag",
";",
"copy",
".",
"fiCol",
"=",... | Returns a copy of this sketch
@return a copy of this sketch | [
"Returns",
"a",
"copy",
"of",
"this",
"sketch"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L101-L114 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.getMaxSerializedBytes | public static int getMaxSerializedBytes(final int lgK) {
checkLgK(lgK);
if (lgK <= 19) { return empiricalMaxBytes[lgK - 4] + 40; }
final int k = 1 << lgK;
return (int) (0.6 * k) + 40; // 0.6 = 4.8 / 8.0
} | java | public static int getMaxSerializedBytes(final int lgK) {
checkLgK(lgK);
if (lgK <= 19) { return empiricalMaxBytes[lgK - 4] + 40; }
final int k = 1 << lgK;
return (int) (0.6 * k) + 40; // 0.6 = 4.8 / 8.0
} | [
"public",
"static",
"int",
"getMaxSerializedBytes",
"(",
"final",
"int",
"lgK",
")",
"{",
"checkLgK",
"(",
"lgK",
")",
";",
"if",
"(",
"lgK",
"<=",
"19",
")",
"{",
"return",
"empiricalMaxBytes",
"[",
"lgK",
"-",
"4",
"]",
"+",
"40",
";",
"}",
"final"... | The actual size of a compressed CPC sketch has a small random variance, but the following
empirically measured size should be large enough for at least 99.9 percent of sketches.
<p>For small values of <i>n</i> the size can be much smaller.
@param lgK the given value of lgK.
@return the estimated maximum compressed serialized size of a sketch. | [
"The",
"actual",
"size",
"of",
"a",
"compressed",
"CPC",
"sketch",
"has",
"a",
"small",
"random",
"variance",
"but",
"the",
"following",
"empirically",
"measured",
"size",
"should",
"be",
"large",
"enough",
"for",
"at",
"least",
"99",
".",
"9",
"percent",
... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L188-L193 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.heapify | public static CpcSketch heapify(final Memory mem, final long seed) {
final CompressedState state = CompressedState.importFromMemory(mem);
return uncompress(state, seed);
} | java | public static CpcSketch heapify(final Memory mem, final long seed) {
final CompressedState state = CompressedState.importFromMemory(mem);
return uncompress(state, seed);
} | [
"public",
"static",
"CpcSketch",
"heapify",
"(",
"final",
"Memory",
"mem",
",",
"final",
"long",
"seed",
")",
"{",
"final",
"CompressedState",
"state",
"=",
"CompressedState",
".",
"importFromMemory",
"(",
"mem",
")",
";",
"return",
"uncompress",
"(",
"state",... | Return the given Memory as a CpcSketch on the Java heap.
@param mem the given Memory
@param seed the seed used to create the original sketch from which the Memory was derived.
@return the given Memory as a CpcSketch on the Java heap. | [
"Return",
"the",
"given",
"Memory",
"as",
"a",
"CpcSketch",
"on",
"the",
"Java",
"heap",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L232-L235 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.heapify | public static CpcSketch heapify(final byte[] byteArray, final long seed) {
final Memory mem = Memory.wrap(byteArray);
return heapify(mem, seed);
} | java | public static CpcSketch heapify(final byte[] byteArray, final long seed) {
final Memory mem = Memory.wrap(byteArray);
return heapify(mem, seed);
} | [
"public",
"static",
"CpcSketch",
"heapify",
"(",
"final",
"byte",
"[",
"]",
"byteArray",
",",
"final",
"long",
"seed",
")",
"{",
"final",
"Memory",
"mem",
"=",
"Memory",
".",
"wrap",
"(",
"byteArray",
")",
";",
"return",
"heapify",
"(",
"mem",
",",
"se... | Return the given byte array as a CpcSketch on the Java heap.
@param byteArray the given byte array
@param seed the seed used to create the original sketch from which the byte array was derived.
@return the given byte array as a CpcSketch on the Java heap. | [
"Return",
"the",
"given",
"byte",
"array",
"as",
"a",
"CpcSketch",
"on",
"the",
"Java",
"heap",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L243-L246 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.reset | public final void reset() {
numCoupons = 0;
mergeFlag = false;
fiCol = 0;
windowOffset = 0;
slidingWindow = null;
pairTable = null;
kxp = 1 << lgK;
hipEstAccum = 0;
} | java | public final void reset() {
numCoupons = 0;
mergeFlag = false;
fiCol = 0;
windowOffset = 0;
slidingWindow = null;
pairTable = null;
kxp = 1 << lgK;
hipEstAccum = 0;
} | [
"public",
"final",
"void",
"reset",
"(",
")",
"{",
"numCoupons",
"=",
"0",
";",
"mergeFlag",
"=",
"false",
";",
"fiCol",
"=",
"0",
";",
"windowOffset",
"=",
"0",
";",
"slidingWindow",
"=",
"null",
";",
"pairTable",
"=",
"null",
";",
"kxp",
"=",
"1",
... | Resets this sketch to empty but retains the original LgK and Seed. | [
"Resets",
"this",
"sketch",
"to",
"empty",
"but",
"retains",
"the",
"original",
"LgK",
"and",
"Seed",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L259-L270 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.toByteArray | public byte[] toByteArray() {
final CompressedState state = CompressedState.compress(this);
final long cap = state.getRequiredSerializedBytes();
final WritableMemory wmem = WritableMemory.allocate((int) cap);
state.exportToMemory(wmem);
return (byte[]) wmem.getArray();
} | java | public byte[] toByteArray() {
final CompressedState state = CompressedState.compress(this);
final long cap = state.getRequiredSerializedBytes();
final WritableMemory wmem = WritableMemory.allocate((int) cap);
state.exportToMemory(wmem);
return (byte[]) wmem.getArray();
} | [
"public",
"byte",
"[",
"]",
"toByteArray",
"(",
")",
"{",
"final",
"CompressedState",
"state",
"=",
"CompressedState",
".",
"compress",
"(",
"this",
")",
";",
"final",
"long",
"cap",
"=",
"state",
".",
"getRequiredSerializedBytes",
"(",
")",
";",
"final",
... | Return this sketch as a compressed byte array.
@return this sketch as a compressed byte array. | [
"Return",
"this",
"sketch",
"as",
"a",
"compressed",
"byte",
"array",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L276-L282 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.update | public void update(final long datum) {
final long[] data = { datum };
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
} | java | public void update(final long datum) {
final long[] data = { datum };
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
} | [
"public",
"void",
"update",
"(",
"final",
"long",
"datum",
")",
"{",
"final",
"long",
"[",
"]",
"data",
"=",
"{",
"datum",
"}",
";",
"final",
"long",
"[",
"]",
"arr",
"=",
"hash",
"(",
"data",
",",
"seed",
")",
";",
"hashUpdate",
"(",
"arr",
"[",... | Present the given long as a potential unique item.
@param datum The given long datum. | [
"Present",
"the",
"given",
"long",
"as",
"a",
"potential",
"unique",
"item",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L289-L293 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.update | public void update(final int[] data) {
if ((data == null) || (data.length == 0)) { return; }
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
} | java | public void update(final int[] data) {
if ((data == null) || (data.length == 0)) { return; }
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
} | [
"public",
"void",
"update",
"(",
"final",
"int",
"[",
"]",
"data",
")",
"{",
"if",
"(",
"(",
"data",
"==",
"null",
")",
"||",
"(",
"data",
".",
"length",
"==",
"0",
")",
")",
"{",
"return",
";",
"}",
"final",
"long",
"[",
"]",
"arr",
"=",
"ha... | Present the given integer array as a potential unique item.
If the integer array is null or empty no update attempt is made and the method returns.
@param data The given int array. | [
"Present",
"the",
"given",
"integer",
"array",
"as",
"a",
"potential",
"unique",
"item",
".",
"If",
"the",
"integer",
"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/cpc/CpcSketch.java#L365-L369 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.getFormat | Format getFormat() {
final int ordinal;
final Flavor f = getFlavor();
if ((f == Flavor.HYBRID) || (f == Flavor.SPARSE)) {
ordinal = 2 | ( mergeFlag ? 0 : 1 ); //Hybrid is serialized as SPARSE
} else {
ordinal = ((slidingWindow != null) ? 4 : 0)
| (((pairTable != null) && (pairTable.getNumPairs() > 0)) ? 2 : 0)
| ( mergeFlag ? 0 : 1 );
}
return Format.ordinalToFormat(ordinal);
} | java | Format getFormat() {
final int ordinal;
final Flavor f = getFlavor();
if ((f == Flavor.HYBRID) || (f == Flavor.SPARSE)) {
ordinal = 2 | ( mergeFlag ? 0 : 1 ); //Hybrid is serialized as SPARSE
} else {
ordinal = ((slidingWindow != null) ? 4 : 0)
| (((pairTable != null) && (pairTable.getNumPairs() > 0)) ? 2 : 0)
| ( mergeFlag ? 0 : 1 );
}
return Format.ordinalToFormat(ordinal);
} | [
"Format",
"getFormat",
"(",
")",
"{",
"final",
"int",
"ordinal",
";",
"final",
"Flavor",
"f",
"=",
"getFlavor",
"(",
")",
";",
"if",
"(",
"(",
"f",
"==",
"Flavor",
".",
"HYBRID",
")",
"||",
"(",
"f",
"==",
"Flavor",
".",
"SPARSE",
")",
")",
"{",
... | Returns the Format of the serialized form of this sketch.
@return the Format of the serialized form of this sketch. | [
"Returns",
"the",
"Format",
"of",
"the",
"serialized",
"form",
"of",
"this",
"sketch",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L411-L422 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.promoteSparseToWindowed | private static void promoteSparseToWindowed(final CpcSketch sketch) {
final int lgK = sketch.lgK;
final int k = (1 << lgK);
final long c32 = sketch.numCoupons << 5;
assert ((c32 == (3 * k)) || ((lgK == 4) && (c32 > (3 * k))));
final byte[] window = new byte[k];
final PairTable newTable = new PairTable(2, 6 + lgK);
final PairTable oldTable = sketch.pairTable;
final int[] oldSlots = oldTable.getSlotsArr();
final int oldNumSlots = (1 << oldTable.getLgSizeInts());
assert (sketch.windowOffset == 0);
for (int i = 0; i < oldNumSlots; i++) {
final int rowCol = oldSlots[i];
if (rowCol != -1) {
final int col = rowCol & 63;
if (col < 8) {
final int row = rowCol >>> 6;
window[row] |= (1 << col);
}
else {
// cannot use Table.mustInsert(), because it doesn't provide for growth
final boolean isNovel = PairTable.maybeInsert(newTable, rowCol);
assert (isNovel == true);
}
}
}
assert (sketch.slidingWindow == null);
sketch.slidingWindow = window;
sketch.pairTable = newTable;
} | java | private static void promoteSparseToWindowed(final CpcSketch sketch) {
final int lgK = sketch.lgK;
final int k = (1 << lgK);
final long c32 = sketch.numCoupons << 5;
assert ((c32 == (3 * k)) || ((lgK == 4) && (c32 > (3 * k))));
final byte[] window = new byte[k];
final PairTable newTable = new PairTable(2, 6 + lgK);
final PairTable oldTable = sketch.pairTable;
final int[] oldSlots = oldTable.getSlotsArr();
final int oldNumSlots = (1 << oldTable.getLgSizeInts());
assert (sketch.windowOffset == 0);
for (int i = 0; i < oldNumSlots; i++) {
final int rowCol = oldSlots[i];
if (rowCol != -1) {
final int col = rowCol & 63;
if (col < 8) {
final int row = rowCol >>> 6;
window[row] |= (1 << col);
}
else {
// cannot use Table.mustInsert(), because it doesn't provide for growth
final boolean isNovel = PairTable.maybeInsert(newTable, rowCol);
assert (isNovel == true);
}
}
}
assert (sketch.slidingWindow == null);
sketch.slidingWindow = window;
sketch.pairTable = newTable;
} | [
"private",
"static",
"void",
"promoteSparseToWindowed",
"(",
"final",
"CpcSketch",
"sketch",
")",
"{",
"final",
"int",
"lgK",
"=",
"sketch",
".",
"lgK",
";",
"final",
"int",
"k",
"=",
"(",
"1",
"<<",
"lgK",
")",
";",
"final",
"long",
"c32",
"=",
"sketc... | In terms of flavor, this promotes SPARSE to HYBRID. | [
"In",
"terms",
"of",
"flavor",
"this",
"promotes",
"SPARSE",
"to",
"HYBRID",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L431-L466 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.refreshKXP | static void refreshKXP(final CpcSketch sketch, final long[] bitMatrix) {
final int k = (1 << sketch.lgK);
// for improved numerical accuracy, we separately sum the bytes of the U64's
final double[] byteSums = new double[8];
for (int j = 0; j < 8; j++) { byteSums[j] = 0.0; }
for (int i = 0; i < k; i++) {
long row = bitMatrix[i];
for (int j = 0; j < 8; j++) {
final int byteIdx = (int) (row & 0XFFL);
byteSums[j] += kxpByteLookup[byteIdx];
row >>>= 8;
}
}
double total = 0.0;
for (int j = 7; j-- > 0; ) { // the reverse order is important
final double factor = invPow2(8 * j); // pow(256, -j) == pow(2, -8 * j);
total += factor * byteSums[j];
}
sketch.kxp = total;
} | java | static void refreshKXP(final CpcSketch sketch, final long[] bitMatrix) {
final int k = (1 << sketch.lgK);
// for improved numerical accuracy, we separately sum the bytes of the U64's
final double[] byteSums = new double[8];
for (int j = 0; j < 8; j++) { byteSums[j] = 0.0; }
for (int i = 0; i < k; i++) {
long row = bitMatrix[i];
for (int j = 0; j < 8; j++) {
final int byteIdx = (int) (row & 0XFFL);
byteSums[j] += kxpByteLookup[byteIdx];
row >>>= 8;
}
}
double total = 0.0;
for (int j = 7; j-- > 0; ) { // the reverse order is important
final double factor = invPow2(8 * j); // pow(256, -j) == pow(2, -8 * j);
total += factor * byteSums[j];
}
sketch.kxp = total;
} | [
"static",
"void",
"refreshKXP",
"(",
"final",
"CpcSketch",
"sketch",
",",
"final",
"long",
"[",
"]",
"bitMatrix",
")",
"{",
"final",
"int",
"k",
"=",
"(",
"1",
"<<",
"sketch",
".",
"lgK",
")",
";",
"// for improved numerical accuracy, we separately sum the bytes... | Also used in test | [
"Also",
"used",
"in",
"test"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L477-L501 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.modifyOffset | private static void modifyOffset(final CpcSketch sketch, final int newOffset) {
assert ((newOffset >= 0) && (newOffset <= 56));
assert (newOffset == (sketch.windowOffset + 1));
assert (newOffset == CpcUtil.determineCorrectOffset(sketch.lgK, sketch.numCoupons));
assert (sketch.slidingWindow != null);
assert (sketch.pairTable != null);
final int k = 1 << sketch.lgK;
// Construct the full-sized bit matrix that corresponds to the sketch
final long[] bitMatrix = CpcUtil.bitMatrixOfSketch(sketch);
// refresh the KXP register on every 8th window shift.
if ((newOffset & 0x7) == 0) { refreshKXP(sketch, bitMatrix); }
sketch.pairTable.clear();
final PairTable table = sketch.pairTable;
final byte[] window = sketch.slidingWindow;
final long maskForClearingWindow = (0XFFL << newOffset) ^ -1L;
final long maskForFlippingEarlyZone = (1L << newOffset) - 1L;
long allSurprisesORed = 0;
for (int i = 0; i < k; i++) {
long pattern = bitMatrix[i];
window[i] = (byte) ((pattern >>> newOffset) & 0XFFL);
pattern &= maskForClearingWindow;
// The following line converts surprising 0's to 1's in the "early zone",
// (and vice versa, which is essential for this procedure's O(k) time cost).
pattern ^= maskForFlippingEarlyZone;
allSurprisesORed |= pattern; // a cheap way to recalculate fiCol
while (pattern != 0) {
final int col = Long.numberOfTrailingZeros(pattern);
pattern = pattern ^ (1L << col); // erase the 1.
final int rowCol = (i << 6) | col;
final boolean isNovel = PairTable.maybeInsert(table, rowCol);
assert isNovel == true;
}
}
sketch.windowOffset = newOffset;
sketch.fiCol = Long.numberOfTrailingZeros(allSurprisesORed);
if (sketch.fiCol > newOffset) {
sketch.fiCol = newOffset; // corner case
}
} | java | private static void modifyOffset(final CpcSketch sketch, final int newOffset) {
assert ((newOffset >= 0) && (newOffset <= 56));
assert (newOffset == (sketch.windowOffset + 1));
assert (newOffset == CpcUtil.determineCorrectOffset(sketch.lgK, sketch.numCoupons));
assert (sketch.slidingWindow != null);
assert (sketch.pairTable != null);
final int k = 1 << sketch.lgK;
// Construct the full-sized bit matrix that corresponds to the sketch
final long[] bitMatrix = CpcUtil.bitMatrixOfSketch(sketch);
// refresh the KXP register on every 8th window shift.
if ((newOffset & 0x7) == 0) { refreshKXP(sketch, bitMatrix); }
sketch.pairTable.clear();
final PairTable table = sketch.pairTable;
final byte[] window = sketch.slidingWindow;
final long maskForClearingWindow = (0XFFL << newOffset) ^ -1L;
final long maskForFlippingEarlyZone = (1L << newOffset) - 1L;
long allSurprisesORed = 0;
for (int i = 0; i < k; i++) {
long pattern = bitMatrix[i];
window[i] = (byte) ((pattern >>> newOffset) & 0XFFL);
pattern &= maskForClearingWindow;
// The following line converts surprising 0's to 1's in the "early zone",
// (and vice versa, which is essential for this procedure's O(k) time cost).
pattern ^= maskForFlippingEarlyZone;
allSurprisesORed |= pattern; // a cheap way to recalculate fiCol
while (pattern != 0) {
final int col = Long.numberOfTrailingZeros(pattern);
pattern = pattern ^ (1L << col); // erase the 1.
final int rowCol = (i << 6) | col;
final boolean isNovel = PairTable.maybeInsert(table, rowCol);
assert isNovel == true;
}
}
sketch.windowOffset = newOffset;
sketch.fiCol = Long.numberOfTrailingZeros(allSurprisesORed);
if (sketch.fiCol > newOffset) {
sketch.fiCol = newOffset; // corner case
}
} | [
"private",
"static",
"void",
"modifyOffset",
"(",
"final",
"CpcSketch",
"sketch",
",",
"final",
"int",
"newOffset",
")",
"{",
"assert",
"(",
"(",
"newOffset",
">=",
"0",
")",
"&&",
"(",
"newOffset",
"<=",
"56",
")",
")",
";",
"assert",
"(",
"newOffset",
... | This moves the sliding window
@param sketch the given sketch
@param newOffset the new offset, which must be oldOffset + 1 | [
"This",
"moves",
"the",
"sliding",
"window"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L508-L552 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.updateHIP | private static void updateHIP(final CpcSketch sketch, final int rowCol) {
final int k = 1 << sketch.lgK;
final int col = rowCol & 63;
final double oneOverP = k / sketch.kxp;
sketch.hipEstAccum += oneOverP;
sketch.kxp -= invPow2(col + 1); // notice the "+1"
} | java | private static void updateHIP(final CpcSketch sketch, final int rowCol) {
final int k = 1 << sketch.lgK;
final int col = rowCol & 63;
final double oneOverP = k / sketch.kxp;
sketch.hipEstAccum += oneOverP;
sketch.kxp -= invPow2(col + 1); // notice the "+1"
} | [
"private",
"static",
"void",
"updateHIP",
"(",
"final",
"CpcSketch",
"sketch",
",",
"final",
"int",
"rowCol",
")",
"{",
"final",
"int",
"k",
"=",
"1",
"<<",
"sketch",
".",
"lgK",
";",
"final",
"int",
"col",
"=",
"rowCol",
"&",
"63",
";",
"final",
"do... | Call this whenever a new coupon has been collected.
@param sketch the given sketch
@param rowCol the given row / column | [
"Call",
"this",
"whenever",
"a",
"new",
"coupon",
"has",
"been",
"collected",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L559-L565 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.updateWindowed | private static void updateWindowed(final CpcSketch sketch, final int rowCol) {
assert ((sketch.windowOffset >= 0) && (sketch.windowOffset <= 56));
final int k = 1 << sketch.lgK;
final long c32pre = sketch.numCoupons << 5;
assert c32pre >= (3L * k); // C < 3K/32, in other words flavor >= HYBRID
final long c8pre = sketch.numCoupons << 3;
final int w8pre = sketch.windowOffset << 3;
assert c8pre < ((27L + w8pre) * k); // C < (K * 27/8) + (K * windowOffset)
boolean isNovel = false; //novel if new coupon
final int col = rowCol & 63;
if (col < sketch.windowOffset) { // track the surprising 0's "before" the window
isNovel = PairTable.maybeDelete(sketch.pairTable, rowCol); // inverted logic
}
else if (col < (sketch.windowOffset + 8)) { // track the 8 bits inside the window
assert (col >= sketch.windowOffset);
final int row = rowCol >>> 6;
final byte oldBits = sketch.slidingWindow[row];
final byte newBits = (byte) (oldBits | (1 << (col - sketch.windowOffset)));
if (newBits != oldBits) {
sketch.slidingWindow[row] = newBits;
isNovel = true;
}
}
else { // track the surprising 1's "after" the window
assert col >= (sketch.windowOffset + 8);
isNovel = PairTable.maybeInsert(sketch.pairTable, rowCol); // normal logic
}
if (isNovel) {
sketch.numCoupons += 1;
updateHIP(sketch, rowCol);
final long c8post = sketch.numCoupons << 3;
if (c8post >= ((27L + w8pre) * k)) {
modifyOffset(sketch, sketch.windowOffset + 1);
assert (sketch.windowOffset >= 1) && (sketch.windowOffset <= 56);
final int w8post = sketch.windowOffset << 3;
assert c8post < ((27L + w8post) * k); // C < (K * 27/8) + (K * windowOffset)
}
}
} | java | private static void updateWindowed(final CpcSketch sketch, final int rowCol) {
assert ((sketch.windowOffset >= 0) && (sketch.windowOffset <= 56));
final int k = 1 << sketch.lgK;
final long c32pre = sketch.numCoupons << 5;
assert c32pre >= (3L * k); // C < 3K/32, in other words flavor >= HYBRID
final long c8pre = sketch.numCoupons << 3;
final int w8pre = sketch.windowOffset << 3;
assert c8pre < ((27L + w8pre) * k); // C < (K * 27/8) + (K * windowOffset)
boolean isNovel = false; //novel if new coupon
final int col = rowCol & 63;
if (col < sketch.windowOffset) { // track the surprising 0's "before" the window
isNovel = PairTable.maybeDelete(sketch.pairTable, rowCol); // inverted logic
}
else if (col < (sketch.windowOffset + 8)) { // track the 8 bits inside the window
assert (col >= sketch.windowOffset);
final int row = rowCol >>> 6;
final byte oldBits = sketch.slidingWindow[row];
final byte newBits = (byte) (oldBits | (1 << (col - sketch.windowOffset)));
if (newBits != oldBits) {
sketch.slidingWindow[row] = newBits;
isNovel = true;
}
}
else { // track the surprising 1's "after" the window
assert col >= (sketch.windowOffset + 8);
isNovel = PairTable.maybeInsert(sketch.pairTable, rowCol); // normal logic
}
if (isNovel) {
sketch.numCoupons += 1;
updateHIP(sketch, rowCol);
final long c8post = sketch.numCoupons << 3;
if (c8post >= ((27L + w8pre) * k)) {
modifyOffset(sketch, sketch.windowOffset + 1);
assert (sketch.windowOffset >= 1) && (sketch.windowOffset <= 56);
final int w8post = sketch.windowOffset << 3;
assert c8post < ((27L + w8post) * k); // C < (K * 27/8) + (K * windowOffset)
}
}
} | [
"private",
"static",
"void",
"updateWindowed",
"(",
"final",
"CpcSketch",
"sketch",
",",
"final",
"int",
"rowCol",
")",
"{",
"assert",
"(",
"(",
"sketch",
".",
"windowOffset",
">=",
"0",
")",
"&&",
"(",
"sketch",
".",
"windowOffset",
"<=",
"56",
")",
")"... | The flavor is HYBRID, PINNED, or SLIDING.
@param sketch the given sketch
@param rowCol the given rowCol | [
"The",
"flavor",
"is",
"HYBRID",
"PINNED",
"or",
"SLIDING",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L586-L627 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.uncompress | static CpcSketch uncompress(final CompressedState source, final long seed) {
checkSeedHashes(computeSeedHash(seed), source.seedHash);
final CpcSketch sketch = new CpcSketch(source.lgK, seed);
sketch.numCoupons = source.numCoupons;
sketch.windowOffset = source.getWindowOffset();
sketch.fiCol = source.fiCol;
sketch.mergeFlag = source.mergeFlag;
sketch.kxp = source.kxp;
sketch.hipEstAccum = source.hipEstAccum;
sketch.slidingWindow = null;
sketch.pairTable = null;
CpcCompression.uncompress(source, sketch);
return sketch;
} | java | static CpcSketch uncompress(final CompressedState source, final long seed) {
checkSeedHashes(computeSeedHash(seed), source.seedHash);
final CpcSketch sketch = new CpcSketch(source.lgK, seed);
sketch.numCoupons = source.numCoupons;
sketch.windowOffset = source.getWindowOffset();
sketch.fiCol = source.fiCol;
sketch.mergeFlag = source.mergeFlag;
sketch.kxp = source.kxp;
sketch.hipEstAccum = source.hipEstAccum;
sketch.slidingWindow = null;
sketch.pairTable = null;
CpcCompression.uncompress(source, sketch);
return sketch;
} | [
"static",
"CpcSketch",
"uncompress",
"(",
"final",
"CompressedState",
"source",
",",
"final",
"long",
"seed",
")",
"{",
"checkSeedHashes",
"(",
"computeSeedHash",
"(",
"seed",
")",
",",
"source",
".",
"seedHash",
")",
";",
"final",
"CpcSketch",
"sketch",
"=",
... | also used in test | [
"also",
"used",
"in",
"test"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L631-L644 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.hashUpdate | void hashUpdate(final long hash0, final long hash1) {
int col = Long.numberOfLeadingZeros(hash1);
if (col < fiCol) { return; } // important speed optimization
if (col > 63) { col = 63; } // clip so that 0 <= col <= 63
final long c = numCoupons;
if (c == 0) { promoteEmptyToSparse(this); }
final long k = 1L << lgK;
final int row = (int) (hash0 & (k - 1L));
int rowCol = (row << 6) | col;
// Avoid the hash table's "empty" value which is (2^26 -1, 63) (all ones) by changing it
// to the pair (2^26 - 2, 63), which effectively merges the two cells.
// This case is *extremely* unlikely, but we might as well handle it.
// It can't happen at all if lgK (or maxLgK) < 26.
if (rowCol == -1) { rowCol ^= (1 << 6); } //set the LSB of row to 0
if ((c << 5) < (3L * k)) { updateSparse(this, rowCol); }
else { updateWindowed(this, rowCol); }
} | java | void hashUpdate(final long hash0, final long hash1) {
int col = Long.numberOfLeadingZeros(hash1);
if (col < fiCol) { return; } // important speed optimization
if (col > 63) { col = 63; } // clip so that 0 <= col <= 63
final long c = numCoupons;
if (c == 0) { promoteEmptyToSparse(this); }
final long k = 1L << lgK;
final int row = (int) (hash0 & (k - 1L));
int rowCol = (row << 6) | col;
// Avoid the hash table's "empty" value which is (2^26 -1, 63) (all ones) by changing it
// to the pair (2^26 - 2, 63), which effectively merges the two cells.
// This case is *extremely* unlikely, but we might as well handle it.
// It can't happen at all if lgK (or maxLgK) < 26.
if (rowCol == -1) { rowCol ^= (1 << 6); } //set the LSB of row to 0
if ((c << 5) < (3L * k)) { updateSparse(this, rowCol); }
else { updateWindowed(this, rowCol); }
} | [
"void",
"hashUpdate",
"(",
"final",
"long",
"hash0",
",",
"final",
"long",
"hash1",
")",
"{",
"int",
"col",
"=",
"Long",
".",
"numberOfLeadingZeros",
"(",
"hash1",
")",
";",
"if",
"(",
"col",
"<",
"fiCol",
")",
"{",
"return",
";",
"}",
"// important sp... | Used here and for testing | [
"Used",
"here",
"and",
"for",
"testing"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L647-L665 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcSketch.java | CpcSketch.rowColUpdate | void rowColUpdate(final int rowCol) {
final int col = rowCol & 63;
if (col < fiCol) { return; } // important speed optimization
final long c = numCoupons;
if (c == 0) { promoteEmptyToSparse(this); }
final long k = 1L << lgK;
if ((c << 5) < (3L * k)) { updateSparse(this, rowCol); }
else { updateWindowed(this, rowCol); }
} | java | void rowColUpdate(final int rowCol) {
final int col = rowCol & 63;
if (col < fiCol) { return; } // important speed optimization
final long c = numCoupons;
if (c == 0) { promoteEmptyToSparse(this); }
final long k = 1L << lgK;
if ((c << 5) < (3L * k)) { updateSparse(this, rowCol); }
else { updateWindowed(this, rowCol); }
} | [
"void",
"rowColUpdate",
"(",
"final",
"int",
"rowCol",
")",
"{",
"final",
"int",
"col",
"=",
"rowCol",
"&",
"63",
";",
"if",
"(",
"col",
"<",
"fiCol",
")",
"{",
"return",
";",
"}",
"// important speed optimization",
"final",
"long",
"c",
"=",
"numCoupons... | Used by union and in testing | [
"Used",
"by",
"union",
"and",
"in",
"testing"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcSketch.java#L668-L676 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/cpc/CpcUnion.java | CpcUnion.getBitMatrix | static long[] getBitMatrix(final CpcUnion union) {
checkUnionState(union);
return (union.bitMatrix != null)
? union.bitMatrix
: CpcUtil.bitMatrixOfSketch(union.accumulator);
} | java | static long[] getBitMatrix(final CpcUnion union) {
checkUnionState(union);
return (union.bitMatrix != null)
? union.bitMatrix
: CpcUtil.bitMatrixOfSketch(union.accumulator);
} | [
"static",
"long",
"[",
"]",
"getBitMatrix",
"(",
"final",
"CpcUnion",
"union",
")",
"{",
"checkUnionState",
"(",
"union",
")",
";",
"return",
"(",
"union",
".",
"bitMatrix",
"!=",
"null",
")",
"?",
"union",
".",
"bitMatrix",
":",
"CpcUtil",
".",
"bitMatr... | used for testing only | [
"used",
"for",
"testing",
"only"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/cpc/CpcUnion.java#L160-L165 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/UpdatableSketchBuilder.java | UpdatableSketchBuilder.setSamplingProbability | public UpdatableSketchBuilder<U, S> setSamplingProbability(final float samplingProbability) {
if ((samplingProbability < 0) || (samplingProbability > 1f)) {
throw new SketchesArgumentException("sampling probability must be between 0 and 1");
}
samplingProbability_ = samplingProbability;
return this;
} | java | public UpdatableSketchBuilder<U, S> setSamplingProbability(final float samplingProbability) {
if ((samplingProbability < 0) || (samplingProbability > 1f)) {
throw new SketchesArgumentException("sampling probability must be between 0 and 1");
}
samplingProbability_ = samplingProbability;
return this;
} | [
"public",
"UpdatableSketchBuilder",
"<",
"U",
",",
"S",
">",
"setSamplingProbability",
"(",
"final",
"float",
"samplingProbability",
")",
"{",
"if",
"(",
"(",
"samplingProbability",
"<",
"0",
")",
"||",
"(",
"samplingProbability",
">",
"1f",
")",
")",
"{",
"... | This is to set sampling probability.
Default probability is 1.
@param samplingProbability sampling probability from 0 to 1
@return this UpdatableSketchBuilder | [
"This",
"is",
"to",
"set",
"sampling",
"probability",
".",
"Default",
"probability",
"is",
"1",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/UpdatableSketchBuilder.java#L68-L74 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/UpdatableSketchBuilder.java | UpdatableSketchBuilder.build | public UpdatableSketch<U, S> build() {
return new UpdatableSketch<>(nomEntries_, resizeFactor_.lg(), samplingProbability_,
summaryFactory_);
} | java | public UpdatableSketch<U, S> build() {
return new UpdatableSketch<>(nomEntries_, resizeFactor_.lg(), samplingProbability_,
summaryFactory_);
} | [
"public",
"UpdatableSketch",
"<",
"U",
",",
"S",
">",
"build",
"(",
")",
"{",
"return",
"new",
"UpdatableSketch",
"<>",
"(",
"nomEntries_",
",",
"resizeFactor_",
".",
"lg",
"(",
")",
",",
"samplingProbability_",
",",
"summaryFactory_",
")",
";",
"}"
] | Returns an UpdatableSketch with the current configuration of this Builder.
@return an UpdatableSketch | [
"Returns",
"an",
"UpdatableSketch",
"with",
"the",
"current",
"configuration",
"of",
"this",
"Builder",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/UpdatableSketchBuilder.java#L80-L83 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/quantiles/HeapCompactDoublesSketch.java | HeapCompactDoublesSketch.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 k = getK();
combinedBuffer_ = new double[combBufCap];
if (srcIsCompact) {
// just load the array, sort base buffer if serVer 2
srcMem.getDoubleArray(preBytes, combinedBuffer_, 0, combBufCap);
if (serVer == 2) {
Arrays.sort(combinedBuffer_, 0, baseBufferCount_);
}
} else {
// non-compact source
// load base buffer and ensure it's sorted
srcMem.getDoubleArray(preBytes, combinedBuffer_, 0, baseBufferCount_);
Arrays.sort(combinedBuffer_, 0, baseBufferCount_);
// iterate through levels
int srcOffset = preBytes + ((2 * k) << 3);
int dstOffset = baseBufferCount_;
long bitPattern = bitPattern_;
for (; bitPattern != 0; srcOffset += (k << 3), bitPattern >>>= 1) {
if ((bitPattern & 1L) > 0L) {
srcMem.getDoubleArray(srcOffset, combinedBuffer_, dstOffset, k);
dstOffset += k;
}
}
}
} | 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 k = getK();
combinedBuffer_ = new double[combBufCap];
if (srcIsCompact) {
// just load the array, sort base buffer if serVer 2
srcMem.getDoubleArray(preBytes, combinedBuffer_, 0, combBufCap);
if (serVer == 2) {
Arrays.sort(combinedBuffer_, 0, baseBufferCount_);
}
} else {
// non-compact source
// load base buffer and ensure it's sorted
srcMem.getDoubleArray(preBytes, combinedBuffer_, 0, baseBufferCount_);
Arrays.sort(combinedBuffer_, 0, baseBufferCount_);
// iterate through levels
int srcOffset = preBytes + ((2 * k) << 3);
int dstOffset = baseBufferCount_;
long bitPattern = bitPattern_;
for (; bitPattern != 0; srcOffset += (k << 3), bitPattern >>>= 1) {
if ((bitPattern & 1L) > 0L) {
srcMem.getDoubleArray(srcOffset, combinedBuffer_, dstOffset, k);
dstOffset += k;
}
}
}
} | [
"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 from the given source Memory.
The resulting Combined Buffer is allocated in this method and is always in compact form.
@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",
"from",
"the",
"given",
"source",
"Memory",
".",
"The",
"resulting",
"Combined",
"Buffer",
"is",
"allocated",
"in",
"this",
"method",
"and",
"is",
"always",
"in",
"compact",
"form",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/quantiles/HeapCompactDoublesSketch.java#L222-L254 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hll/Hll4Update.java | Hll4Update.internalHll4Update | static final void internalHll4Update(final AbstractHllArray host, final int slotNo, final int newValue) {
assert ((0 <= slotNo) && (slotNo < (1 << host.getLgConfigK())));
assert (newValue > 0);
final int curMin = host.getCurMin();
AuxHashMap auxHashMap = host.getAuxHashMap(); //may be null
final int rawStoredOldValue = host.getSlot(slotNo); //could be 0
//This is provably a LB:
final int lbOnOldValue = rawStoredOldValue + curMin; //lower bound, could be 0
if (newValue > lbOnOldValue) { //842:
//Note: if an AUX_TOKEN exists, then auxHashMap must already exist
final int actualOldValue = (rawStoredOldValue < AUX_TOKEN)
? lbOnOldValue
//846 rawStoredOldValue == AUX_TOKEN
: auxHashMap.mustFindValueFor(slotNo); //lgtm [java/dereferenced-value-may-be-null]
if (newValue > actualOldValue) { //848: actualOldValue could still be 0; newValue > 0
//We know that the array will be changed, but we haven't actually updated yet.
AbstractHllArray.hipAndKxQIncrementalUpdate(host, actualOldValue, newValue);
assert (newValue >= curMin)
: "New value " + newValue + " is less than current minimum " + curMin;
//newValue >= curMin
final int shiftedNewValue = newValue - curMin; //874
assert (shiftedNewValue >= 0);
if (rawStoredOldValue == AUX_TOKEN) { //879
//Given that we have an AUX_TOKEN, there are four cases for how to
// actually modify the data structure
if (shiftedNewValue >= AUX_TOKEN) { //CASE 1: //881
//the byte array already contains aux token
//This is the case where old and new values are both exceptions.
//Therefore, the 4-bit array already is AUX_TOKEN. Only need to update auxMap
auxHashMap.mustReplace(slotNo, newValue); //lgtm [java/dereferenced-value-may-be-null]
}
else { //CASE 2: //885
//This is the (hypothetical) case where old value is an exception and the new one is not.
// which is impossible given that curMin has not changed here and the newValue > oldValue.
throw new SketchesStateException("Impossible case");
}
}
else { //rawStoredOldValue != AUX_TOKEN
if (shiftedNewValue >= AUX_TOKEN) { //CASE 3: //892
//This is the case where the old value is not an exception and the new value is.
//Therefore the AUX_TOKEN must be stored in the 4-bit array and the new value
// added to the exception table.
host.putSlot(slotNo, AUX_TOKEN);
if (auxHashMap == null) {
auxHashMap = host.getNewAuxHashMap();
host.putAuxHashMap(auxHashMap, false);
}
auxHashMap.mustAdd(slotNo, newValue);
}
else { // CASE 4: //897
//This is the case where neither the old value nor the new value is an exception.
//Therefore we just overwrite the 4-bit array with the shifted new value.
host.putSlot(slotNo, shiftedNewValue);
}
}
// we just increased a pair value, so it might be time to change curMin
if (actualOldValue == curMin) { //908
assert (host.getNumAtCurMin() >= 1);
host.decNumAtCurMin();
while (host.getNumAtCurMin() == 0) {
shiftToBiggerCurMin(host); //increases curMin by 1, and builds a new aux table,
//shifts values in 4-bit table, and recounts curMin
}
}
} //end newValue <= actualOldValue
} //end newValue <= lbOnOldValue -> return, no need to update array
} | java | static final void internalHll4Update(final AbstractHllArray host, final int slotNo, final int newValue) {
assert ((0 <= slotNo) && (slotNo < (1 << host.getLgConfigK())));
assert (newValue > 0);
final int curMin = host.getCurMin();
AuxHashMap auxHashMap = host.getAuxHashMap(); //may be null
final int rawStoredOldValue = host.getSlot(slotNo); //could be 0
//This is provably a LB:
final int lbOnOldValue = rawStoredOldValue + curMin; //lower bound, could be 0
if (newValue > lbOnOldValue) { //842:
//Note: if an AUX_TOKEN exists, then auxHashMap must already exist
final int actualOldValue = (rawStoredOldValue < AUX_TOKEN)
? lbOnOldValue
//846 rawStoredOldValue == AUX_TOKEN
: auxHashMap.mustFindValueFor(slotNo); //lgtm [java/dereferenced-value-may-be-null]
if (newValue > actualOldValue) { //848: actualOldValue could still be 0; newValue > 0
//We know that the array will be changed, but we haven't actually updated yet.
AbstractHllArray.hipAndKxQIncrementalUpdate(host, actualOldValue, newValue);
assert (newValue >= curMin)
: "New value " + newValue + " is less than current minimum " + curMin;
//newValue >= curMin
final int shiftedNewValue = newValue - curMin; //874
assert (shiftedNewValue >= 0);
if (rawStoredOldValue == AUX_TOKEN) { //879
//Given that we have an AUX_TOKEN, there are four cases for how to
// actually modify the data structure
if (shiftedNewValue >= AUX_TOKEN) { //CASE 1: //881
//the byte array already contains aux token
//This is the case where old and new values are both exceptions.
//Therefore, the 4-bit array already is AUX_TOKEN. Only need to update auxMap
auxHashMap.mustReplace(slotNo, newValue); //lgtm [java/dereferenced-value-may-be-null]
}
else { //CASE 2: //885
//This is the (hypothetical) case where old value is an exception and the new one is not.
// which is impossible given that curMin has not changed here and the newValue > oldValue.
throw new SketchesStateException("Impossible case");
}
}
else { //rawStoredOldValue != AUX_TOKEN
if (shiftedNewValue >= AUX_TOKEN) { //CASE 3: //892
//This is the case where the old value is not an exception and the new value is.
//Therefore the AUX_TOKEN must be stored in the 4-bit array and the new value
// added to the exception table.
host.putSlot(slotNo, AUX_TOKEN);
if (auxHashMap == null) {
auxHashMap = host.getNewAuxHashMap();
host.putAuxHashMap(auxHashMap, false);
}
auxHashMap.mustAdd(slotNo, newValue);
}
else { // CASE 4: //897
//This is the case where neither the old value nor the new value is an exception.
//Therefore we just overwrite the 4-bit array with the shifted new value.
host.putSlot(slotNo, shiftedNewValue);
}
}
// we just increased a pair value, so it might be time to change curMin
if (actualOldValue == curMin) { //908
assert (host.getNumAtCurMin() >= 1);
host.decNumAtCurMin();
while (host.getNumAtCurMin() == 0) {
shiftToBiggerCurMin(host); //increases curMin by 1, and builds a new aux table,
//shifts values in 4-bit table, and recounts curMin
}
}
} //end newValue <= actualOldValue
} //end newValue <= lbOnOldValue -> return, no need to update array
} | [
"static",
"final",
"void",
"internalHll4Update",
"(",
"final",
"AbstractHllArray",
"host",
",",
"final",
"int",
"slotNo",
",",
"final",
"int",
"newValue",
")",
"{",
"assert",
"(",
"(",
"0",
"<=",
"slotNo",
")",
"&&",
"(",
"slotNo",
"<",
"(",
"1",
"<<",
... | Only called by Hll4Array and DirectHll4Array | [
"Only",
"called",
"by",
"Hll4Array",
"and",
"DirectHll4Array"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hll/Hll4Update.java#L23-L102 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/BoundsOnRatiosInSampledSets.java | BoundsOnRatiosInSampledSets.getLowerBoundForBoverA | public static double getLowerBoundForBoverA(final long a, final long b, final double f) {
checkInputs(a, b, f);
if (a == 0) { return 0.0; }
if (f == 1.0) { return (double) b / a; }
return approximateLowerBoundOnP(a, b, NUM_STD_DEVS * hackyAdjuster(f));
} | java | public static double getLowerBoundForBoverA(final long a, final long b, final double f) {
checkInputs(a, b, f);
if (a == 0) { return 0.0; }
if (f == 1.0) { return (double) b / a; }
return approximateLowerBoundOnP(a, b, NUM_STD_DEVS * hackyAdjuster(f));
} | [
"public",
"static",
"double",
"getLowerBoundForBoverA",
"(",
"final",
"long",
"a",
",",
"final",
"long",
"b",
",",
"final",
"double",
"f",
")",
"{",
"checkInputs",
"(",
"a",
",",
"b",
",",
"f",
")",
";",
"if",
"(",
"a",
"==",
"0",
")",
"{",
"return... | Return the approximate lower bound based on a 95% confidence interval
@param a See class javadoc
@param b See class javadoc
@param f the inclusion probability used to produce the set with size <i>a</i> and should
generally be less than 0.5. Above this value, the results not be reliable.
When <i>f</i> = 1.0 this returns the estimate.
@return the approximate upper bound | [
"Return",
"the",
"approximate",
"lower",
"bound",
"based",
"on",
"a",
"95%",
"confidence",
"interval"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/BoundsOnRatiosInSampledSets.java#L38-L43 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/BoundsOnRatiosInSampledSets.java | BoundsOnRatiosInSampledSets.getUpperBoundForBoverA | public static double getUpperBoundForBoverA(final long a, final long b, final double f) {
checkInputs(a, b, f);
if (a == 0) { return 1.0; }
if (f == 1.0) { return (double) b / a; }
return approximateUpperBoundOnP(a, b, NUM_STD_DEVS * hackyAdjuster(f));
} | java | public static double getUpperBoundForBoverA(final long a, final long b, final double f) {
checkInputs(a, b, f);
if (a == 0) { return 1.0; }
if (f == 1.0) { return (double) b / a; }
return approximateUpperBoundOnP(a, b, NUM_STD_DEVS * hackyAdjuster(f));
} | [
"public",
"static",
"double",
"getUpperBoundForBoverA",
"(",
"final",
"long",
"a",
",",
"final",
"long",
"b",
",",
"final",
"double",
"f",
")",
"{",
"checkInputs",
"(",
"a",
",",
"b",
",",
"f",
")",
";",
"if",
"(",
"a",
"==",
"0",
")",
"{",
"return... | Return the approximate upper bound based on a 95% confidence interval
@param a See class javadoc
@param b See class javadoc
@param f the inclusion probability used to produce the set with size <i>a</i>.
@return the approximate lower bound | [
"Return",
"the",
"approximate",
"upper",
"bound",
"based",
"on",
"a",
"95%",
"confidence",
"interval"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/BoundsOnRatiosInSampledSets.java#L52-L57 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/BoundsOnRatiosInSampledSets.java | BoundsOnRatiosInSampledSets.hackyAdjuster | private static double hackyAdjuster(final double f) {
final double tmp = Math.sqrt(1.0 - f);
return (f <= 0.5) ? tmp : tmp + (0.01 * (f - 0.5));
} | java | private static double hackyAdjuster(final double f) {
final double tmp = Math.sqrt(1.0 - f);
return (f <= 0.5) ? tmp : tmp + (0.01 * (f - 0.5));
} | [
"private",
"static",
"double",
"hackyAdjuster",
"(",
"final",
"double",
"f",
")",
"{",
"final",
"double",
"tmp",
"=",
"Math",
".",
"sqrt",
"(",
"1.0",
"-",
"f",
")",
";",
"return",
"(",
"f",
"<=",
"0.5",
")",
"?",
"tmp",
":",
"tmp",
"+",
"(",
"0.... | This hackyAdjuster is tightly coupled with the width of the confidence interval normally
specified with number of standard deviations. To simplify this interface the number of
standard deviations has been fixed to 2.0, which corresponds to a confidence interval of
95%.
@param f the inclusion probability used to produce the set with size <i>a</i>.
@return the hacky Adjuster | [
"This",
"hackyAdjuster",
"is",
"tightly",
"coupled",
"with",
"the",
"width",
"of",
"the",
"confidence",
"interval",
"normally",
"specified",
"with",
"number",
"of",
"standard",
"deviations",
".",
"To",
"simplify",
"this",
"interface",
"the",
"number",
"of",
"sta... | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/BoundsOnRatiosInSampledSets.java#L79-L82 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hllmap/Map.java | Map.coupon16 | static final int coupon16(final byte[] identifier) {
final long[] hash = MurmurHash3.hash(identifier, SEED);
final int hllIdx = (int) (((hash[0] >>> 1) % 1024) & TEN_BIT_MASK); //hash[0] for 10-bit address
final int lz = Long.numberOfLeadingZeros(hash[1]);
final int value = (lz > 62 ? 62 : lz) + 1;
return (value << 10) | hllIdx;
} | java | static final int coupon16(final byte[] identifier) {
final long[] hash = MurmurHash3.hash(identifier, SEED);
final int hllIdx = (int) (((hash[0] >>> 1) % 1024) & TEN_BIT_MASK); //hash[0] for 10-bit address
final int lz = Long.numberOfLeadingZeros(hash[1]);
final int value = (lz > 62 ? 62 : lz) + 1;
return (value << 10) | hllIdx;
} | [
"static",
"final",
"int",
"coupon16",
"(",
"final",
"byte",
"[",
"]",
"identifier",
")",
"{",
"final",
"long",
"[",
"]",
"hash",
"=",
"MurmurHash3",
".",
"hash",
"(",
"identifier",
",",
"SEED",
")",
";",
"final",
"int",
"hllIdx",
"=",
"(",
"int",
")"... | Returns the HLL array index and value as a 16-bit coupon given the identifier to be hashed
and k.
@param identifier the given identifier
@return the HLL array index and value | [
"Returns",
"the",
"HLL",
"array",
"index",
"and",
"value",
"as",
"a",
"16",
"-",
"bit",
"coupon",
"given",
"the",
"identifier",
"to",
"be",
"hashed",
"and",
"k",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hllmap/Map.java#L155-L161 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/Sketches.java | Sketches.heapifySketch | public static <S extends Summary> Sketch<S> heapifySketch(final Memory mem,
final SummaryDeserializer<S> deserializer) {
final SerializerDeserializer.SketchType sketchType = SerializerDeserializer.getSketchType(mem);
if (sketchType == SerializerDeserializer.SketchType.QuickSelectSketch) {
return new QuickSelectSketch<S>(mem, deserializer, null);
}
return new CompactSketch<S>(mem, deserializer);
} | java | public static <S extends Summary> Sketch<S> heapifySketch(final Memory mem,
final SummaryDeserializer<S> deserializer) {
final SerializerDeserializer.SketchType sketchType = SerializerDeserializer.getSketchType(mem);
if (sketchType == SerializerDeserializer.SketchType.QuickSelectSketch) {
return new QuickSelectSketch<S>(mem, deserializer, null);
}
return new CompactSketch<S>(mem, deserializer);
} | [
"public",
"static",
"<",
"S",
"extends",
"Summary",
">",
"Sketch",
"<",
"S",
">",
"heapifySketch",
"(",
"final",
"Memory",
"mem",
",",
"final",
"SummaryDeserializer",
"<",
"S",
">",
"deserializer",
")",
"{",
"final",
"SerializerDeserializer",
".",
"SketchType"... | Instantiate Sketch from a given Memory
@param <S> Type of Summary
@param mem Memory object representing a Sketch
@param deserializer instance of SummaryDeserializer
@return Sketch created from its Memory representation | [
"Instantiate",
"Sketch",
"from",
"a",
"given",
"Memory"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/Sketches.java#L30-L37 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/Sketches.java | Sketches.heapifyUpdatableSketch | public static <U, S extends
UpdatableSummary<U>> UpdatableSketch<U, S> heapifyUpdatableSketch(final Memory mem,
final SummaryDeserializer<S> deserializer, final SummaryFactory<S> summaryFactory) {
return new UpdatableSketch<U, S>(mem, deserializer, summaryFactory);
} | java | public static <U, S extends
UpdatableSummary<U>> UpdatableSketch<U, S> heapifyUpdatableSketch(final Memory mem,
final SummaryDeserializer<S> deserializer, final SummaryFactory<S> summaryFactory) {
return new UpdatableSketch<U, S>(mem, deserializer, summaryFactory);
} | [
"public",
"static",
"<",
"U",
",",
"S",
"extends",
"UpdatableSummary",
"<",
"U",
">",
">",
"UpdatableSketch",
"<",
"U",
",",
"S",
">",
"heapifyUpdatableSketch",
"(",
"final",
"Memory",
"mem",
",",
"final",
"SummaryDeserializer",
"<",
"S",
">",
"deserializer"... | Instantiate UpdatableSketch from a given Memory
@param <U> Type of update value
@param <S> Type of Summary
@param mem Memory object representing a Sketch
@param deserializer instance of SummaryDeserializer
@param summaryFactory instance of SummaryFactory
@return Sketch created from its Memory representation | [
"Instantiate",
"UpdatableSketch",
"from",
"a",
"given",
"Memory"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/Sketches.java#L48-L52 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hll/BaseHllSketch.java | BaseHllSketch.update | public void update(final long[] data) {
if ((data == null) || (data.length == 0)) { return; }
couponUpdate(coupon(hash(data, DEFAULT_UPDATE_SEED)));
} | java | public void update(final long[] data) {
if ((data == null) || (data.length == 0)) { return; }
couponUpdate(coupon(hash(data, DEFAULT_UPDATE_SEED)));
} | [
"public",
"void",
"update",
"(",
"final",
"long",
"[",
"]",
"data",
")",
"{",
"if",
"(",
"(",
"data",
"==",
"null",
")",
"||",
"(",
"data",
".",
"length",
"==",
"0",
")",
")",
"{",
"return",
";",
"}",
"couponUpdate",
"(",
"coupon",
"(",
"hash",
... | Present the given long array as a potential unique item.
If the long array is null or empty no update attempt is made and the method returns.
@param data The given long array. | [
"Present",
"the",
"given",
"long",
"array",
"as",
"a",
"potential",
"unique",
"item",
".",
"If",
"the",
"long",
"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/hll/BaseHllSketch.java#L323-L326 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hash/XxHash.java | XxHash.hash | public static long hash(final long in, final long seed) {
long hash = seed + P5;
hash += 8;
long k1 = in;
k1 *= P2;
k1 = Long.rotateLeft(k1, 31);
k1 *= P1;
hash ^= k1;
hash = (Long.rotateLeft(hash, 27) * P1) + P4;
return finalize(hash);
} | java | public static long hash(final long in, final long seed) {
long hash = seed + P5;
hash += 8;
long k1 = in;
k1 *= P2;
k1 = Long.rotateLeft(k1, 31);
k1 *= P1;
hash ^= k1;
hash = (Long.rotateLeft(hash, 27) * P1) + P4;
return finalize(hash);
} | [
"public",
"static",
"long",
"hash",
"(",
"final",
"long",
"in",
",",
"final",
"long",
"seed",
")",
"{",
"long",
"hash",
"=",
"seed",
"+",
"P5",
";",
"hash",
"+=",
"8",
";",
"long",
"k1",
"=",
"in",
";",
"k1",
"*=",
"P2",
";",
"k1",
"=",
"Long",... | Returns a 64-bit hash.
@param in a long
@param seed A long valued seed.
@return the hash | [
"Returns",
"a",
"64",
"-",
"bit",
"hash",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hash/XxHash.java#L48-L58 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/CompactSketch.java | CompactSketch.toByteArray | @SuppressWarnings("null")
@Override
public byte[] toByteArray() {
int summariesBytesLength = 0;
byte[][] summariesBytes = null;
final int count = getRetainedEntries();
if (count > 0) {
summariesBytes = new byte[count][];
for (int i = 0; i < count; i++) {
summariesBytes[i] = summaries_[i].toByteArray();
summariesBytesLength += summariesBytes[i].length;
}
}
int sizeBytes =
Byte.BYTES // preamble longs
+ Byte.BYTES // serial version
+ Byte.BYTES // family id
+ Byte.BYTES // sketch type
+ Byte.BYTES; // flags
final boolean isThetaIncluded = theta_ < Long.MAX_VALUE;
if (isThetaIncluded) {
sizeBytes += Long.BYTES; // theta
}
if (count > 0) {
sizeBytes +=
+ Integer.BYTES // count
+ (Long.BYTES * count) + summariesBytesLength;
}
final byte[] bytes = new byte[sizeBytes];
int offset = 0;
bytes[offset++] = PREAMBLE_LONGS;
bytes[offset++] = serialVersionUID;
bytes[offset++] = (byte) Family.TUPLE.getID();
bytes[offset++] = (byte) SerializerDeserializer.SketchType.CompactSketch.ordinal();
final boolean isBigEndian = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN);
bytes[offset++] = (byte) (
(isBigEndian ? 1 << Flags.IS_BIG_ENDIAN.ordinal() : 0)
| (isEmpty_ ? 1 << Flags.IS_EMPTY.ordinal() : 0)
| (count > 0 ? 1 << Flags.HAS_ENTRIES.ordinal() : 0)
| (isThetaIncluded ? 1 << Flags.IS_THETA_INCLUDED.ordinal() : 0)
);
if (isThetaIncluded) {
ByteArrayUtil.putLongLE(bytes, offset, theta_);
offset += Long.BYTES;
}
if (count > 0) {
ByteArrayUtil.putIntLE(bytes, offset, getRetainedEntries());
offset += Integer.BYTES;
for (int i = 0; i < count; i++) {
ByteArrayUtil.putLongLE(bytes, offset, keys_[i]);
offset += Long.BYTES;
}
for (int i = 0; i < count; i++) {
System.arraycopy(summariesBytes[i], 0, bytes, offset, summariesBytes[i].length);
offset += summariesBytes[i].length;
}
}
return bytes;
} | java | @SuppressWarnings("null")
@Override
public byte[] toByteArray() {
int summariesBytesLength = 0;
byte[][] summariesBytes = null;
final int count = getRetainedEntries();
if (count > 0) {
summariesBytes = new byte[count][];
for (int i = 0; i < count; i++) {
summariesBytes[i] = summaries_[i].toByteArray();
summariesBytesLength += summariesBytes[i].length;
}
}
int sizeBytes =
Byte.BYTES // preamble longs
+ Byte.BYTES // serial version
+ Byte.BYTES // family id
+ Byte.BYTES // sketch type
+ Byte.BYTES; // flags
final boolean isThetaIncluded = theta_ < Long.MAX_VALUE;
if (isThetaIncluded) {
sizeBytes += Long.BYTES; // theta
}
if (count > 0) {
sizeBytes +=
+ Integer.BYTES // count
+ (Long.BYTES * count) + summariesBytesLength;
}
final byte[] bytes = new byte[sizeBytes];
int offset = 0;
bytes[offset++] = PREAMBLE_LONGS;
bytes[offset++] = serialVersionUID;
bytes[offset++] = (byte) Family.TUPLE.getID();
bytes[offset++] = (byte) SerializerDeserializer.SketchType.CompactSketch.ordinal();
final boolean isBigEndian = ByteOrder.nativeOrder().equals(ByteOrder.BIG_ENDIAN);
bytes[offset++] = (byte) (
(isBigEndian ? 1 << Flags.IS_BIG_ENDIAN.ordinal() : 0)
| (isEmpty_ ? 1 << Flags.IS_EMPTY.ordinal() : 0)
| (count > 0 ? 1 << Flags.HAS_ENTRIES.ordinal() : 0)
| (isThetaIncluded ? 1 << Flags.IS_THETA_INCLUDED.ordinal() : 0)
);
if (isThetaIncluded) {
ByteArrayUtil.putLongLE(bytes, offset, theta_);
offset += Long.BYTES;
}
if (count > 0) {
ByteArrayUtil.putIntLE(bytes, offset, getRetainedEntries());
offset += Integer.BYTES;
for (int i = 0; i < count; i++) {
ByteArrayUtil.putLongLE(bytes, offset, keys_[i]);
offset += Long.BYTES;
}
for (int i = 0; i < count; i++) {
System.arraycopy(summariesBytes[i], 0, bytes, offset, summariesBytes[i].length);
offset += summariesBytes[i].length;
}
}
return bytes;
} | [
"@",
"SuppressWarnings",
"(",
"\"null\"",
")",
"@",
"Override",
"public",
"byte",
"[",
"]",
"toByteArray",
"(",
")",
"{",
"int",
"summariesBytesLength",
"=",
"0",
";",
"byte",
"[",
"]",
"[",
"]",
"summariesBytes",
"=",
"null",
";",
"final",
"int",
"count... | 0 || | Flags | SkType | FamID | SerVer | Preamble_Longs | | [
"0",
"||",
"|",
"Flags",
"|",
"SkType",
"|",
"FamID",
"|",
"SerVer",
"|",
"Preamble_Longs",
"|"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/CompactSketch.java#L110-L169 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/tuple/HeapArrayOfDoublesUnion.java | HeapArrayOfDoublesUnion.heapifyUnion | static ArrayOfDoublesUnion heapifyUnion(final Memory mem, final long seed) {
final SerializerDeserializer.SketchType type = SerializerDeserializer.getSketchType(mem);
// compatibility with version 0.9.1 and lower
if (type == SerializerDeserializer.SketchType.ArrayOfDoublesQuickSelectSketch) {
final ArrayOfDoublesQuickSelectSketch sketch = new HeapArrayOfDoublesQuickSelectSketch(mem, seed);
return new HeapArrayOfDoublesUnion(sketch);
}
final byte version = mem.getByte(SERIAL_VERSION_BYTE);
if (version != serialVersionUID) {
throw new SketchesArgumentException("Serial version mismatch. Expected: "
+ serialVersionUID + ", actual: " + version);
}
SerializerDeserializer.validateFamily(mem.getByte(FAMILY_ID_BYTE), mem.getByte(PREAMBLE_LONGS_BYTE));
SerializerDeserializer.validateType(mem.getByte(SKETCH_TYPE_BYTE),
SerializerDeserializer.SketchType.ArrayOfDoublesUnion);
final long unionTheta = mem.getLong(THETA_LONG);
final Memory sketchMem = mem.region(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES);
final ArrayOfDoublesQuickSelectSketch sketch = new HeapArrayOfDoublesQuickSelectSketch(sketchMem, seed);
final ArrayOfDoublesUnion union = new HeapArrayOfDoublesUnion(sketch);
union.theta_ = unionTheta;
return union;
} | java | static ArrayOfDoublesUnion heapifyUnion(final Memory mem, final long seed) {
final SerializerDeserializer.SketchType type = SerializerDeserializer.getSketchType(mem);
// compatibility with version 0.9.1 and lower
if (type == SerializerDeserializer.SketchType.ArrayOfDoublesQuickSelectSketch) {
final ArrayOfDoublesQuickSelectSketch sketch = new HeapArrayOfDoublesQuickSelectSketch(mem, seed);
return new HeapArrayOfDoublesUnion(sketch);
}
final byte version = mem.getByte(SERIAL_VERSION_BYTE);
if (version != serialVersionUID) {
throw new SketchesArgumentException("Serial version mismatch. Expected: "
+ serialVersionUID + ", actual: " + version);
}
SerializerDeserializer.validateFamily(mem.getByte(FAMILY_ID_BYTE), mem.getByte(PREAMBLE_LONGS_BYTE));
SerializerDeserializer.validateType(mem.getByte(SKETCH_TYPE_BYTE),
SerializerDeserializer.SketchType.ArrayOfDoublesUnion);
final long unionTheta = mem.getLong(THETA_LONG);
final Memory sketchMem = mem.region(PREAMBLE_SIZE_BYTES, mem.getCapacity() - PREAMBLE_SIZE_BYTES);
final ArrayOfDoublesQuickSelectSketch sketch = new HeapArrayOfDoublesQuickSelectSketch(sketchMem, seed);
final ArrayOfDoublesUnion union = new HeapArrayOfDoublesUnion(sketch);
union.theta_ = unionTheta;
return union;
} | [
"static",
"ArrayOfDoublesUnion",
"heapifyUnion",
"(",
"final",
"Memory",
"mem",
",",
"final",
"long",
"seed",
")",
"{",
"final",
"SerializerDeserializer",
".",
"SketchType",
"type",
"=",
"SerializerDeserializer",
".",
"getSketchType",
"(",
"mem",
")",
";",
"// com... | This is to create an instance given a serialized form and a custom seed
@param mem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
@param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
@return a ArrayOfDoublesUnion on the Java heap | [
"This",
"is",
"to",
"create",
"an",
"instance",
"given",
"a",
"serialized",
"form",
"and",
"a",
"custom",
"seed"
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/tuple/HeapArrayOfDoublesUnion.java#L38-L62 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hash/MurmurHash3Adaptor.java | MurmurHash3Adaptor.asInteger | private static int asInteger(final long[] data, final int n) {
int t;
int cnt = 0;
long seed = 0;
if (n < 2) {
throw new SketchesArgumentException("Given value of n must be > 1.");
}
if (n > (1 << 30)) {
while (++cnt < 10000) {
final long[] h = MurmurHash3.hash(data, seed);
t = (int) (h[0] & INT_MASK);
if (t < n) {
return t;
}
t = (int) ((h[0] >>> 33));
if (t < n) {
return t;
}
t = (int) (h[1] & INT_MASK);
if (t < n) {
return t;
}
t = (int) ((h[1] >>> 33));
if (t < n) {
return t;
}
seed += PRIME;
} // end while
throw new SketchesStateException(
"Internal Error: Failed to find integer < n within 10000 iterations.");
}
final long mask = ceilingPowerOf2(n) - 1;
while (++cnt < 10000) {
final long[] h = MurmurHash3.hash(data, seed);
t = (int) (h[0] & mask);
if (t < n) {
return t;
}
t = (int) ((h[0] >>> 33) & mask);
if (t < n) {
return t;
}
t = (int) (h[1] & mask);
if (t < n) {
return t;
}
t = (int) ((h[1] >>> 33) & mask);
if (t < n) {
return t;
}
seed += PRIME;
} // end while
throw new SketchesStateException(
"Internal Error: Failed to find integer < n within 10000 iterations.");
} | java | private static int asInteger(final long[] data, final int n) {
int t;
int cnt = 0;
long seed = 0;
if (n < 2) {
throw new SketchesArgumentException("Given value of n must be > 1.");
}
if (n > (1 << 30)) {
while (++cnt < 10000) {
final long[] h = MurmurHash3.hash(data, seed);
t = (int) (h[0] & INT_MASK);
if (t < n) {
return t;
}
t = (int) ((h[0] >>> 33));
if (t < n) {
return t;
}
t = (int) (h[1] & INT_MASK);
if (t < n) {
return t;
}
t = (int) ((h[1] >>> 33));
if (t < n) {
return t;
}
seed += PRIME;
} // end while
throw new SketchesStateException(
"Internal Error: Failed to find integer < n within 10000 iterations.");
}
final long mask = ceilingPowerOf2(n) - 1;
while (++cnt < 10000) {
final long[] h = MurmurHash3.hash(data, seed);
t = (int) (h[0] & mask);
if (t < n) {
return t;
}
t = (int) ((h[0] >>> 33) & mask);
if (t < n) {
return t;
}
t = (int) (h[1] & mask);
if (t < n) {
return t;
}
t = (int) ((h[1] >>> 33) & mask);
if (t < n) {
return t;
}
seed += PRIME;
} // end while
throw new SketchesStateException(
"Internal Error: Failed to find integer < n within 10000 iterations.");
} | [
"private",
"static",
"int",
"asInteger",
"(",
"final",
"long",
"[",
"]",
"data",
",",
"final",
"int",
"n",
")",
"{",
"int",
"t",
";",
"int",
"cnt",
"=",
"0",
";",
"long",
"seed",
"=",
"0",
";",
"if",
"(",
"n",
"<",
"2",
")",
"{",
"throw",
"ne... | Returns a deterministic uniform random integer with a minimum inclusive value of zero and a
maximum exclusive value of n given the input data.
<p>The integer values produced are only as random as the MurmurHash3 algorithm, which may be
adequate for many applications. However, if you are looking for high guarantees of randomness
you should turn to more sophisticated random generators such as Mersenne Twister or Well19937c
algorithms.
@param data The input data (key)
@param n The upper exclusive bound of the integers produced. Must be > 1.
@return deterministic uniform random integer | [
"Returns",
"a",
"deterministic",
"uniform",
"random",
"integer",
"with",
"a",
"minimum",
"inclusive",
"value",
"of",
"zero",
"and",
"a",
"maximum",
"exclusive",
"value",
"of",
"n",
"given",
"the",
"input",
"data",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hash/MurmurHash3Adaptor.java#L326-L380 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/hash/MurmurHash3Adaptor.java | MurmurHash3Adaptor.modulo | public static int modulo(final long h0, final long h1, final int divisor) {
final long d = divisor;
final long modH0 = (h0 < 0L) ? addRule(mulRule(BIT62, 2L, d), (h0 & MAX_LONG), d) : h0 % d;
final long modH1 = (h1 < 0L) ? addRule(mulRule(BIT62, 2L, d), (h1 & MAX_LONG), d) : h1 % d;
final long modTop = mulRule(mulRule(BIT62, 4L, d), modH1, d);
return (int) addRule(modTop, modH0, d);
} | java | public static int modulo(final long h0, final long h1, final int divisor) {
final long d = divisor;
final long modH0 = (h0 < 0L) ? addRule(mulRule(BIT62, 2L, d), (h0 & MAX_LONG), d) : h0 % d;
final long modH1 = (h1 < 0L) ? addRule(mulRule(BIT62, 2L, d), (h1 & MAX_LONG), d) : h1 % d;
final long modTop = mulRule(mulRule(BIT62, 4L, d), modH1, d);
return (int) addRule(modTop, modH0, d);
} | [
"public",
"static",
"int",
"modulo",
"(",
"final",
"long",
"h0",
",",
"final",
"long",
"h1",
",",
"final",
"int",
"divisor",
")",
"{",
"final",
"long",
"d",
"=",
"divisor",
";",
"final",
"long",
"modH0",
"=",
"(",
"h0",
"<",
"0L",
")",
"?",
"addRul... | Returns the remainder from the modulo division of the 128-bit output of the murmurHash3 by the
divisor.
@param h0 The lower 64-bits of the 128-bit MurmurHash3 hash.
@param h1 The upper 64-bits of the 128-bit MurmurHash3 hash.
@param divisor Must be positive and greater than zero.
@return the modulo result. | [
"Returns",
"the",
"remainder",
"from",
"the",
"modulo",
"division",
"of",
"the",
"128",
"-",
"bit",
"output",
"of",
"the",
"murmurHash3",
"by",
"the",
"divisor",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/hash/MurmurHash3Adaptor.java#L407-L413 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/fdt/FdtSketch.java | FdtSketch.getResult | public List<Group> getResult(final int[] priKeyIndices, final int limit, final int numStdDev,
final char sep) {
final PostProcessor proc = new PostProcessor(this, new Group(), sep);
return proc.getGroupList(priKeyIndices, numStdDev, limit);
} | java | public List<Group> getResult(final int[] priKeyIndices, final int limit, final int numStdDev,
final char sep) {
final PostProcessor proc = new PostProcessor(this, new Group(), sep);
return proc.getGroupList(priKeyIndices, numStdDev, limit);
} | [
"public",
"List",
"<",
"Group",
">",
"getResult",
"(",
"final",
"int",
"[",
"]",
"priKeyIndices",
",",
"final",
"int",
"limit",
",",
"final",
"int",
"numStdDev",
",",
"final",
"char",
"sep",
")",
"{",
"final",
"PostProcessor",
"proc",
"=",
"new",
"PostPr... | Returns an ordered List of Groups of the most frequent distinct population of subset tuples
represented by the count of entries of each group.
@param priKeyIndices these indices define the dimensions used for the Primary Keys.
@param limit the maximum number of groups to return. If this value is ≤ 0, all
groups will be returned.
@param numStdDev the number of standard deviations for the upper and lower 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 sep the separator character
@return an ordered List of Groups of the most frequent distinct population of subset tuples
represented by the count of entries of each group. | [
"Returns",
"an",
"ordered",
"List",
"of",
"Groups",
"of",
"the",
"most",
"frequent",
"distinct",
"population",
"of",
"subset",
"tuples",
"represented",
"by",
"the",
"count",
"of",
"entries",
"of",
"each",
"group",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/FdtSketch.java#L89-L93 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/fdt/FdtSketch.java | FdtSketch.getLowerBound | public double getLowerBound(final int numStdDev, final int numSubsetEntries) {
if (!isEstimationMode()) { return numSubsetEntries; }
return BinomialBoundsN.getLowerBound(numSubsetEntries, getTheta(), numStdDev, isEmpty());
} | java | public double getLowerBound(final int numStdDev, final int numSubsetEntries) {
if (!isEstimationMode()) { return numSubsetEntries; }
return BinomialBoundsN.getLowerBound(numSubsetEntries, getTheta(), numStdDev, isEmpty());
} | [
"public",
"double",
"getLowerBound",
"(",
"final",
"int",
"numStdDev",
",",
"final",
"int",
"numSubsetEntries",
")",
"{",
"if",
"(",
"!",
"isEstimationMode",
"(",
")",
")",
"{",
"return",
"numSubsetEntries",
";",
"}",
"return",
"BinomialBoundsN",
".",
"getLowe... | Gets the estimate of the lower bound of the true distinct population represented by the count
of entries in a group.
@param numStdDev
<a href="{@docRoot}/resources/dictionary.html#numStdDev">See Number of Standard Deviations</a>
@param numSubsetEntries number of entries for a chosen subset of the sketch.
@return the estimate of the lower bound of the true distinct population represented by the count
of entries in a group. | [
"Gets",
"the",
"estimate",
"of",
"the",
"lower",
"bound",
"of",
"the",
"true",
"distinct",
"population",
"represented",
"by",
"the",
"count",
"of",
"entries",
"in",
"a",
"group",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/FdtSketch.java#L135-L138 | train |
DataSketches/sketches-core | src/main/java/com/yahoo/sketches/fdt/FdtSketch.java | FdtSketch.getUpperBound | public double getUpperBound(final int numStdDev, final int numSubsetEntries) {
if (!isEstimationMode()) { return numSubsetEntries; }
return BinomialBoundsN.getUpperBound(numSubsetEntries, getTheta(), numStdDev, isEmpty());
} | java | public double getUpperBound(final int numStdDev, final int numSubsetEntries) {
if (!isEstimationMode()) { return numSubsetEntries; }
return BinomialBoundsN.getUpperBound(numSubsetEntries, getTheta(), numStdDev, isEmpty());
} | [
"public",
"double",
"getUpperBound",
"(",
"final",
"int",
"numStdDev",
",",
"final",
"int",
"numSubsetEntries",
")",
"{",
"if",
"(",
"!",
"isEstimationMode",
"(",
")",
")",
"{",
"return",
"numSubsetEntries",
";",
"}",
"return",
"BinomialBoundsN",
".",
"getUppe... | Gets the estimate of the upper bound of the true distinct population represented by the count
of entries in a group.
@param numStdDev
<a href="{@docRoot}/resources/dictionary.html#numStdDev">See Number of Standard Deviations</a>
@param numSubsetEntries number of entries for a chosen subset of the sketch.
@return the estimate of the upper bound of the true distinct population represented by the count
of entries in a group. | [
"Gets",
"the",
"estimate",
"of",
"the",
"upper",
"bound",
"of",
"the",
"true",
"distinct",
"population",
"represented",
"by",
"the",
"count",
"of",
"entries",
"in",
"a",
"group",
"."
] | 900c8c9668a1e2f1d54d453e956caad54702e540 | https://github.com/DataSketches/sketches-core/blob/900c8c9668a1e2f1d54d453e956caad54702e540/src/main/java/com/yahoo/sketches/fdt/FdtSketch.java#L149-L152 | train |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.