index int64 0 0 | repo_id stringlengths 9 205 | file_path stringlengths 31 246 | content stringlengths 1 12.2M | __index_level_0__ int64 0 10k |
|---|---|---|---|---|
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/thetacommon/BoundsOnRatiosInThetaSketchedSets.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.thetacommon;
import static org.apache.datasketches.common.Util.LONG_MAX_VALUE_AS_DOUBLE;
import org.apache.datasketches.common.BoundsOnRatiosInSampledSets;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.theta.Sketch;
/**
* This class is used to compute the bounds on the estimate of the ratio <i>B / A</i>, where:
* <ul>
* <li><i>A</i> is a Theta Sketch of population <i>PopA</i>.</li>
* <li><i>B</i> is a Theta Sketch of population <i>PopB</i> that is a subset of <i>A</i>,
* obtained by an intersection of <i>A</i> with some other Theta Sketch <i>C</i>,
* which acts like a predicate or selection clause.</li>
* <li>The estimate of the ratio <i>PopB/PopA</i> is
* BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(<i>A, B</i>).</li>
* <li>The Upper Bound estimate on the ratio PopB/PopA is
* BoundsOnRatiosInThetaSketchedSets.getUpperBoundForBoverA(<i>A, B</i>).</li>
* <li>The Lower Bound estimate on the ratio PopB/PopA is
* BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA(<i>A, B</i>).</li>
* </ul>
* Note: The theta of <i>A</i> cannot be greater than the theta of <i>B</i>.
* If <i>B</i> is formed as an intersection of <i>A</i> and some other set <i>C</i>,
* then the theta of <i>B</i> is guaranteed to be less than or equal to the theta of <i>B</i>.
*
* @author Kevin Lang
* @author Lee Rhodes
*/
public final class BoundsOnRatiosInThetaSketchedSets {
private BoundsOnRatiosInThetaSketchedSets() {}
/**
* Gets the approximate lower bound for B over A based on a 95% confidence interval
* @param sketchA the sketch A
* @param sketchB the sketch B
* @return the approximate lower bound for B over A
*/
public static double getLowerBoundForBoverA(final Sketch sketchA, final Sketch sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries(true);
final int countA = (thetaLongB == thetaLongA)
? sketchA.getRetainedEntries(true)
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 0; }
final double f = thetaLongB / LONG_MAX_VALUE_AS_DOUBLE;
return BoundsOnRatiosInSampledSets.getLowerBoundForBoverA(countA, countB, f);
}
/**
* Gets the approximate upper bound for B over A based on a 95% confidence interval
* @param sketchA the sketch A
* @param sketchB the sketch B
* @return the approximate upper bound for B over A
*/
public static double getUpperBoundForBoverA(final Sketch sketchA, final Sketch sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries(true);
final int countA = (thetaLongB == thetaLongA)
? sketchA.getRetainedEntries(true)
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 1.0; }
final double f = thetaLongB / LONG_MAX_VALUE_AS_DOUBLE;
return BoundsOnRatiosInSampledSets.getUpperBoundForBoverA(countA, countB, f);
}
/**
* Gets the estimate for B over A
* @param sketchA the sketch A
* @param sketchB the sketch B
* @return the estimate for B over A
*/
public static double getEstimateOfBoverA(final Sketch sketchA, final Sketch sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries(true);
final int countA = (thetaLongB == thetaLongA)
? sketchA.getRetainedEntries(true)
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 0.5; }
return (double) countB / (double) countA;
}
static void checkThetas(final long thetaLongA, final long thetaLongB) {
if (thetaLongB > thetaLongA) {
throw new SketchesArgumentException("ThetaLongB cannot be > ThetaLongA.");
}
}
}
| 2,700 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/thetacommon/ThetaUtil.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.thetacommon;
import static org.apache.datasketches.hash.MurmurHash3.hash;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.Util;
/**
* Utility methods for the Theta Family of sketches
* @author Lee Rhodes
*
*/
public final class ThetaUtil {
/**
* The smallest Log2 nom entries allowed: 4.
*/
public static final int MIN_LG_NOM_LONGS = 4;
/**
* The largest Log2 nom entries allowed: 26.
*/
public static final int MAX_LG_NOM_LONGS = 26;
/**
* The hash table rebuild threshold = 15.0/16.0.
*/
public static final double REBUILD_THRESHOLD = 15.0 / 16.0;
/**
* The resize threshold = 0.5; tuned for speed.
*/
public static final double RESIZE_THRESHOLD = 0.5;
/**
* The default nominal entries is provided as a convenience for those cases where the
* nominal sketch size in number of entries is not provided.
* A sketch of 4096 entries has a Relative Standard Error (RSE) of +/- 1.56% at a confidence of
* 68%; or equivalently, a Relative Error of +/- 3.1% at a confidence of 95.4%.
* <a href="{@docRoot}/resources/dictionary.html#defaultNomEntries">See Default Nominal Entries</a>
*/
public static final int DEFAULT_NOMINAL_ENTRIES = 4096;
/**
* The seed 9001 used in the sketch update methods is a prime number that
* was chosen very early on in experimental testing. Choosing a seed is somewhat arbitrary, and
* the author cannot prove that this particular seed is somehow superior to other seeds. There
* was some early Internet discussion that a seed of 0 did not produce as clean avalanche diagrams
* as non-zero seeds, but this may have been more related to the MurmurHash2 release, which did
* have some issues. As far as the author can determine, MurmurHash3 does not have these problems.
*
* <p>In order to perform set operations on two sketches it is critical that the same hash
* function and seed are identical for both sketches, otherwise the assumed 1:1 relationship
* between the original source key value and the hashed bit string would be violated. Once
* you have developed a history of stored sketches you are stuck with it.
*
* <p><b>WARNING:</b> This seed is used internally by library sketches in different
* packages and thus must be declared public. However, this seed value must not be used by library
* users with the MurmurHash3 function. It should be viewed as existing for exclusive, private
* use by the library.
*
* <p><a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">See Default Update Seed</a>
*/
public static final long DEFAULT_UPDATE_SEED = 9001L;
private ThetaUtil() {}
/**
* The smallest Log2 cache size allowed: 5.
*/
public static final int MIN_LG_ARR_LONGS = 5;
/**
* Check if the two seed hashes are equal. If not, throw an SketchesArgumentException.
* @param seedHashA the seedHash A
* @param seedHashB the seedHash B
* @return seedHashA if they are equal
*/
public static short checkSeedHashes(final short seedHashA, final short seedHashB) {
if (seedHashA != seedHashB) {
throw new SketchesArgumentException(
"Incompatible Seed Hashes. " + Integer.toHexString(seedHashA & 0XFFFF)
+ ", " + Integer.toHexString(seedHashB & 0XFFFF));
}
return seedHashA;
}
/**
* Computes and checks the 16-bit seed hash from the given long seed.
* The seed hash may not be zero in order to maintain compatibility with older serialized
* versions that did not have this concept.
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>
* @return the seed hash.
*/
public static short computeSeedHash(final long seed) {
final long[] seedArr = {seed};
final short seedHash = (short)(hash(seedArr, 0L)[0] & 0xFFFFL);
if (seedHash == 0) {
throw new SketchesArgumentException(
"The given seed: " + seed + " produced a seedHash of zero. "
+ "You must choose a different seed.");
}
return seedHash;
}
/**
* Gets the smallest allowed exponent of 2 that it is a sub-multiple of the target by zero,
* one or more resize factors.
*
* @param lgTarget Log2 of the target size
* @param lgRF Log_base2 of Resize Factor.
* <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
* @param lgMin Log2 of the minimum allowed starting size
* @return The Log2 of the starting size
*/
public static int startingSubMultiple(final int lgTarget, final int lgRF,
final int lgMin) {
return lgTarget <= lgMin ? lgMin : lgRF == 0 ? lgTarget : (lgTarget - lgMin) % lgRF + lgMin;
}
/**
* Checks that the given nomLongs is within bounds and returns the Log2 of the ceiling power of 2
* of the given nomLongs.
* @param nomLongs the given number of nominal longs. This can be any value from 16 to
* 67108864, inclusive.
* @return The Log2 of the ceiling power of 2 of the given nomLongs.
*/
public static int checkNomLongs(final int nomLongs) {
final int lgNomLongs = Integer.numberOfTrailingZeros(Util.ceilingIntPowerOf2(nomLongs));
if (lgNomLongs > MAX_LG_NOM_LONGS || lgNomLongs < MIN_LG_NOM_LONGS) {
throw new SketchesArgumentException("Nominal Entries must be >= 16 and <= 67108864: "
+ nomLongs);
}
return lgNomLongs;
}
}
| 2,701 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/thetacommon/SetOperationCornerCases.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.thetacommon;
import java.util.HashMap;
import java.util.Map;
import org.apache.datasketches.common.SketchesArgumentException;
/**
* Simplifies and speeds up set operations by resolving specific corner cases.
* @author Lee Rhodes
*/
public class SetOperationCornerCases {
private static final long MAX = Long.MAX_VALUE;
public enum IntersectAction {
DEGEN_MIN_0_F("D", "Degenerate{MinTheta, 0, F}"),
EMPTY_1_0_T("E", "Empty{1.0, 0, T}"),
FULL_INTERSECT("I", "Full Intersect");
private String actionId;
private String actionDescription;
private IntersectAction(final String actionId, final String actionDescription) {
this.actionId = actionId;
this.actionDescription = actionDescription;
}
public String getActionId() {
return actionId;
}
public String getActionDescription() {
return actionDescription;
}
}
public enum AnotbAction {
SKETCH_A("A", "Sketch A Exactly"),
TRIM_A("TA", "Trim Sketch A by MinTheta"),
DEGEN_MIN_0_F("D", "Degenerate{MinTheta, 0, F}"),
DEGEN_THA_0_F("DA", "Degenerate{ThetaA, 0, F}"),
EMPTY_1_0_T("E", "Empty{1.0, 0, T}"),
FULL_ANOTB("N", "Full AnotB");
private String actionId;
private String actionDescription;
private AnotbAction(final String actionId, final String actionDescription) {
this.actionId = actionId;
this.actionDescription = actionDescription;
}
public String getActionId() {
return actionId;
}
public String getActionDescription() {
return actionDescription;
}
}
public enum UnionAction {
SKETCH_A("A", "Sketch A Exactly"),
TRIM_A("TA", "Trim Sketch A by MinTheta"),
SKETCH_B("B", "Sketch B Exactly"),
TRIM_B("TB", "Trim Sketch B by MinTheta"),
DEGEN_MIN_0_F("D", "Degenerate{MinTheta, 0, F}"),
DEGEN_THA_0_F("DA", "Degenerate{ThetaA, 0, F}"),
DEGEN_THB_0_F("DB", "Degenerate{ThetaB, 0, F}"),
EMPTY_1_0_T("E", "Empty{1.0, 0, T}"),
FULL_UNION("N", "Full Union");
private String actionId;
private String actionDescription;
private UnionAction(final String actionId, final String actionDescription) {
this.actionId = actionId;
this.actionDescription = actionDescription;
}
public String getActionId() {
return actionId;
}
public String getActionDescription() {
return actionDescription;
}
}
public enum CornerCase {
Empty_Empty(055, "A{ 1.0, 0, T} ; B{ 1.0, 0, T}",
IntersectAction.EMPTY_1_0_T, AnotbAction.EMPTY_1_0_T, UnionAction.EMPTY_1_0_T),
Empty_Exact(056, "A{ 1.0, 0, T} ; B{ 1.0,>0, F}",
IntersectAction.EMPTY_1_0_T, AnotbAction.EMPTY_1_0_T, UnionAction.SKETCH_B),
Empty_Estimation(052, "A{ 1.0, 0, T} ; B{<1.0,>0, F",
IntersectAction.EMPTY_1_0_T, AnotbAction.EMPTY_1_0_T, UnionAction.SKETCH_B),
Empty_Degen(050, "A{ 1.0, 0, T} ; B{<1.0, 0, F}",
IntersectAction.EMPTY_1_0_T, AnotbAction.EMPTY_1_0_T, UnionAction.DEGEN_THB_0_F),
Exact_Empty(065, "A{ 1.0,>0, F} ; B{ 1.0, 0, T}",
IntersectAction.EMPTY_1_0_T, AnotbAction.SKETCH_A, UnionAction.SKETCH_A),
Exact_Exact(066, "A{ 1.0,>0, F} ; B{ 1.0,>0, F}",
IntersectAction.FULL_INTERSECT, AnotbAction.FULL_ANOTB, UnionAction.FULL_UNION),
Exact_Estimation(062, "A{ 1.0,>0, F} ; B{<1.0,>0, F}",
IntersectAction.FULL_INTERSECT, AnotbAction.FULL_ANOTB, UnionAction.FULL_UNION),
Exact_Degen(060, "A{ 1.0,>0, F} ; B{<1.0, 0, F}",
IntersectAction.DEGEN_MIN_0_F, AnotbAction.TRIM_A, UnionAction.TRIM_A),
Estimation_Empty(025, "A{<1.0,>0, F} ; B{ 1.0, 0, T}",
IntersectAction.EMPTY_1_0_T, AnotbAction.SKETCH_A, UnionAction.SKETCH_A),
Estimation_Exact(026, "A{<1.0,>0, F} ; B{ 1.0,>0, F}",
IntersectAction.FULL_INTERSECT, AnotbAction.FULL_ANOTB, UnionAction.FULL_UNION),
Estimation_Estimation(022, "A{<1.0,>0, F} ; B{<1.0,>0, F}",
IntersectAction.FULL_INTERSECT, AnotbAction.FULL_ANOTB, UnionAction.FULL_UNION),
Estimation_Degen(020, "A{<1.0,>0, F} ; B{<1.0, 0, F}",
IntersectAction.DEGEN_MIN_0_F, AnotbAction.TRIM_A, UnionAction.TRIM_A),
Degen_Empty(005, "A{<1.0, 0, F} ; B{ 1.0, 0, T}",
IntersectAction.EMPTY_1_0_T, AnotbAction.DEGEN_THA_0_F, UnionAction.DEGEN_THA_0_F),
Degen_Exact(006, "A{<1.0, 0, F} ; B{ 1.0,>0, F}",
IntersectAction.DEGEN_MIN_0_F, AnotbAction.DEGEN_THA_0_F, UnionAction.TRIM_B),
Degen_Estimation(002, "A{<1.0, 0, F} ; B{<1.0,>0, F}",
IntersectAction.DEGEN_MIN_0_F, AnotbAction.DEGEN_MIN_0_F, UnionAction.TRIM_B),
Degen_Degen(000, "A{<1.0, 0, F} ; B{<1.0, 0, F}",
IntersectAction.DEGEN_MIN_0_F, AnotbAction.DEGEN_MIN_0_F, UnionAction.DEGEN_MIN_0_F);
private static final Map<Integer, CornerCase> caseIdToCornerCaseMap = new HashMap<>();
private int caseId;
private String caseDescription;
private IntersectAction intersectAction;
private AnotbAction anotbAction;
private UnionAction unionAction;
static {
for (final CornerCase cc : values()) {
caseIdToCornerCaseMap.put(cc.getId(), cc);
}
}
private CornerCase(final int caseId, final String caseDescription,
final IntersectAction intersectAction, final AnotbAction anotbAction, final UnionAction unionAction) {
this.caseId = caseId;
this.caseDescription = caseDescription;
this.intersectAction = intersectAction;
this.anotbAction = anotbAction;
this.unionAction = unionAction;
}
public int getId() {
return caseId;
}
public String getCaseDescription() {
return caseDescription;
}
public IntersectAction getIntersectAction() {
return intersectAction;
}
public AnotbAction getAnotbAction() {
return anotbAction;
}
public UnionAction getUnionAction() {
return unionAction;
}
//See checkById test in /tuple/MiscTest.
public static CornerCase caseIdToCornerCase(final int id) {
final CornerCase cc = caseIdToCornerCaseMap.get(id);
if (cc == null) {
throw new SketchesArgumentException("Possible Corruption: Illegal CornerCase ID: " + Integer.toOctalString(id));
}
return cc;
}
} //end of enum CornerCase
public static int createCornerCaseId(
final long thetaLongA, final int countA, final boolean emptyA,
final long thetaLongB, final int countB, final boolean emptyB) {
return (sketchStateId(emptyA, countA, thetaLongA) << 3) | sketchStateId(emptyB, countB, thetaLongB);
}
public static int sketchStateId(final boolean isEmpty, final int numRetained, final long thetaLong) {
// assume thetaLong = MAX if empty
return (((thetaLong == MAX) || isEmpty) ? 4 : 0) | ((numRetained > 0) ? 2 : 0) | (isEmpty ? 1 : 0);
}
}
| 2,702 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/thetacommon/EquivTables.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.thetacommon;
/**
* Tables for BinomialBoundsN calculations.
*
* <p>These equivTables contain modified values for numSDevs that if used
* WHEN THETA IS VERY SMALL will cause the continuity-corrected version
* of our "classic" confidence intervals to be very close to "exact" confidence
* intervals based on the tails of the actual binomial distirbution.</p>
*
* @author Kevin Lang
*/
final class EquivTables {
private EquivTables() {}
static double getLB(final int index) {
return lbEquivTable[index];
}
static double getUB(final int index) {
return ubEquivTable[index];
}
private static double[] lbEquivTable = {
1.0, 2.0, 3.0, // fake values for k = 0
0.78733703534118149, 3.14426768537558132, 13.56789685109913535, // k = 1
0.94091379266077979, 2.64699271711145911, 6.29302733018320737, // k = 2
0.96869128474958188, 2.46531676590527127, 4.97375283467403051, // k = 3
0.97933572521046131, 2.37418810664669877, 4.44899975481712318, // k = 4
0.98479165917274258, 2.31863116255024693, 4.16712379778553554, // k = 5
0.98806033915698777, 2.28075536565225434, 3.99010556144099837, // k = 6
0.99021896790580399, 2.25302005857281529, 3.86784477136922078, // k = 7
0.99174267079089873, 2.23168103978522936, 3.77784896945266269, // k = 8
0.99287147837287648, 2.21465899260871879, 3.70851932988722410, // k = 9
0.99373900046805375, 2.20070155496262032, 3.65326029076638292, // k = 10
0.99442519013851438, 2.18900651202670815, 3.60803817612955413, // k = 11
0.99498066823221620, 2.17903457780744247, 3.57024330407946877, // k = 12
0.99543899410224412, 2.17040883161922693, 3.53810982030634591, // k = 13
0.99582322541263579, 2.16285726913676513, 3.51039837124298515, // k = 14
0.99614973311747690, 2.15617827879603396, 3.48621230377099778, // k = 15
0.99643042892560629, 2.15021897666090922, 3.46488605693562590, // k = 16
0.99667418783778317, 2.14486114872480016, 3.44591466064832730, // k = 17
0.99688774875812669, 2.14001181420209718, 3.42890765690452781, // k = 18
0.99707632299691795, 2.13559675336844634, 3.41355809420343803, // k = 19
0.99724399084971083, 2.13155592217421486, 3.39962113251016262, // k = 20
0.99739400151915447, 2.12784018863251845, 3.38689892877548004, // k = 21
0.99752896842633731, 2.12440890875851096, 3.37522975271599535, // k = 22
0.99765101725122918, 2.12122815311133195, 3.36448003577621080, // k = 23
0.99776189496810730, 2.11826934724291505, 3.35453840911279144, // k = 24
0.99786304821586214, 2.11550823850916458, 3.34531123809287578, // k = 25
0.99795568665180667, 2.11292409529477254, 3.33671916527694634, // k = 26
0.99804083063483517, 2.11049908609763293, 3.32869446834217797, // k = 27
0.99811933910984862, 2.10821776918189130, 3.32117898316676019, // k = 28
0.99819195457286014, 2.10606671027090897, 3.31412243534683171, // k = 29
0.99825930555178388, 2.10403415237001923, 3.30748113008135647, // k = 30
0.99832193858154028, 2.10210975877822648, 3.30121691946897045, // k = 31
0.99838032666573895, 2.10028440670842542, 3.29529629751144171, // k = 32
0.99843488390555990, 2.09855000145353188, 3.28968974413223236, // k = 33
0.99848596721417948, 2.09689934193824001, 3.28437111460505093, // k = 34
0.99853390005924325, 2.09532599155502908, 3.27931717312372939, // k = 35
0.99857895741078551, 2.09382418262592296, 3.27450718840060517, // k = 36
0.99862138880970974, 2.09238872751677718, 3.26992261182860489, // k = 37
0.99866141580770318, 2.09101494715108061, 3.26554677962434425, // k = 38
0.99869923565267982, 2.08969860402822860, 3.26136468165239535, // k = 39
0.99873502010169091, 2.08843585627218431, 3.25736275677081721, // k = 40
0.99876893292508839, 2.08722321436752623, 3.25352872241415980, // k = 41
0.99880111078502409, 2.08605749165553789, 3.24985141664350863, // k = 42
0.99883168573342118, 2.08493577529222307, 3.24632068399498053, // k = 43
0.99886077231613513, 2.08385540129560809, 3.24292724848112357, // k = 44
0.99888847451828155, 2.08281392374021834, 3.23966263299664092, // k = 45
0.99891488795844907, 2.08180908991394631, 3.23651906111521726, // k = 46
0.99894010085196783, 2.08083882998420222, 3.23348939240611344, // k = 47
0.99896419358239541, 2.07990122528650545, 3.23056705515594444, // k = 48
0.99898723510594323, 2.07899450946285924, 3.22774598963252402, // k = 49
0.99900929266780736, 2.07811704477046533, 3.22502059972006805, // k = 50
0.99903043086155208, 2.07726730587160091, 3.22238570890294795, // k = 51
0.99905070073845081, 2.07644388314946582, 3.21983651940365689, // k = 52
0.99907015770423868, 2.07564546080757850, 3.21736857351049821, // k = 53
0.99908884779227947, 2.07487081196367740, 3.21497773796417619, // k = 54
0.99910681586905525, 2.07411879634256024, 3.21266015316183484, // k = 55
0.99912410177549305, 2.07338834403498140, 3.21041222805715165, // k = 56
0.99914074347179849, 2.07267845454973099, 3.20823061166797174, // k = 57
0.99915677607464204, 2.07198819052374006, 3.20611216970604573, // k = 58
0.99917223149395795, 2.07131667846186929, 3.20405396962596001, // k = 59
0.99918714153457699, 2.07066309019154460, 3.20205326110445299, // k = 60
0.99920153247185794, 2.07002665203046377, 3.20010746990493544, // k = 61
0.99921543193525508, 2.06940663431663552, 3.19821417453343315, // k = 62
0.99922886570365677, 2.06880235245998279, 3.19637109973109546, // k = 63
0.99924185357357942, 2.06821315729285971, 3.19457610621114441, // k = 64
0.99925441845175555, 2.06763843812092318, 3.19282717869864996, // k = 65
0.99926658263325407, 2.06707761824370095, 3.19112241228646099, // k = 66
0.99927836173816331, 2.06653015295219689, 3.18946001739936946, // k = 67
0.99928977431994781, 2.06599552505539918, 3.18783829446098821, // k = 68
0.99930083753795884, 2.06547324585920933, 3.18625564538041317, // k = 69
0.99931156864562354, 2.06496285191821016, 3.18471055124089730, // k = 70
0.99932197985521043, 2.06446390392778767, 3.18320157510865442, // k = 71
0.99933208559809827, 2.06397598606787369, 3.18172735837393361, // k = 72
0.99934190032416836, 2.06349869971447220, 3.18028661102792398, // k = 73
0.99935143390791836, 2.06303166975550312, 3.17887810481605015, // k = 74
0.99936070171270330, 2.06257453607466346, 3.17750067581857820, // k = 75
0.99936971103502970, 2.06212696042919674, 3.17615321728274580, // k = 76
0.99937847392385493, 2.06168861430600714, 3.17483467831510779, // k = 77
0.99938700168914352, 2.06125918927764928, 3.17354405480557489, // k = 78
0.99939530099953799, 2.06083838987589729, 3.17228039269048168, // k = 79
0.99940338278830154, 2.06042593411496000, 3.17104278166036124, // k = 80
0.99941125463777780, 2.06002155276328835, 3.16983035274597569, // k = 81
0.99941892470027938, 2.05962498741951094, 3.16864227952240185, // k = 82
0.99942640059737187, 2.05923599161263837, 3.16747776846497686, // k = 83
0.99943368842187397, 2.05885433061945378, 3.16633606416374391, // k = 84
0.99944079790603269, 2.05847977868873500, 3.16521644518826406, // k = 85
0.99944773295734990, 2.05811212058944193, 3.16411821883858124, // k = 86
0.99945450059186669, 2.05775114781260982, 3.16304072400711789, // k = 87
0.99946110646314423, 2.05739666442039493, 3.16198332650733960, // k = 88
0.99946755770463369, 2.05704847678819647, 3.16094541781455973, // k = 89
0.99947385746861528, 2.05670640500335367, 3.15992641851471490, // k = 90
0.99948001256305474, 2.05637027420314666, 3.15892576988736096, // k = 91
0.99948602689656241, 2.05603991286400856, 3.15794293484717059, // k = 92
0.99949190674294641, 2.05571516158917689, 3.15697740043813724, // k = 93
0.99949765436329585, 2.05539586490317561, 3.15602867309343083, // k = 94
0.99950327557880314, 2.05508187237845164, 3.15509627710042651, // k = 95
0.99950877461972709, 2.05477304104951486, 3.15417975753007340, // k = 96
0.99951415481862682, 2.05446923022574879, 3.15327867462917766, // k = 97
0.99951942042375208, 2.05417030908833453, 3.15239260700215596, // k = 98
0.99952457390890004, 2.05387614661762541, 3.15152114915238712, // k = 99
0.99952962005008317, 2.05358662050909402, 3.15066390921020911, // k = 100
0.99953456216121594, 2.05330161104427589, 3.14982051097524618, // k = 101
0.99953940176368405, 2.05302100378725072, 3.14899059183684926, // k = 102
0.99954414373920031, 2.05274468493067275, 3.14817379948561893, // k = 103
0.99954879047621148, 2.05247255013657082, 3.14736979964868624, // k = 104
0.99955334485656522, 2.05220449388099269, 3.14657826610371671, // k = 105
0.99955780993869325, 2.05194041831310869, 3.14579888316276879, // k = 106
0.99956218652590678, 2.05168022402710903, 3.14503134811607765, // k = 107
0.99956647932785359, 2.05142381889103831, 3.14427536967733090, // k = 108
0.99957069025060719, 2.05117111251445294, 3.14353066260227365, // k = 109
0.99957482032178291, 2.05092201793428330, 3.14279695558593630, // k = 110
0.99957887261450651, 2.05067645094720774, 3.14207398336887422, // k = 111
0.99958284988383639, 2.05043432833224415, 3.14136149076028914, // k = 112
0.99958675435604505, 2.05019557189746138, 3.14065923143530767, // k = 113
0.99959058650074439, 2.04996010556124020, 3.13996696426707445, // k = 114
0.99959434898201494, 2.04972785368377686, 3.13928445867830419, // k = 115
0.99959804437042976, 2.04949874512311681, 3.13861149103462367, // k = 116
0.99960167394553423, 2.04927271043337100, 3.13794784369528656, // k = 117
0.99960523957651048, 2.04904968140490951, 3.13729330661277572, // k = 118
0.99960874253329735, 2.04882959397491504, 3.13664767767019725, // k = 119
0.99961218434327748, 2.04861238220240693, 3.13601075688413289 // k = 120
};
private static double[] ubEquivTable = {
1.0, 2.0, 3.0, // fake values for k = 0
0.99067760836669549, 1.75460517119302040, 2.48055626001627161, // k = 1
0.99270518097577565, 1.78855957509907171, 2.53863835259832626, // k = 2
0.99402032633599902, 1.81047286499563143, 2.57811676180597260, // k = 3
0.99492607629539975, 1.82625928017762362, 2.60759550546498531, // k = 4
0.99558653966013821, 1.83839160339161367, 2.63086812358551470, // k = 5
0.99608981951632813, 1.84812399034444752, 2.64993712523727254, // k = 6
0.99648648035983456, 1.85617372053235385, 2.66598485907860550, // k = 7
0.99680750790483330, 1.86298655802610824, 2.67976541374471822, // k = 8
0.99707292880049181, 1.86885682585270274, 2.69178781407745760, // k = 9
0.99729614928489241, 1.87398826101983218, 2.70241106542158604, // k = 10
0.99748667952445658, 1.87852708449801753, 2.71189717290596377, // k = 11
0.99765127712748836, 1.88258159501103250, 2.72044290303773550, // k = 12
0.99779498340305395, 1.88623391878036273, 2.72819957382063194, // k = 13
0.99792160418357412, 1.88954778748873764, 2.73528576807902368, // k = 14
0.99803398604944960, 1.89257337682371940, 2.74179612106766513, // k = 15
0.99813449883217231, 1.89535099316557876, 2.74780718300419835, // k = 16
0.99822494122659577, 1.89791339232732525, 2.75338173141955167, // k = 17
0.99830679915913834, 1.90028752122407241, 2.75857186416826039, // k = 18
0.99838117410831728, 1.90249575897183831, 2.76342117562634826, // k = 19
0.99844913407071090, 1.90455689090418900, 2.76796659454200267, // k = 20
0.99851147736424650, 1.90648682834171268, 2.77223944710058845, // k = 21
0.99856879856019987, 1.90829917277082473, 2.77626682032629901, // k = 22
0.99862183849734265, 1.91000561415842185, 2.78007199816156003, // k = 23
0.99867096266018507, 1.91161621560812023, 2.78367524259661536, // k = 24
0.99871656986212543, 1.91313978579765376, 2.78709435016625662, // k = 25
0.99875907577771272, 1.91458400425526065, 2.79034488416175463, // k = 26
0.99879885565047744, 1.91595563175945927, 2.79344064132371273, // k = 27
0.99883610756373287, 1.91726064301425936, 2.79639384757751941, // k = 28
0.99887095169674467, 1.91850441099725799, 2.79921543574803877, // k = 29
0.99890379414739527, 1.91969155477030995, 2.80191513182441554, // k = 30
0.99893466279047516, 1.92082633358913313, 2.80450167352080371, // k = 31
0.99896392088177777, 1.92191254955568525, 2.80698295731653502, // k = 32
0.99899147889385631, 1.92295362479495680, 2.80936614404217266, // k = 33
0.99901764688726757, 1.92395267400968351, 2.81165765979318394, // k = 34
0.99904238606342233, 1.92491244978191389, 2.81386337393604435, // k = 35
0.99906590152386343, 1.92583552644848055, 2.81598868034527072, // k = 36
0.99908829040739988, 1.92672418013918900, 2.81803841726804194, // k = 37
0.99910959420023460, 1.92758051694144683, 2.82001709302821268, // k = 38
0.99912996403594434, 1.92840654943159961, 2.82192875763732332, // k = 39
0.99914930224576892, 1.92920397044028391, 2.82377730628954282, // k = 40
0.99916781270195543, 1.92997447498220254, 2.82556612075063640, // k = 41
0.99918553179077207, 1.93071949211818605, 2.82729843191989971, // k = 42
0.99920250730914972, 1.93144048613876862, 2.82897728689417249, // k = 43
0.99921873345181211, 1.93213870990595638, 2.83060537017752267, // k = 44
0.99923435180002684, 1.93281536508689555, 2.83218527795750674, // k = 45
0.99924930425362390, 1.93347145882316340, 2.83371938965598247, // k = 46
0.99926370394567243, 1.93410820221384938, 2.83520990872793277, // k = 47
0.99927750755296074, 1.93472643138986200, 2.83665891945119597, // k = 48
0.99929082941537217, 1.93532697329771963, 2.83806833931606661, // k = 49
0.99930366295501472, 1.93591074716263734, 2.83943997143404658, // k = 50
0.99931598804721489, 1.93647857274021362, 2.84077557836653227, // k = 51
0.99932789059798210, 1.93703110239354714, 2.84207662106302905, // k = 52
0.99933946180485123, 1.93756904936378760, 2.84334468086129277, // k = 53
0.99935053819703512, 1.93809302131219852, 2.84458116874117195, // k = 54
0.99936126637970801, 1.93860365411038060, 2.84578731838604426, // k = 55
0.99937166229284458, 1.93910149816429112, 2.84696443486512862, // k = 56
0.99938169190727422, 1.93958709548454067, 2.84811369085281285, // k = 57
0.99939136927613959, 1.94006085573701625, 2.84923617230361970, // k = 58
0.99940074328745254, 1.94052339623206649, 2.85033291216254270, // k = 59
0.99940993070470086, 1.94097508636855309, 2.85140492437699322, // k = 60
0.99941868577388959, 1.94141633372043998, 2.85245314430358121, // k = 61
0.99942734443487780, 1.94184757038001976, 2.85347839582286156, // k = 62
0.99943556385736088, 1.94226915100517772, 2.85448160365493209, // k = 63
0.99944374522542034, 1.94268143723749631, 2.85546346373061510, // k = 64
0.99945159955424856, 1.94308482059116727, 2.85642486111805738, // k = 65
0.99945915301904620, 1.94347956957849988, 2.85736639994965458, // k = 66
0.99946660663832176, 1.94386600964031686, 2.85828887832701639, // k = 67
0.99947383703224091, 1.94424436597356021, 2.85919278275500233, // k = 68
0.99948075442870277, 1.94461502153473020, 2.86007887186090670, // k = 69
0.99948766082269458, 1.94497821937304138, 2.86094774077355396, // k = 70
0.99949422748713346, 1.94533411296001191, 2.86179981848076181, // k = 71
0.99950070756119658, 1.94568300035135167, 2.86263579405672886, // k = 72
0.99950704321753392, 1.94602523449961495, 2.86345610449197352, // k = 73
0.99951320334216121, 1.94636083782822311, 2.86426125541271404, // k = 74
0.99951920293474927, 1.94669011080745236, 2.86505169255406145, // k = 75
0.99952501670378524, 1.94701327348536779, 2.86582788270862920, // k = 76
0.99953071209267819, 1.94733044372333097, 2.86659027602854621, // k = 77
0.99953632734991515, 1.94764180764266825, 2.86733927778843167, // k = 78
0.99954171164873173, 1.94794766430732125, 2.86807526143834934, // k = 79
0.99954699274462655, 1.94824807472994621, 2.86879864789403882, // k = 80
0.99955216611081710, 1.94854317889829076, 2.86950970901679625, // k = 81
0.99955730019613043, 1.94883320227168610, 2.87020887436986527, // k = 82
0.99956213770650493, 1.94911826561721568, 2.87089648477021342, // k = 83
0.99956704264963037, 1.94939848545763539, 2.87157281693902178, // k = 84
0.99957166306481327, 1.94967401618316671, 2.87223821840905202, // k = 85
0.99957632713136491, 1.94994497791333288, 2.87289293193450135, // k = 86
0.99958087233392234, 1.95021155752212394, 2.87353731228213860, // k = 87
0.99958532555996271, 1.95047376805584349, 2.87417154907075201, // k = 88
0.99958956246481989, 1.95073180380688882, 2.87479599765507032, // k = 89
0.99959389351869277, 1.95098572880579013, 2.87541081987382086, // k = 90
0.99959807862052230, 1.95123574036898617, 2.87601637401948551, // k = 91
0.99960214057801977, 1.95148186921983324, 2.87661283691068093, // k = 92
0.99960607527256684, 1.95172415829728152, 2.87720042968334155, // k = 93
0.99960996433179616, 1.95196280898670693, 2.87777936649376898, // k = 94
0.99961379137860717, 1.95219787713926962, 2.87834989933620022, // k = 95
0.99961756088146103, 1.95242944583677058, 2.87891216133900230, // k = 96
0.99962125605327401, 1.95265762420910960, 2.87946647367488140, // k = 97
0.99962486179100551, 1.95288245314810638, 2.88001290210658567, // k = 98
0.99962843240297161, 1.95310404286672679, 2.88055166523392359, // k = 99
0.99963187276145504, 1.95332251980147475, 2.88108300006589957, // k = 100
0.99963525453173929, 1.95353785898848287, 2.88160703591438505, // k = 101
0.99963855412988778, 1.95375019354571577, 2.88212393551896184, // k = 102
0.99964190254169694, 1.95395953472205974, 2.88263389761985422, // k = 103
0.99964506565942202, 1.95416607430155409, 2.88313700661564098, // k = 104
0.99964834424233118, 1.95436972855640079, 2.88363350163803034, // k = 105
0.99965136548857458, 1.95457068540693513, 2.88412349413960101, // k = 106
0.99965436594726498, 1.95476896383092935, 2.88460710620208260, // k = 107
0.99965736463468602, 1.95496457504532373, 2.88508450078833789, // k = 108
0.99966034130443404, 1.95515761150707590, 2.88555580586194083, // k = 109
0.99966326130828520, 1.95534810382198998, 2.88602118761679094, // k = 110
0.99966601446035952, 1.95553622237747504, 2.88648066384146773, // k = 111
0.99966887679593697, 1.95572186728168163, 2.88693444915907094, // k = 112
0.99967161286551232, 1.95590523410490391, 2.88738271495714116, // k = 113
0.99967435412270333, 1.95608626483223702, 2.88782540459769166, // k = 114
0.99967701261934394, 1.95626497627117146, 2.88826277189363623, // k = 115
0.99967963265157778, 1.95644153684824573, 2.88869486674335008, // k = 116
0.99968216317182623, 1.95661589936000269, 2.88912184353694101, // k = 117
0.99968479674396349, 1.95678821614791332, 2.88954376359643561, // k = 118
0.99968729031337489, 1.95695842061650183, 2.88996069422501023, // k = 119
0.99968963358631413, 1.95712651709766305, 2.89037285320668502 // k = 120
};
}
| 2,703 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/thetacommon/QuickSelect.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.thetacommon;
/**
* QuickSelect algorithm improved from Sedgewick. Gets the kth order value
* (1-based or 0-based) from the array.
* Warning! This changes the ordering of elements in the given array!<br>
* Also see:<br>
* blog.teamleadnet.com/2012/07/quick-select-algorithm-find-kth-element.html<br>
* See QuickSelectTest for examples and testNG tests.
*
* @author Lee Rhodes
*/
public final class QuickSelect {
private QuickSelect() {}
/**
* Gets the 0-based kth order statistic from the array. Warning! This changes the ordering
* of elements in the given array!
*
* @param arr The array to be re-arranged.
* @param lo The lowest 0-based index to be considered.
* @param hi The highest 0-based index to be considered.
* @param pivot The 0-based index of the value to pivot on.
* @return The value of the smallest (n)th element where n is 0-based.
*/
public static long select(final long[] arr, int lo, int hi, final int pivot) {
while (hi > lo) {
final int j = partition(arr, lo, hi);
if (j == pivot) {
return arr[pivot];
}
if (j > pivot) {
hi = j - 1;
}
else {
lo = j + 1;
}
}
return arr[pivot];
}
/**
* Gets the 1-based kth order statistic from the array including any zero values in the
* array. Warning! This changes the ordering of elements in the given array!
*
* @param arr The hash array.
* @param pivot The 1-based index of the value that is chosen as the pivot for the array.
* After the operation all values below this 1-based index will be less than this value
* and all values above this index will be greater. The 0-based index of the pivot will be
* pivot-1.
* @return The value of the smallest (N)th element including zeros, where N is 1-based.
*/
public static long selectIncludingZeros(final long[] arr, final int pivot) {
final int arrSize = arr.length;
final int adj = pivot - 1;
return select(arr, 0, arrSize - 1, adj);
}
/**
* Gets the 1-based kth order statistic from the array excluding any zero values in the
* array. Warning! This changes the ordering of elements in the given array!
*
* @param arr The hash array.
* @param nonZeros The number of non-zero values in the array.
* @param pivot The 1-based index of the value that is chosen as the pivot for the array.
* After the operation all values below this 1-based index will be less than this value
* and all values above this index will be greater. The 0-based index of the pivot will be
* pivot+arr.length-nonZeros-1.
* @return The value of the smallest (N)th element excluding zeros, where N is 1-based.
*/
public static long selectExcludingZeros(final long[] arr, final int nonZeros, final int pivot) {
if (pivot > nonZeros) {
return 0L;
}
final int arrSize = arr.length;
final int zeros = arrSize - nonZeros;
final int adjK = (pivot + zeros) - 1;
return select(arr, 0, arrSize - 1, adjK);
}
/**
* Partition arr[] into arr[lo .. i-1], arr[i], arr[i+1,hi]
*
* @param arr The given array to partition
* @param lo the low index
* @param hi the high index
* @return the next partition value. Ultimately, the desired pivot.
*/
private static int partition(final long[] arr, final int lo, final int hi) {
int i = lo, j = hi + 1; //left and right scan indices
final long v = arr[lo]; //partitioning item value
while (true) {
//Scan right, scan left, check for scan complete, and exchange
while (arr[ ++i] < v) {
if (i == hi) {
break;
}
}
while (v < arr[ --j]) {
if (j == lo) {
break;
}
}
if (i >= j) {
break;
}
final long x = arr[i];
arr[i] = arr[j];
arr[j] = x;
}
//put v=arr[j] into position with a[lo .. j-1] <= a[j] <= a[j+1 .. hi]
final long x = arr[lo];
arr[lo] = arr[j];
arr[j] = x;
return j;
}
//For double arrays
/**
* Gets the 0-based kth order statistic from the array. Warning! This changes the ordering
* of elements in the given array!
*
* @param arr The array to be re-arranged.
* @param lo The lowest 0-based index to be considered.
* @param hi The highest 0-based index to be considered.
* @param pivot The 0-based smallest value to pivot on.
* @return The value of the smallest (n)th element where n is 0-based.
*/
public static double select(final double[] arr, int lo, int hi, final int pivot) {
while (hi > lo) {
final int j = partition(arr, lo, hi);
if (j == pivot) {
return arr[pivot];
}
if (j > pivot) {
hi = j - 1;
}
else {
lo = j + 1;
}
}
return arr[pivot];
}
/**
* Gets the 1-based kth order statistic from the array including any zero values in the
* array. Warning! This changes the ordering of elements in the given array!
*
* @param arr The hash array.
* @param pivot The 1-based index of the value that is chosen as the pivot for the array.
* After the operation all values below this 1-based index will be less than this value
* and all values above this index will be greater. The 0-based index of the pivot will be
* pivot-1.
* @return The value of the smallest (N)th element including zeros, where N is 1-based.
*/
public static double selectIncludingZeros(final double[] arr, final int pivot) {
final int arrSize = arr.length;
final int adj = pivot - 1;
return select(arr, 0, arrSize - 1, adj);
}
/**
* Gets the 1-based kth order statistic from the array excluding any zero values in the
* array. Warning! This changes the ordering of elements in the given array!
*
* @param arr The hash array.
* @param nonZeros The number of non-zero values in the array.
* @param pivot The 1-based index of the value that is chosen as the pivot for the array.
* After the operation all values below this 1-based index will be less than this value
* and all values above this index will be greater. The 0-based index of the pivot will be
* pivot+arr.length-nonZeros-1.
* @return The value of the smallest (N)th element excluding zeros, where N is 1-based.
*/
public static double selectExcludingZeros(final double[] arr, final int nonZeros, final int pivot) {
if (pivot > nonZeros) {
return 0L;
}
final int arrSize = arr.length;
final int zeros = arrSize - nonZeros;
final int adjK = (pivot + zeros) - 1;
return select(arr, 0, arrSize - 1, adjK);
}
/**
* Partition arr[] into arr[lo .. i-1], arr[i], arr[i+1,hi]
*
* @param arr The given array to partition
* @param lo the low index
* @param hi the high index
* @return the next partition value. Ultimately, the desired pivot.
*/
private static int partition(final double[] arr, final int lo, final int hi) {
int i = lo, j = hi + 1; //left and right scan indices
final double v = arr[lo]; //partitioning item value
while (true) {
//Scan right, scan left, check for scan complete, and exchange
while (arr[ ++i] < v) {
if (i == hi) {
break;
}
}
while (v < arr[ --j]) {
if (j == lo) {
break;
}
}
if (i >= j) {
break;
}
final double x = arr[i];
arr[i] = arr[j];
arr[j] = x;
}
//put v=arr[j] into position with a[lo .. j-1] <= a[j] <= a[j+1 .. hi]
final double x = arr[lo];
arr[lo] = arr[j];
arr[j] = x;
return j;
}
}
| 2,704 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/thetacommon/BoundsOnRatiosInTupleSketchedSets.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.thetacommon;
import static org.apache.datasketches.common.Util.LONG_MAX_VALUE_AS_DOUBLE;
import org.apache.datasketches.common.BoundsOnRatiosInSampledSets;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.tuple.Sketch;
import org.apache.datasketches.tuple.Summary;
/**
* This class is used to compute the bounds on the estimate of the ratio <i>B / A</i>, where:
* <ul>
* <li><i>A</i> is a Tuple Sketch of population <i>PopA</i>.</li>
* <li><i>B</i> is a Tuple or Theta Sketch of population <i>PopB</i> that is a subset of <i>A</i>,
* obtained by an intersection of <i>A</i> with some other Tuple or Theta Sketch <i>C</i>,
* which acts like a predicate or selection clause.</li>
* <li>The estimate of the ratio <i>PopB/PopA</i> is
* BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA(<i>A, B</i>).</li>
* <li>The Upper Bound estimate on the ratio PopB/PopA is
* BoundsOnRatiosInThetaSketchedSets.getUpperBoundForBoverA(<i>A, B</i>).</li>
* <li>The Lower Bound estimate on the ratio PopB/PopA is
* BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA(<i>A, B</i>).</li>
* </ul>
* Note: The theta of <i>A</i> cannot be greater than the theta of <i>B</i>.
* If <i>B</i> is formed as an intersection of <i>A</i> and some other set <i>C</i>,
* then the theta of <i>B</i> is guaranteed to be less than or equal to the theta of <i>B</i>.
*
* @author Kevin Lang
* @author Lee Rhodes
* @author David Cromberge
*/
public final class BoundsOnRatiosInTupleSketchedSets {
private BoundsOnRatiosInTupleSketchedSets() {}
/**
* Gets the approximate lower bound for B over A based on a 95% confidence interval
* @param sketchA the Tuple sketch A with summary type <i>S</i>
* @param sketchB the Tuple sketch B with summary type <i>S</i>
* @param <S> Summary
* @return the approximate lower bound for B over A
*/
public static <S extends Summary> double getLowerBoundForBoverA(
final Sketch<S> sketchA,
final Sketch<S> sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries();
final int countA = thetaLongB == thetaLongA
? sketchA.getRetainedEntries()
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 0; }
final double f = thetaLongB / LONG_MAX_VALUE_AS_DOUBLE;
return BoundsOnRatiosInSampledSets.getLowerBoundForBoverA(countA, countB, f);
}
/**
* Gets the approximate lower bound for B over A based on a 95% confidence interval
* @param sketchA the Tuple sketch A with summary type <i>S</i>
* @param sketchB the Theta sketch B
* @param <S> Summary
* @return the approximate lower bound for B over A
*/
public static <S extends Summary> double getLowerBoundForBoverA(
final Sketch<S> sketchA,
final org.apache.datasketches.theta.Sketch sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries();
final int countA = thetaLongB == thetaLongA
? sketchA.getRetainedEntries()
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 0; }
final double f = thetaLongB / LONG_MAX_VALUE_AS_DOUBLE;
return BoundsOnRatiosInSampledSets.getLowerBoundForBoverA(countA, countB, f);
}
/**
* Gets the approximate upper bound for B over A based on a 95% confidence interval
* @param sketchA the Tuple sketch A with summary type <i>S</i>
* @param sketchB the Tuple sketch B with summary type <i>S</i>
* @param <S> Summary
* @return the approximate upper bound for B over A
*/
public static <S extends Summary> double getUpperBoundForBoverA(
final Sketch<S> sketchA,
final Sketch<S> sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries();
final int countA = thetaLongB == thetaLongA
? sketchA.getRetainedEntries()
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 1.0; }
final double f = thetaLongB / LONG_MAX_VALUE_AS_DOUBLE;
return BoundsOnRatiosInSampledSets.getUpperBoundForBoverA(countA, countB, f);
}
/**
* Gets the approximate upper bound for B over A based on a 95% confidence interval
* @param sketchA the Tuple sketch A with summary type <i>S</i>
* @param sketchB the Theta sketch B
* @param <S> Summary
* @return the approximate upper bound for B over A
*/
public static <S extends Summary> double getUpperBoundForBoverA(
final Sketch<S> sketchA,
final org.apache.datasketches.theta.Sketch sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries(true);
final int countA = thetaLongB == thetaLongA
? sketchA.getRetainedEntries()
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 1.0; }
final double f = thetaLongB / LONG_MAX_VALUE_AS_DOUBLE;
return BoundsOnRatiosInSampledSets.getUpperBoundForBoverA(countA, countB, f);
}
/**
* Gets the estimate for B over A
* @param sketchA the Tuple sketch A with summary type <i>S</i>
* @param sketchB the Tuple sketch B with summary type <i>S</i>
* @param <S> Summary
* @return the estimate for B over A
*/
public static <S extends Summary> double getEstimateOfBoverA(
final Sketch<S> sketchA,
final Sketch<S> sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries();
final int countA = thetaLongB == thetaLongA
? sketchA.getRetainedEntries()
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 0.5; }
return (double) countB / (double) countA;
}
/**
* Gets the estimate for B over A
* @param sketchA the Tuple sketch A with summary type <i>S</i>
* @param sketchB the Theta sketch B
* @param <S> Summary
* @return the estimate for B over A
*/
public static <S extends Summary> double getEstimateOfBoverA(
final Sketch<S> sketchA,
final org.apache.datasketches.theta.Sketch sketchB) {
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
checkThetas(thetaLongA, thetaLongB);
final int countB = sketchB.getRetainedEntries(true);
final int countA = thetaLongB == thetaLongA
? sketchA.getRetainedEntries()
: sketchA.getCountLessThanThetaLong(thetaLongB);
if (countA <= 0) { return 0.5; }
return (double) countB / (double) countA;
}
static void checkThetas(final long thetaLongA, final long thetaLongB) {
if (thetaLongB > thetaLongA) {
throw new SketchesArgumentException("ThetaLongB cannot be > ThetaLongA.");
}
}
}
| 2,705 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/thetacommon/HashOperations.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.thetacommon;
import static java.lang.Math.max;
import static org.apache.datasketches.common.Util.ceilingIntPowerOf2;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesStateException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
/**
* Helper class for the common hash table methods.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
public final class HashOperations {
private static final int STRIDE_HASH_BITS = 7;
private static final int EMPTY = 0;
/**
* The stride mask for the Open Address, Double Hashing (OADH) hash table algorithm.
*/
public static final int STRIDE_MASK = (1 << STRIDE_HASH_BITS) - 1;
private HashOperations() {}
//Make odd and independent of index assuming lgArrLongs lowest bits of the hash were used for
// index. This results in a 8 bit value that is always odd.
private static int getStride(final long hash, final int lgArrLongs) {
return (2 * (int) ((hash >>> lgArrLongs) & STRIDE_MASK) ) + 1;
}
//ON-HEAP
/**
* This is a classical Knuth-style Open Addressing, Double Hash (OADH) search scheme for on-heap.
* Returns the index if found, -1 if not found.
*
* @param hashTable The hash table to search. Its size must be a power of 2.
* @param lgArrLongs The log_base2(hashTable.length).
* <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @param hash The hash value to search for. It must not be zero.
* @return Current probe index if found, -1 if not found.
*/
public static int hashSearch(final long[] hashTable, final int lgArrLongs, final long hash) {
if (hash == 0) {
throw new SketchesArgumentException("Given hash must not be zero: " + hash);
}
final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1
final int stride = getStride(hash, lgArrLongs);
int curProbe = (int) (hash & arrayMask);
// search for duplicate or empty slot
final int loopIndex = curProbe;
do {
final long arrVal = hashTable[curProbe];
if (arrVal == EMPTY) {
return -1; // not found
} else if (arrVal == hash) {
return curProbe; // found
}
curProbe = (curProbe + stride) & arrayMask;
} while (curProbe != loopIndex);
return -1;
}
/**
* This is a classical Knuth-style Open Addressing, Double Hash (OADH) insert scheme for on-heap.
* This method assumes that the input hash is not a duplicate.
* Useful for rebuilding tables to avoid unnecessary comparisons.
* Returns the index of insertion, which is always positive or zero.
* Throws an exception if the table has no empty slot.
*
* @param hashTable the hash table to insert into. Its size must be a power of 2.
* @param lgArrLongs The log_base2(hashTable.length).
* <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @param hash The hash value to be potentially inserted into an empty slot. It must not be zero.
* @return index of insertion. Always positive or zero.
*/
public static int hashInsertOnly(final long[] hashTable, final int lgArrLongs, final long hash) {
final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1
final int stride = getStride(hash, lgArrLongs);
int curProbe = (int) (hash & arrayMask);
final long loopIndex = curProbe;
do {
final long arrVal = hashTable[curProbe];
if (arrVal == EMPTY) {
hashTable[curProbe] = hash;
return curProbe;
}
curProbe = (curProbe + stride) & arrayMask;
} while (curProbe != loopIndex);
throw new SketchesArgumentException("No empty slot in table!");
}
/**
* This is a classical Knuth-style Open Addressing, Double Hash (OADH) insert scheme for on-heap.
* Returns index ≥ 0 if found (duplicate); < 0 if inserted, inserted at -(index + 1).
* Throws an exception if the value is not found and table has no empty slot.
*
* @param hashTable The hash table to insert into. Its size must be a power of 2.
* @param lgArrLongs The log_base2(hashTable.length).
* <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @param hash The hash value to be potentially inserted into an empty slot only if it is not
* a duplicate of any other hash value in the table. It must not be zero.
* @return index ≥ 0 if found (duplicate); < 0 if inserted, inserted at -(index + 1).
*/
public static int hashSearchOrInsert(final long[] hashTable, final int lgArrLongs,
final long hash) {
final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1
final int stride = getStride(hash, lgArrLongs);
int curProbe = (int) (hash & arrayMask);
// search for duplicate or zero
final int loopIndex = curProbe;
do {
final long arrVal = hashTable[curProbe];
if (arrVal == EMPTY) {
hashTable[curProbe] = hash; // insert value
return ~curProbe;
} else if (arrVal == hash) {
return curProbe; // found a duplicate
}
curProbe = (curProbe + stride) & arrayMask;
} while (curProbe != loopIndex);
throw new SketchesArgumentException("Hash not found and no empty slots!");
}
/**
* Inserts the given long array into the given OADH hashTable of the target size,
* ignores duplicates and counts the values inserted.
* The hash values must not be negative, zero values and values ≥ thetaLong are ignored.
* The given hash table may have values, but they must have been inserted by this method or one
* of the other OADH insert methods in this class.
* This method performs additional checks against potentially invalid hash values or theta values.
* Returns the count of values actually inserted.
*
* @param srcArr the source hash array to be potentially inserted
* @param hashTable The hash table to insert into. Its size must be a power of 2.
* @param lgArrLongs The log_base2(hashTable.length).
* <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @param thetaLong The theta value that all input hash values are compared against.
* It must greater than zero.
* <a href="{@docRoot}/resources/dictionary.html#thetaLong">See Theta Long</a>
* @return the count of values actually inserted
*/
public static int hashArrayInsert(final long[] srcArr, final long[] hashTable,
final int lgArrLongs, final long thetaLong) {
int count = 0;
final int arrLen = srcArr.length;
checkThetaCorruption(thetaLong);
for (int i = 0; i < arrLen; i++ ) { // scan source array, build target array
final long hash = srcArr[i];
checkHashCorruption(hash);
if (continueCondition(thetaLong, hash) ) {
continue;
}
if (hashSearchOrInsert(hashTable, lgArrLongs, hash) < 0) {
count++ ;
}
}
return count;
}
//With Memory or WritableMemory
/**
* This is a classical Knuth-style Open Addressing, Double Hash (OADH) search scheme for Memory.
* Returns the index if found, -1 if not found.
*
* @param mem The <i>Memory</i> containing the hash table to search.
* The hash table portion must be a power of 2 in size.
* @param lgArrLongs The log_base2(hashTable.length).
* <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @param hash The hash value to search for. Must not be zero.
* @param memOffsetBytes offset in the memory where the hashTable starts
* @return Current probe index if found, -1 if not found.
*/
public static int hashSearchMemory(final Memory mem, final int lgArrLongs, final long hash,
final int memOffsetBytes) {
if (hash == 0) {
throw new SketchesArgumentException("Given hash must not be zero: " + hash);
}
final int arrayMask = (1 << lgArrLongs) - 1;
final int stride = getStride(hash, lgArrLongs);
int curProbe = (int) (hash & arrayMask);
final int loopIndex = curProbe;
do {
final int curProbeOffsetBytes = (curProbe << 3) + memOffsetBytes;
final long curArrayHash = mem.getLong(curProbeOffsetBytes);
if (curArrayHash == EMPTY) { return -1; }
else if (curArrayHash == hash) { return curProbe; }
curProbe = (curProbe + stride) & arrayMask;
} while (curProbe != loopIndex);
return -1;
}
/**
* This is a classical Knuth-style Open Addressing, Double Hash (OADH) insert scheme for Memory.
* This method assumes that the input hash is not a duplicate.
* Useful for rebuilding tables to avoid unnecessary comparisons.
* Returns the index of insertion, which is always positive or zero.
* Throws an exception if table has no empty slot.
*
* @param wmem The <i>WritableMemory</i> that contains the hashTable to insert into.
* The size of the hashTable portion must be a power of 2.
* @param lgArrLongs The log_base2(hashTable.length.
* <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @param hash value that must not be zero and will be inserted into the array into an empty slot.
* @param memOffsetBytes offset in the <i>WritableMemory</i> where the hashTable starts
* @return index of insertion. Always positive or zero.
*/
public static int hashInsertOnlyMemory(final WritableMemory wmem, final int lgArrLongs,
final long hash, final int memOffsetBytes) {
final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1
final int stride = getStride(hash, lgArrLongs);
int curProbe = (int) (hash & arrayMask);
// search for duplicate or zero
final int loopIndex = curProbe;
do {
final int curProbeOffsetBytes = (curProbe << 3) + memOffsetBytes;
final long curArrayHash = wmem.getLong(curProbeOffsetBytes);
if (curArrayHash == EMPTY) {
wmem.putLong(curProbeOffsetBytes, hash);
return curProbe;
}
curProbe = (curProbe + stride) & arrayMask;
} while (curProbe != loopIndex);
throw new SketchesArgumentException("No empty slot in table!");
}
/**
* This is a classical Knuth-style Open Addressing, Double Hash insert scheme, but inserts
* values directly into a Memory.
* Returns index ≥ 0 if found (duplicate); < 0 if inserted, inserted at -(index + 1).
* Throws an exception if the value is not found and table has no empty slot.
*
* @param wmem The <i>WritableMemory</i> that contains the hashTable to insert into.
* @param lgArrLongs The log_base2(hashTable.length).
* <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @param hash The hash value to be potentially inserted into an empty slot only if it is not
* a duplicate of any other hash value in the table. It must not be zero.
* @param memOffsetBytes offset in the <i>WritableMemory</i> where the hash array starts
* @return index ≥ 0 if found (duplicate); < 0 if inserted, inserted at -(index + 1).
*/
public static int hashSearchOrInsertMemory(final WritableMemory wmem, final int lgArrLongs,
final long hash, final int memOffsetBytes) {
final int arrayMask = (1 << lgArrLongs) - 1; // current Size -1
final int stride = getStride(hash, lgArrLongs);
int curProbe = (int) (hash & arrayMask);
// search for duplicate or zero
final int loopIndex = curProbe;
do {
final int curProbeOffsetBytes = (curProbe << 3) + memOffsetBytes;
final long curArrayHash = wmem.getLong(curProbeOffsetBytes);
if (curArrayHash == EMPTY) {
wmem.putLong(curProbeOffsetBytes, hash);
return ~curProbe;
} else if (curArrayHash == hash) { return curProbe; } // curArrayHash is a duplicate
// curArrayHash is not a duplicate and not zero, continue searching
curProbe = (curProbe + stride) & arrayMask;
} while (curProbe != loopIndex);
throw new SketchesArgumentException("Key not found and no empty slot in table!");
}
//Other related methods
/**
* @param thetaLong must be greater than zero otherwise throws an exception.
* <a href="{@docRoot}/resources/dictionary.html#thetaLong">See Theta Long</a>
*/
public static void checkThetaCorruption(final long thetaLong) {
//if any one of the groups go negative it fails.
if (( thetaLong | (thetaLong - 1) ) < 0L ) {
throw new SketchesStateException(
"Data Corruption: thetaLong was negative or zero: " + "ThetaLong: " + thetaLong);
}
}
/**
* @param hash must be greater than -1 otherwise throws an exception.
* Note a hash of zero is normally ignored, but a negative hash is never allowed.
*/
public static void checkHashCorruption(final long hash) {
if ( hash < 0L ) {
throw new SketchesArgumentException(
"Data Corruption: hash was negative: " + "Hash: " + hash);
}
}
/**
* Return true (continue) if hash is greater than or equal to thetaLong, or if hash == 0,
* or if hash == Long.MAX_VALUE.
* @param thetaLong must be greater than the hash value
* <a href="{@docRoot}/resources/dictionary.html#thetaLong">See Theta Long</a>
* @param hash must be less than thetaLong and not less than or equal to zero.
* @return true (continue) if hash is greater than or equal to thetaLong, or if hash == 0,
* or if hash == Long.MAX_VALUE.
*/
public static boolean continueCondition(final long thetaLong, final long hash) {
//if any one of the groups go negative it returns true
return (( (hash - 1L) | (thetaLong - hash - 1L)) < 0L );
}
/**
* Converts the given array to a hash table.
* @param hashArr The given array of hashes. Gaps are OK.
* @param count The number of valid hashes in the array
* @param thetaLong Any hashes equal to or greater than thetaLong will be ignored
* @param rebuildThreshold The fill fraction for the hash table forcing a rebuild or resize.
* @return a HashTable
*/
public static long[] convertToHashTable(
final long[] hashArr,
final int count,
final long thetaLong,
final double rebuildThreshold) {
final int lgArrLongs = minLgHashTableSize(count, rebuildThreshold);
final int arrLongs = 1 << lgArrLongs;
final long[] hashTable = new long[arrLongs];
hashArrayInsert(hashArr, hashTable, lgArrLongs, thetaLong);
return hashTable;
}
/**
* Returns the smallest log hash table size given the count of items and the rebuild threshold.
* @param count the given count of items
* @param rebuild_threshold the rebuild threshold as a fraction between zero and one.
* @return the smallest log hash table size
*/
public static int minLgHashTableSize(final int count, final double rebuild_threshold) {
final int upperCount = (int) Math.ceil(count / rebuild_threshold);
final int arrLongs = max(ceilingIntPowerOf2(upperCount), 1 << ThetaUtil.MIN_LG_ARR_LONGS);
final int newLgArrLongs = Integer.numberOfTrailingZeros(arrLongs);
return newLgArrLongs;
}
/**
* Counts the cardinality of the first Log2 values of the given source array.
* @param srcArr the given source array
* @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>
* @param thetaLong <a href="{@docRoot}/resources/dictionary.html#thetaLong">See Theta Long</a>
* @return the cardinality
*/
public static int countPart(final long[] srcArr, final int lgArrLongs, final long thetaLong) {
int cnt = 0;
final int len = 1 << lgArrLongs;
for (int i = len; i-- > 0;) {
final long hash = srcArr[i];
if (continueCondition(thetaLong, hash) ) {
continue;
}
cnt++ ;
}
return cnt;
}
/**
* Counts the cardinality of the given source array.
* @param srcArr the given source array
* @param thetaLong <a href="{@docRoot}/resources/dictionary.html#thetaLong">See Theta Long</a>
* @return the cardinality
*/
public static int count(final long[] srcArr, final long thetaLong) {
int cnt = 0;
final int len = srcArr.length;
for (int i = len; i-- > 0;) {
final long hash = srcArr[i];
if (continueCondition(thetaLong, hash) ) {
continue;
}
cnt++ ;
}
return cnt;
}
}
| 2,706 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/thetacommon/package-info.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* This package contains common tools and methods for the <i>theta</i>,
* <i>tuple</i>, <i>tuple/*</i> and <i>fdt</i> packages.
*/
package org.apache.datasketches.thetacommon;
| 2,707 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesSketchIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* The quantiles sketch iterator for primitive type double.
* @see QuantilesSketchIterator
* @author Lee Rhodes
*/
public interface QuantilesDoublesSketchIterator extends QuantilesSketchIterator {
/**
* Gets the double quantile at the current index.
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @return the double quantile at the current index.
*/
double getQuantile();
}
| 2,708 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesAPI.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* <p>This is a stochastic streaming sketch that enables near-real time analysis of the
* approximate distribution of items from a very large stream in a single pass, requiring only
* that the items are comparable.
* The analysis is obtained using the <i>getQuantile()</i> function or the
* inverse functions getRank(), getPMF() (the Probability Mass Function), and getCDF()
* (the Cumulative Distribution Function).</p>
*
* <p>Given an input stream of <i>N</i> items, the <i>natural rank</i> of any specific
* item is defined as its index <i>(1 to N)</i> in the hypothetical sorted stream of all
* <i>N</i> input items.</p>
*
* <p>The <i>normalized rank</i> (<i>rank</i>) of any specific item is defined as its
* <i>natural rank</i> divided by <i>N</i>, which is a number in the interval [0.0, 1.0].
* In the Javadocs for all the quantile sketches <i>natural rank</i> is seldom used
* so any reference to just <i>rank</i> should be interpreted as <i>normalized rank</i>.</p>
*
* <p>Inputs into a quantile sketch are called "items" that can be either generic or specific
* primitives, like <i>float</i> or <i>double</i> depending on the sketch implementation.
* In order to keep its size small, sketches don't retain all the items offered and retain only
* a small fraction of all the items, thus purging most of the items. The items retained are
* then sorted and associated with a rank. At this point we call the retained items <i>quantiles</i>.
* Thus, all quantiles are items, but only a few items become quantiles. Depending on the context
* the two terms can be interchangeable.</p>
*
* <p>All quantile sketches are configured with a parameter <i>k</i>, which affects the size of
* the sketch and its estimation error.</p>
*
* <p>In the research literature, the estimation error is commonly called <i>epsilon</i>
* (or <i>eps</i>) and is a fraction between zero and one.
* Larger sizes of <i>k</i> result in a smaller epsilon, but also a larger sketch.
* The epsilon error is always with respect to the rank domain. Estimating the confidence interval
* in the quantile domain can be done by first computing the error in the rank domain and then
* translating that to the quantile domain. The sketch provides methods to assist with that.</p>
*
* <p>The relationship between the normalized rank and the corresponding quantiles can be viewed
* as a two dimensional monotonic plot with the normalized rank on one axis and the
* corresponding quantiles on the other axis. Let <i>q := quantile</i> and <i>r := rank</i> then both
* <i>q = getQuantile(r)</i> and <i>r = getRank(q)</i> are monotonically increasing functions.
* If the y-axis is used for the rank domain and the x-axis for the quantile domain,
* then <i>y = getRank(x)</i> is also the single point Cumulative Distribution Function (CDF).</p>
*
* <p>The functions <i>getQuantile()</i> translate ranks into corresponding quantiles.
* The functions <i>getRank(), getCDF(), and getPMF() (Probability Mass Function)</i>
* perform the opposite operation and translate quantiles into ranks (or cumulative probabilities,
* or probability masses, depending on the context).</p>
*
* <p>As an example, consider a large stream of one million items such as packet sizes coming into a network node.
* The absolute rank of any specific item size is simply its index in the hypothetical sorted
* array of such items.
* The normalized rank is the natural rank divided by the stream size, or <i>N</i>,
* in this case one million.
* The quantile corresponding to the normalized rank of 0.5 represents the 50th percentile or median
* of the distribution, obtained from getQuantile(0.5). Similarly, the 95th percentile is obtained from
* getQuantile(0.95).</p>
*
* <p>From the min and max quantiles, for example, say 1 and 1000 bytes,
* you can obtain the PMF from getPMF(100, 500, 900) that will result in an array of
* 4 probability masses such as {.4, .3, .2, .1}, which means that
* <ul>
* <li>40% of the mass was < 100,</li>
* <li>30% of the mass was ≥ 100 and < 500,</li>
* <li>20% of the mass was ≥ 500 and < 900, and</li>
* <li>10% of the mass was ≥ 900.</li>
* </ul>
* A frequency histogram can be obtained by simply multiplying these probability masses by getN(),
* which is the total count of items received.
* The <i>getCDF()</i> works similarly, but produces the cumulative distribution instead.
*
* <p>The accuracy of this sketch is a function of the configured <i>k</i>, which also affects
* the overall size of the sketch. Accuracy of this quantile sketch is always with respect to
* the normalized rank.
*
* <p>The <i>getPMF()</i> function has about 13 to 47% worse rank error (depending
* on <i>k</i>) than the other queries because the mass of each "bin" of the PMF has
* "double-sided" error from the upper and lower edges of the bin as a result of a subtraction
* of random variables where the errors from the two edges can sometimes add.</p>
*
* <p>A <i>getQuantile(rank)</i> query has the following probabilistic guarantees:</p>
* <ul>
* <li>Let <i>q = getQuantile(r)</i> where <i>r</i> is the rank between zero and one.</li>
* <li>The quantile <i>q</i> will be a quantile from the input stream.</li>
* <li>Let <i>trueRank</i> be the true rank of <i>q</i> derived from the hypothetical sorted
* stream of all <i>N</i> quantiles.</li>
* <li>Let <i>eps = getNormalizedRankError(false)</i>[*].</li>
* <li>Then <i>r - eps ≤ trueRank ≤ r + eps</i>.
* Note that the error is on the rank, not the quantile.</li>
* </ul>
*
* <p>A <i>getRank(quantile)</i> query has the following probabilistic guarantees:</p>
* <ul>
* <li>Let <i>r = getRank(q)</i> where <i>q</i> is a quantile between the min and max quantiles of
* the input stream.</li>
* <li>Let <i>trueRank</i> be the true rank of <i>q</i> derived from the hypothetical sorted
* stream of all <i>N</i> quantiles.</li>
* <li>Let <i>eps = getNormalizedRankError(false)</i>[*].</li>
* <li>Then <i>r - eps ≤ trueRank ≤ r + eps</i>.</li>
* </ul>
*
* <p>A <i>getPMF()</i> query has the following probabilistic guarantees:</p>
* <ul>
* <li>Let <i>{r<sub>1</sub>, r<sub>2</sub>, ..., r<sub>m+1</sub>}
* = getPMF(v<sub>1</sub>, v<sub>2</sub>, ..., v<sub>m</sub>)</i> where
* <i>q<sub>1</sub>, q<sub>2</sub>, ..., q<sub>m</sub></i> are monotonically increasing quantiles
* supplied by the user that are part of the monotonic sequence
* <i>q<sub>0</sub> = min, q<sub>1</sub>, q<sub>2</sub>, ..., q<sub>m</sub>, q<sub>m+1</sub> = max</i>,
* and where <i>min</i> and <i>max</i> are the actual minimum and maximum quantiles of the input
* stream automatically included in the sequence by the <i>getPMF(...)</i> function.
*
* <li>Let <i>r<sub>i</sub> = mass<sub>i</sub></i> = estimated mass between
* <i>v<sub>i-1</sub></i> and <i>q<sub>i</sub></i> where <i>q<sub>0</sub> = min</i>
* and <i>q<sub>m+1</sub> = max</i>.</li>
*
* <li>Let <i>trueMass</i> be the true mass between the quantiles of <i>q<sub>i</sub>,
* q<sub>i+1</sub></i> derived from the hypothetical sorted stream of all <i>N</i> quantiles.</li>
* <li>Let <i>eps = getNormalizedRankError(true)</i>[*].</li>
* <li>Then <i>mass - eps ≤ trueMass ≤ mass + eps</i>.</li>
* <li><i>r<sub>1</sub></i> includes the mass of all points between <i>min = q<sub>0</sub></i> and
* <i>q<sub>1</sub></i>.</li>
* <li><i>r<sub>m+1</sub></i> includes the mass of all points between <i>q<sub>m</sub></i> and
* <i>max = q<sub>m+1</sub></i>.</li>
* </ul>
*
* <p>A <i>getCDF(...)</i> query has the following probabilistic guarantees:</p>
* <ul>
* <li>Let <i>{r<sub>1</sub>, r<sub>2</sub>, ..., r<sub>m+1</sub>}
* = getCDF(q<sub>1</sub>, q<sub>2</sub>, ..., q<sub>m</sub>)</i> where
* <i>q<sub>1</sub>, q<sub>2</sub>, ..., q<sub>m</sub>)</i> are monotonically increasing quantiles
* supplied by the user that are part of the monotonic sequence
* <i>{q<sub>0</sub> = min, q<sub>1</sub>, q<sub>2</sub>, ..., q<sub>m</sub>, q<sub>m+1</sub> = max}</i>,
* and where <i>min</i> and <i>max</i> are the actual minimum and maximum quantiles of the input
* stream automatically included in the sequence by the <i>getCDF(...)</i> function.
*
* <li>Let <i>r<sub>i</sub> = mass<sub>i</sub></i> = estimated mass between
* <i>q<sub>0</sub> = min</i> and <i>q<sub>i</sub></i>.</li>
*
* <li>Let <i>trueMass</i> be the true mass between the true ranks of <i>q<sub>i</sub>,
* q<sub>i+1</sub></i> derived from the hypothetical sorted stream of all <i>N</i> quantiles.</li>
* <li>Let <i>eps = getNormalizedRankError(true)</i>[*].</li>
* <li>then <i>mass - eps ≤ trueMass ≤ mass + eps</i>.</li>
* <li><i>r<sub>1</sub></i> includes the mass of all points between <i>min = q<sub>0</sub></i> and
* <i>q<sub>1</sub></i>.</li>
* <li><i>r<sub>m+1</sub></i> includes the mass of all points between <i>min = q<sub>0</sub></i> and
* <i>max = q<sub>m+1</sub></i>.</li>
* </ul>
*
* <p>Because errors are independent, we can make some estimates of the size of the confidence bounds
* for the <em>quantile</em> returned from a call to <em>getQuantile()</em>, but not error bounds.
* These confidence bounds may be quite large for certain distributions.</p>
*
* <ul>
* <li>Let <i>q = getQuantile(r)</i>, the estimated quantile of rank <i>r</i>.</li>
* <li>Let <i>eps = getNormalizedRankError(false)</i>[*].</li>
* <li>Let <i>q<sub>lo</sub></i> = estimated quantile of rank <i>(r - eps)</i>.</li>
* <li>Let <i>q<sub>hi</sub></i> = estimated quantile of rank <i>(r + eps)</i>.</li>
* <li>Then <i>q<sub>lo</sub> ≤ q ≤ q<sub>hi</sub></i>.</li>
* </ul>
*
* <p>This sketch is order and distribution insensitive</p>
*
* <p>This algorithm intentionally inserts randomness into the sampling process for items that
* ultimately get retained in the sketch. Thus, the results produced by this algorithm are not
* deterministic. For example, if the same stream is inserted into two different instances of this
* sketch, the answers obtained from the two sketches should be close, but may not be be identical.</p>
*
* <p>Similarly, there may be directional inconsistencies. For example, if a quantile obtained
* from getQuantile(rank) is input into the reverse query
* getRank(quantile), the resulting rank should be close, but may not exactly equal the original rank.</p>
*
* <p>Please visit our website: <a href="https://datasketches.apache.org">DataSketches Home Page</a>
* and specific Javadocs for more information.</p>
*
* <p>[*] Note that obtaining epsilon may require using a similar function but with more parameters
* based on the specific sketch implementation.</p>
*
* @see <a href="https://datasketches.apache.org/docs/Quantiles/SketchingQuantilesAndRanksTutorial.html">
* Sketching Quantiles and Ranks, Tutorial</a>
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*
* @author Lee Rhodes
* @author Kevin Lang
* @author Alexander Saydakov
*/
public interface QuantilesAPI {
String EMPTY_MSG = "The sketch must not be empty for this operation. ";
String UNSUPPORTED_MSG = "Unsupported operation for this Sketch Type. ";
String NOT_SINGLE_ITEM_MSG = "Sketch does not have just one item. ";
String MEM_REQ_SVR_NULL_MSG = "MemoryRequestServer must not be null. ";
String TGT_IS_READ_ONLY_MSG = "Target sketch is Read Only, cannot write. ";
/**
* Gets the user configured parameter k, which controls the accuracy of the sketch
* and its memory space usage.
* @return the user configured parameter k, which controls the accuracy of the sketch
* and its memory space usage.
*/
int getK();
/**
* Gets the length of the input stream.
* @return the length of the input stream.
*/
long getN();
/**
* Gets the number of quantiles retained by the sketch.
* @return the number of quantiles retained by the sketch
*/
int getNumRetained();
/**
* Gets the lower bound of the rank confidence interval in which the true rank of the
* given rank exists.
* @param rank the given normalized rank.
* @return the lower bound of the rank confidence interval in which the true rank of the
* given rank exists.
*/
double getRankLowerBound(double rank);
/**
* Gets the upper bound of the rank confidence interval in which the true rank of the
* given rank exists.
* @param rank the given normalized rank.
* @return the upper bound of the rank confidence interval in which the true rank of the
* given rank exists.
*/
double getRankUpperBound(double rank);
/**
* Returns true if this sketch's data structure is backed by Memory or WritableMemory.
* @return true if this sketch's data structure is backed by Memory or WritableMemory.
*/
boolean hasMemory();
/**
* Returns true if this sketch's data structure is off-heap (a.k.a., Direct or Native memory).
* @return true if this sketch's data structure is off-heap (a.k.a., Direct or Native memory).
*/
boolean isDirect();
/**
* Returns true if this sketch is empty.
* @return true if this sketch is empty.
*/
boolean isEmpty();
/**
* Returns true if this sketch is in estimation mode.
* @return true if this sketch is in estimation mode.
*/
boolean isEstimationMode();
/**
* Returns true if this sketch is read only.
* @return true if this sketch is read only.
*/
boolean isReadOnly();
/**
* Resets this sketch to the empty state.
* If the sketch is <i>read only</i> this does nothing.
*
* <p>The parameter <i>k</i> will not change.</p>
*/
void reset();
/**
* Returns a summary of the key parameters of the sketch.
* @return a summary of the key parameters of the sketch.
*/
@Override
String toString();
}
| 2,709 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/DoublesSortedView.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* The Sorted View for quantiles of primitive type double.
* @see SortedView
* @author Alexander Saydakov
* @author Lee Rhodes
*/
public interface DoublesSortedView extends SortedView {
/**
* Returns an approximation to the Cumulative Distribution Function (CDF) of the input stream
* as a monotonically increasing array of double ranks (or cumulative probabilities) on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(false) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> overlapping intervals.
*
* <p>The start of each interval is below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and the end of the interval
* is the rank or cumulative probability corresponding to the split point.</p>
*
* <p>The <i>(m+1)th</i> interval represents 100% of the distribution represented by the sketch
* and consistent with the definition of a cumulative probability distribution, thus the <i>(m+1)th</i>
* rank or probability in the returned array is always 1.0.</p>
*
* <p>If a split point exactly equals a retained item of the sketch and the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, the resulting cumulative probability will include that item.</li>
* <li>EXCLUSIVE, the resulting cumulative probability will not include the weight of that split point.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getCDF(double[] splitPoints, QuantileSearchCriteria searchCrit) {
QuantilesUtil.checkDoublesSplitPointsOrder(splitPoints);
final int len = splitPoints.length + 1;
final double[] buckets = new double[len];
for (int i = 0; i < len - 1; i++) {
buckets[i] = getRank(splitPoints[i], searchCrit);
}
buckets[len - 1] = 1.0;
return buckets;
}
/**
* Returns an approximation to the Probability Mass Function (PMF) of the input stream
* as an array of probability masses as doubles on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(true) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> consecutive, non-overlapping intervals.
*
* <p>Each interval except for the end intervals starts with a split point and ends with the next split
* point in sequence.</p>
*
* <p>The first interval starts below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and ends with the first split point</p>
*
* <p>The last <i>(m+1)th</i> interval starts with the last split point and ends after the last
* item retained by the sketch corresponding to a rank or probability of 1.0. </p>
*
* <p>The sum of the probability masses of all <i>(m+1)</i> intervals is 1.0.</p>
*
* <p>If the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will include that item. If the lower split point equals an item retained by the sketch, the interval will exclude
* that item.</li>
* <li>EXCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will exclude that item. If the lower split point equals an item retained by the sketch, the interval will include
* that item.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getPMF(double[] splitPoints, QuantileSearchCriteria searchCrit) {
final double[] buckets = getCDF(splitPoints, searchCrit);
final int len = buckets.length;
for (int i = len; i-- > 1; ) {
buckets[i] -= buckets[i - 1];
}
return buckets;
}
/**
* Gets the approximate quantile of the given normalized rank and the given search criterion.
*
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @param searchCrit If INCLUSIVE, the given rank includes all quantiles ≤
* the quantile directly corresponding to the given rank.
* If EXCLUSIVE, he given rank includes all quantiles <
* the quantile directly corresponding to the given rank.
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double getQuantile(double rank, QuantileSearchCriteria searchCrit);
/**
* Returns the array of quantiles.
* @return the array of quantiles.
*/
double[] getQuantiles();
/**
* Gets the normalized rank corresponding to the given a quantile.
*
* @param quantile the given quantile
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
* @return the normalized rank corresponding to the given quantile.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double getRank(double quantile, QuantileSearchCriteria searchCrit);
@Override
DoublesSortedViewIterator iterator();
}
| 2,710 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/InequalitySearch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
import java.util.Objects;
import org.apache.datasketches.common.SketchesArgumentException;
/**
* This provides efficient, unique and unambiguous binary searching for inequality comparison criteria
* for ordered arrays of values that may include duplicate values. The inequality criteria include
* <, ≤, ==, ≥, >. All the inequality criteria use the same search algorithm.
* (Although == is not an inequality, it is included for convenience.)
*
* <p>In order to make the searching unique and unambiguous, we modified the traditional binary
* search algorithm to search for adjacent pairs of values <i>{A, B}</i> in the values array
* instead of just a single value, where <i>a</i> and <i>b</i> are the array indices of two
* adjacent values in the array. For all the search criteria, when the algorithm has narrowed the
* search down to a single value or adjacent pair of values, the <i>resolve()</i> method provides the
* final result of the search. If there is no valid value in the array that satisfies the search
* criterion, the algorithm will return -1 to the caller.</p>
*
* <p>Given a sorted array of values <i>arr[]</i> and a search key value <i>v</i>, the algorithms for
* the searching criteria are given with each enum criterion.</p>
*
* @see <a href="https://datasketches.apache.org/docs/Quantiles/SketchingQuantilesAndRanksTutorial.html">
* Sketching Quantiles and Ranks Tutorial</a>
* @author Lee Rhodes
*/
public enum InequalitySearch {
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>v</i>,
* this criterion instructs the binary search algorithm to find the highest adjacent pair of
* values <i>{A,B}</i> such that <i>A < v ≤ B</i>.<br>
* Let <i>low</i> = index of the lowest value in the range.<br>
* Let <i>high</i> = index of the highest value in the range.
*
* <p>If <i>v</i> > arr[high], return arr[high].<br>
* If <i>v</i> ≤ arr[low], return -1.<br>
* Else return index of A.</p>
*/
LT { //arr[A] < V <= arr[B], return A
@Override
int compare(final double[] arr, final int a, final int b, final double v) {
return v <= arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int compare(final float[] arr, final int a, final int b, final float v) {
return v <= arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int compare(final long[] arr, final int a, final int b, final long v) {
return v <= arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int getIndex(final double[] arr, final int a, final int b, final double v) {
return a;
}
@Override
int getIndex(final float[] arr, final int a, final int b, final float v) {
return a;
}
@Override
int getIndex(final long[] arr, final int a, final int b, final long v) {
return a;
}
@Override
int resolve(final double[] arr, final int lo, final int hi, final double v) {
return (lo == hi)
? (v > arr[lo] ? lo : -1)
: v > arr[hi] ? hi : (v > arr[lo] ? lo : -1);
}
@Override
int resolve(final float[] arr, final int lo, final int hi, final float v) {
return (lo == hi)
? (v > arr[lo] ? lo : -1)
: v > arr[hi] ? hi : (v > arr[lo] ? lo : -1);
}
@Override
int resolve(final long[] arr, final int lo, final int hi, final long v) {
return (lo == hi)
? (v > arr[lo] ? lo : -1)
: v > arr[hi] ? hi : (v > arr[lo] ? lo : -1);
}
@Override
public String desc(final double[] arr, final int low, final int high, final double v, final int idx) {
if (idx == -1) {
return "LT: " + v + " <= arr[" + low + "]=" + arr[low] + "; return -1";
}
if (idx == high) {
return "LT: " + v + " > arr[" + high + "]=" + arr[high]
+ "; return arr[" + high + "]=" + arr[high];
} //idx < high
return "LT: " + v
+ ": arr[" + idx + "]=" + arr[idx] + " < " + v + " <= arr[" + (idx + 1) + "]=" + arr[idx + 1]
+ "; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final float[] arr, final int low, final int high, final float v, final int idx) {
if (idx == -1) {
return "LT: " + v + " <= arr[" + low + "]=" + arr[low] + "; return -1";
}
if (idx == high) {
return "LT: " + v + " > arr[" + high + "]=" + arr[high]
+ "; return arr[" + high + "]=" + arr[high];
} //idx < high
return "LT: " + v
+ ": arr[" + idx + "]=" + arr[idx] + " < " + v + " <= arr[" + (idx + 1) + "]=" + arr[idx + 1]
+ "; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final long[] arr, final int low, final int high, final long v, final int idx) {
if (idx == -1) {
return "LT: " + v + " <= arr[" + low + "]=" + arr[low] + "; return -1";
}
if (idx == high) {
return "LT: " + v + " > arr[" + high + "]=" + arr[high]
+ "; return arr[" + high + "]=" + arr[high];
} //idx < high
return "LT: " + v
+ ": arr[" + idx + "]=" + arr[idx] + " < " + v + " <= arr[" + (idx + 1) + "]=" + arr[idx + 1]
+ "; return arr[" + idx + "]=" + arr[idx];
}
},
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>V</i>,
* this criterion instructs the binary search algorithm to find the highest adjacent pair of
* values <i>{A,B}</i> such that <i>A ≤ V < B</i>.<br>
* Let <i>low</i> = index of the lowest value in the range.<br>
* Let <i>high</i> = index of the highest value in the range.
*
* <p>If <i>v</i> ≥ arr[high], return arr[high].<br>
* If <i>v</i> < arr[low], return -1.<br>
* Else return index of A.</p>
*/
LE { //arr[A] <= V < arr[B], return A
@Override
int compare(final double[] arr, final int a, final int b, final double v) {
return v < arr[a] ? -1 : arr[b] <= v ? 1 : 0;
}
@Override
int compare(final float[] arr, final int a, final int b, final float v) {
return v < arr[a] ? -1 : arr[b] <= v ? 1 : 0;
}
@Override
int compare(final long[] arr, final int a, final int b, final long v) {
return v < arr[a] ? -1 : arr[b] <= v ? 1 : 0;
}
@Override
int getIndex(final double[] arr, final int a, final int b, final double v) {
return a;
}
@Override
int getIndex(final float[] arr, final int a, final int b, final float v) {
return a;
}
@Override
int getIndex(final long[] arr, final int a, final int b, final long v) {
return a;
}
@Override
int resolve(final double[] arr, final int lo, final int hi, final double v) {
return (lo == hi)
? (v >= arr[lo] ? lo : -1)
: v >= arr[hi] ? hi : (v >= arr[lo] ? lo : -1);
}
@Override
int resolve(final float[] arr, final int lo, final int hi, final float v) {
return (lo == hi)
? (v >= arr[lo] ? lo : -1)
: v >= arr[hi] ? hi : (v >= arr[lo] ? lo : -1);
}
@Override
int resolve(final long[] arr, final int lo, final int hi, final long v) {
return (lo == hi)
? (v >= arr[lo] ? lo : -1)
: v >= arr[hi] ? hi : (v >= arr[lo] ? lo : -1);
}
@Override
public String desc(final double[] arr, final int low, final int high, final double v, final int idx) {
if (idx == -1) {
return "LE: " + v + " < arr[" + low + "]=" + arr[low] + "; return -1";
}
if (idx == high) {
return "LE: " + v + " >= arr[" + high + "]=" + arr[high]
+ "; return arr[" + high + "]=" + arr[high];
}
return "LE: " + v
+ ": arr[" + idx + "]=" + arr[idx] + " <= " + v + " < arr[" + (idx + 1) + "]=" + arr[idx + 1]
+ "; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final float[] arr, final int low, final int high, final float v, final int idx) {
if (idx == -1) {
return "LE: " + v + " < arr[" + low + "]=" + arr[low] + "; return -1";
}
if (idx == high) {
return "LE: " + v + " >= arr[" + high + "]=" + arr[high]
+ "; return arr[" + high + "]=" + arr[high];
}
return "LE: " + v
+ ": arr[" + idx + "]=" + arr[idx] + " <= " + v + " < arr[" + (idx + 1) + "]=" + arr[idx + 1]
+ "; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final long[] arr, final int low, final int high, final long v, final int idx) {
if (idx == -1) {
return "LE: " + v + " < arr[" + low + "]=" + arr[low] + "; return -1";
}
if (idx == high) {
return "LE: " + v + " >= arr[" + high + "]=" + arr[high]
+ "; return arr[" + high + "]=" + arr[high];
}
return "LE: " + v
+ ": arr[" + idx + "]=" + arr[idx] + " <= " + v + " < arr[" + (idx + 1) + "]=" + arr[idx + 1]
+ "; return arr[" + idx + "]=" + arr[idx];
}
},
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>V</i>,
* this criterion instructs the binary search algorithm to find the adjacent pair of
* values <i>{A,B}</i> such that <i>A ≤ V ≤ B</i>.
* The returned value from the binary search algorithm will be the index of <i>A</i> or <i>B</i>,
* if one of them is equal to <i>V</i>, or -1 if V is not equal to either one.
*/
EQ { //arr[A] <= V <= arr[B], return A or B
@Override
int compare(final double[] arr, final int a, final int b, final double v) {
return v < arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int compare(final float[] arr, final int a, final int b, final float v) {
return v < arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int compare(final long[] arr, final int a, final int b, final long v) {
return v < arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int getIndex(final double[] arr, final int a, final int b, final double v) {
return v == arr[a] ? a : v == arr[b] ? b : -1;
}
@Override
int getIndex(final float[] arr, final int a, final int b, final float v) {
return v == arr[a] ? a : v == arr[b] ? b : -1;
}
@Override
int getIndex(final long[] arr, final int a, final int b, final long v) {
return v == arr[a] ? a : v == arr[b] ? b : -1;
}
@Override
int resolve(final double[] arr, final int lo, final int hi, final double v) {
return (lo == hi)
? (v == arr[lo] ? lo : -1)
: v == arr[lo] ? lo : (v == arr[hi] ? hi : -1);
}
@Override
int resolve(final float[] arr, final int lo, final int hi, final float v) {
return (lo == hi)
? (v == arr[lo] ? lo : -1)
: v == arr[lo] ? lo : (v == arr[hi] ? hi : -1);
}
@Override
int resolve(final long[] arr, final int lo, final int hi, final long v) {
return (lo == hi)
? (v == arr[lo] ? lo : -1)
: v == arr[lo] ? lo : (v == arr[hi] ? hi : -1);
}
@Override
public String desc(final double[] arr, final int low, final int high, final double v, final int idx) {
if (idx == -1) {
if (v > arr[high]) {
return "EQ: " + v + " > arr[" + high + "]; return -1";
}
if (v < arr[low]) {
return "EQ: " + v + " < arr[" + low + "]; return -1";
}
return "EQ: " + v + " Cannot be found within arr[" + low + "], arr[" + high + "]; return -1";
}
return "EQ: " + v + " == arr[" + idx + "]; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final float[] arr, final int low, final int high, final float v, final int idx) {
if (idx == -1) {
if (v > arr[high]) {
return "EQ: " + v + " > arr[" + high + "]; return -1";
}
if (v < arr[low]) {
return "EQ: " + v + " < arr[" + low + "]; return -1";
}
return "EQ: " + v + " Cannot be found within arr[" + low + "], arr[" + high + "]; return -1";
}
return "EQ: " + v + " == arr[" + idx + "]; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final long[] arr, final int low, final int high, final long v, final int idx) {
if (idx == -1) {
if (v > arr[high]) {
return "EQ: " + v + " > arr[" + high + "]; return -1";
}
if (v < arr[low]) {
return "EQ: " + v + " < arr[" + low + "]; return -1";
}
return "EQ: " + v + " Cannot be found within arr[" + low + "], arr[" + high + "]; return -1";
}
return "EQ: " + v + " == arr[" + idx + "]; return arr[" + idx + "]=" + arr[idx];
}
},
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>V</i>,
* this criterion instructs the binary search algorithm to find the lowest adjacent pair of
* values <i>{A,B}</i> such that <i>A < V ≤ B</i>.<br>
* Let <i>low</i> = index of the lowest value in the range.<br>
* Let <i>high</i> = index of the highest value in the range.
*
* <p>If <i>v</i> ≤ arr[low], return arr[low].<br>
* If <i>v</i> > arr[high], return -1.<br>
* Else return index of B.</p>
*/
GE { //arr[A] < V <= arr[B], return B
@Override
int compare(final double[] arr, final int a, final int b, final double v) {
return v <= arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int compare(final float[] arr, final int a, final int b, final float v) {
return v <= arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int compare(final long[] arr, final int a, final int b, final long v) {
return v <= arr[a] ? -1 : arr[b] < v ? 1 : 0;
}
@Override
int getIndex(final double[] arr, final int a, final int b, final double v) {
return b;
}
@Override
int getIndex(final float[] arr, final int a, final int b, final float v) {
return b;
}
@Override
int getIndex(final long[] arr, final int a, final int b, final long v) {
return b;
}
@Override
int resolve(final double[] arr, final int lo, final int hi, final double v) {
return (lo == hi)
? (v <= arr[lo] ? lo : -1)
: v <= arr[lo] ? lo : (v <= arr[hi] ? hi : -1);
}
@Override
int resolve(final float[] arr, final int lo, final int hi, final float v) {
return (lo == hi)
? (v <= arr[lo] ? lo : -1)
: v <= arr[lo] ? lo : (v <= arr[hi] ? hi : -1);
}
@Override
int resolve(final long[] arr, final int lo, final int hi, final long v) {
return (lo == hi)
? (v <= arr[lo] ? lo : -1)
: v <= arr[lo] ? lo : (v <= arr[hi] ? hi : -1);
}
@Override
public String desc(final double[] arr, final int low, final int high, final double v, final int idx) {
if (idx == -1) {
return "GE: " + v + " > arr[" + high + "]=" + arr[high] + "; return -1";
}
if (idx == low) {
return "GE: " + v + " <= arr[" + low + "]=" + arr[low]
+ "; return arr[" + low + "]=" + arr[low];
} //idx > low
return "GE: " + v
+ ": arr[" + (idx - 1) + "]=" + arr[idx - 1] + " < " + v + " <= arr[" + idx + "]=" + arr[idx]
+ "; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final float[] arr, final int low, final int high, final float v, final int idx) {
if (idx == -1) {
return "GE: " + v + " > arr[" + high + "]=" + arr[high] + "; return -1";
}
if (idx == low) {
return "GE: " + v + " <= arr[" + low + "]=" + arr[low]
+ "; return arr[" + low + "]=" + arr[low];
} //idx > low
return "GE: " + v
+ ": arr[" + (idx - 1) + "]=" + arr[idx - 1] + " < " + v + " <= arr[" + idx + "]=" + arr[idx]
+ "; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final long[] arr, final int low, final int high, final long v, final int idx) {
if (idx == -1) {
return "GE: " + v + " > arr[" + high + "]=" + arr[high] + "; return -1";
}
if (idx == low) {
return "GE: " + v + " <= arr[" + low + "]=" + arr[low]
+ "; return arr[" + low + "]=" + arr[low];
} //idx > low
return "GE: " + v
+ ": arr[" + (idx - 1) + "]=" + arr[idx - 1] + " < " + v + " <= arr[" + idx + "]=" + arr[idx]
+ "; return arr[" + idx + "]=" + arr[idx];
}
},
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>V</i>,
* this criterion instructs the binary search algorithm to find the lowest adjacent pair of
* values <i>{A,B}</i> such that <i>A ≤ V < B</i>.<br>
* Let <i>low</i> = index of the lowest value in the range.<br>
* Let <i>high</i> = index of the highest value in the range.
*
* <p>If <i>v</i> < arr[low], return arr[low].<br>
* If <i>v</i> ≥ arr[high], return -1.<br>
* Else return index of B.</p>
*/
GT { //arr[A] <= V < arr[B], return B
@Override
int compare(final double[] arr, final int a, final int b, final double v) {
return v < arr[a] ? -1 : arr[b] <= v ? 1 : 0;
}
@Override
int compare(final float[] arr, final int a, final int b, final float v) {
return v < arr[a] ? -1 : arr[b] <= v ? 1 : 0;
}
@Override
int compare(final long[] arr, final int a, final int b, final long v) {
return v < arr[a] ? -1 : arr[b] <= v ? 1 : 0;
}
@Override
int getIndex(final double[] arr, final int a, final int b, final double v) {
return b;
}
@Override
int getIndex(final float[] arr, final int a, final int b, final float v) {
return b;
}
@Override
int getIndex(final long[] arr, final int a, final int b, final long v) {
return b;
}
@Override
int resolve(final double[] arr, final int lo, final int hi, final double v) {
return (lo == hi)
? (v < arr[lo] ? lo : -1)
: v < arr[lo] ? lo : (v < arr[hi] ? hi : -1);
}
@Override
int resolve(final float[] arr, final int lo, final int hi, final float v) {
return (lo == hi)
? (v < arr[lo] ? lo : -1)
: v < arr[lo] ? lo : (v < arr[hi] ? hi : -1);
}
@Override
int resolve(final long[] arr, final int lo, final int hi, final long v) {
return (lo == hi)
? (v < arr[lo] ? lo : -1)
: v < arr[lo] ? lo : (v < arr[hi] ? hi : -1);
}
@Override
public String desc(final double[] arr, final int low, final int high, final double v, final int idx) {
if (idx == -1) {
return "GT: " + v + " >= arr[" + high + "]=" + arr[high] + "; return -1";
}
if (idx == low) {
return "GT: " + v + " < arr[" + low + "]=" + arr[low]
+ "; return arr[" + low + "]=" + arr[low];
} //idx > low
return "GT: " + v
+ ": arr[" + (idx - 1) + "]=" + arr[idx - 1] + " <= " + v + " < arr[" + idx + "]=" + arr[idx]
+ "; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final float[] arr, final int low, final int high, final float v, final int idx) {
if (idx == -1) {
return "GT: " + v + " >= arr[" + high + "]=" + arr[high] + "; return -1";
}
if (idx == low) {
return "GT: " + v + " < arr[" + low + "]=" + arr[low]
+ "; return arr[" + low + "]=" + arr[low];
} //idx > low
return "GT: " + v
+ ": arr[" + (idx - 1) + "]=" + arr[idx - 1] + " <= " + v + " < arr[" + idx + "]=" + arr[idx]
+ "; return arr[" + idx + "]=" + arr[idx];
}
@Override
public String desc(final long[] arr, final int low, final int high, final long v, final int idx) {
if (idx == -1) {
return "GT: " + v + " >= arr[" + high + "]=" + arr[high] + "; return -1";
}
if (idx == low) {
return "GT: " + v + " < arr[" + low + "]=" + arr[low]
+ "; return arr[" + low + "]=" + arr[low];
} //idx > low
return "GT: " + v
+ ": arr[" + (idx - 1) + "]=" + arr[idx - 1] + " <= " + v + " < arr[" + idx + "]=" + arr[idx]
+ "; return arr[" + idx + "]=" + arr[idx];
}
};
/**
* The call to compare index a and index b with the value v.
* @param arr The underlying sorted array of double values
* @param a the lower index of the current pair
* @param b the higher index of the current pair
* @param v the double value to search for
* @return +1, which means we must search higher in the array, or -1, which means we must
* search lower in the array, or 0, which means we have found the correct bounding pair.
*/
abstract int compare(double[] arr, int a, int b, double v);
/**
* The call to compare index a and index b with the value v.
* @param arr The underlying sorted array of float values
* @param a the lower index of the current pair
* @param b the higher index of the current pair
* @param v the float value to search for
* @return +1, which means we must search higher in the array, or -1, which means we must
* search lower in the array, or 0, which means we have found the correct bounding pair.
*/
abstract int compare(float[] arr, int a, int b, float v);
/**
* The call to compare index a and index b with the value v.
* @param arr The underlying sorted array of long values
* @param a the lower index of the current pair
* @param b the higher index of the current pair
* @param v the long value to search for
* @return +1, which means we must search higher in the array, or -1, which means we must
* search lower in the array, or 0, which means we have found the correct bounding pair.
*/
abstract int compare(long[] arr, int a, int b, long v);
/**
* If the compare operation returns 0, which means "found", this returns the index of the
* found value that satisfies the selected criteria.
* @param arr the array being searched
* @param a the lower index of the current pair
* @param b the higher index of the current pair
* @param v the value being searched for.
* @return the index of the found value that satisfies the selected criteria.
*/
abstract int getIndex(double[] arr, int a, int b, double v);
/**
* If the compare operation returns 0, which means "found", this returns the index of the
* found value that satisfies the selected criteria.
* @param arr the array being searched
* @param a the lower index of the current pair
* @param b the higher index of the current pair
* @param v the value being searched for.
* @return the index of the found value that satisfies the selected criteria.
*/
abstract int getIndex(float[] arr, int a, int b, float v);
/**
* If the compare operation returns 0, which means "found", this returns the index of the
* found value that satisfies the selected criteria.
* @param arr the array being searched
* @param a the lower index of the current pair
* @param b the higher index of the current pair
* @param v the value being searched for.
* @return the index of the found value that satisfies the selected criteria.
*/
abstract int getIndex(long[] arr, int a, int b, long v);
/**
* Called to resolve the search when the hi and lo pointers are equal or adjacent.
* @param arr the array being searched
* @param lo the current lo value
* @param hi the current hi value
* @param v the value being searched for
* @return the index of the resolution or -1, if it cannot be resolved.
*/
abstract int resolve(double[] arr, int lo, int hi, double v);
/**
* Called to resolve the search when the hi and lo pointers are equal or adjacent.
* @param arr the array being searched
* @param lo the current lo value
* @param hi the current hi value
* @param v the value being searched for
* @return the index of the resolution or -1, if it cannot be resolved.
*/
abstract int resolve(float[] arr, int lo, int hi, float v);
/**
* Called to resolve the search when the hi and lo pointers are equal or adjacent.
* @param arr the array being searched
* @param lo the current lo value
* @param hi the current hi value
* @param v the value being searched for
* @return the index of the resolution or -1, if it cannot be resolved.
*/
abstract int resolve(long[] arr, int lo, int hi, long v);
/**
* Optional call that describes the details of the results of the search.
* Used primarily for debugging.
* @param arr The underlying sorted array of double values
* @param low the low index of the range
* @param high the high index of the range
* @param v the double value to search for
* @param idx the resolved index from the search
* @return the descriptive string.
*/
public abstract String desc(double[] arr, int low, int high, double v, int idx);
/**
* Optional call that describes the details of the results of the search.
* Used primarily for debugging.
* @param arr The underlying sorted array of double values
* @param low the low index of the range
* @param high the high index of the range
* @param v the double value to search for
* @param idx the resolved index from the search
* @return the descriptive string.
*/
public abstract String desc(float[] arr, int low, int high, float v, int idx);
/**
* Optional call that describes the details of the results of the search.
* Used primarily for debugging.
* @param arr The underlying sorted array of double values
* @param low the low index of the range
* @param high the high index of the range
* @param v the double value to search for
* @param idx the resolved index from the search
* @return the descriptive string.
*/
public abstract String desc(long[] arr, int low, int high, long v, int idx);
/**
* Binary Search for the index of the double value in the given search range that satisfies
* the given InequalitySearch criterion.
* If -1 is returned there are no values in the search range that satisfy the criterion.
*
* @param arr the given array of comparable values that must be sorted with increasing values.
* The array must not be null and the values of the array must not be NaN in the range [low, high].
* @param low the lowest index of the lowest value in the search range, inclusive.
* @param high the highest index of the highest value in the search range, inclusive.
* @param v the value to search for. It must not be NaN.
* @param crit one of the InequalitySearch criteria: LT, LE, EQ, GT, GE. It must not be null.
* @return the index of the value in the given search range that satisfies the InequalitySearch criterion
*/
public static int find(final double[] arr, final int low, final int high,
final double v, final InequalitySearch crit) {
Objects.requireNonNull(arr, "Input arr must not be null");
Objects.requireNonNull(crit, "Input crit must not be null");
if (arr.length == 0) { throw new SketchesArgumentException("Input array must not be empty."); }
if (Double.isNaN(v)) { throw new SketchesArgumentException("Input v must not be NaN."); }
int lo = low;
int hi = high;
while (lo <= hi) {
if (hi - lo <= 1) {
return crit.resolve(arr, lo, hi, v);
}
final int mid = lo + (hi - lo) / 2;
final int ret = crit.compare(arr, mid, mid + 1, v);
if (ret == -1 ) { hi = mid; }
else if (ret == 1) { lo = mid + 1; }
else { return crit.getIndex(arr, mid, mid + 1, v); }
}
return -1; //should never return here
}
/**
* Binary Search for the index of the float value in the given search range that satisfies
* the given InequalitySearch criterion.
* If -1 is returned there are no values in the search range that satisfy the criterion.
*
* @param arr the given array that must be sorted.
* It must not be null and must not contain any NaN values in the range {low, high} inclusive.
* @param low the lowest index of the lowest value in the search range, inclusive.
* @param high the highest index of the highest value in the search range, inclusive.
* @param v the value to search for. It must not be NaN.
* @param crit one of LT, LE, EQ, GT, GE
* @return the index of the value in the given search range that satisfies the criterion
*/
public static int find(final float[] arr, final int low, final int high,
final float v, final InequalitySearch crit) {
Objects.requireNonNull(arr, "Input arr must not be null");
Objects.requireNonNull(crit, "Input crit must not be null");
if (arr.length == 0) { throw new SketchesArgumentException("Input array must not be empty."); }
if (Float.isNaN(v)) { throw new SketchesArgumentException("Input v must not be NaN."); }
int lo = low;
int hi = high;
while (lo <= hi) {
if (hi - lo <= 1) {
return crit.resolve(arr, lo, hi, v);
}
final int mid = lo + (hi - lo) / 2;
final int ret = crit.compare(arr, mid, mid + 1, v);
if (ret == -1 ) { hi = mid; }
else if (ret == 1) { lo = mid + 1; }
else { return crit.getIndex(arr, mid, mid + 1, v); }
}
return -1; //should never return here
}
/**
* Binary Search for the index of the long value in the given search range that satisfies
* the given InequalitySearch criterion.
* If -1 is returned there are no values in the search range that satisfy the criterion.
*
* @param arr the given array that must be sorted.
* @param low the lowest index of the lowest value in the search range, inclusive.
* @param high the highest index of the highest value in the search range, inclusive.
* @param v the value to search for.
* @param crit one of LT, LE, EQ, GT, GE
* @return the index of the value in the given search range that satisfies the criterion
*/
public static int find(final long[] arr, final int low, final int high,
final long v, final InequalitySearch crit) {
Objects.requireNonNull(arr, "Input arr must not be null");
Objects.requireNonNull(crit, "Input crit must not be null");
if (arr.length == 0) { throw new SketchesArgumentException("Input array must not be empty."); }
int lo = low;
int hi = high;
while (lo <= hi) {
if (hi - lo <= 1) {
return crit.resolve(arr, lo, hi, v);
}
final int mid = lo + (hi - lo) / 2;
final int ret = crit.compare(arr, mid, mid + 1, v);
if (ret == -1 ) { hi = mid; }
else if (ret == 1) { lo = mid + 1; }
else { return crit.getIndex(arr, mid, mid + 1, v); }
}
return -1; //should never return here
}
} //End of enum
| 2,711 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/GenericInequalitySearch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
import java.util.Comparator;
import java.util.Objects;
import org.apache.datasketches.common.SketchesArgumentException;
/**
* This provides efficient, unique and unambiguous binary searching for inequality comparison criteria
* for ordered arrays of values that may include duplicate values. The inequality criteria include
* <, ≤, ==, ≥, >. All the inequality criteria use the same search algorithm.
* (Although == is not an inequality, it is included for convenience.)
*
* <p>In order to make the searching unique and unambiguous, we modified the traditional binary
* search algorithm to search for adjacent pairs of values <i>{A, B}</i> in the values array
* instead of just a single value, where <i>a</i> and <i>b</i> are the array indices of two
* adjacent values in the array. For all the search criteria, when the algorithm has narrowed the
* search down to a single value or adjacent pair of values, the <i>resolve()</i> method provides the
* final result of the search. If there is no valid value in the array that satisfies the search
* criterion, the algorithm will return -1 to the caller.</p>
*
* <p>Given a sorted array of values <i>arr[]</i> and a search key value <i>v</i>, the algorithms for
* the searching criteria are given with each enum criterion.</p>
*
* @see <a href="https://datasketches.apache.org/docs/Quantiles/SketchingQuantilesAndRanksTutorial.html">
* Sketching Quantiles and Ranks Tutorial</a>
* @author Lee Rhodes
*/
public final class GenericInequalitySearch {
/**
* The enumerator of inequalities
*/
public enum Inequality {
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>v</i>,
* this criterion instructs the binary search algorithm to find the highest adjacent pair of
* values <i>{A,B}</i> such that <i>A < v ≤ B</i>.<br>
* Let <i>low</i> = index of the lowest value in the range.<br>
* Let <i>high</i> = index of the highest value in the range.
*
* <p>If <i>v</i> > arr[high], return arr[high].<br>
* If <i>v</i> ≤ arr[low], return -1.<br>
* Else return index of A.</p>
*/
LT,
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>V</i>,
* this criterion instructs the binary search algorithm to find the highest adjacent pair of
* values <i>{A,B}</i> such that <i>A ≤ V < B</i>.<br>
* Let <i>low</i> = index of the lowest value in the range.<br>
* Let <i>high</i> = index of the highest value in the range.
*
* <p>If <i>v</i> ≥ arr[high], return arr[high].<br>
* If <i>v</i> < arr[low], return -1.<br>
* Else return index of A.</p>
*/
LE,
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>V</i>,
* this criterion instructs the binary search algorithm to find the adjacent pair of
* values <i>{A,B}</i> such that <i>A ≤ V ≤ B</i>.
* The returned value from the binary search algorithm will be the index of <i>A</i> or <i>B</i>,
* if one of them is equal to <i>V</i>, or -1 if V is not equal to either one.
*/
EQ,
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>V</i>,
* this criterion instructs the binary search algorithm to find the lowest adjacent pair of
* values <i>{A,B}</i> such that <i>A < V ≤ B</i>.<br>
* Let <i>low</i> = index of the lowest value in the range.<br>
* Let <i>high</i> = index of the highest value in the range.
*
* <p>If <i>v</i> ≤ arr[low], return arr[low].<br>
* If <i>v</i> > arr[high], return -1.<br>
* Else return index of B.</p>
*/
GE,
/**
* Given a sorted array of increasing values <i>arr[]</i> and a key value <i>V</i>,
* this criterion instructs the binary search algorithm to find the lowest adjacent pair of
* values <i>{A,B}</i> such that <i>A ≤ V < B</i>.<br>
* Let <i>low</i> = index of the lowest value in the range.<br>
* Let <i>high</i> = index of the highest value in the range.
*
* <p>If <i>v</i> < arr[low], return arr[low].<br>
* If <i>v</i> ≥ arr[high], return -1.<br>
* Else return index of B.</p>
*/
GT
}
/**
* Binary Search for the index of the generic value in the given search range that satisfies
* the given Inequality criterion.
* If -1 is returned there are no values in the search range that satisfy the inequality.
*
* @param arr the given array of comparable values that must be sorted.
* The array must not be null or empty and the values of the array must not be null (or NaN)
* in the range [low, high].
* @param low the lowest index of the lowest value in the search range, inclusive.
* @param high the highest index of the highest value in the search range, inclusive.
* @param v the value to search for. It must not be null (or NaN).
* @param crit one of the Inequality criteria: LT, LE, EQ, GE, GT. It must not be null.
* @param comparator for the type T.
* It must not be null. It must return: -1 if A < B, 0 if A == B, and +1 if A > B.
* @param <T> The generic type of value to be used in the search process.
* @return the index of the value in the given search range that satisfies the Inequality criterion.
*/
public static <T> int find(final T[] arr, final int low, final int high, final T v,
final Inequality crit, final Comparator<T> comparator) {
Objects.requireNonNull(arr, "Input arr must not be null");
Objects.requireNonNull(v,"Input v must not be null");
Objects.requireNonNull(crit, "Input inequality must not be null");
Objects.requireNonNull(comparator,"Input comparator must not be null");
if (arr.length == 0) { throw new SketchesArgumentException("Input array must not be empty."); }
int lo = low;
int hi = high;
while (lo <= hi) {
if (hi - lo <= 1) {
return resolve(arr, lo, hi, v, crit, comparator);
}
final int mid = lo + (hi - lo) / 2;
final int ret = compare(arr, mid, mid + 1, v, crit, comparator);
if (ret == -1 ) { hi = mid; }
else if (ret == 1) { lo = mid + 1; }
else { return getIndex(arr, mid, mid + 1, v, crit, comparator); }
}
return -1; //should never return here
}
private static <T> int compare(final T[] arr, final int a, final int b, final T v,
final Inequality crit, final Comparator<T> comparator) {
int result = 0;
switch (crit) {
case GE:
case LT: {
result = comparator.compare(v, arr[a]) <= 0 ? -1 : comparator.compare(arr[b], v) < 0 ? 1 : 0;
break;
}
case GT:
case LE: {
result = comparator.compare(v, arr[a]) < 0 ? -1 : comparator.compare(arr[b], v) <= 0 ? 1 : 0;
break;
}
case EQ: {
result = comparator.compare(v, arr[a]) < 0 ? -1 : comparator.compare(arr[b], v) < 0 ? 1 : 0;
break;
}
}
return result;
}
private static <T> int getIndex(final T[] arr, final int a, final int b, final T v,
final Inequality crit, final Comparator<T> comparator) {
int result = 0;
switch (crit) {
case LT:
case LE: {
result = a; break;
}
case GE:
case GT: {
result = b; break;
}
case EQ: {
result = comparator.compare(v, arr[a]) == 0 ? a : comparator.compare(v, arr[b]) == 0 ? b : -1;
}
}
return result;
}
private static <T> int resolve(final T[] arr, final int lo, final int hi, final T v,
final Inequality crit, final Comparator<T> comparator) {
int result = 0;
switch (crit) {
case LT: {
result = (lo == hi)
? (comparator.compare(v, arr[lo]) > 0 ? lo : -1)
: (comparator.compare(v, arr[hi]) > 0
? hi
: (comparator.compare(v, arr[lo]) > 0 ? lo : -1));
break;
}
case LE: {
result = (lo == hi)
? (comparator.compare(v, arr[lo]) >= 0 ? lo : -1)
: (comparator.compare(v, arr[hi]) >= 0
? hi
: (comparator.compare(v, arr[lo]) >= 0 ? lo : -1));
break;
}
case EQ: {
result = (lo == hi)
? (comparator.compare(v, arr[lo]) == 0 ? lo : -1)
: (comparator.compare(v, arr[hi]) == 0
? hi
: (comparator.compare(v, arr[lo]) == 0 ? lo : -1));
break;
}
case GE: {
result = (lo == hi)
? (comparator.compare(v, arr[lo]) <= 0 ? lo : -1)
: (comparator.compare(v, arr[lo]) <= 0
? lo
: (comparator.compare(v, arr[hi]) <= 0 ? hi : -1));
break;
}
case GT: {
result = (lo == hi)
? (comparator.compare(v, arr[lo]) < 0 ? lo : -1)
: (comparator.compare(v, arr[lo]) < 0
? lo
: (comparator.compare(v, arr[hi]) < 0 ? hi : -1));
break;
}
}
return result;
}
}
| 2,712 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/SortedViewIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* This is the base interface for the SortedViewIterator hierarchy used with a SortedView obtained
* from a quantile-type sketch. This provides an ordered iterator over the retained quantiles of
* the associated quantile-type sketch.
*
* <p>Prototype example of the recommended iteration loop:</p>
* <pre>{@code
* SortedViewIterator itr = sketch.getSortedView().iterator();
* while (itr.next()) {
* long weight = itr.getWeight();
* ...
* }
* }</pre>
* @author Alexander Saydakov
* @author Lee Rhodes
*/
public interface SortedViewIterator {
/**
* Gets the cumulative weight at the current index (or previous index) based on the chosen search criterion.
* This is also referred to as the "Natural Rank".
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @param searchCrit if INCLUSIVE, includes the weight at the current index in the cumulative sum.
* Otherwise, it will return the cumulative weight of the previous index.
* @return cumulative weight at the current index on the chosen search criterion.
*/
long getCumulativeWeight(QuantileSearchCriteria searchCrit);
/**
* Gets the total count of all items presented to the sketch.
* @return the total count of all items presented to the sketch.
*/
long getN();
/**
* Gets the normalized rank at the current index (or previous index)
* based on the chosen search criterion.
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @param searchCrit if INCLUSIVE, includes the normalized rank at the current index.
* Otherwise, returns the normalized rank of the previous index.
* @return the normalized rank at the current index (or previous index)
* based on the chosen search criterion.
*/
double getNormalizedRank(QuantileSearchCriteria searchCrit);
/**
* Gets the natural weight at the current index.
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @return the natural weight at the current index.
*/
long getWeight();
/**
* Advances the index and checks if it is valid.
* The state of this iterator is undefined before the first call of this method.
* @return true if the next index is valid.
*/
boolean next();
}
| 2,713 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedView.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
import java.util.Comparator;
import org.apache.datasketches.common.SketchesArgumentException;
/**
* The Sorted View for quantiles of generic type.
* @param <T> The generic quantile type.
* @see SortedView
* @author Alexander Saydakov
* @author Lee Rhodes
*/
public interface GenericSortedView<T> extends SortedView {
/**
* Returns an approximation to the Cumulative Distribution Function (CDF) of the input stream
* as a monotonically increasing array of double ranks (or cumulative probabilities) on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>If the sketch is empty this returns null.</p>
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(false) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> overlapping intervals.
*
* <p>The start of each interval is below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and the end of the interval
* is the rank or cumulative probability corresponding to the split point.</p>
*
* <p>The <i>(m+1)th</i> interval represents 100% of the distribution represented by the sketch
* and consistent with the definition of a cumulative probability distribution, thus the <i>(m+1)th</i>
* rank or probability in the returned array is always 1.0.</p>
*
* <p>If a split point exactly equals a retained item of the sketch and the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, the resulting cumulative probability will include that item.</li>
* <li>EXCLUSIVE, the resulting cumulative probability will not include the weight of that split point.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
double[] getCDF(T[] splitPoints, QuantileSearchCriteria searchCrit);
/**
* Returns an approximation to the Probability Mass Function (PMF) of the input stream
* as an array of probability masses as doubles on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(true) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> consecutive, non-overlapping intervals.
*
* <p>Each interval except for the end intervals starts with a split point and ends with the next split
* point in sequence.</p>
*
* <p>The first interval starts below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and ends with the first split point</p>
*
* <p>The last <i>(m+1)th</i> interval starts with the last split point and ends after the last
* item retained by the sketch corresponding to a rank or probability of 1.0. </p>
*
* <p>The sum of the probability masses of all <i>(m+1)</i> intervals is 1.0.</p>
*
* <p>If the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will include that item. If the lower split point equals an item retained by the sketch, the interval will exclude
* that item.</li>
* <li>EXCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will exclude that item. If the lower split point equals an item retained by the sketch, the interval will include
* that item.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
double[] getPMF(T[] splitPoints, QuantileSearchCriteria searchCrit);
/**
* Gets the approximate quantile of the given normalized rank and the given search criterion.
*
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @param searchCrit If INCLUSIVE, the given rank includes all quantiles ≤
* the quantile directly corresponding to the given rank.
* If EXCLUSIVE, he given rank includes all quantiles <
* the quantile directly corresponding to the given rank.
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
T getQuantile(double rank, QuantileSearchCriteria searchCrit);
/**
* Returns the array of quantiles.
* @return the array of quantiles.
*/
T[] getQuantiles();
/**
* Gets the normalized rank corresponding to the given a quantile.
*
* @param quantile the given quantile
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
* @return the normalized rank corresponding to the given quantile.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double getRank(T quantile, QuantileSearchCriteria searchCrit);
@Override
GenericSortedViewIterator<T> iterator();
/**
* Checks the sequential validity of the given array of generic items.
* They must be unique, monotonically increasing and not null.
* @param <T> the data type
* @param items given array of generic items
* @param comparator the comparator for generic item data type T
*/
static <T> void validateItems(final T[] items, final Comparator<? super T> comparator) {
final int len = items.length;
if (len == 1 && items[0] == null) {
throw new SketchesArgumentException(
"Items must be unique, monotonically increasing and not null.");
}
for (int j = 0; j < len - 1; j++) {
if ((items[j] != null) && (items[j + 1] != null)
&& (comparator.compare(items[j], items[j + 1]) < 0)) {
continue;
}
throw new SketchesArgumentException(
"Items must be unique, monotonically increasing and not null.");
}
}
}
| 2,714 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/SortedView.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* This is the base interface for the Sorted View interface hierarchy.
*
* <p>The Sorted View provides a view of the data retained by a quantiles-type sketch
* that would be cumbersome to get any other way.
* One can iterate over the contents of the sketch using the sketch's iterator, but the result is not sorted.</p>
*
* <p>Once this sorted view has been created, it provides not only a sorted view of the data retained by the sketch
* but also the basic queries, such as getRank(), getQuantile(), and getCDF() and getPMF().
* In addition, the iterator obtained from this sorted view provides useful detailed information about each entry.</p>
*
* <p>The data from a Sorted view is an unbiased sample of the input stream that can be used for other kinds of
* analysis not directly provided by the sketch. For example, comparing two sketches using the Kolmogorov-Smirnov
* test.</p>
*
* @author Alexander Saydakov
* @author Lee Rhodes
*/
public interface SortedView {
/**
* Returns the array of cumulative weights
* @return the array of cumulative weights
*/
long[] getCumulativeWeights();
/**
* Returns true if this sorted view is empty.
* @return true if this sorted view is empty.
*/
boolean isEmpty();
/**
* Returns an iterator for this Sorted View.
* @return an iterator for this Sorted View.
*/
SortedViewIterator iterator();
}
| 2,715 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesSketchIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* This is the base interface for the SketchIterator hierarchy used for viewing the
* non-ordered quantiles retained by a sketch.
*
* <p>Prototype example of the recommended iteration loop:</p>
* <pre>{@code
* SketchIterator itr = sketch.iterator();
* while (itr.next()) {
* ...get*();
* }
* }</pre>
*
* @author Lee Rhodes
*/
public interface QuantilesSketchIterator {
/**
* Gets the natural weight at the current index.
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @return the natural weight at the current index.
*/
long getWeight();
/**
* Advances the index and checks if it is valid.
* The state of this iterator is undefined before the first call of this method.
* @return true if the next index is valid.
*/
boolean next();
}
| 2,716 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/DoublesSortedViewIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* The quantiles SortedView iterator for type double.
* @see SortedViewIterator
* @author Alexander Saydakov
* @author Lee Rhodes
*/
public interface DoublesSortedViewIterator extends SortedViewIterator {
/**
* Gets the quantile at the current index.
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @return the quantile at the current index.
*/
double getQuantile();
}
| 2,717 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/FloatsSortedView.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* The Sorted View for quantiles of primitive type float.
* @see SortedView
* @author Alexander Saydakov
* @author Lee Rhodes
*/
public interface FloatsSortedView extends SortedView {
/**
* Returns an approximation to the Cumulative Distribution Function (CDF) of the input stream
* as a monotonically increasing array of double ranks (or cumulative probabilities) on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(false) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> overlapping intervals.
*
* <p>The start of each interval is below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and the end of the interval
* is the rank or cumulative probability corresponding to the split point.</p>
*
* <p>The <i>(m+1)th</i> interval represents 100% of the distribution represented by the sketch
* and consistent with the definition of a cumulative probability distribution, thus the <i>(m+1)th</i>
* rank or probability in the returned array is always 1.0.</p>
*
* <p>If a split point exactly equals a retained item of the sketch and the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, the resulting cumulative probability will include that item.</li>
* <li>EXCLUSIVE, the resulting cumulative probability will not include the weight of that split point.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getCDF(float[] splitPoints, QuantileSearchCriteria searchCrit) {
QuantilesUtil.checkFloatsSplitPointsOrder(splitPoints);
final int len = splitPoints.length + 1;
final double[] buckets = new double[len];
for (int i = 0; i < len - 1; i++) {
buckets[i] = getRank(splitPoints[i], searchCrit);
}
buckets[len - 1] = 1.0;
return buckets;
}
/**
* Returns an approximation to the Probability Mass Function (PMF) of the input stream
* as an array of probability masses as doubles on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(true) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> consecutive, non-overlapping intervals.
*
* <p>Each interval except for the end intervals starts with a split point and ends with the next split
* point in sequence.</p>
*
* <p>The first interval starts below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and ends with the first split point</p>
*
* <p>The last <i>(m+1)th</i> interval starts with the last split point and ends after the last
* item retained by the sketch corresponding to a rank or probability of 1.0. </p>
*
* <p>The sum of the probability masses of all <i>(m+1)</i> intervals is 1.0.</p>
*
* <p>If the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will include that item. If the lower split point equals an item retained by the sketch, the interval will exclude
* that item.</li>
* <li>EXCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will exclude that item. If the lower split point equals an item retained by the sketch, the interval will include
* that item.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getPMF(float[] splitPoints, QuantileSearchCriteria searchCrit) {
final double[] buckets = getCDF(splitPoints, searchCrit);
final int len = buckets.length;
for (int i = len; i-- > 1; ) {
buckets[i] -= buckets[i - 1];
}
return buckets;
}
/**
* Gets the approximate quantile of the given normalized rank and the given search criterion.
*
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @param searchCrit If INCLUSIVE, the given rank includes all quantiles ≤
* the quantile directly corresponding to the given rank.
* If EXCLUSIVE, he given rank includes all quantiles <
* the quantile directly corresponding to the given rank.
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
float getQuantile(double rank, QuantileSearchCriteria searchCrit);
/**
* Returns the array of quantiles
* @return the array of quantiles
*/
float[] getQuantiles();
/**
* Gets the normalized rank corresponding to the given a quantile.
*
* @param quantile the given quantile
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
* @return the normalized rank corresponding to the given quantile.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double getRank(float quantile, QuantileSearchCriteria searchCrit);
@Override
FloatsSortedViewIterator iterator();
}
| 2,718 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesDoublesAPI.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
/**
* The Quantiles API for item type <i>double</i>.
* @see QuantilesAPI
*
* @author Lee Rhodes
*/
public interface QuantilesDoublesAPI extends QuantilesAPI {
/**
* This is equivalent to {@link #getCDF(double[], QuantileSearchCriteria) getCDF(splitPoints, INCLUSIVE)}
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getCDF(double[] splitPoints) {
return getCDF(splitPoints, INCLUSIVE);
}
/**
* Returns an approximation to the Cumulative Distribution Function (CDF) of the input stream
* as a monotonically increasing array of double ranks (or cumulative probabilities) on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(false) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> overlapping intervals.
*
* <p>The start of each interval is below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and the end of the interval
* is the rank or cumulative probability corresponding to the split point.</p>
*
* <p>The <i>(m+1)th</i> interval represents 100% of the distribution represented by the sketch
* and consistent with the definition of a cumulative probability distribution, thus the <i>(m+1)th</i>
* rank or probability in the returned array is always 1.0.</p>
*
* <p>If a split point exactly equals a retained item of the sketch and the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, the resulting cumulative probability will include that item.</li>
* <li>EXCLUSIVE, the resulting cumulative probability will not include the weight of that split point.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
double[] getCDF(double[] splitPoints, QuantileSearchCriteria searchCrit);
/**
* Returns the maximum item of the stream. This is provided for convenience, but may be different from the largest
* item retained by the sketch algorithm.
*
* @return the maximum item of the stream
* @throws IllegalArgumentException if sketch is empty.
*/
double getMaxItem();
/**
* Returns the minimum item of the stream. This is provided for convenience, but is distinct from the smallest
* item retained by the sketch algorithm.
*
* @return the minimum item of the stream
* @throws IllegalArgumentException if sketch is empty.
*/
double getMinItem();
/**
* This method returns an instance of {@link DoublesPartitionBoundaries DoublesPartitionBoundaries} which provides
* sufficient information for the user to create the given number of equally weighted partitions.
*
* <p>This method is equivalent to
* {@link #getPartitionBoundaries(int, QuantileSearchCriteria) getPartitionBoundaries(numEquallyWeighted, INCLUSIVE)}.
* </p>
*
* @param numEquallyWeighted an integer that specifies the number of equally weighted partitions between
* {@link #getMinItem() getMinItem()} and {@link #getMaxItem() getMaxItem()}.
* This must be a positive integer greater than zero.
* <ul>
* <li>A 1 will return: minItem, maxItem.</li>
* <li>A 2 will return: minItem, median quantile, maxItem.</li>
* <li>Etc.</li>
* </ul>
*
* @return an instance of {@link DoublesPartitionBoundaries DoublesPartitionBoundaries}.
* @throws IllegalArgumentException if sketch is empty.
* @throws IllegalArgumentException if <i>numEquallyWeighted</i> is less than 1.
*/
default DoublesPartitionBoundaries getPartitionBoundaries(int numEquallyWeighted) {
return getPartitionBoundaries(numEquallyWeighted, INCLUSIVE);
}
/**
* This method returns an instance of {@link DoublesPartitionBoundaries DoublesPartitionBoundaries} which provides
* sufficient information for the user to create the given number of equally weighted partitions.
*
* @param numEquallyWeighted an integer that specifies the number of equally weighted partitions between
* {@link #getMinItem() getMinItem()} and {@link #getMaxItem() getMaxItem()}.
* This must be a positive integer greater than zero.
* <ul>
* <li>A 1 will return: minItem, maxItem.</li>
* <li>A 2 will return: minItem, median quantile, maxItem.</li>
* <li>Etc.</li>
* </ul>
*
* @param searchCrit
* If INCLUSIVE, all the returned quantiles are the upper boundaries of the equally weighted partitions
* with the exception of the lowest returned quantile, which is the lowest boundary of the lowest ranked partition.
* If EXCLUSIVE, all the returned quantiles are the lower boundaries of the equally weighted partitions
* with the exception of the highest returned quantile, which is the upper boundary of the highest ranked partition.
*
* @return an instance of {@link DoublesPartitionBoundaries DoublesPartitionBoundaries}.
* @throws IllegalArgumentException if sketch is empty.
* @throws IllegalArgumentException if <i>numEquallyWeighted</i> is less than 1.
*/
DoublesPartitionBoundaries getPartitionBoundaries(int numEquallyWeighted, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getPMF(double[], QuantileSearchCriteria) getPMF(splitPoints, INCLUSIVE)}
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getPMF(double[] splitPoints) {
return getPMF(splitPoints, INCLUSIVE);
}
/**
* Returns an approximation to the Probability Mass Function (PMF) of the input stream
* as an array of probability masses as doubles on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(true) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> consecutive, non-overlapping intervals.
*
* <p>Each interval except for the end intervals starts with a split point and ends with the next split
* point in sequence.</p>
*
* <p>The first interval starts below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and ends with the first split point</p>
*
* <p>The last <i>(m+1)th</i> interval starts with the last split point and ends after the last
* item retained by the sketch corresponding to a rank or probability of 1.0. </p>
*
* <p>The sum of the probability masses of all <i>(m+1)</i> intervals is 1.0.</p>
*
* <p>If the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will include that item. If the lower split point equals an item retained by the sketch, the interval will exclude
* that item.</li>
* <li>EXCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will exclude that item. If the lower split point equals an item retained by the sketch, the interval will include
* that item.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
double[] getPMF(double[] splitPoints, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getQuantile(double, QuantileSearchCriteria) getQuantile(rank, INCLUSIVE)}
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
*/
default double getQuantile(double rank) {
return getQuantile(rank, INCLUSIVE);
}
/**
* Gets the approximate quantile of the given normalized rank and the given search criterion.
*
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @param searchCrit If INCLUSIVE, the given rank includes all quantiles ≤
* the quantile directly corresponding to the given rank.
* If EXCLUSIVE, he given rank includes all quantiles <
* the quantile directly corresponding to the given rank.
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double getQuantile(double rank, QuantileSearchCriteria searchCrit);
/**
* Gets the lower bound of the quantile confidence interval in which the quantile of the
* given rank exists.
*
* <p>Although it is possible to estimate the probability that the true quantile
* exists within the quantile confidence interval specified by the upper and lower quantile bounds,
* it is not possible to guarantee the width of the quantile confidence interval
* as an additive or multiplicative percent of the true quantile.</p>
*
* @param rank the given normalized rank
* @return the lower bound of the quantile confidence interval in which the quantile of the
* given rank exists.
* @throws IllegalArgumentException if sketch is empty.
*/
double getQuantileLowerBound(double rank);
/**
* Gets the upper bound of the quantile confidence interval in which the true quantile of the
* given rank exists.
*
* <p>Although it is possible to estimate the probability that the true quantile
* exists within the quantile confidence interval specified by the upper and lower quantile bounds,
* it is not possible to guarantee the width of the quantile interval
* as an additive or multiplicative percent of the true quantile.</p>
*
* @param rank the given normalized rank
* @return the upper bound of the quantile confidence interval in which the true quantile of the
* given rank exists.
* @throws IllegalArgumentException if sketch is empty.
*/
double getQuantileUpperBound(double rank);
/**
* This is equivalent to {@link #getQuantiles(double[], QuantileSearchCriteria) getQuantiles(ranks, INCLUSIVE)}
* @param ranks the given array of normalized ranks, each of which must be
* in the interval [0.0,1.0].
* @return an array of quantiles corresponding to the given array of normalized ranks.
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getQuantiles(double[] ranks) {
return getQuantiles(ranks, INCLUSIVE);
}
/**
* Gets an array of quantiles from the given array of normalized ranks.
*
* @param ranks the given array of normalized ranks, each of which must be
* in the interval [0.0,1.0].
* @param searchCrit if INCLUSIVE, the given ranks include all quantiles ≤
* the quantile directly corresponding to each rank.
* @return an array of quantiles corresponding to the given array of normalized ranks.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double[] getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getRank(double, QuantileSearchCriteria) getRank(quantile, INCLUSIVE)}
* @param quantile the given quantile
* @return the normalized rank corresponding to the given quantile
* @throws IllegalArgumentException if sketch is empty.
*/
default double getRank(double quantile) {
return getRank(quantile, INCLUSIVE);
}
/**
* Gets the normalized rank corresponding to the given a quantile.
*
* @param quantile the given quantile
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
* @return the normalized rank corresponding to the given quantile
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double getRank(double quantile, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getRanks(double[], QuantileSearchCriteria) getRanks(quantiles, INCLUSIVE)}
* @param quantiles the given array of quantiles
* @return an array of normalized ranks corresponding to the given array of quantiles.
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getRanks(double[] quantiles) {
return getRanks(quantiles, INCLUSIVE);
}
/**
* Gets an array of normalized ranks corresponding to the given array of quantiles and the given
* search criterion.
*
* @param quantiles the given array of quantiles
* @param searchCrit if INCLUSIVE, the given quantiles include the rank directly corresponding to each quantile.
* @return an array of normalized ranks corresponding to the given array of quantiles.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double[] getRanks(double[] quantiles, QuantileSearchCriteria searchCrit);
/**
* Returns the current number of bytes this Sketch would require if serialized.
* @return the number of bytes this sketch would require if serialized.
*/
int getSerializedSizeBytes();
/**
* Gets the sorted view of this sketch
* @return the sorted view of this sketch
*/
DoublesSortedView getSortedView();
/**
* Gets the iterator for this sketch, which is not sorted.
* @return the iterator for this sketch
*/
QuantilesDoublesSketchIterator iterator();
/**
* Returns a byte array representation of this sketch.
* @return a byte array representation of this sketch.
*/
byte[] toByteArray();
/**
* Updates this sketch with the given item.
* @param item from a stream of quantiles. NaNs are ignored.
*/
void update(double item);
/**
* This encapsulates the essential information needed to construct actual partitions and is returned from the
* <i>getPartitionBoundaries(int, QuantileSearchCritera)</i> method.
*/
static class DoublesPartitionBoundaries {
/**
* The total number of items presented to the sketch.
*
* <p>To compute the weight or density of a specific
* partition <i>i</i> where <i>i</i> varies from 1 to <i>m</i> partitions:
* <pre>{@code
* long N = getN();
* double[] ranks = getRanks();
* long weight = Math.round((ranks[i] - ranks[i - 1]) * N);
* }</pre>
*/
public long N;
/**
* The normalized ranks that correspond to the returned boundaries.
* The returned array is of size <i>(m + 1)</i>, where <i>m</i> is the requested number of partitions.
* Index 0 of the returned array is always 0.0, and index <i>m</i> is always 1.0.
*/
public double[] ranks;
/**
* The partition boundaries as quantiles.
* The returned array is of size <i>(m + 1)</i>, where <i>m</i> is the requested number of partitions.
* Index 0 of the returned array is always {@link #getMinItem() getMinItem()}, and index <i>m</i> is always
* {@link #getMaxItem() getMaxItem()}.
*/
public double[] boundaries;
}
}
| 2,719 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericAPI.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
/**
* The Quantiles API for item type <i>generic</i>.
* @see QuantilesAPI
* @param <T> The given item type
* @author Lee Rhodes
*/
public interface QuantilesGenericAPI<T> extends QuantilesAPI {
/**
* This is equivalent to {@link #getCDF(Object[], QuantileSearchCriteria) getCDF(splitPoints, INCLUSIVE)}
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getCDF(T[] splitPoints) {
return getCDF(splitPoints, INCLUSIVE);
}
/**
* Returns an approximation to the Cumulative Distribution Function (CDF) of the input stream
* as a monotonically increasing array of double ranks (or cumulative probabilities) on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(false) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> overlapping intervals.
*
* <p>The start of each interval is below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and the end of the interval
* is the rank or cumulative probability corresponding to the split point.</p>
*
* <p>The <i>(m+1)th</i> interval represents 100% of the distribution represented by the sketch
* and consistent with the definition of a cumulative probability distribution, thus the <i>(m+1)th</i>
* rank or probability in the returned array is always 1.0.</p>
*
* <p>If a split point exactly equals a retained item of the sketch and the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, the resulting cumulative probability will include that item.</li>
* <li>EXCLUSIVE, the resulting cumulative probability will not include the weight of that split point.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
double[] getCDF(T[] splitPoints, QuantileSearchCriteria searchCrit);
/**
* Returns the maximum item of the stream. This may be distinct from the largest item retained by the
* sketch algorithm.
*
* @return the maximum item of the stream
* @throws IllegalArgumentException if sketch is empty.
*/
T getMaxItem();
/**
* Returns the minimum item of the stream. This may be distinct from the smallest item retained by the
* sketch algorithm.
*
* @return the minimum item of the stream
* @throws IllegalArgumentException if sketch is empty.
*/
T getMinItem();
/**
* This method returns an instance of
* {@link GenericPartitionBoundaries GenericPartitionBoundaries} which provides
* sufficient information for the user to create the given number of equally weighted partitions.
*
* <p>This method is equivalent to
* {@link #getPartitionBoundaries(int, QuantileSearchCriteria) getPartitionBoundaries(numEquallyWeighted, INCLUSIVE)}.
* </p>
*
* @param numEquallyWeighted an integer that specifies the number of equally weighted partitions between
* {@link #getMinItem() getMinItem()} and {@link #getMaxItem() getMaxItem()}.
* This must be a positive integer greater than zero.
* <ul>
* <li>A 1 will return: minItem, maxItem.</li>
* <li>A 2 will return: minItem, median quantile, maxItem.</li>
* <li>Etc.</li>
* </ul>
*
* @return an instance of {@link GenericPartitionBoundaries GenericPartitionBoundaries}.
* @throws IllegalArgumentException if sketch is empty.
* @throws IllegalArgumentException if <i>numEquallyWeighted</i> is less than 1.
*/
default GenericPartitionBoundaries<T> getPartitionBoundaries(int numEquallyWeighted) {
return getPartitionBoundaries(numEquallyWeighted, INCLUSIVE);
}
/**
* This method returns an instance of
* {@link GenericPartitionBoundaries GenericPartitionBoundaries} which provides
* sufficient information for the user to create the given number of equally weighted partitions.
*
* @param numEquallyWeighted an integer that specifies the number of equally weighted partitions between
* {@link #getMinItem() getMinItem()} and {@link #getMaxItem() getMaxItem()}.
* This must be a positive integer greater than zero.
* <ul>
* <li>A 1 will return: minItem, maxItem.</li>
* <li>A 2 will return: minItem, median quantile, maxItem.</li>
* <li>Etc.</li>
* </ul>
*
* @param searchCrit
* If INCLUSIVE, all the returned quantiles are the upper boundaries of the equally weighted partitions
* with the exception of the lowest returned quantile, which is the lowest boundary of the lowest ranked partition.
* If EXCLUSIVE, all the returned quantiles are the lower boundaries of the equally weighted partitions
* with the exception of the highest returned quantile, which is the upper boundary of the highest ranked partition.
*
* @return an instance of {@link GenericPartitionBoundaries GenericPartitionBoundaries}.
* @throws IllegalArgumentException if sketch is empty.
* @throws IllegalArgumentException if <i>numEquallyWeighted</i> is less than 1.
*/
GenericPartitionBoundaries<T> getPartitionBoundaries(int numEquallyWeighted, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getPMF(Object[], QuantileSearchCriteria) getPMF(splitPoints, INCLUSIVE)}
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getPMF(T[] splitPoints) {
return getPMF(splitPoints, INCLUSIVE);
}
/**
* Returns an approximation to the Probability Mass Function (PMF) of the input stream
* as an array of probability masses as doubles on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(true) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> consecutive, non-overlapping intervals.
*
* <p>Each interval except for the end intervals starts with a split point and ends with the next split
* point in sequence.</p>
*
* <p>The first interval starts below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and ends with the first split point</p>
*
* <p>The last <i>(m+1)th</i> interval starts with the last split point and ends after the last
* item retained by the sketch corresponding to a rank or probability of 1.0. </p>
*
* <p>The sum of the probability masses of all <i>(m+1)</i> intervals is 1.0.</p>
*
* <p>If the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will include that item. If the lower split point equals an item retained by the sketch, the interval will exclude
* that item.</li>
* <li>EXCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will exclude that item. If the lower split point equals an item retained by the sketch, the interval will include
* that item.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
double[] getPMF(T[] splitPoints, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getQuantile(double, QuantileSearchCriteria) getQuantile(rank, INCLUSIVE)}
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
*/
default T getQuantile(double rank) {
return getQuantile(rank, INCLUSIVE);
}
/**
* Gets the approximate quantile of the given normalized rank and the given search criterion.
*
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @param searchCrit If INCLUSIVE, the given rank includes all quantiles ≤
* the quantile directly corresponding to the given rank.
* If EXCLUSIVE, he given rank includes all quantiles <
* the quantile directly corresponding to the given rank.
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
T getQuantile(double rank, QuantileSearchCriteria searchCrit);
/**
* Gets the lower bound of the quantile confidence interval in which the quantile of the
* given rank exists.
*
* <p>Although it is possible to estimate the probability that the true quantile
* exists within the quantile confidence interval specified by the upper and lower quantile bounds,
* it is not possible to guarantee the width of the quantile confidence interval
* as an additive or multiplicative percent of the true quantile.</p>
*
* @param rank the given normalized rank
* @return the lower bound of the quantile confidence interval in which the quantile of the
* given rank exists.
* @throws IllegalArgumentException if sketch is empty.
*/
T getQuantileLowerBound(double rank);
/**
* Gets the upper bound of the quantile confidence interval in which the true quantile of the
* given rank exists.
*
* <p>Although it is possible to estimate the probability that the true quantile
* exists within the quantile confidence interval specified by the upper and lower quantile bounds,
* it is not possible to guarantee the width of the quantile interval
* as an additive or multiplicative percent of the true quantile.</p>
*
* @param rank the given normalized rank
* @return the upper bound of the quantile confidence interval in which the true quantile of the
* given rank exists.
* @throws IllegalArgumentException if sketch is empty.
*/
T getQuantileUpperBound(double rank);
/**
* This is equivalent to {@link #getQuantiles(double[], QuantileSearchCriteria) getQuantiles(ranks, INCLUSIVE)}
* @param ranks the given array of normalized ranks, each of which must be
* in the interval [0.0,1.0].
* @return an array of quantiles corresponding to the given array of normalized ranks.
* @throws IllegalArgumentException if sketch is empty.
*/
default T[] getQuantiles(double[] ranks) {
return getQuantiles(ranks, INCLUSIVE);
}
/**
* Gets an array of quantiles from the given array of normalized ranks.
*
* @param ranks the given array of normalized ranks, each of which must be
* in the interval [0.0,1.0].
* @param searchCrit if INCLUSIVE, the given ranks include all quantiles ≤
* the quantile directly corresponding to each rank.
* @return an array of quantiles corresponding to the given array of normalized ranks.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
T[] getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getRank(Object, QuantileSearchCriteria) getRank(T quantile, INCLUSIVE)}
* @param quantile the given quantile
* @return the normalized rank corresponding to the given quantile.
* @throws IllegalArgumentException if sketch is empty.
*/
default double getRank(T quantile) {
return getRank(quantile, INCLUSIVE);
}
/**
* Gets the normalized rank corresponding to the given a quantile.
*
* @param quantile the given quantile
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
* @return the normalized rank corresponding to the given quantile.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double getRank(T quantile, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getRanks(Object[], QuantileSearchCriteria) getRanks(quantiles, INCLUSIVE)}
* @param quantiles the given array of quantiles
* @return an array of normalized ranks corresponding to the given array of quantiles.
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getRanks(T[] quantiles) {
return getRanks(quantiles, INCLUSIVE);
}
/**
* Gets an array of normalized ranks corresponding to the given array of quantiles and the given
* search criterion.
*
* @param quantiles the given array of quantiles
* @param searchCrit if INCLUSIVE, the given quantiles include the rank directly corresponding to each quantile.
* @return an array of normalized ranks corresponding to the given array of quantiles.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double[] getRanks(T[] quantiles, QuantileSearchCriteria searchCrit);
/**
* Gets the sorted view of this sketch
* @return the sorted view of this sketch
*/
GenericSortedView<T> getSortedView();
/**
* Gets the iterator for this sketch, which is not sorted.
* @return the iterator for this sketch
*/
QuantilesGenericSketchIterator<T> iterator();
/**
* Updates this sketch with the given item.
* @param item from a stream of items. Nulls are ignored.
*/
void update(T item);
/**
* This encapsulates the essential information needed to construct actual partitions and is returned from the
* <i>getPartitionBoundaries(int, QuantileSearchCritera)</i> method.
* @param <T> generic value T for the item type
*/
static class GenericPartitionBoundaries<T> {
/**
* The total number of items presented to the sketch.
*
* <p>To compute the weight or density of a specific
* partition <i>i</i> where <i>i</i> varies from 1 to <i>m</i> partitions:
* <pre>{@code
* long N = getN();
* double[] ranks = getRanks();
* long weight = Math.round((ranks[i] - ranks[i - 1]) * N);
* }</pre>
*/
public long N;
/**
* The normalized ranks that correspond to the returned boundaries.
* The returned array is of size <i>(m + 1)</i>, where <i>m</i> is the requested number of partitions.
* Index 0 of the returned array is always 0.0, and index <i>m</i> is always 1.0.
*/
public double[] ranks;
/**
* The partition boundaries as quantiles.
* The returned array is of size <i>(m + 1)</i>, where <i>m</i> is the requested number of partitions.
* Index 0 of the returned array is always {@link #getMinItem() getMinItem()}, and index <i>m</i> is always
* {@link #getMaxItem() getMaxItem()}.
*/
public T[] boundaries;
}
}
| 2,720 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantileSearchCriteria.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* These search criteria are used by the KLL, REQ and Classic Quantiles sketches in the DataSketches library.
*
* @see <a href="https://datasketches.apache.org/docs/Quantiles/SketchingQuantilesAndRanksTutorial.html">
* Sketching Quantiles and Ranks Tutorial</a>
*
* @author Lee Rhodes
*/
public enum QuantileSearchCriteria {
/**
* <b>Definition of INCLUSIVE <i>getQuantile(r)</i> search:</b><br>
* Given rank <i>r</i>, return the quantile of the smallest rank that is
* strictly greater than or equal to <i>r</i>.
*
* <p><b>Definition of INCLUSIVE <i>getRank(q)</i> search:</b><br>
* Given quantile <i>q</i>, return the rank, <i>r</i>, of the largest quantile that is
* less than or equal to <i>q</i>.</p>
*/
INCLUSIVE,
/**
* <b>Definition of EXCLUSIVE <i>getQuantile(r)</i> search:</b><br>
* Given rank <i>r</i>, return the quantile of the smallest rank that is
* strictly greater than <i>r</i>.
*
* <p>However, if the given rank is is equal to 1.0, or there is no quantile that satisfies this criterion
* the method will return a <i>NaN</i> or <i>null</i>.</p>
*
* <p><b>Definition of EXCLUSIVE <i>getRank(q)</i> search:</b><br>
* Given quantile <i>q</i>, return the rank, <i>r</i>, of the largest quantile that is
* strictly less than <i>q</i>.</p>
*
* <p>If there is no quantile value that is strictly less than <i>q</i>,
* the method will return a rank of zero.</p>
*
*/
EXCLUSIVE;
}
| 2,721 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/GenericSortedViewIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
/**
* The quantiles SortedView Iterator for generic types.
* @see SortedViewIterator
* @param <T> The generic quantile type
* @author Alexander Saydakov
* @author Lee Rhodes
*/
public class GenericSortedViewIterator<T> implements SortedViewIterator {
private final T[] quantiles;
private final long[] cumWeights;
private final long totalN;
private int index;
public GenericSortedViewIterator(final T[] quantiles, final long[] cumWeights) {
this.quantiles = quantiles; //SpotBugs EI_EXPOSE_REP2 suppressed by FindBugsExcludeFilter
this.cumWeights = cumWeights; //SpotBugs EI_EXPOSE_REP2 suppressed by FindBugsExcludeFilter
this.totalN = (cumWeights.length > 0) ? cumWeights[cumWeights.length - 1] : 0;
index = -1;
}
@Override
public long getCumulativeWeight(final QuantileSearchCriteria searchCrit) {
if (searchCrit == INCLUSIVE) { return cumWeights[index]; }
return (index == 0) ? 0 : cumWeights[index - 1];
}
public T getQuantile() {
return quantiles[index];
}
@Override
public long getN() {
return totalN;
}
@Override
public double getNormalizedRank(final QuantileSearchCriteria searchCrit) {
return (double) getCumulativeWeight(searchCrit) / totalN;
}
@Override
public long getWeight() {
if (index == 0) { return cumWeights[0]; }
return cumWeights[index] - cumWeights[index - 1];
}
@Override
public boolean next() {
index++;
return index < quantiles.length;
}
}
| 2,722 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesFloatsSketchIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* The quantiles sketch iterator for primitive type float.
* @see QuantilesSketchIterator
* @author Lee Rhodes
*/
public interface QuantilesFloatsSketchIterator extends QuantilesSketchIterator {
/**
* Gets the float quantile at the current index.
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @return the float quantile at the current index.
*/
float getQuantile();
}
| 2,723 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/BinarySearch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* Contains common equality binary search algorithms.
*
* @author Lee Rhodes
*/
public final class BinarySearch {
/**
* Binary Search for the index of the exact float value in the given search range.
* If -1 is returned there are no values in the search range that equals the given value.
* @param arr The given ordered array to search.
* @param low the index of the lowest value of the search range
* @param high the index of the highest value of the search range
* @param v the value to search for
* @return return the index of the value, if found, otherwise, return -1;
*/
public static int find(final float[] arr, final int low, final int high, final float v) {
int lo = low;
int hi = high;
while (lo <= hi) {
final int mid = lo + (hi - lo) / 2;
if (v < arr[mid]) { hi = mid - 1; }
else {
if (v > arr[mid]) { lo = mid + 1; }
else { return mid; }
}
}
return -1;
}
/**
* Binary Search for the index of the exact double value in the given search range.
* If -1 is returned there are no values in the search range that equals the given value.
* @param arr The given ordered array to search.
* @param low the index of the lowest value of the search range
* @param high the index of the highest value of the search range
* @param v the value to search for
* @return return the index of the value, if found, otherwise, return -1;
*/
public static int find(final double[] arr, final int low, final int high, final double v) {
int lo = low;
int hi = high;
while (lo <= hi) {
final int mid = lo + (hi - lo) / 2;
if (v < arr[mid]) { hi = mid - 1; }
else {
if (v > arr[mid]) { lo = mid + 1; }
else { return mid; }
}
}
return -1;
}
/**
* Binary Search for the index of the exact long value in the given search range.
* If -1 is returned there are no values in the search range that equals the given value.
* @param arr The given ordered array to search.
* @param low the index of the lowest value of the search range
* @param high the index of the highest value of the search range
* @param v the value to search for
* @return return the index of the value, if found, otherwise, return -1;
*/
public static int find(final long[] arr, final int low, final int high, final long v) {
int lo = low;
int hi = high;
while (lo <= hi) {
final int mid = lo + (hi - lo) / 2;
if (v < arr[mid]) { hi = mid - 1; }
else {
if (v > arr[mid]) { lo = mid + 1; }
else { return mid; }
}
}
return -1;
}
}
| 2,724 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesUtil.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
import static java.lang.Math.log;
import static java.lang.Math.pow;
import java.util.Objects;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.Util;
/**
* Utilities for the quantiles sketches.
*
* @author Lee Rhodes
*/
public final class QuantilesUtil {
private QuantilesUtil() {}
/**
* Checks that the given normalized rank: <i>0 ≤ nRank ≤ 1.0</i>.
* @param nRank the given normalized rank.
*/
public static final void checkNormalizedRankBounds(final double nRank) {
if ((nRank < 0.0) || (nRank > 1.0)) {
throw new SketchesArgumentException(
"A normalized rank must be >= 0 and <= 1.0: " + nRank);
}
}
/**
* Checks the sequential validity of the given array of double values.
* They must be unique, monotonically increasing and not NaN.
* @param values the given array of double values
*/
public static final void checkDoublesSplitPointsOrder(final double[] values) {
Objects.requireNonNull(values);
final int len = values.length;
if (len == 1 && Double.isNaN(values[0])) {
throw new SketchesArgumentException(
"Values must be unique, monotonically increasing and not NaN.");
}
for (int j = 0; j < len - 1; j++) {
if (values[j] < values[j + 1]) { continue; }
throw new SketchesArgumentException(
"Values must be unique, monotonically increasing and not NaN.");
}
}
/**
* Checks the sequential validity of the given array of float values.
* They must be unique, monotonically increasing and not NaN.
* @param values the given array of double values
*/
public static final void checkFloatsSplitPointsOrder(final float[] values) {
Objects.requireNonNull(values);
final int len = values.length;
if (len == 1 && Float.isNaN(values[0])) {
throw new SketchesArgumentException(
"Values must be unique, monotonically increasing and not NaN.");
}
for (int j = 0; j < len - 1; j++) {
if (values[j] < values[j + 1]) { continue; }
throw new SketchesArgumentException(
"Values must be unique, monotonically increasing and not NaN.");
}
}
/**
* Returns a double array of ranks that defines equally weighted regions between 0.0, inclusive and 1.0, inclusive.
* The 0.0 and 1.0 end points are part of the returned array and are the getMinItem() and getMaxItem() values of the
* sketch.
* For example, if num == 2, three values will be returned: 0.0, .5, and 1, where the two equally weighted regions are
* 0.0 to 0.5, and 0.5 to 1.0.
* @param num the total number of equally weighted regions between 0.0 and 1.0 defined by the ranks in the returned
* array. <i>num</i> must be 1 or greater.
* @return a double array of <i>num + 1</i> ranks that define the boundaries of <i>num</i> equally weighted
* regions between 0.0, inclusive and 1.0, inclusive.
* @throws IllegalArgumentException if <i>num</i> is less than 1.
*/
public static double[] equallyWeightedRanks(final int num) {
if (num < 1) { throw new IllegalArgumentException("num must be >= 1"); }
final double[] out = new double[num + 1];
out[0] = 0.0;
out[num] = 1.0;
final double delta = 1.0 / num;
for (int i = 1; i < num; i++) { out[i] = i * delta; }
return out;
}
/**
* Returns a float array of evenly spaced values between value1, inclusive, and value2 inclusive.
* If value2 > value1, the resulting sequence will be increasing.
* If value2 < value1, the resulting sequence will be decreasing.
* @param value1 will be in index 0 of the returned array
* @param value2 will be in the highest index of the returned array
* @param num the total number of values including value1 and value2. Must be 2 or greater.
* @return a float array of evenly spaced values between value1, inclusive, and value2 inclusive.
*/
public static float[] evenlySpacedFloats(final float value1, final float value2, final int num) {
if (num < 2) {
throw new SketchesArgumentException("num must be >= 2");
}
final float[] out = new float[num];
out[0] = value1;
out[num - 1] = value2;
if (num == 2) { return out; }
final float delta = (value2 - value1) / (num - 1);
for (int i = 1; i < num - 1; i++) { out[i] = i * delta + value1; }
return out;
}
/**
* Returns a double array of evenly spaced values between value1, inclusive, and value2 inclusive.
* If value2 > value1, the resulting sequence will be increasing.
* If value2 < value1, the resulting sequence will be decreasing.
* @param value1 will be in index 0 of the returned array
* @param value2 will be in the highest index of the returned array
* @param num the total number of values including value1 and value2. Must be 2 or greater.
* @return a float array of evenly spaced values between value1, inclusive, and value2 inclusive.
*/
public static double[] evenlySpacedDoubles(final double value1, final double value2, final int num) {
if (num < 2) {
throw new SketchesArgumentException("num must be >= 2");
}
final double[] out = new double[num];
out[0] = value1;
out[num - 1] = value2;
if (num == 2) { return out; }
final double delta = (value2 - value1) / (num - 1);
for (int i = 1; i < num - 1; i++) { out[i] = i * delta + value1; }
return out;
}
/**
* Returns a double array of values between min and max inclusive where the log of the
* returned values are evenly spaced.
* If value2 > value1, the resulting sequence will be increasing.
* If value2 < value1, the resulting sequence will be decreasing.
* @param value1 will be in index 0 of the returned array, and must be greater than zero.
* @param value2 will be in the highest index of the returned array, and must be greater than zero.
* @param num the total number of values including value1 and value2. Must be 2 or greater
* @return a double array of exponentially spaced values between value1 and value2 inclusive.
*/
public static double[] evenlyLogSpaced(final double value1, final double value2, final int num) {
if (num < 2) {
throw new SketchesArgumentException("num must be >= 2");
}
if (value1 <= 0 || value2 <= 0) {
throw new SketchesArgumentException("value1 and value2 must be > 0.");
}
final double[] arr = evenlySpacedDoubles(log(value1) / Util.LOG2, log(value2) / Util.LOG2, num);
for (int i = 0; i < arr.length; i++) { arr[i] = pow(2.0,arr[i]); }
return arr;
}
}
| 2,725 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesFloatsAPI.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
/**
* The Quantiles API for item type <i>float</i>.
* @see QuantilesAPI
* @author Lee Rhodes
*/
public interface QuantilesFloatsAPI extends QuantilesAPI {
/**
* This is equivalent to {@link #getCDF(float[], QuantileSearchCriteria) getCDF(splitPoints, INCLUSIVE)}
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getCDF(float[] splitPoints) {
return getCDF(splitPoints, INCLUSIVE);
}
/**
* Returns an approximation to the Cumulative Distribution Function (CDF) of the input stream
* as a monotonically increasing array of double ranks (or cumulative probabilities) on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(false) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> overlapping intervals.
*
* <p>The start of each interval is below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and the end of the interval
* is the rank or cumulative probability corresponding to the split point.</p>
*
* <p>The <i>(m+1)th</i> interval represents 100% of the distribution represented by the sketch
* and consistent with the definition of a cumulative probability distribution, thus the <i>(m+1)th</i>
* rank or probability in the returned array is always 1.0.</p>
*
* <p>If a split point exactly equals a retained item of the sketch and the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, the resulting cumulative probability will include that item.</li>
* <li>EXCLUSIVE, the resulting cumulative probability will not include the weight of that split point.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a discrete CDF array of m+1 double ranks (or cumulative probabilities) on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
double[] getCDF(float[] splitPoints, QuantileSearchCriteria searchCrit);
/**
* Returns the maximum item of the stream. This is provided for convenience, but may be different from the largest
* item retained by the sketch algorithm.
*
* @return the maximum item of the stream
* @throws IllegalArgumentException if sketch is empty.
*/
float getMaxItem();
/**
* Returns the minimum item of the stream. This is provided for convenience, but is distinct from the smallest
* item retained by the sketch algorithm.
*
* @return the minimum item of the stream
* @throws IllegalArgumentException if sketch is empty.
*/
float getMinItem();
/**
* This method returns an instance of {@link FloatsPartitionBoundaries FloatsPartitionBoundaries} which provides
* sufficient information for the user to create the given number of equally weighted partitions.
*
* <p>This method is equivalent to
* {@link #getPartitionBoundaries(int, QuantileSearchCriteria) getPartitionBoundaries(numEquallyWeighted, INCLUSIVE)}.
* </p>
*
* @param numEquallyWeighted an integer that specifies the number of equally weighted partitions between
* {@link #getMinItem() getMinItem()} and {@link #getMaxItem() getMaxItem()}.
* This must be a positive integer greater than zero.
* <ul>
* <li>A 1 will return: minItem, maxItem.</li>
* <li>A 2 will return: minItem, median quantile, maxItem.</li>
* <li>Etc.</li>
* </ul>
*
* @return an instance of {@link FloatsPartitionBoundaries FloatsPartitionBoundaries}.
* @throws IllegalArgumentException if sketch is empty.
* @throws IllegalArgumentException if <i>numEquallyWeighted</i> is less than 1.
*/
default FloatsPartitionBoundaries getPartitionBoundaries(int numEquallyWeighted) {
return getPartitionBoundaries(numEquallyWeighted, INCLUSIVE);
}
/**
* This method returns an instance of {@link FloatsPartitionBoundaries FloatsPartitionBoundaries} which provides
* sufficient information for the user to create the given number of equally weighted partitions.
*
* @param numEquallyWeighted an integer that specifies the number of equally weighted partitions between
* {@link #getMinItem() getMinItem()} and {@link #getMaxItem() getMaxItem()}.
* This must be a positive integer greater than zero.
* <ul>
* <li>A 1 will return: minItem, maxItem.</li>
* <li>A 2 will return: minItem, median quantile, maxItem.</li>
* <li>Etc.</li>
* </ul>
*
* @param searchCrit
* If INCLUSIVE, all the returned quantiles are the upper boundaries of the equally weighted partitions
* with the exception of the lowest returned quantile, which is the lowest boundary of the lowest ranked partition.
* If EXCLUSIVE, all the returned quantiles are the lower boundaries of the equally weighted partitions
* with the exception of the highest returned quantile, which is the upper boundary of the highest ranked partition.
*
* @return an instance of {@link FloatsPartitionBoundaries FloatsPartitionBoundaries}.
* @throws IllegalArgumentException if sketch is empty.
* @throws IllegalArgumentException if <i>numEquallyWeighted</i> is less than 1.
*/
FloatsPartitionBoundaries getPartitionBoundaries(int numEquallyWeighted, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getPMF(float[], QuantileSearchCriteria) getPMF(splitPoints, INCLUSIVE)}
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getPMF(float[] splitPoints) {
return getPMF(splitPoints, INCLUSIVE);
}
/**
* Returns an approximation to the Probability Mass Function (PMF) of the input stream
* as an array of probability masses as doubles on the interval [0.0, 1.0],
* given a set of splitPoints.
*
* <p>The resulting approximations have a probabilistic guarantee that can be obtained from the
* getNormalizedRankError(true) function.</p>
*
* @param splitPoints an array of <i>m</i> unique, monotonically increasing items
* (of the same type as the input items)
* that divide the item input domain into <i>m+1</i> consecutive, non-overlapping intervals.
*
* <p>Each interval except for the end intervals starts with a split point and ends with the next split
* point in sequence.</p>
*
* <p>The first interval starts below the lowest item retained by the sketch
* corresponding to a zero rank or zero probability, and ends with the first split point</p>
*
* <p>The last <i>(m+1)th</i> interval starts with the last split point and ends after the last
* item retained by the sketch corresponding to a rank or probability of 1.0. </p>
*
* <p>The sum of the probability masses of all <i>(m+1)</i> intervals is 1.0.</p>
*
* <p>If the search criterion is:</p>
*
* <ul>
* <li>INCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will include that item. If the lower split point equals an item retained by the sketch, the interval will exclude
* that item.</li>
* <li>EXCLUSIVE, and the upper split point of an interval equals an item retained by the sketch, the interval
* will exclude that item. If the lower split point equals an item retained by the sketch, the interval will include
* that item.</li>
* </ul>
*
* <p>It is not recommended to include either the minimum or maximum items of the input stream.</p>
*
* @param searchCrit the desired search criteria.
* @return a PMF array of m+1 probability masses as doubles on the interval [0.0, 1.0].
* @throws IllegalArgumentException if sketch is empty.
*/
double[] getPMF(float[] splitPoints, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getQuantile(double, QuantileSearchCriteria) getQuantile(rank, INCLUSIVE)}
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
*/
default float getQuantile(double rank) {
return getQuantile(rank, INCLUSIVE);
}
/**
* Gets the approximate quantile of the given normalized rank and the given search criterion.
*
* @param rank the given normalized rank, a double in the range [0.0, 1.0].
* @param searchCrit If INCLUSIVE, the given rank includes all quantiles ≤
* the quantile directly corresponding to the given rank.
* If EXCLUSIVE, he given rank includes all quantiles <
* the quantile directly corresponding to the given rank.
* @return the approximate quantile given the normalized rank.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
float getQuantile(double rank, QuantileSearchCriteria searchCrit);
/**
* Gets the lower bound of the quantile confidence interval in which the quantile of the
* given rank exists.
*
* <p>Although it is possible to estimate the probablity that the true quantile
* exists within the quantile confidence interval specified by the upper and lower quantile bounds,
* it is not possible to guarantee the width of the quantile confidence interval
* as an additive or multiplicative percent of the true quantile.</p>
*
* @param rank the given normalized rank
* @return the lower bound of the quantile confidence interval in which the quantile of the
* given rank exists.
* @throws IllegalArgumentException if sketch is empty.
*/
float getQuantileLowerBound(double rank);
/**
* Gets the upper bound of the quantile confidence interval in which the true quantile of the
* given rank exists.
*
* <p>Although it is possible to estimate the probablity that the true quantile
* exists within the quantile confidence interval specified by the upper and lower quantile bounds,
* it is not possible to guarantee the width of the quantile interval
* as an additive or multiplicative percent of the true quantile.</p>
*
* @param rank the given normalized rank
* @return the upper bound of the quantile confidence interval in which the true quantile of the
* given rank exists.
* @throws IllegalArgumentException if sketch is empty.
*/
float getQuantileUpperBound(double rank);
/**
* This is equivalent to {@link #getQuantiles(double[], QuantileSearchCriteria) getQuantiles(ranks, INCLUSIVE)}
* @param ranks the given array of normalized ranks, each of which must be
* in the interval [0.0,1.0].
* @return an array of quantiles corresponding to the given array of normalized ranks.
* @throws IllegalArgumentException if sketch is empty.
*/
default float[] getQuantiles(double[] ranks) {
return getQuantiles(ranks, INCLUSIVE);
}
/**
* Gets an array of quantiles from the given array of normalized ranks.
*
* @param ranks the given array of normalized ranks, each of which must be
* in the interval [0.0,1.0].
* @param searchCrit if INCLUSIVE, the given ranks include all quantiles ≤
* the quantile directly corresponding to each rank.
* @return an array of quantiles corresponding to the given array of normalized ranks.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
float[] getQuantiles(double[] ranks, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getRank(float, QuantileSearchCriteria) getRank(quantile, INCLUSIVE)}
* @param quantile the given quantile
* @return the normalized rank corresponding to the given quantile.
* @throws IllegalArgumentException if sketch is empty.
*/
default double getRank(float quantile) {
return getRank(quantile, INCLUSIVE);
}
/**
* Gets the normalized rank corresponding to the given a quantile.
*
* @param quantile the given quantile
* @param searchCrit if INCLUSIVE the given quantile is included into the rank.
* @return the normalized rank corresponding to the given quantile.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double getRank(float quantile, QuantileSearchCriteria searchCrit);
/**
* This is equivalent to {@link #getRanks(float[], QuantileSearchCriteria) getRanks(quantiles, INCLUSIVE)}
* @param quantiles the given array of quantiles
* @return an array of normalized ranks corresponding to the given array of quantiles.
* @throws IllegalArgumentException if sketch is empty.
*/
default double[] getRanks(float[] quantiles) {
return getRanks(quantiles, INCLUSIVE);
}
/**
* Gets an array of normalized ranks corresponding to the given array of quantiles and the given
* search criterion.
*
* @param quantiles the given array of quantiles
* @param searchCrit if INCLUSIVE, the given quantiles include the rank directly corresponding to each quantile.
* @return an array of normalized ranks corresponding to the given array of quantiles.
* @throws IllegalArgumentException if sketch is empty.
* @see org.apache.datasketches.quantilescommon.QuantileSearchCriteria
*/
double[] getRanks(float[] quantiles, QuantileSearchCriteria searchCrit);
/**
* Returns the current number of bytes this Sketch would require if serialized.
* @return the number of bytes this sketch would require if serialized.
*/
int getSerializedSizeBytes();
/**
* Gets the sorted view of this sketch
* @return the sorted view of this sketch
*/
FloatsSortedView getSortedView();
/**
* Gets the iterator for this sketch, which is not sorted.
* @return the iterator for this sketch
*/
QuantilesFloatsSketchIterator iterator();
/**
* Returns a byte array representation of this sketch.
* @return a byte array representation of this sketch.
*/
byte[] toByteArray();
/**
* Updates this sketch with the given item.
* @param item from a stream of quantiles. NaNs are ignored.
*/
void update(float item);
/**
* This encapsulates the essential information needed to construct actual partitions and is returned from the
* <i>getPartitionBoundaries(int, QuantileSearchCritera)</i> method.
*/
static class FloatsPartitionBoundaries {
/**
* The total number of items presented to the sketch.
*
* <p>To compute the weight or density of a specific
* partition <i>i</i> where <i>i</i> varies from 1 to <i>m</i> partitions:
* <pre>{@code
* long N = getN();
* double[] ranks = getRanks();
* long weight = Math.round((ranks[i] - ranks[i - 1]) * N);
* }</pre>
*/
public long N;
/**
* The normalized ranks that correspond to the returned boundaries.
* The returned array is of size <i>(m + 1)</i>, where <i>m</i> is the requested number of partitions.
* Index 0 of the returned array is always 0.0, and index <i>m</i> is always 1.0.
*/
public double[] ranks;
/**
* The partition boundaries as quantiles.
* The returned array is of size <i>(m + 1)</i>, where <i>m</i> is the requested number of partitions.
* Index 0 of the returned array is always {@link #getMinItem() getMinItem()}, and index <i>m</i> is always
* {@link #getMaxItem() getMaxItem()}.
*/
public float[] boundaries;
}
}
| 2,726 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/QuantilesGenericSketchIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* The quantiles sketch iterator for generic types.
* @see QuantilesSketchIterator
* @param <T> The generic quantile type
* @author Lee Rhodes
*/
public interface QuantilesGenericSketchIterator<T> extends QuantilesSketchIterator {
/**
* Gets the generic quantile at the current index.
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @return the generic quantile at the current index.
*/
T getQuantile();
}
| 2,727 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/FloatsSortedViewIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantilescommon;
/**
* The quantiles SortedView Iterator for type float.
* @see SortedViewIterator
* @author Alexander Saydakov
* @author Lee Rhodes
*/
public interface FloatsSortedViewIterator extends SortedViewIterator {
/**
* Gets the quantile at the current index.
*
* <p>Don't call this before calling next() for the first time
* or after getting false from next().</p>
*
* @return the quantile at the current index.
*/
float getQuantile();
}
| 2,728 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantilescommon/package-info.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* This package contains common tools and methods for the <i>quantiles</i>, <i>kll</i> and
* <i>req</i> packages.
*/
package org.apache.datasketches.quantilescommon;
| 2,729 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CpcSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static java.lang.Math.log;
import static java.lang.Math.sqrt;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.datasketches.common.Util.invPow2;
import static org.apache.datasketches.common.Util.zeroPad;
import static org.apache.datasketches.cpc.CpcUtil.bitMatrixOfSketch;
import static org.apache.datasketches.cpc.CpcUtil.checkLgK;
import static org.apache.datasketches.cpc.CpcUtil.countBitsSetInMatrix;
import static org.apache.datasketches.hash.MurmurHash3.hash;
import java.util.Arrays;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* This is a unique-counting sketch that implements the
* <i>Compressed Probabilistic Counting (CPC, a.k.a FM85)</i> algorithms developed by Kevin Lang in
* his paper
* <a href="https://arxiv.org/abs/1708.06839">Back to the Future: an Even More Nearly
* Optimal Cardinality Estimation Algorithm</a>.
*
* <p>This sketch is extremely space-efficient when serialized. In an apples-to-apples empirical
* comparison against compressed HyperLogLog sketches, this new algorithm simultaneously wins on
* the two dimensions of the space/accuracy tradeoff and produces sketches that are
* smaller than the entropy of HLL, so no possible implementation of compressed HLL can match its
* space efficiency for a given accuracy. As described in the paper this sketch implements a newly
* developed ICON estimator algorithm that survives unioning operations, another
* well-known estimator, the
* <a href="https://arxiv.org/abs/1306.3284">Historical Inverse Probability (HIP)</a> estimator
* does not.
* The update speed performance of this sketch is quite fast and is comparable to the speed of HLL.
* The unioning (merging) capability of this sketch also allows for merging of sketches with
* different configurations of K.
*
* <p>For additional security this sketch can be configured with a user-specified hash seed.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
public final class CpcSketch {
private static final String LS = System.getProperty("line.separator");
private static final double[] kxpByteLookup = new double[256];
/**
* The default Log_base2 of K
*/
public static final int DEFAULT_LG_K = 11;
final long seed;
//common variables
final int lgK;
long numCoupons; // The number of coupons collected so far.
boolean mergeFlag; // Is the sketch the result of merging?
int fiCol; // First Interesting Column. This is part of a speed optimization.
int windowOffset;
byte[] slidingWindow; //either null or size K bytes
PairTable pairTable; //for sparse and surprising values, either null or variable size
//The following variables are only valid in HIP varients
double kxp; //used with HIP
double hipEstAccum; //used with HIP
/**
* Constructor with default log_base2 of k
*/
public CpcSketch() {
this(DEFAULT_LG_K, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Constructor with log_base2 of k.
* @param lgK the given log_base2 of k
*/
public CpcSketch(final int lgK) {
this(lgK, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Constructor with log_base2 of k and seed.
* @param lgK the given log_base2 of k
* @param seed the given seed
*/
public CpcSketch(final int lgK, final long seed) {
checkLgK(lgK);
this.lgK = (byte) lgK;
this.seed = seed;
kxp = 1 << lgK;
reset();
}
/**
* Returns a copy of this sketch
* @return a copy of this sketch
*/
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;
}
/**
* Returns the best estimate of the cardinality of the sketch.
* @return the best estimate of the cardinality of the sketch.
*/
public double getEstimate() {
if (mergeFlag) { return IconEstimator.getIconEstimate(lgK, numCoupons); }
return hipEstAccum;
}
/**
* Return the DataSketches identifier for this CPC family of sketches.
* @return the DataSketches identifier for this CPC family of sketches.
*/
public static Family getFamily() {
return Family.CPC;
}
/**
* Return the parameter LgK.
* @return the parameter LgK.
*/
public int getLgK() {
return lgK;
}
/**
* Returns the best estimate of the lower bound of the confidence interval given <i>kappa</i>,
* the number of standard deviations from the mean.
* @param kappa the given number of standard deviations from the mean: 1, 2 or 3.
* @return the best estimate of the lower bound of the confidence interval given <i>kappa</i>.
*/
public double getLowerBound(final int kappa) {
if (mergeFlag) {
return CpcConfidence.getIconConfidenceLB(lgK, numCoupons, kappa);
}
return CpcConfidence.getHipConfidenceLB(lgK, numCoupons, hipEstAccum, kappa);
}
/*
* These empirical values for the 99.9th percentile of size in bytes were measured using 100,000
* trials. The value for each trial is the maximum of 5*16=80 measurements that were equally
* spaced over values of the quantity C/K between 3.0 and 8.0. This table does not include the
* worst-case space for the preamble, which is added by the function.
*/
private static final int empiricalSizeMaxLgK = 19;
private static final int[] empiricalMaxBytes = {
24, // lgK = 4
36, // lgK = 5
56, // lgK = 6
100, // lgK = 7
180, // lgK = 8
344, // lgK = 9
660, // lgK = 10
1292, // lgK = 11
2540, // lgK = 12
5020, // lgK = 13
9968, // lgK = 14
19836, // lgK = 15
39532, // lgK = 16
78880, // lgK = 17
157516, // lgK = 18
314656 // lgK = 19
};
private static final double empiricalMaxSizeFactor = 0.6; // 0.6 = 4.8 / 8.0
private static final int maxPreambleSizeBytes = 40;
/**
* 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.
*/
public static int getMaxSerializedBytes(final int lgK) {
checkLgK(lgK);
if (lgK <= empiricalSizeMaxLgK) { return empiricalMaxBytes[lgK - CpcUtil.minLgK] + maxPreambleSizeBytes; }
final int k = 1 << lgK;
return (int) (empiricalMaxSizeFactor * k) + maxPreambleSizeBytes;
}
/**
* Returns the best estimate of the upper bound of the confidence interval given <i>kappa</i>,
* the number of standard deviations from the mean.
* @param kappa the given number of standard deviations from the mean: 1, 2 or 3.
* @return the best estimate of the upper bound of the confidence interval given <i>kappa</i>.
*/
public double getUpperBound(final int kappa) {
if (mergeFlag) {
return CpcConfidence.getIconConfidenceUB(lgK, numCoupons, kappa);
}
return CpcConfidence.getHipConfidenceUB(lgK, numCoupons, hipEstAccum, kappa);
}
/**
* Return the given Memory as a CpcSketch on the Java heap using the DEFAULT_UPDATE_SEED.
* @param mem the given Memory
* @return the given Memory as a CpcSketch on the Java heap.
*/
public static CpcSketch heapify(final Memory mem) {
return heapify(mem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Return the given byte array as a CpcSketch on the Java heap using the DEFAULT_UPDATE_SEED.
* @param byteArray the given byte array
* @return the given byte array as a CpcSketch on the Java heap.
*/
public static CpcSketch heapify(final byte[] byteArray) {
return heapify(byteArray, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* 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.
*/
public static CpcSketch heapify(final Memory mem, final long seed) {
final CompressedState state = CompressedState.importFromMemory(mem);
return uncompress(state, seed);
}
/**
* 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.
*/
public static CpcSketch heapify(final byte[] byteArray, final long seed) {
final Memory mem = Memory.wrap(byteArray);
return heapify(mem, seed);
}
/**
* Return true if this sketch is empty
* @return true if this sketch is empty
*/
public boolean isEmpty() {
return numCoupons == 0;
}
/**
* Resets this sketch to empty but retains the original LgK and Seed.
*/
public final void reset() {
numCoupons = 0;
mergeFlag = false;
fiCol = 0;
windowOffset = 0;
slidingWindow = null;
pairTable = null;
kxp = 1 << lgK;
hipEstAccum = 0;
}
/**
* Return this sketch as a compressed byte array.
* @return this sketch as a compressed byte array.
*/
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();
}
/**
* Present the given long as a potential unique item.
*
* @param datum The given long datum.
*/
public void update(final long datum) {
final long[] data = { datum };
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
}
/**
* Present the given double (or float) datum as a potential unique item.
* The double will be converted to a long using Double.doubleToLongBits(datum),
* which normalizes all NaN values to a single NaN representation.
* Plus and minus zero will be normalized to plus zero.
* The special floating-point values NaN and +/- Infinity are treated as distinct.
*
* @param datum The given double datum.
*/
public void update(final double datum) {
final double d = (datum == 0.0) ? 0.0 : datum; // canonicalize -0.0, 0.0
final long[] data = { Double.doubleToLongBits(d) };// canonicalize all NaN forms
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
}
/**
* Present the given String as a potential unique item.
* The string is converted to a byte array using UTF8 encoding.
* If the string is null or empty no update attempt is made and the method returns.
*
* <p>Note: About 2X faster performance can be obtained by first converting the String to a
* char[] and updating the sketch with that. This bypasses the complexity of the Java UTF_8
* encoding. This, of course, will not produce the same internal hash values as updating directly
* with a String. So be consistent! Unioning two sketches, one fed with strings and the other
* fed with char[] will be meaningless.
* </p>
*
* @param datum The given String.
*/
public void update(final String datum) {
if ((datum == null) || datum.isEmpty()) { return; }
final byte[] data = datum.getBytes(UTF_8);
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
}
/**
* Present the given byte array as a potential unique item.
* If the byte array is null or empty no update attempt is made and the method returns.
*
* @param data The given byte array.
*/
public void update(final byte[] data) {
if ((data == null) || (data.length == 0)) { return; }
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
}
/**
* Present the given char array as a potential unique item.
* If the char array is null or empty no update attempt is made and the method returns.
*
* <p>Note: this will not produce the same output hash values as the {@link #update(String)}
* method but will be a little faster as it avoids the complexity of the UTF8 encoding.</p>
*
* @param data The given char array.
*/
public void update(final char[] data) {
if ((data == null) || (data.length == 0)) { return; }
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
}
/**
* 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.
*/
public void update(final int[] data) {
if ((data == null) || (data.length == 0)) { return; }
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
}
/**
* 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.
*/
public void update(final long[] data) {
if ((data == null) || (data.length == 0)) { return; }
final long[] arr = hash(data, seed);
hashUpdate(arr[0], arr[1]);
}
/**
* Convience function that this Sketch is valid. This is a troubleshooting tool
* for sketches that have been heapified from serialized images.
*
* <p>If you are starting with a serialized image as a byte array, first heapify
* the byte array to a sketch, which performs a number of checks. Then use this
* function as one additional check on the sketch.</p>
*
* @return true if this sketch is validated.
*/
public boolean validate() {
final long[] bitMatrix = bitMatrixOfSketch(this);
final long matrixCoupons = countBitsSetInMatrix(bitMatrix);
return matrixCoupons == numCoupons;
}
/**
* Returns the current Flavor of this sketch.
* @return the current Flavor of this sketch.
*/
Flavor getFlavor() {
return CpcUtil.determineFlavor(lgK, numCoupons);
}
/**
* Returns the Format of the serialized form of this sketch.
* @return the Format of the serialized form of this sketch.
*/
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);
}
private static void promoteEmptyToSparse(final CpcSketch sketch) {
assert sketch.numCoupons == 0;
assert sketch.pairTable == null;
sketch.pairTable = new PairTable(2, 6 + sketch.lgK);
}
//In terms of flavor, this promotes SPARSE to HYBRID.
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;
}
/**
* The KXP register is a double with roughly 50 bits of precision, but
* it might need roughly 90 bits to track the value with perfect accuracy.
* Therefore we recalculate KXP occasionally from the sketch's full bitMatrix
* so that it will reflect changes that were previously outside the mantissa.
* @param sketch the given sketch
* @param bitMatrix the given bit Matrix
*/
//Also used in test
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];
Arrays.fill(byteSums, 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;
}
/**
* This moves the sliding window
* @param sketch the given sketch
* @param newOffset the new offset, which must be oldOffset + 1
*/
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
}
}
/**
* Call this whenever a new coupon has been collected.
* @param sketch the given sketch
* @param rowCol the given row / column
*/
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 updateSparse(final CpcSketch sketch, final int rowCol) {
final int k = 1 << sketch.lgK;
final long c32pre = sketch.numCoupons << 5;
assert (c32pre < (3L * k)); // C < 3K/32, in other words, flavor == SPARSE
assert (sketch.pairTable != null);
final boolean isNovel = PairTable.maybeInsert(sketch.pairTable, rowCol);
if (isNovel) {
sketch.numCoupons += 1;
updateHIP(sketch, rowCol);
final long c32post = sketch.numCoupons << 5;
if (c32post >= (3L * k)) { promoteSparseToWindowed(sketch); } // C >= 3K/32
}
}
/**
* The flavor is HYBRID, PINNED, or SLIDING.
* @param sketch the given sketch
* @param rowCol the given rowCol
*/
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)
}
}
}
//also used in test
static CpcSketch uncompress(final CompressedState source, final long seed) {
ThetaUtil.checkSeedHashes(ThetaUtil.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;
}
//Used here and for testing
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); }
}
//Used by union and in testing
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); }
}
/**
* Return a human-readable string summary of this sketch
*/
@Override
public String toString() {
return toString(false);
}
/**
* Return a human-readable string summary of this sketch
* @param detail include data detail
* @return a human-readable string summary of this sketch
*/
public String toString(final boolean detail) {
final int numPairs = (pairTable == null) ? 0 : pairTable.getNumPairs();
final int seedHash = Short.toUnsignedInt(ThetaUtil.computeSeedHash(seed));
final double errConst = mergeFlag ? log(2) : sqrt(log(2) / 2.0);
final double rse = errConst / Math.sqrt(1 << lgK);
final StringBuilder sb = new StringBuilder();
sb.append("### CPD SKETCH - PREAMBLE:").append(LS);
sb.append(" Flavor : ").append(getFlavor()).append(LS);
sb.append(" LgK : ").append(lgK).append(LS);
sb.append(" Merge Flag : ").append(mergeFlag).append(LS);
sb.append(" Error Const : ").append(errConst).append(LS);
sb.append(" RSE : ").append(rse).append(LS);
sb.append(" Seed Hash : ").append(Integer.toHexString(seedHash))
.append(" | ").append(seedHash).append(LS);
sb.append(" Num Coupons : ").append(numCoupons).append(LS);
sb.append(" Num Pairs (SV) : ").append(numPairs).append(LS);
sb.append(" First Inter Col: ").append(fiCol).append(LS);
sb.append(" Valid Window : ").append(slidingWindow != null).append(LS);
sb.append(" Valid PairTable: ").append(pairTable != null).append(LS);
sb.append(" Window Offset : ").append(windowOffset).append(LS);
sb.append(" KxP : ").append(kxp).append(LS);
sb.append(" HIP Accum : ").append(hipEstAccum).append(LS);
if (detail) {
sb.append(LS).append("### CPC SKETCH - DATA").append(LS);
if (pairTable != null) {
sb.append(pairTable.toString(true));
}
if (slidingWindow != null) {
sb.append("SlidingWindow : ").append(LS);
sb.append(" Index Bits (lsb ->)").append(LS);
for (int i = 0; i < slidingWindow.length; i++) {
final String bits = zeroPad(Integer.toBinaryString(slidingWindow[i] & 0XFF), 8);
sb.append(String.format("%9d %8s" + LS, i, bits));
}
}
}
sb.append("### END CPC SKETCH");
return sb.toString();
}
/**
* Returns a human readable string of the preamble of a byte array image of a CpcSketch.
* @param byteArr the given byte array
* @param detail if true, a dump of the compressed window and surprising value streams will be
* included.
* @return a human readable string of the preamble of a byte array image of a CpcSketch.
*/
public static String toString(final byte[] byteArr, final boolean detail) {
return PreambleUtil.toString(byteArr, detail);
}
/**
* Returns a human readable string of the preamble of a Memory image of a CpcSketch.
* @param mem the given Memory
* @param detail if true, a dump of the compressed window and surprising value streams will be
* included.
* @return a human readable string of the preamble of a Memory image of a CpcSketch.
*/
public static String toString(final Memory mem, final boolean detail) {
return PreambleUtil.toString(mem, detail);
}
private static void fillKxpByteLookup() { //called from static initializer
for (int b = 0; b < 256; b++) {
double sum = 0;
for (int col = 0; col < 8; col++) {
final int bit = (b >>> col) & 1;
if (bit == 0) { // note the inverted logic
sum += invPow2(col + 1); //note the "+1"
}
}
kxpByteLookup[b] = sum;
}
}
static {
fillKxpByteLookup();
}
}
| 2,730 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/Flavor.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
/**
* Note: except for brief transitional moments, these sketches always obey the following strict
* mapping between the flavor of a sketch and the number of coupons that it has collected.
* @author Lee Rhodes
* @author Kevin Lang
*/
enum Flavor {
EMPTY, // 0 == C < 1
SPARSE, // 1 <= C < 3K/32
HYBRID, // 3K/32 <= C < K/2
PINNED, // K/2 <= C < 27K/8 [NB: 27/8 = 3 + 3/8]
SLIDING; // 27K/8 <= C
private static Flavor[] fmtArr = Flavor.class.getEnumConstants();
/**
* Returns the Flavor given its enum ordinal
* @param ordinal the given enum ordinal
* @return the Flavor given its enum ordinal
*/
static Flavor ordinalToFlavor(final int ordinal) {
return fmtArr[ordinal];
}
}
| 2,731 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/Format.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
/**
* There are seven different preamble formats (8 combinations) that determine the layout of the
* <i>HiField</i> variables after the first 8 bytes of the preamble.
* Do not change the order.
*/
enum Format {
EMPTY_MERGED,
EMPTY_HIP,
SPARSE_HYBRID_MERGED,
SPARSE_HYBRID_HIP,
PINNED_SLIDING_MERGED_NOSV,
PINNED_SLIDING_HIP_NOSV,
PINNED_SLIDING_MERGED,
PINNED_SLIDING_HIP;
private static Format[] fmtArr = Format.class.getEnumConstants();
/**
* Returns the Format given its enum ordinal
* @param ordinal the given enum ordinal
* @return the Format given its enum ordinal
*/
static Format ordinalToFormat(final int ordinal) {
return fmtArr[ordinal];
}
} //end enum Format
| 2,732 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/BitMatrix.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.hash.MurmurHash3.hash;
import java.util.Arrays;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* Used only in test.
* @author Lee Rhodes
* @author Kevin Lang
*/
class BitMatrix {
private final int lgK;
private final long seed;
private long numCoupons;
private long[] bitMatrix;
private boolean numCouponsInvalid; //only used if we allowed merges
BitMatrix(final int lgK) {
this(lgK, ThetaUtil.DEFAULT_UPDATE_SEED);
}
BitMatrix(final int lgK, final long seed) {
this.lgK = lgK;
this.seed = seed;
bitMatrix = new long[1 << lgK];
numCoupons = 0;
numCouponsInvalid = false;
}
//leaves lgK and seed untouched
void reset() {
Arrays.fill(bitMatrix, 0);
numCoupons = 0;
numCouponsInvalid = false;
}
long getNumCoupons() {
if (numCouponsInvalid) {
numCoupons = countCoupons(bitMatrix);
numCouponsInvalid = false;
}
return numCoupons;
}
long[] getMatrix() {
return bitMatrix;
}
/**
* Present the given long as a potential unique item.
*
* @param datum The given long datum.
*/
public void update(final long datum) {
final long[] data = { datum };
final long[] harr = hash(data, seed);
hashUpdate(harr[0], harr[1]);
}
private void hashUpdate(final long hash0, final long hash1) {
int col = Long.numberOfLeadingZeros(hash1);
if (col > 63) { col = 63; } // clip so that 0 <= col <= 63
final long kMask = (1L << lgK) - 1L;
int row = (int) (hash0 & kMask);
final 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) { row ^= 1; } //set the LSB of row to 0
final long oldPattern = bitMatrix[row];
final long newPattern = oldPattern | (1L << col);
if (newPattern != oldPattern) {
numCoupons++;
bitMatrix[row] = newPattern;
}
}
static long countCoupons(final long[] bitMatrix) {
long count = 0;
final int len = bitMatrix.length;
for (int i = 0; i < len; i++) { count += Long.bitCount(bitMatrix[i]); }
return count;
}
}
| 2,733 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/MergingValidation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.common.Util.INVERSE_GOLDEN_U64;
import static org.apache.datasketches.common.Util.powerSeriesNextDouble;
import static org.apache.datasketches.cpc.IconEstimator.getIconEstimate;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssert;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssertEquals;
import java.io.PrintStream;
import java.io.PrintWriter;
import org.apache.datasketches.common.SuppressFBWarnings;
/**
* This code is used both by unit tests, for short running tests,
* and by the characterization repository for longer running, more exhaustive testing. To be
* accessible for both, this code is part of the main hierarchy. It is not used during normal
* production runtime.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
public class MergingValidation {
private String hfmt;
private String dfmt;
private String[] hStrArr;
private long vIn = 0;
//inputs
private int lgMinK;
private int lgMaxK; //inclusive
private int lgMulK; //multiplier of K to produce maxNa, maxNb
private int uPPO;
private int incLgK; //increment of lgK
private PrintStream printStream;
private PrintWriter printWriter;
/**
*
* @param lgMinK lgMinK
* @param lgMaxK lgMaxK
* @param lgMulK lgMulK
* @param uPPO uPPO
* @param incLgK incLgK
* @param pS pS
* @param pW pW
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "This is OK here")
public MergingValidation(final int lgMinK, final int lgMaxK, final int lgMulK, final int uPPO,
final int incLgK, final PrintStream pS, final PrintWriter pW) {
this.lgMinK = lgMinK;
this.lgMaxK = lgMaxK;
this.lgMulK = lgMulK;
this.uPPO = Math.max(uPPO, 1);
this.incLgK = Math.max(incLgK, 1);
printStream = pS;
printWriter = pW;
assembleFormats();
}
/**
*
*/
public void start() {
printf(hfmt, (Object[]) hStrArr); //print header
doRangeOfLgK();
}
private void doRangeOfLgK() {
for (int lgK = lgMinK; lgK <= lgMaxK; lgK += incLgK) {
multiTestMerging(lgK, lgK - 1, lgK - 1);
multiTestMerging(lgK, lgK - 1, lgK + 0);
multiTestMerging(lgK, lgK - 1, lgK + 1);
multiTestMerging(lgK, lgK + 0, lgK - 1);
multiTestMerging(lgK, lgK + 0, lgK + 0);
multiTestMerging(lgK, lgK + 0, lgK + 1);
multiTestMerging(lgK, lgK + 1, lgK - 1);
multiTestMerging(lgK, lgK + 1, lgK + 0);
multiTestMerging(lgK, lgK + 1, lgK + 1);
}
}
private void multiTestMerging(final int lgKm, final int lgKa, final int lgKb) {
final long limA = 1L << (lgKa + lgMulK);
final long limB = 1L << (lgKa + lgMulK);
long nA = 0;
while (nA <= limA) {
long nB = 0;
while (nB <= limB) {
testMerging(lgKm, lgKa, lgKb, nA, nB);
nB = Math.round(powerSeriesNextDouble(uPPO, nB, true, 2.0));
}
nA = Math.round(powerSeriesNextDouble(uPPO, nA, true, 2.0));
}
}
private void testMerging(final int lgKm, final int lgKa, final int lgKb, final long nA,
final long nB) {
final CpcUnion ugM = new CpcUnion(lgKm);
// int lgKd = ((nA != 0) && (lgKa < lgKm)) ? lgKa : lgKm;
// lgKd = ((nB != 0) && (lgKb < lgKd)) ? lgKb : lgKd;
int lgKd = lgKm;
if ((lgKa < lgKd) && (nA != 0)) { lgKd = lgKa; } //d = min(a,m) : m
if ((lgKb < lgKd) && (nB != 0)) { lgKd = lgKb; } //d = min(b,d) : d
final CpcSketch skD = new CpcSketch(lgKd); // direct sketch, updated with both streams
final CpcSketch skA = new CpcSketch(lgKa);
final CpcSketch skB = new CpcSketch(lgKb);
for (long i = 0; i < nA; i++) {
final long in = (vIn += INVERSE_GOLDEN_U64);
skA.update(in);
skD.update(in);
}
for (long i = 0; i < nB; i++) {
final long in = (vIn += INVERSE_GOLDEN_U64);
skB.update(in);
skD.update(in);
}
ugM.update(skA);
ugM.update(skB);
final int finalLgKm = ugM.getLgK();
final long[] matrixM = CpcUnion.getBitMatrix(ugM);
final long cM = ugM.getNumCoupons();//countBitsSetInMatrix(matrixM);
final long cD = skD.numCoupons;
final Flavor flavorD = skD.getFlavor();
final Flavor flavorA = skA.getFlavor();
final Flavor flavorB = skB.getFlavor();
final String dOff = Integer.toString(skD.windowOffset);
final String aOff = Integer.toString(skA.windowOffset);
final String bOff = Integer.toString(skB.windowOffset);
final String flavorDoff = flavorD + String.format("%2s",dOff);
final String flavorAoff = flavorA + String.format("%2s",aOff);
final String flavorBoff = flavorB + String.format("%2s",bOff);
final double iconEstD = getIconEstimate(lgKd, cD);
rtAssert(finalLgKm <= lgKm);
rtAssert(cM <= (skA.numCoupons + skB.numCoupons));
rtAssertEquals(cM, cD);
rtAssertEquals(finalLgKm, lgKd);
final long[] matrixD = CpcUtil.bitMatrixOfSketch(skD);
rtAssertEquals(matrixM, matrixD);
final CpcSketch skR = ugM.getResult();
final double iconEstR = getIconEstimate(skR.lgK, skR.numCoupons);
rtAssertEquals(iconEstD, iconEstR, 0.0);
rtAssert(TestUtil.specialEquals(skD, skR, false, true));
printf(dfmt, lgKm, lgKa, lgKb, lgKd, nA, nB, (nA + nB),
flavorAoff, flavorBoff, flavorDoff,
skA.numCoupons, skB.numCoupons, cD, iconEstR);
}
private void printf(final String format, final Object ... args) {
if (printStream != null) { printStream.printf(format, args); }
if (printWriter != null) { printWriter.printf(format, args); }
}
private void assembleFormats() {
final String[][] assy = {
{"lgKm", "%4s", "%4d"},
{"lgKa", "%4s", "%4d"},
{"lgKb", "%4s", "%4d"},
{"lgKfd", "%6s", "%6d"},
{"nA", "%12s", "%12d"},
{"nB", "%12s", "%12d"},
{"nA+nB", "%12s", "%12d"},
{"Flavor_a", "%11s", "%11s"},
{"Flavor_b", "%11s", "%11s"},
{"Flavor_fd", "%11s", "%11s"},
{"Coupons_a", "%9s", "%9d"},
{"Coupons_b", "%9s", "%9d"},
{"Coupons_fd", "%9s", "%9d"},
{"IconEst_dr", "%12s", "%,12.0f"}
};
final int cols = assy.length;
hStrArr = new String[cols];
final StringBuilder headerFmt = new StringBuilder();
final StringBuilder dataFmt = new StringBuilder();
headerFmt.append("\nMerging Validation\n");
for (int i = 0; i < cols; i++) {
hStrArr[i] = assy[i][0];
headerFmt.append(assy[i][1]);
headerFmt.append((i < (cols - 1)) ? "\t" : "\n");
dataFmt.append(assy[i][2]);
dataFmt.append((i < (cols - 1)) ? "\t" : "\n");
}
hfmt = headerFmt.toString();
dfmt = dataFmt.toString();
}
}
| 2,734 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CpcWrapper.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.cpc.CpcConfidence.getHipConfidenceLB;
import static org.apache.datasketches.cpc.CpcConfidence.getHipConfidenceUB;
import static org.apache.datasketches.cpc.CpcConfidence.getIconConfidenceLB;
import static org.apache.datasketches.cpc.CpcConfidence.getIconConfidenceUB;
import static org.apache.datasketches.cpc.IconEstimator.getIconEstimate;
import static org.apache.datasketches.cpc.PreambleUtil.checkLoPreamble;
import static org.apache.datasketches.cpc.PreambleUtil.getHipAccum;
import static org.apache.datasketches.cpc.PreambleUtil.getNumCoupons;
import static org.apache.datasketches.cpc.PreambleUtil.hasHip;
import static org.apache.datasketches.cpc.PreambleUtil.isCompressed;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssert;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SuppressFBWarnings;
import org.apache.datasketches.memory.Memory;
/**
* This provides a read-only view of a serialized image of a CpcSketch, which can be
* on-heap or off-heap represented as a Memory object, or on-heap represented as a byte array.
* @author Lee Rhodes
* @author Kevin Lang
*/
public final class CpcWrapper {
Memory mem;
/**
* Construct a read-only view of the given Memory that contains a CpcSketch
* @param mem the given Memory
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "This is OK here")
public CpcWrapper(final Memory mem) {
this.mem = mem;
checkLoPreamble(mem);
rtAssert(isCompressed(mem));
}
/**
* Construct a read-only view of the given byte array that contains a CpcSketch.
* @param byteArray the given byte array
*/
public CpcWrapper(final byte[] byteArray) {
this(Memory.wrap(byteArray));
}
/**
* Returns the best estimate of the cardinality of the sketch.
* @return the best estimate of the cardinality of the sketch.
*/
public double getEstimate() {
if (!hasHip(mem)) {
return getIconEstimate(PreambleUtil.getLgK(mem), getNumCoupons(mem));
}
return getHipAccum(mem);
}
/**
* Return the DataSketches identifier for this CPC family of sketches.
* @return the DataSketches identifier for this CPC family of sketches.
*/
public static Family getFamily() {
return Family.CPC;
}
/**
* Returns the configured Log_base2 of K of this sketch.
* @return the configured Log_base2 of K of this sketch.
*/
public int getLgK() {
return PreambleUtil.getLgK(mem);
}
/**
* Returns the best estimate of the lower bound of the confidence interval given <i>kappa</i>,
* the number of standard deviations from the mean.
* @param kappa the given number of standard deviations from the mean: 1, 2 or 3.
* @return the best estimate of the lower bound of the confidence interval given <i>kappa</i>.
*/
public double getLowerBound(final int kappa) {
if (!hasHip(mem)) {
return getIconConfidenceLB(PreambleUtil.getLgK(mem), getNumCoupons(mem), kappa);
}
return getHipConfidenceLB(PreambleUtil.getLgK(mem), getNumCoupons(mem), getHipAccum(mem), kappa);
}
/**
* Returns the best estimate of the upper bound of the confidence interval given <i>kappa</i>,
* the number of standard deviations from the mean.
* @param kappa the given number of standard deviations from the mean: 1, 2 or 3.
* @return the best estimate of the upper bound of the confidence interval given <i>kappa</i>.
*/
public double getUpperBound(final int kappa) {
if (!hasHip(mem)) {
return getIconConfidenceUB(PreambleUtil.getLgK(mem), getNumCoupons(mem), kappa);
}
return getHipConfidenceUB(PreambleUtil.getLgK(mem), getNumCoupons(mem), getHipAccum(mem), kappa);
}
}
| 2,735 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/RuntimeAsserts.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
/**
* These asserts act like the <i>assert</i> in C/C++. They will throw an AssertionError whether the
* JVM -ea is set or not.
*
* @author Lee Rhodes
*/
final class RuntimeAsserts {
static void rtAssert(final boolean b) {
if (!b) { error("False, expected True."); }
}
static void rtAssertFalse(final boolean b) {
if (b) { error("True, expected False."); }
}
static void rtAssertEquals(final long a, final long b) {
if (a != b) { error(a + " != " + b); }
}
static void rtAssertEquals(final double a, final double b, final double eps) {
if (Math.abs(a - b) > eps) { error("abs(" + a + " - " + b + ") > " + eps); }
}
static void rtAssertEquals(final boolean a, final boolean b) {
if (a != b) { error(a + " != " + b); }
}
static void rtAssertEquals(final byte[] a, final byte[] b) {
if ((a == null) && (b == null)) { return; }
if ((a != null) && (b != null)) {
final int alen = a.length;
if (alen != b.length) { error("Array lengths not equal: " + a.length + ", " + b.length); }
for (int i = 0; i < alen; i++) {
if (a[i] != b[i]) { error(a[i] + " != " + b[i] + " at index " + i); }
}
} else { error("Array " + ((a == null) ? "a" : "b") + " is null"); }
}
static void rtAssertEquals(final short[] a, final short[] b) {
if ((a == null) && (b == null)) { return; }
if ((a != null) && (b != null)) {
final int alen = a.length;
if (alen != b.length) { error("Array lengths not equal: " + a.length + ", " + b.length); }
for (int i = 0; i < alen; i++) {
if (a[i] != b[i]) { error(a[i] + " != " + b[i] + " at index " + i); }
}
} else { error("Array " + ((a == null) ? "a" : "b") + " is null"); }
}
static void rtAssertEquals(final int[] a, final int[] b) {
if ((a == null) && (b == null)) { return; }
if ((a != null) && (b != null)) {
final int alen = a.length;
if (alen != b.length) { error("Array lengths not equal: " + a.length + ", " + b.length); }
for (int i = 0; i < alen; i++) {
if (a[i] != b[i]) { error(a[i] + " != " + b[i] + " at index " + i); }
}
} else { error("Array " + ((a == null) ? "a" : "b") + " is null"); }
}
static void rtAssertEquals(final long[] a, final long[] b) {
if ((a == null) && (b == null)) { return; }
if ((a != null) && (b != null)) {
final int alen = a.length;
if (alen != b.length) { error("Array lengths not equal: " + a.length + ", " + b.length); }
for (int i = 0; i < alen; i++) {
if (a[i] != b[i]) { error(a[i] + " != " + b[i] + " at index " + i); }
}
} else { error("Array " + ((a == null) ? "a" : "b") + " is null"); }
}
static void rtAssertEquals(final float[] a, final float[] b, final float eps) {
if ((a == null) && (b == null)) { return; }
if ((a != null) && (b != null)) {
final int alen = a.length;
if (alen != b.length) { error("Array lengths not equal: " + a.length + ", " + b.length); }
for (int i = 0; i < alen; i++) {
if (Math.abs(a[i] - b[i]) > eps) { error("abs(" + a[i] + " - " + b[i] + ") > " + eps); }
}
} else { error("Array " + ((a == null) ? "a" : "b") + " is null"); }
}
static void rtAssertEquals(final double[] a, final double[] b, final double eps) {
if ((a == null) && (b == null)) { return; }
if ((a != null) && (b != null)) {
final int alen = a.length;
if (alen != b.length) { error("Array lengths not equal: " + alen + ", " + b.length); }
for (int i = 0; i < alen; i++) {
if (Math.abs(a[i] - b[i]) > eps) { error("abs(" + a[i] + " - " + b[i] + ") > " + eps); }
}
} else { error("Array " + ((a == null) ? "a" : "b") + " is null"); }
}
private static void error(final String message) {
throw new AssertionError(message);
}
}
| 2,736 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CpcUtil.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import java.util.Arrays;
import org.apache.datasketches.common.SketchesArgumentException;
/**
* @author Lee Rhodes
* @author Kevin Lang
*/
final class CpcUtil {
static final int minLgK = 4;
static final int maxLgK = 26;
static void checkLgK(final int lgK) {
if ((lgK < minLgK) || (lgK > maxLgK)) {
throw new SketchesArgumentException("LgK must be >= 4 and <= 26: " + lgK);
}
}
static Flavor determineFlavor(final int lgK, final long numCoupons) {
final long c = numCoupons;
final long k = 1L << lgK;
final long c2 = c << 1;
final long c8 = c << 3;
final long c32 = c << 5;
if (c == 0) {
return Flavor.EMPTY; // 0 == C < 1
}
if (c32 < (3 * k)) {
return Flavor.SPARSE; // 1 <= C < 3K/32
}
if (c2 < k) {
return Flavor.HYBRID; // 3K/32 <= C < K/2
}
if (c8 < (27 * k)) {
return Flavor.PINNED; // K/2 <= C < 27K/8
}
else {
return Flavor.SLIDING; // 27K/8 <= C
}
}
/**
* Warning: this is called in several places, including during the
* transitional moments during which sketch invariants involving
* flavor and offset are out of whack and in fact we are re-imposing
* them. Therefore it cannot rely on determineFlavor() or
* determineCorrectOffset(). Instead it interprets the low level data
* structures "as is".
*
* <p>This produces a full-size k-by-64 bit matrix from any Live sketch.
*
* @param sketch the given sketch
* @return the bit matrix as an array of longs.
*/
static long[] bitMatrixOfSketch(final CpcSketch sketch) {
final int k = (1 << sketch.lgK);
final int offset = sketch.windowOffset;
assert (offset >= 0) && (offset <= 56);
final long[] matrix = new long[k];
if (sketch.numCoupons == 0) {
return matrix; // Returning a matrix of zeros rather than NULL.
}
//Fill the matrix with default rows in which the "early zone" is filled with ones.
//This is essential for the routine's O(k) time cost (as opposed to O(C)).
final long defaultRow = (1L << offset) - 1L;
Arrays.fill(matrix, defaultRow);
final byte[] window = sketch.slidingWindow;
if (window != null) { // In other words, we are in window mode, not sparse mode.
for (int i = 0; i < k; i++) { // set the window bits, trusting the sketch's current offset.
matrix[i] |= ((window[i] & 0XFFL) << offset);
}
}
final PairTable table = sketch.pairTable;
assert (table != null);
final int[] slots = table.getSlotsArr();
final int numSlots = 1 << table.getLgSizeInts();
for (int i = 0; i < numSlots; i++) {
final int rowCol = slots[i];
if (rowCol != -1) {
final int col = rowCol & 63;
final int row = rowCol >>> 6;
// Flip the specified matrix bit from its default value.
// In the "early" zone the bit changes from 1 to 0.
// In the "late" zone the bit changes from 0 to 1.
matrix[row] ^= (1L << col);
}
}
return matrix;
}
static long countBitsSetInMatrix(final long[] matrix) {
long count = 0;
final int len = matrix.length;
for (int i = 0; i < len; i++) { count += Long.bitCount(matrix[i]); }
return count;
}
static int determineCorrectOffset(final int lgK, final long numCoupons) {
final long c = numCoupons;
final long k = (1L << lgK);
final long tmp = (c << 3) - (19L * k); // 8C - 19K
if (tmp < 0) { return 0; }
return (int) (tmp >>> (lgK + 3)); // tmp / 8K
}
}
| 2,737 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/QuickMergingValidation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.common.Util.INVERSE_GOLDEN_U64;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssert;
import java.io.PrintStream;
import java.io.PrintWriter;
import org.apache.datasketches.common.SuppressFBWarnings;
/**
* This code is used both by unit tests, for short running tests,
* and by the characterization repository for longer running, more exhaustive testing. To be
* accessible for both, this code is part of the main hierarchy. It is not used during normal
* production runtime.
*
* <p>This test of merging is the equal K case and is less exhaustive than TestAlltest
* but is more practical for large values of K.</p>
*
* @author Lee Rhodes
* @author Kevin Lang
*/
public class QuickMergingValidation {
private String hfmt;
private String dfmt;
private String[] hStrArr;
private long vIn = 0;
//inputs
private int lgMinK;
private int lgMaxK; //inclusive
private int incLgK; //increment of lgK
private PrintStream printStream;
private PrintWriter printWriter;
/**
*
* @param lgMinK lgMinK
* @param lgMaxK lgMaxK
* @param incLgK incLgK
* @param ps ps
* @param pw pw
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "This is OK here")
public QuickMergingValidation(final int lgMinK, final int lgMaxK, final int incLgK,
final PrintStream ps, final PrintWriter pw) {
this.lgMinK = lgMinK;
this.lgMaxK = lgMaxK;
this.incLgK = incLgK;
printStream = ps;
printWriter = pw;
assembleFormats();
}
/**
*
*/
public void start() {
printf(hfmt, (Object[]) hStrArr); //print header
doRangeOfLgK();
}
private void doRangeOfLgK() {
for (int lgK = lgMinK; lgK <= lgMaxK; lgK += incLgK) {
multiQuickTest(lgK);
}
}
private void multiQuickTest(final int lgK) {
final int k = 1 << lgK;
final int[] targetC = new int[] { 0, 1, ((3 * k) / 32) - 1, k / 3, k, (7 * k) / 2 };
final int len = targetC.length;
for (int i = 0; i < len; i++) {
for (int j = 0; j < len; j++) {
quickTest(lgK, targetC[i], targetC[j]);
}
}
}
void quickTest(final int lgK, final long cA, final long cB) {
final CpcSketch skA = new CpcSketch(lgK);
final CpcSketch skB = new CpcSketch(lgK);
final CpcSketch skD = new CpcSketch(lgK); // direct sketch
final long t0, t1, t2, t3, t4, t5;
t0 = System.nanoTime();
while (skA.numCoupons < cA) {
final long in = vIn += INVERSE_GOLDEN_U64;
skA.update(in);
skD.update(in);
}
t1 = System.nanoTime();
while (skB.numCoupons < cB) {
final long in = vIn += INVERSE_GOLDEN_U64;
skB.update(in);
skD.update(in);
}
t2 = System.nanoTime();
final CpcUnion ugM = new CpcUnion(lgK);
ugM.update(skA);
t3 = System.nanoTime();
ugM.update(skB);
t4 = System.nanoTime();
final CpcSketch skR = ugM.getResult();
t5 = System.nanoTime();
rtAssert(TestUtil.specialEquals(skD, skR, false, true));
final Flavor fA = skA.getFlavor();
final Flavor fB = skB.getFlavor();
final Flavor fR = skR.getFlavor();
final String aOff = Integer.toString(skA.windowOffset);
final String bOff = Integer.toString(skB.windowOffset);
final String rOff = Integer.toString(skR.windowOffset);
final String fAoff = fA + String.format("%2s",aOff);
final String fBoff = fB + String.format("%2s",bOff);
final String fRoff = fR + String.format("%2s",rOff);
final double updA_mS = (t1 - t0) / 2E6; //update A,D to cA
final double updB_mS = (t2 - t1) / 2E6; //update B,D to cB
final double mrgA_mS = (t3 - t2) / 1E6; //merge A
final double mrgB_mS = (t4 - t3) / 1E6; //merge B
final double rslt_mS = (t5 - t4) / 1E6; //get Result
printf(dfmt, lgK, cA, cB, fAoff, fBoff, fRoff,
updA_mS, updB_mS, mrgA_mS, mrgB_mS, rslt_mS);
}
private void printf(final String format, final Object ... args) {
if (printStream != null) { printStream.printf(format, args); }
if (printWriter != null) { printWriter.printf(format, args); }
}
private void assembleFormats() {
final String[][] assy = {
{"lgK", "%3s", "%3d"},
{"Ca", "%10s", "%10d"},
{"Cb", "%10s", "%10d"},
{"Flavor_a", "%10s", "%10s"},
{"Flavor_b", "%10s", "%10s"},
{"Flavor_m", "%10s", "%10s"},
{"updA_mS", "%9s", "%9.3f"},
{"updB_mS", "%9s", "%9.3f"},
{"mrgA_mS", "%9s", "%9.3f"},
{"mrgB_mS", "%9s", "%9.3f"},
{"rslt_mS", "%9s", "%9.3f"}
};
final int cols = assy.length;
hStrArr = new String[cols];
final StringBuilder headerFmt = new StringBuilder();
final StringBuilder dataFmt = new StringBuilder();
headerFmt.append("\nQuick Merging Validation\n");
for (int i = 0; i < cols; i++) {
hStrArr[i] = assy[i][0];
headerFmt.append(assy[i][1]);
headerFmt.append((i < (cols - 1)) ? "\t" : "\n");
dataFmt.append(assy[i][2]);
dataFmt.append((i < (cols - 1)) ? "\t" : "\n");
}
hfmt = headerFmt.toString();
dfmt = dataFmt.toString();
}
}
| 2,738 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CompressionCharacterization.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.common.Util.INVERSE_GOLDEN_U64;
import static org.apache.datasketches.common.Util.ceilingIntPowerOf2;
import static org.apache.datasketches.common.Util.log2;
import static org.apache.datasketches.common.Util.powerSeriesNextDouble;
import static org.apache.datasketches.cpc.CompressedState.importFromMemory;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssert;
import java.io.PrintStream;
import java.io.PrintWriter;
import org.apache.datasketches.common.SuppressFBWarnings;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* This code is used both by unit tests, for short running tests,
* and by the characterization repository for longer running, more exhaustive testing. To be
* accessible for both, this code is part of the main hierarchy. It is not used during normal
* production runtime.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
public class CompressionCharacterization {
private String hfmt;
private String dfmt;
private String[] hStrArr;
private long vIn = 0;
//inputs
private int lgMinK;
private int lgMaxK; //inclusive
private int lgMinT; //Trials at end
private int lgMaxT; //Trials at start
private int lgMulK; //multiplier of K to produce maxU
private int uPPO;
private int incLgK; //increment of lgK
private PrintStream ps;
private PrintWriter pw;
//intermediates
private CpcSketch[] streamSketches;
private CompressedState[] compressedStates1;
private WritableMemory[] memoryArr;
private CompressedState[] compressedStates2;
private CpcSketch[] unCompressedSketches;
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "This is OK here")
public CompressionCharacterization(
final int lgMinK,
final int lgMaxK,
final int lgMinT,
final int lgMaxT,
final int lgMulK,
final int uPPO,
final int incLgK,
final PrintStream pS,
final PrintWriter pW) {
this.lgMinK = lgMinK;
this.lgMaxK = lgMaxK;
this.lgMinT = lgMinT;
this.lgMaxT = lgMaxT;
this.lgMulK = lgMulK;
this.uPPO = Math.max(uPPO, 1);
this.incLgK = Math.max(incLgK, 1);
ps = pS;
pw = pW;
assembleFormats();
}
public void start() {
printf(hfmt, (Object[]) hStrArr); //print header
doRangeOfLgK();
}
private void doRangeOfLgK() {
for (int lgK = lgMinK; lgK <= lgMaxK; lgK += incLgK) {
doRangeOfNAtLgK(lgK);
}
}
private void doRangeOfNAtLgK(final int lgK) {
long n = 1;
final int lgMaxN = lgK + lgMulK;
final long maxN = 1L << lgMaxN;
final double slope = -(double)(lgMaxT - lgMinT) / lgMaxN;
while (n <= maxN) {
final double lgT = (slope * log2(n)) + lgMaxT;
final int totTrials = Math.max(ceilingIntPowerOf2((int) Math.pow(2.0, lgT)), (1 << lgMinT));
doTrialsAtLgKAtN(lgK, n, totTrials);
n = Math.round(powerSeriesNextDouble(uPPO, n, true, 2.0));
}
}
private void doTrialsAtLgKAtN(final int lgK, final long n, final int totalTrials) {
final int k = 1 << lgK;
final int minNK = (int) ((k < n) ? k : n);
final double nOverK = (double) n / k;
final int lgTotTrials = Integer.numberOfTrailingZeros(totalTrials);
final int lgWaves = Math.max(lgTotTrials - 10, 0);
final int trialsPerWave = 1 << (lgTotTrials - lgWaves);
//printf("%d %d %d %d\n", totalTrials, lgTotTrials, 1 << lgWaves, trialsPerWave);
streamSketches = new CpcSketch[trialsPerWave];
compressedStates1 = new CompressedState[trialsPerWave];
memoryArr = new WritableMemory[trialsPerWave];
compressedStates2 = new CompressedState[trialsPerWave];
unCompressedSketches = new CpcSketch[trialsPerWave];
//update: fill, compress, uncompress sketches arrays in waves
long totalC = 0;
long totalW = 0;
long sumCtor_nS = 0;
long sumUpd_nS = 0;
long sumCom_nS = 0;
long sumSer_nS = 0;
long sumDes_nS = 0;
long sumUnc_nS = 0;
long sumEqu_nS = 0;
long nanoStart, nanoEnd;
final long start = System.currentTimeMillis();
//Wave Loop
for (int w = 0; w < (1 << lgWaves); w++) {
//Construct array with sketches loop
nanoStart = System.nanoTime();
for (int trial = 0; trial < trialsPerWave; trial++) {
final CpcSketch sketch = new CpcSketch(lgK);
streamSketches[trial] = sketch;
}
nanoEnd = System.nanoTime();
sumCtor_nS += nanoEnd - nanoStart;
nanoStart = nanoEnd;
//Sketch Update loop
for (int trial = 0; trial < trialsPerWave; trial++) {
final CpcSketch sketch = streamSketches[trial];
for (long i = 0; i < n; i++) { //increment loop
sketch.update(vIn += INVERSE_GOLDEN_U64);
}
}
nanoEnd = System.nanoTime();
sumUpd_nS += nanoEnd - nanoStart;
nanoStart = nanoEnd;
//Compress loop
for (int trial = 0; trial < trialsPerWave; trial++) {
final CpcSketch sketch = streamSketches[trial];
final CompressedState state = CompressedState.compress(sketch);
compressedStates1[trial] = state;
totalC += sketch.numCoupons;
totalW += state.csvLengthInts + state.cwLengthInts;
}
nanoEnd = System.nanoTime();
sumCom_nS += nanoEnd - nanoStart;
nanoStart = nanoEnd;
//State to Memory loop
for (int trial = 0; trial < trialsPerWave; trial++) {
final CompressedState state = compressedStates1[trial];
final long cap = state.getRequiredSerializedBytes();
final WritableMemory wmem = WritableMemory.allocate((int) cap);
state.exportToMemory(wmem);
memoryArr[trial] = wmem;
}
nanoEnd = System.nanoTime();
sumSer_nS += nanoEnd - nanoStart;
nanoStart = nanoEnd;
//Memory to State loop
for (int trial = 0; trial < trialsPerWave; trial++) {
final Memory mem = memoryArr[trial];
final CompressedState state = importFromMemory(mem);
compressedStates2[trial] = state;
}
nanoEnd = System.nanoTime();
sumDes_nS += nanoEnd - nanoStart;
nanoStart = nanoEnd;
//Uncompress loop
for (int trial = 0; trial < trialsPerWave; trial++) {
final CompressedState state = compressedStates2[trial];
CpcSketch uncSk = null;
uncSk = CpcSketch.uncompress(state, ThetaUtil.DEFAULT_UPDATE_SEED);
unCompressedSketches[trial] = uncSk;
}
nanoEnd = System.nanoTime();
sumUnc_nS += nanoEnd - nanoStart;
nanoStart = nanoEnd;
//Equals check
for (int trial = 0; trial < trialsPerWave; trial++) {
rtAssert(TestUtil.specialEquals(streamSketches[trial], unCompressedSketches[trial], false, false));
}
nanoEnd = System.nanoTime();
sumEqu_nS += nanoEnd - nanoStart;
nanoStart = nanoEnd;
} // end wave loop
final double total_S = (System.currentTimeMillis() - start) / 1E3;
final double avgC = (1.0 * totalC) / totalTrials;
final double avgCoK = avgC / k;
final double avgWords = (1.0 * totalW) / totalTrials;
final double avgBytes = (4.0 * totalW) / totalTrials;
final double avgCtor_nS = Math.round((double) sumCtor_nS / totalTrials);
final double avgUpd_nS = Math.round((double) sumUpd_nS / totalTrials);
final double avgUpd_nSperN = avgUpd_nS / n;
final double avgCom_nS = Math.round((double) sumCom_nS / totalTrials);
final double avgCom_nSper2C = avgCom_nS / (2.0 * avgC);
final double avgCom_nSperK = avgCom_nS / k;
final double avgSer_nS = Math.round((double) sumSer_nS / totalTrials);
final double avgSer_nSperW = avgSer_nS / avgWords;
final double avgDes_nS = Math.round((double) sumDes_nS / totalTrials);
final double avgDes_nSperW = avgDes_nS / avgWords;
final double avgUnc_nS = Math.round((double) sumUnc_nS / totalTrials);
final double avgUnc_nSper2C = avgUnc_nS / (2.0 * avgC);
final double avgUnc_nSperK = avgUnc_nS / k;
final double avgEqu_nS = Math.round((double) sumEqu_nS / totalTrials);
final double avgEqu_nSperMinNK = avgEqu_nS / minNK;
final int len = unCompressedSketches.length;
final Flavor finFlavor = unCompressedSketches[len - 1].getFlavor();
final String offStr = Integer.toString(unCompressedSketches[len - 1].windowOffset);
final String flavorOff = finFlavor.toString() + String.format("%2s", offStr);
printf(dfmt,
lgK,
totalTrials,
n,
minNK,
avgCoK,
flavorOff,
nOverK,
avgBytes,
avgCtor_nS,
avgUpd_nS,
avgCom_nS,
avgSer_nS,
avgDes_nS,
avgUnc_nS,
avgEqu_nS,
avgUpd_nSperN,
avgCom_nSper2C,
avgCom_nSperK,
avgSer_nSperW,
avgDes_nSperW,
avgUnc_nSper2C,
avgUnc_nSperK,
avgEqu_nSperMinNK,
total_S);
}
private void printf(final String format, final Object ... args) {
if (ps != null) { ps.printf(format, args); }
if (pw != null) { pw.printf(format, args); }
}
private void assembleFormats() {
final String[][] assy = {
{"lgK", "%3s", "%3d"},
{"Trials", "%9s", "%9d"},
{"n", "%12s", "%12d"},
{"MinKN", "%9s", "%9d"},
{"AvgC/K", "%9s", "%9.4g"},
{"FinFlavor", "%11s", "%11s"},
{"N/K", "%9s", "%9.4g"},
{"AvgBytes", "%9s", "%9.0f"},
{"AvgCtor_nS", "%11s", "%11.0f"},
{"AvgUpd_nS", "%10s", "%10.4e"},
{"AvgCom_nS", "%10s", "%10.0f"},
{"AvgSer_nS", "%10s", "%10.2f"},
{"AvgDes_nS", "%10s", "%10.2f"},
{"AvgUnc_nS", "%10s", "%10.0f"},
{"AvgEqu_nS", "%10s", "%10.0f"},
{"AvgUpd_nSperN", "%14s", "%14.2f"},
{"AvgCom_nSper2C", "%15s", "%15.4g"},
{"AvgCom_nSperK", "%14s", "%14.4g"},
{"AvgSer_nSperW", "%14s", "%14.2f"},
{"AvgDes_nSperW", "%14s", "%14.2f"},
{"AvgUnc_nSper2C", "%15s", "%15.4g"},
{"AvgUnc_nSperK", "%14s", "%14.4g"},
{"AvgEqu_nSperMinNK", "%18s", "%18.4g"},
{"Total_S", "%8s", "%8.3f"}
};
final int cols = assy.length;
hStrArr = new String[cols];
final StringBuilder headerFmt = new StringBuilder();
final StringBuilder dataFmt = new StringBuilder();
headerFmt.append("\nCompression Characterization\n");
for (int i = 0; i < cols; i++) {
hStrArr[i] = assy[i][0];
headerFmt.append(assy[i][1]);
headerFmt.append((i < (cols - 1)) ? "\t" : "\n");
dataFmt.append(assy[i][2]);
dataFmt.append((i < (cols - 1)) ? "\t" : "\n");
}
hfmt = headerFmt.toString();
dfmt = dataFmt.toString();
}
}
| 2,739 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CpcConfidence.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static java.lang.Math.ceil;
import static java.lang.Math.log;
import static java.lang.Math.sqrt;
import static org.apache.datasketches.cpc.IconEstimator.getIconEstimate;
/**
* Tables and methods for estimating upper and lower bounds.
*
* <p>Tables were generated from empirical measurements at N = 1000 * K using millions of trials.
*
* @author Lee Rhodes
*/
final class CpcConfidence {
private static final double iconErrorConstant = log(2.0); //0.693147180559945286
private static final double hipErrorConstant = sqrt(log(2.0) / 2.0); //0.588705011257737332
static short[] iconLowSideData = {
//1, 2, 3, kappa
// lgK numtrials
6037, 5720, 5328, // 4 1000000
6411, 6262, 5682, // 5 1000000
6724, 6403, 6127, // 6 1000000
6665, 6411, 6208, // 7 1000000
6959, 6525, 6427, // 8 1000000
6892, 6665, 6619, // 9 1000000
6792, 6752, 6690, // 10 1000000
6899, 6818, 6708, // 11 1000000
6871, 6845, 6812, // 12 1046369
6909, 6861, 6828, // 13 1043411
6919, 6897, 6842, // 14 1000297
};
static short[] iconHighSideData = {
//1, 2, 3, kappa
// lgK numtrials
8031, 8559, 9309, // 4 1000000
7084, 7959, 8660, // 5 1000000
7141, 7514, 7876, // 6 1000000
7458, 7430, 7572, // 7 1000000
6892, 7141, 7497, // 8 1000000
6889, 7132, 7290, // 9 1000000
7075, 7118, 7185, // 10 1000000
7040, 7047, 7085, // 11 1000000
6993, 7019, 7053, // 12 1046369
6953, 7001, 6983, // 13 1043411
6944, 6966, 7004, // 14 1000297
};
static short[] hipLowSideData = {
//1, 2, 3, kappa
// lgK numtrials
5871, 5247, 4826, // 4 1000000
5877, 5403, 5070, // 5 1000000
5873, 5533, 5304, // 6 1000000
5878, 5632, 5464, // 7 1000000
5874, 5690, 5564, // 8 1000000
5880, 5745, 5619, // 9 1000000
5875, 5784, 5701, // 10 1000000
5866, 5789, 5742, // 11 1000000
5869, 5827, 5784, // 12 1046369
5876, 5860, 5827, // 13 1043411
5881, 5853, 5842, // 14 1000297
};
static short[] hipHighSideData = {
//1, 2, 3, kappa
// lgK numtrials
5855, 6688, 7391, // 4 1000000
5886, 6444, 6923, // 5 1000000
5885, 6254, 6594, // 6 1000000
5889, 6134, 6326, // 7 1000000
5900, 6072, 6203, // 8 1000000
5875, 6005, 6089, // 9 1000000
5871, 5980, 6040, // 10 1000000
5889, 5941, 6015, // 11 1000000
5871, 5926, 5973, // 12 1046369
5866, 5901, 5915, // 13 1043411
5880, 5914, 5953, // 14 1000297
};
static double getIconConfidenceLB(final int lgK, final long numCoupons, final int kappa) {
if (numCoupons == 0) { return 0.0; }
assert lgK >= 4;
assert (kappa >= 1) && (kappa <= 3);
double x = iconErrorConstant;
if (lgK <= 14) { x = (iconHighSideData[(3 * (lgK - 4)) + (kappa - 1)]) / 10000.0; }
final double rel = x / sqrt(1 << lgK);
final double eps = kappa * rel;
final double est = getIconEstimate(lgK, numCoupons);
double result = est / (1.0 + eps);
if (result < numCoupons) { result = numCoupons; }
return result;
}
static double getIconConfidenceUB(final int lgK, final long numCoupons, final int kappa) {
if (numCoupons == 0) { return 0.0; }
assert lgK >= 4;
assert (kappa >= 1) && (kappa <= 3);
double x = iconErrorConstant;
if (lgK <= 14) { x = (iconLowSideData[(3 * (lgK - 4)) + (kappa - 1)]) / 10000.0; }
final double rel = x / sqrt(1 << lgK);
final double eps = kappa * rel;
final double est = getIconEstimate(lgK, numCoupons);
final double result = est / (1.0 - eps);
return ceil(result); // slight widening of interval to be conservative
}
//mergeFlag must already be checked as false
static double getHipConfidenceLB(final int lgK, final long numCoupons, final double hipEstAccum,
final int kappa) {
if (numCoupons == 0) { return 0.0; }
assert lgK >= 4;
assert (kappa >= 1) && (kappa <= 3);
double x = hipErrorConstant;
if (lgK <= 14) { x = (hipHighSideData[(3 * (lgK - 4)) + (kappa - 1)]) / 10000.0; }
final double rel = x / sqrt(1 << lgK);
final double eps = kappa * rel;
final double est = hipEstAccum;
double result = est / (1.0 + eps);
if (result < numCoupons) { result = numCoupons; }
return result;
}
//mergeFlag must already be checked as false
static double getHipConfidenceUB(final int lgK, final long numCoupons, final double hipEstAccum,
final int kappa) {
if (numCoupons == 0) { return 0.0; }
assert lgK >= 4;
assert (kappa >= 1) && (kappa <= 3);
double x = hipErrorConstant;
if (lgK <= 14) { x = (hipLowSideData[(3 * (lgK - 4)) + (kappa - 1)]) / 10000.0; }
final double rel = x / sqrt(1 << lgK);
final double eps = kappa * rel;
final double est = hipEstAccum;
final double result = est / (1.0 - eps);
return ceil(result); // widening for coverage
}
}
| 2,740 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CompressedState.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.cpc.PreambleUtil.checkCapacity;
import static org.apache.datasketches.cpc.PreambleUtil.checkLoPreamble;
import static org.apache.datasketches.cpc.PreambleUtil.getDefinedPreInts;
import static org.apache.datasketches.cpc.PreambleUtil.getFiCol;
import static org.apache.datasketches.cpc.PreambleUtil.getFormatOrdinal;
import static org.apache.datasketches.cpc.PreambleUtil.getHipAccum;
import static org.apache.datasketches.cpc.PreambleUtil.getKxP;
import static org.apache.datasketches.cpc.PreambleUtil.getLgK;
import static org.apache.datasketches.cpc.PreambleUtil.getNumCoupons;
import static org.apache.datasketches.cpc.PreambleUtil.getNumSv;
import static org.apache.datasketches.cpc.PreambleUtil.getPreInts;
import static org.apache.datasketches.cpc.PreambleUtil.getSeedHash;
import static org.apache.datasketches.cpc.PreambleUtil.getSvLengthInts;
import static org.apache.datasketches.cpc.PreambleUtil.getSvStream;
import static org.apache.datasketches.cpc.PreambleUtil.getWLengthInts;
import static org.apache.datasketches.cpc.PreambleUtil.getWStream;
import static org.apache.datasketches.cpc.PreambleUtil.isCompressed;
import static org.apache.datasketches.cpc.PreambleUtil.putEmptyHip;
import static org.apache.datasketches.cpc.PreambleUtil.putEmptyMerged;
import static org.apache.datasketches.cpc.PreambleUtil.putPinnedSlidingHip;
import static org.apache.datasketches.cpc.PreambleUtil.putPinnedSlidingHipNoSv;
import static org.apache.datasketches.cpc.PreambleUtil.putPinnedSlidingMerged;
import static org.apache.datasketches.cpc.PreambleUtil.putPinnedSlidingMergedNoSv;
import static org.apache.datasketches.cpc.PreambleUtil.putSparseHybridHip;
import static org.apache.datasketches.cpc.PreambleUtil.putSparseHybridMerged;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssert;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* @author Lee Rhodes
* @author Kevin Lang
*/
final class CompressedState {
private static final String LS = System.getProperty("line.separator");
private boolean csvIsValid = false;
private boolean windowIsValid = false;
final int lgK;
final short seedHash;
int fiCol = 0;
boolean mergeFlag = false; //compliment of HIP Flag
long numCoupons = 0;
double kxp;
double hipEstAccum = 0.0;
int numCsv = 0;
int[] csvStream = null; //may be longer than required
int csvLengthInts = 0;
int[] cwStream = null; //may be longer than required
int cwLengthInts = 0;
//int cpcRequiredBytes = 0;
private CompressedState(final int lgK, final short seedHash) {
this.lgK = lgK;
this.seedHash = seedHash;
kxp = 1 << lgK;
}
static CompressedState compress(final CpcSketch source) {
final short seedHash = ThetaUtil.computeSeedHash(source.seed);
final CompressedState target = new CompressedState(source.lgK, seedHash);
target.fiCol = source.fiCol;
target.mergeFlag = source.mergeFlag;
target.numCoupons = source.numCoupons;
target.kxp = source.kxp;
target.hipEstAccum = source.hipEstAccum;
target.csvIsValid = source.pairTable != null;
target.windowIsValid = (source.slidingWindow != null);
CpcCompression.compress(source, target);
return target;
}
Flavor getFlavor() {
return CpcUtil.determineFlavor(lgK, numCoupons);
}
Format getFormat() {
final int ordinal = ((cwLengthInts > 0) ? 4 : 0)
| ((numCsv > 0) ? 2 : 0)
| ( mergeFlag ? 0 : 1 ); //complement of HIP
return Format.ordinalToFormat(ordinal);
}
int getWindowOffset() {
return CpcUtil.determineCorrectOffset(lgK, numCoupons);
}
long getRequiredSerializedBytes() {
final Format format = getFormat();
final int preInts = getDefinedPreInts(format);
return 4L * (preInts + csvLengthInts + cwLengthInts);
}
static CompressedState importFromMemory(final Memory mem) {
checkLoPreamble(mem);
rtAssert(isCompressed(mem));
final int lgK = getLgK(mem);
final short seedHash = getSeedHash(mem);
final CompressedState state = new CompressedState(lgK, seedHash);
final int fmtOrd = getFormatOrdinal(mem);
final Format format = Format.ordinalToFormat(fmtOrd);
state.mergeFlag = !((fmtOrd & 1) > 0); //merge flag is complement of HIP
state.csvIsValid = (fmtOrd & 2) > 0;
state.windowIsValid = (fmtOrd & 4) > 0;
switch (format) {
case EMPTY_MERGED :
case EMPTY_HIP : {
checkCapacity(mem.getCapacity(), 8L);
break;
}
case SPARSE_HYBRID_MERGED : {
//state.fiCol = getFiCol(mem);
state.numCoupons = getNumCoupons(mem);
state.numCsv = (int) state.numCoupons; //only true for sparse_hybrid
state.csvLengthInts = getSvLengthInts(mem);
//state.cwLength = getCwLength(mem);
//state.kxp = getKxP(mem);
//state.hipEstAccum = getHipAccum(mem);
checkCapacity(mem.getCapacity(), state.getRequiredSerializedBytes());
//state.cwStream = getCwStream(mem);
state.csvStream = getSvStream(mem);
break;
}
case SPARSE_HYBRID_HIP : {
//state.fiCol = getFiCol(mem);
state.numCoupons = getNumCoupons(mem);
state.numCsv = (int) state.numCoupons; //only true for sparse_hybrid
state.csvLengthInts = getSvLengthInts(mem);
//state.cwLength = getCwLength(mem);
state.kxp = getKxP(mem);
state.hipEstAccum = getHipAccum(mem);
checkCapacity(mem.getCapacity(), state.getRequiredSerializedBytes());
//state.cwStream = getCwStream(mem);
state.csvStream = getSvStream(mem);
break;
}
case PINNED_SLIDING_MERGED_NOSV : {
state.fiCol = getFiCol(mem);
state.numCoupons = getNumCoupons(mem);
//state.numCsv = getNumCsv(mem);
//state.csvLength = getCsvLength(mem);
state.cwLengthInts = getWLengthInts(mem);
//state.kxp = getKxP(mem);
//state.hipEstAccum = getHipAccum(mem);
checkCapacity(mem.getCapacity(), state.getRequiredSerializedBytes());
state.cwStream = getWStream(mem);
//state.csvStream = getCsvStream(mem);
break;
}
case PINNED_SLIDING_HIP_NOSV : {
state.fiCol = getFiCol(mem);
state.numCoupons = getNumCoupons(mem);
//state.numCsv = getNumCsv(mem);
//state.csvLength = getCsvLength(mem);
state.cwLengthInts = getWLengthInts(mem);
state.kxp = getKxP(mem);
state.hipEstAccum = getHipAccum(mem);
checkCapacity(mem.getCapacity(), state.getRequiredSerializedBytes());
state.cwStream = getWStream(mem);
//state.csvStream = getCsvStream(mem);
break;
}
case PINNED_SLIDING_MERGED : {
state.fiCol = getFiCol(mem);
state.numCoupons = getNumCoupons(mem);
state.numCsv = getNumSv(mem);
state.csvLengthInts = getSvLengthInts(mem);
state.cwLengthInts = getWLengthInts(mem);
//state.kxp = getKxP(mem);
//state.hipEstAccum = getHipAccum(mem);
checkCapacity(mem.getCapacity(), state.getRequiredSerializedBytes());
state.cwStream = getWStream(mem);
state.csvStream = getSvStream(mem);
break;
}
case PINNED_SLIDING_HIP : {
state.fiCol = getFiCol(mem);
state.numCoupons = getNumCoupons(mem);
state.numCsv = getNumSv(mem);
state.csvLengthInts = getSvLengthInts(mem);
state.cwLengthInts = getWLengthInts(mem);
state.kxp = getKxP(mem);
state.hipEstAccum = getHipAccum(mem);
checkCapacity(mem.getCapacity(), state.getRequiredSerializedBytes());
state.cwStream = getWStream(mem);
state.csvStream = getSvStream(mem);
break;
}
}
checkCapacity(mem.getCapacity(),
4L * (getPreInts(mem) + state.csvLengthInts + state.cwLengthInts));
return state;
}
void exportToMemory(final WritableMemory wmem) {
final Format format = getFormat();
switch (format) {
case EMPTY_MERGED : {
putEmptyMerged(wmem, lgK, seedHash);
break;
}
case EMPTY_HIP : {
putEmptyHip(wmem, lgK, seedHash);
break;
}
case SPARSE_HYBRID_MERGED : {
putSparseHybridMerged(wmem,
lgK,
(int) numCoupons, //unsigned
csvLengthInts,
seedHash,
csvStream);
break;
}
case SPARSE_HYBRID_HIP : {
putSparseHybridHip(wmem,
lgK,
(int) numCoupons, //unsigned
csvLengthInts,
kxp,
hipEstAccum,
seedHash,
csvStream);
break;
}
case PINNED_SLIDING_MERGED_NOSV : {
putPinnedSlidingMergedNoSv(wmem,
lgK,
fiCol,
(int) numCoupons, //unsigned
cwLengthInts,
seedHash,
cwStream);
break;
}
case PINNED_SLIDING_HIP_NOSV : {
putPinnedSlidingHipNoSv(wmem,
lgK,
fiCol,
(int) numCoupons, //unsigned
cwLengthInts,
kxp,
hipEstAccum,
seedHash,
cwStream);
break;
}
case PINNED_SLIDING_MERGED : {
putPinnedSlidingMerged(wmem,
lgK,
fiCol,
(int) numCoupons, //unsigned
numCsv,
csvLengthInts,
cwLengthInts,
seedHash,
csvStream,
cwStream);
break;
}
case PINNED_SLIDING_HIP : {
putPinnedSlidingHip(wmem,
lgK,
fiCol,
(int) numCoupons, //unsigned
numCsv,
kxp,
hipEstAccum,
csvLengthInts,
cwLengthInts,
seedHash,
csvStream,
cwStream);
break;
}
}
}
@Override
public String toString() {
return toString(this, false);
}
public static String toString(final CompressedState state, final boolean detail) {
final StringBuilder sb = new StringBuilder();
sb.append("CompressedState").append(LS);
sb.append(" Flavor : ").append(state.getFlavor()).append(LS);
sb.append(" Format : ").append(state.getFormat()).append(LS);
sb.append(" lgK : ").append(state.lgK).append(LS);
sb.append(" seedHash : ").append(state.seedHash).append(LS);
sb.append(" fiCol : ").append(state.fiCol).append(LS);
sb.append(" mergeFlag : ").append(state.mergeFlag).append(LS);
sb.append(" csvStream : ").append(state.csvIsValid).append(LS);
sb.append(" cwStream : ").append(state.windowIsValid).append(LS);
sb.append(" numCoupons : ").append(state.numCoupons).append(LS);
sb.append(" kxp : ").append(state.kxp).append(LS);
sb.append(" hipAccum : ").append(state.hipEstAccum).append(LS);
sb.append(" numCsv : ").append(state.numCsv).append(LS);
sb.append(" csvLengthInts : ").append(state.csvLengthInts).append(LS);
sb.append(" csLength : ").append(state.cwLengthInts).append(LS);
if (detail) {
if (state.csvStream != null) {
sb.append(" CsvStream : ").append(LS);
for (int i = 0; i < state.csvLengthInts; i++) {
sb.append(String.format("%8d %12d" + LS, i, state.csvStream[i]));
}
}
if (state.cwStream != null) {
sb.append(" CwStream : ").append(LS);
for (int i = 0; i < state.cwLengthInts; i++) {
sb.append(String.format("%8d %12d" + LS, i, state.cwStream[i]));
}
}
}
return sb.toString();
}
}
| 2,741 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/StreamingValidation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.common.Util.INVERSE_GOLDEN_U64;
import static org.apache.datasketches.common.Util.powerSeriesNextDouble;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssertEquals;
import java.io.PrintStream;
import java.io.PrintWriter;
import org.apache.datasketches.common.SuppressFBWarnings;
/**
* This code is used both by unit tests, for short running tests,
* and by the characterization repository for longer running, more exhaustive testing. To be
* accessible for both, this code is part of the main hierarchy. It is not used during normal
* production runtime.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
public class StreamingValidation {
private String hfmt;
private String dfmt;
private String[] hStrArr;
private long vIn = 0;
//inputs
private int lgMinK;
private int lgMaxK; //inclusive
private int trials;
private int ppoN;
private PrintStream printStream;
private PrintWriter printWriter;
//sketches
private CpcSketch sketch = null;
private BitMatrix matrix = null;
/**
*
* @param lgMinK lgMinK
* @param lgMaxK lgMaxK
* @param trials trials
* @param ppoN ppoN
* @param pS pS
* @param pW pW
*/
@SuppressFBWarnings(value = "EI_EXPOSE_REP2", justification = "This is OK here")
public StreamingValidation(final int lgMinK, final int lgMaxK, final int trials, final int ppoN,
final PrintStream pS, final PrintWriter pW) {
this.lgMinK = lgMinK;
this.lgMaxK = lgMaxK;
this.trials = trials;
this.ppoN = ppoN;
printStream = pS;
printWriter = pW;
assembleStrings();
}
/**
*
*/
public void start() {
printf(hfmt, (Object[]) hStrArr);
doRangeOfLgK();
}
private void doRangeOfLgK() {
for (int lgK = lgMinK; lgK <= lgMaxK; lgK++) {
doRangeOfNAtLgK(lgK);
}
}
private void doRangeOfNAtLgK(final int lgK) {
long n = 1;
final long maxN = 64L * (1L << lgK); //1200
while (n < maxN) {
doTrialsAtLgKAtN(lgK, n);
n = Math.round(powerSeriesNextDouble(ppoN, n, true, 2.0));
}
}
/**
* Performs the given number of trials at a lgK and at an N.
* @param lgK the configured lgK
* @param n the current value of n
*/
private void doTrialsAtLgKAtN(final int lgK, final long n) {
double sumC = 0.0;
double sumIconEst = 0.0;
double sumHipEst = 0.0;
sketch = new CpcSketch(lgK);
matrix = new BitMatrix(lgK);
for (int t = 0; t < trials; t++) {
sketch.reset();
matrix.reset();
for (long i = 0; i < n; i++) {
final long in = (vIn += INVERSE_GOLDEN_U64);
sketch.update(in);
matrix.update(in);
}
sumC += sketch.numCoupons;
sumIconEst += IconEstimator.getIconEstimate(lgK, sketch.numCoupons);
sumHipEst += sketch.hipEstAccum;
rtAssertEquals(sketch.numCoupons, matrix.getNumCoupons());
final long[] bitMatrix = CpcUtil.bitMatrixOfSketch(sketch);
rtAssertEquals(bitMatrix, matrix.getMatrix());
}
final long finC = sketch.numCoupons;
final Flavor finFlavor = sketch.getFlavor();
final int finOff = sketch.windowOffset;
final double avgC = sumC / trials;
final double avgIconEst = sumIconEst / trials;
final double avgHipEst = sumHipEst / trials;
printf(dfmt, lgK, trials, n, finC, finFlavor, finOff, avgC, avgIconEst, avgHipEst);
}
private void printf(final String format, final Object ... args) {
if (printStream != null) { printStream.printf(format, args); }
if (printWriter != null) { printWriter.printf(format, args); }
}
private void assembleStrings() {
final String[][] assy = {
{"lgK", "%3s", "%3d"},
{"Trials", "%7s", "%7d"},
{"n", "%8s", "%8d"},
{"FinC", "%8s", "%8d"},
{"FinFlavor", "%10s", "%10s"},
{"FinOff", "%7s", "%7d"},
{"AvgC", "%12s", "%12.3f"},
{"AvgICON", "%12s", "%12.3f"},
{"AvgHIP", "%12s", "%12.3f"}
};
final int cols = assy.length;
hStrArr = new String[cols];
final StringBuilder headerFmt = new StringBuilder();
final StringBuilder dataFmt = new StringBuilder();
headerFmt.append("\nStreaming Validation\n");
for (int i = 0; i < cols; i++) {
hStrArr[i] = assy[i][0];
headerFmt.append(assy[i][1]);
headerFmt.append((i < (cols - 1)) ? "\t" : "\n");
dataFmt.append(assy[i][2]);
dataFmt.append((i < (cols - 1)) ? "\t" : "\n");
}
hfmt = headerFmt.toString();
dfmt = dataFmt.toString();
}
}
| 2,742 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CompressionData.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
/**
* The 23 length-limited Huffman codes in this file were created by the ocaml program
* "generateHuffmanCodes.ml", which was compiled and run as follows:
*
* <p>~/ocaml-4.03.0/bin/ocamlopt -o generateHuffmanCodes columnProbabilities.ml generateHuffmanCodes.ml
*
* <p>./generateHuffmanCodes > raw-encoding-tables.c
*
* <p>Some manual cutting and pasting was then done to transfer the contents
* of that file into this one.
*
* <p>Only the encoding tables are defined by this file. The decoding tables
* (which are exact inverses) are created at library startup time by the function
* makeDecodingTable (), which is defined in fm85Compression.c.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
final class CompressionData {
private static byte[] makeInversePermutation(final byte[]encodePermu) {
final int length = encodePermu.length;
final byte[] inverse = new byte[length];
for (int i = 0; i < length; i++) {
inverse[encodePermu[i]] = (byte) i;
}
for (int i = 0; i < length; i++) {
assert ((encodePermu[inverse[i]] & 0XFF) == i);
}
return inverse;
}
/**
* 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
*/
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);
}
/**
* These short arrays are being treated as unsigned
* @param decodingTable unsigned
* @param encodingTable unsigned
*/
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)));
}
}
private static void makeTheDecodingTables() {
lengthLimitedUnaryDecodingTable65 = makeDecodingTable(lengthLimitedUnaryEncodingTable65, 65);
validateDecodingTable(lengthLimitedUnaryDecodingTable65, lengthLimitedUnaryEncodingTable65);
for (int i = 0; i < (16 + 6); i++) {
decodingTablesForHighEntropyByte[i] = makeDecodingTable(encodingTablesForHighEntropyByte[i], 256);
validateDecodingTable(decodingTablesForHighEntropyByte[i], encodingTablesForHighEntropyByte[i]);
}
for (int i = 0; i < 16; i++) {
columnPermutationsForDecoding[i] = makeInversePermutation(columnPermutationsForEncoding[i]);
}
}
/**
* These decoding tables are created at library startup time by inverting the encoding tables.
* Sixteen tables for the steady state (chosen based on the "phase" of C/K).
* Six more tables for the gradual transition between warmup mode and the steady state.
*/
static short[][] decodingTablesForHighEntropyByte = new short[22][];
/**
* Sixteen Encoding Tables for the Steady State.
*/
static short[][] encodingTablesForHighEntropyByte = new short[][] //[22][256]
{
// (table 0 of 22) (steady 0 of 16) (phase = 0.031250000 = 1.0 / 32.0)
// entropy: 4.4619200780464778333
// avg_length: 4.5415773046232610355; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x9017, // ( 9, 23) 0
(short) 0x5009, // ( 5, 9) 1
(short) 0x7033, // ( 7, 51) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0x9117, // ( 9, 279) 4
(short) 0x5019, // ( 5, 25) 5
(short) 0x7073, // ( 7, 115) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xa177, // (10, 375) 8
(short) 0x601d, // ( 6, 29) 9
(short) 0x803b, // ( 8, 59) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xa377, // (10, 887) 12
(short) 0x5005, // ( 5, 5) 13
(short) 0x80bb, // ( 8, 187) 14
(short) 0x3006, // ( 3, 6) 15
(short) 0xb0cf, // (11, 207) 16
(short) 0x700b, // ( 7, 11) 17
(short) 0xa0f7, // (10, 247) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xb4cf, // (11, 1231) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0x9097, // ( 9, 151) 22
(short) 0x500d, // ( 5, 13) 23
(short) 0xc4af, // (12, 1199) 24
(short) 0x807b, // ( 8, 123) 25
(short) 0xa2f7, // (10, 759) 26
(short) 0x603d, // ( 6, 61) 27
(short) 0xccaf, // (12, 3247) 28
(short) 0x80fb, // ( 8, 251) 29
(short) 0xa1f7, // (10, 503) 30
(short) 0x6003, // ( 6, 3) 31
(short) 0xc2af, // (12, 687) 32
(short) 0x8007, // ( 8, 7) 33
(short) 0xb2cf, // (11, 719) 34
(short) 0x6023, // ( 6, 35) 35
(short) 0xcaaf, // (12, 2735) 36
(short) 0x8087, // ( 8, 135) 37
(short) 0xa3f7, // (10, 1015) 38
(short) 0x6013, // ( 6, 19) 39
(short) 0xc6af, // (12, 1711) 40
(short) 0x9197, // ( 9, 407) 41
(short) 0xceaf, // (12, 3759) 42
(short) 0x702b, // ( 7, 43) 43
(short) 0xc1af, // (12, 431) 44
(short) 0x9057, // ( 9, 87) 45
(short) 0xb6cf, // (11, 1743) 46
(short) 0x706b, // ( 7, 107) 47
(short) 0xc9af, // (12, 2479) 48
(short) 0xa00f, // (10, 15) 49
(short) 0xc5af, // (12, 1455) 50
(short) 0x8047, // ( 8, 71) 51
(short) 0xcdaf, // (12, 3503) 52
(short) 0xa20f, // (10, 527) 53
(short) 0xc3af, // (12, 943) 54
(short) 0x80c7, // ( 8, 199) 55
(short) 0xcbaf, // (12, 2991) 56
(short) 0xb1cf, // (11, 463) 57
(short) 0xc7af, // (12, 1967) 58
(short) 0x9157, // ( 9, 343) 59
(short) 0xcfaf, // (12, 4015) 60
(short) 0xb5cf, // (11, 1487) 61
(short) 0xc06f, // (12, 111) 62
(short) 0x90d7, // ( 9, 215) 63
(short) 0xc86f, // (12, 2159) 64
(short) 0x91d7, // ( 9, 471) 65
(short) 0xc46f, // (12, 1135) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xcc6f, // (12, 3183) 68
(short) 0x9037, // ( 9, 55) 69
(short) 0xb3cf, // (11, 975) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xc26f, // (12, 623) 72
(short) 0xa10f, // (10, 271) 73
(short) 0xca6f, // (12, 2671) 74
(short) 0x8027, // ( 8, 39) 75
(short) 0xc66f, // (12, 1647) 76
(short) 0xa30f, // (10, 783) 77
(short) 0xce6f, // (12, 3695) 78
(short) 0x80a7, // ( 8, 167) 79
(short) 0xc16f, // (12, 367) 80
(short) 0xb7cf, // (11, 1999) 81
(short) 0xc96f, // (12, 2415) 82
(short) 0x9137, // ( 9, 311) 83
(short) 0xc56f, // (12, 1391) 84
(short) 0xb02f, // (11, 47) 85
(short) 0xcd6f, // (12, 3439) 86
(short) 0x90b7, // ( 9, 183) 87
(short) 0xc36f, // (12, 879) 88
(short) 0xcb6f, // (12, 2927) 89
(short) 0xc76f, // (12, 1903) 90
(short) 0xa08f, // (10, 143) 91
(short) 0xcf6f, // (12, 3951) 92
(short) 0xc0ef, // (12, 239) 93
(short) 0xc8ef, // (12, 2287) 94
(short) 0xa28f, // (10, 655) 95
(short) 0xc4ef, // (12, 1263) 96
(short) 0xccef, // (12, 3311) 97
(short) 0xc2ef, // (12, 751) 98
(short) 0xa18f, // (10, 399) 99
(short) 0xcaef, // (12, 2799) 100
(short) 0xc6ef, // (12, 1775) 101
(short) 0xceef, // (12, 3823) 102
(short) 0xa38f, // (10, 911) 103
(short) 0xc1ef, // (12, 495) 104
(short) 0xc9ef, // (12, 2543) 105
(short) 0xc5ef, // (12, 1519) 106
(short) 0xb42f, // (11, 1071) 107
(short) 0xcdef, // (12, 3567) 108
(short) 0xc3ef, // (12, 1007) 109
(short) 0xcbef, // (12, 3055) 110
(short) 0xb22f, // (11, 559) 111
(short) 0xc7ef, // (12, 2031) 112
(short) 0xcfef, // (12, 4079) 113
(short) 0xc01f, // (12, 31) 114
(short) 0xc81f, // (12, 2079) 115
(short) 0xc41f, // (12, 1055) 116
(short) 0xcc1f, // (12, 3103) 117
(short) 0xc21f, // (12, 543) 118
(short) 0xca1f, // (12, 2591) 119
(short) 0xc61f, // (12, 1567) 120
(short) 0xce1f, // (12, 3615) 121
(short) 0xc11f, // (12, 287) 122
(short) 0xc91f, // (12, 2335) 123
(short) 0xc51f, // (12, 1311) 124
(short) 0xcd1f, // (12, 3359) 125
(short) 0xc31f, // (12, 799) 126
(short) 0xcb1f, // (12, 2847) 127
(short) 0xc71f, // (12, 1823) 128
(short) 0xa04f, // (10, 79) 129
(short) 0xcf1f, // (12, 3871) 130
(short) 0x8067, // ( 8, 103) 131
(short) 0xc09f, // (12, 159) 132
(short) 0xa24f, // (10, 591) 133
(short) 0xc89f, // (12, 2207) 134
(short) 0x80e7, // ( 8, 231) 135
(short) 0xc49f, // (12, 1183) 136
(short) 0xb62f, // (11, 1583) 137
(short) 0xcc9f, // (12, 3231) 138
(short) 0x91b7, // ( 9, 439) 139
(short) 0xc29f, // (12, 671) 140
(short) 0xb12f, // (11, 303) 141
(short) 0xca9f, // (12, 2719) 142
(short) 0x9077, // ( 9, 119) 143
(short) 0xc69f, // (12, 1695) 144
(short) 0xce9f, // (12, 3743) 145
(short) 0xc19f, // (12, 415) 146
(short) 0xa14f, // (10, 335) 147
(short) 0xc99f, // (12, 2463) 148
(short) 0xc59f, // (12, 1439) 149
(short) 0xcd9f, // (12, 3487) 150
(short) 0xa34f, // (10, 847) 151
(short) 0xc39f, // (12, 927) 152
(short) 0xcb9f, // (12, 2975) 153
(short) 0xc79f, // (12, 1951) 154
(short) 0xb52f, // (11, 1327) 155
(short) 0xcf9f, // (12, 3999) 156
(short) 0xc05f, // (12, 95) 157
(short) 0xc85f, // (12, 2143) 158
(short) 0xb32f, // (11, 815) 159
(short) 0xc45f, // (12, 1119) 160
(short) 0xcc5f, // (12, 3167) 161
(short) 0xc25f, // (12, 607) 162
(short) 0xb72f, // (11, 1839) 163
(short) 0xca5f, // (12, 2655) 164
(short) 0xc65f, // (12, 1631) 165
(short) 0xce5f, // (12, 3679) 166
(short) 0xb0af, // (11, 175) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 1 of 22) (steady 1 of 16) (phase = 0.093750000 = 3.0 / 32.0)
// entropy: 4.4574755684414029133
// avg_length: 4.5336306265208552446; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0xa177, // (10, 375) 0
(short) 0x5009, // ( 5, 9) 1
(short) 0x803b, // ( 8, 59) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0x9017, // ( 9, 23) 4
(short) 0x5019, // ( 5, 25) 5
(short) 0x700b, // ( 7, 11) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xb34f, // (11, 847) 8
(short) 0x601d, // ( 6, 29) 9
(short) 0x9117, // ( 9, 279) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xa377, // (10, 887) 12
(short) 0x603d, // ( 6, 61) 13
(short) 0x80bb, // ( 8, 187) 14
(short) 0x3006, // ( 3, 6) 15
(short) 0xc4af, // (12, 1199) 16
(short) 0x704b, // ( 7, 75) 17
(short) 0xa0f7, // (10, 247) 18
(short) 0x5005, // ( 5, 5) 19
(short) 0xb74f, // (11, 1871) 20
(short) 0x702b, // ( 7, 43) 21
(short) 0x9097, // ( 9, 151) 22
(short) 0x5015, // ( 5, 21) 23
(short) 0xccaf, // (12, 3247) 24
(short) 0x807b, // ( 8, 123) 25
(short) 0xb0cf, // (11, 207) 26
(short) 0x6003, // ( 6, 3) 27
(short) 0xc2af, // (12, 687) 28
(short) 0x80fb, // ( 8, 251) 29
(short) 0xa2f7, // (10, 759) 30
(short) 0x500d, // ( 5, 13) 31
(short) 0xcaaf, // (12, 2735) 32
(short) 0x8007, // ( 8, 7) 33
(short) 0xb4cf, // (11, 1231) 34
(short) 0x6023, // ( 6, 35) 35
(short) 0xc6af, // (12, 1711) 36
(short) 0x8087, // ( 8, 135) 37
(short) 0xa1f7, // (10, 503) 38
(short) 0x6013, // ( 6, 19) 39
(short) 0xceaf, // (12, 3759) 40
(short) 0x9197, // ( 9, 407) 41
(short) 0xc1af, // (12, 431) 42
(short) 0x706b, // ( 7, 107) 43
(short) 0xc9af, // (12, 2479) 44
(short) 0x9057, // ( 9, 87) 45
(short) 0xb2cf, // (11, 719) 46
(short) 0x6033, // ( 6, 51) 47
(short) 0xc5af, // (12, 1455) 48
(short) 0xa3f7, // (10, 1015) 49
(short) 0xcdaf, // (12, 3503) 50
(short) 0x8047, // ( 8, 71) 51
(short) 0xc3af, // (12, 943) 52
(short) 0xa00f, // (10, 15) 53
(short) 0xcbaf, // (12, 2991) 54
(short) 0x80c7, // ( 8, 199) 55
(short) 0xc7af, // (12, 1967) 56
(short) 0xb6cf, // (11, 1743) 57
(short) 0xcfaf, // (12, 4015) 58
(short) 0x9157, // ( 9, 343) 59
(short) 0xc06f, // (12, 111) 60
(short) 0xb1cf, // (11, 463) 61
(short) 0xc86f, // (12, 2159) 62
(short) 0x90d7, // ( 9, 215) 63
(short) 0xc46f, // (12, 1135) 64
(short) 0x91d7, // ( 9, 471) 65
(short) 0xcc6f, // (12, 3183) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xc26f, // (12, 623) 68
(short) 0x9037, // ( 9, 55) 69
(short) 0xb5cf, // (11, 1487) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xca6f, // (12, 2671) 72
(short) 0xa20f, // (10, 527) 73
(short) 0xc66f, // (12, 1647) 74
(short) 0x8027, // ( 8, 39) 75
(short) 0xce6f, // (12, 3695) 76
(short) 0xa10f, // (10, 271) 77
(short) 0xc16f, // (12, 367) 78
(short) 0x80a7, // ( 8, 167) 79
(short) 0xc96f, // (12, 2415) 80
(short) 0xb3cf, // (11, 975) 81
(short) 0xc56f, // (12, 1391) 82
(short) 0x9137, // ( 9, 311) 83
(short) 0xcd6f, // (12, 3439) 84
(short) 0xb7cf, // (11, 1999) 85
(short) 0xc36f, // (12, 879) 86
(short) 0x90b7, // ( 9, 183) 87
(short) 0xcb6f, // (12, 2927) 88
(short) 0xc76f, // (12, 1903) 89
(short) 0xcf6f, // (12, 3951) 90
(short) 0xa30f, // (10, 783) 91
(short) 0xc0ef, // (12, 239) 92
(short) 0xc8ef, // (12, 2287) 93
(short) 0xc4ef, // (12, 1263) 94
(short) 0xa08f, // (10, 143) 95
(short) 0xccef, // (12, 3311) 96
(short) 0xc2ef, // (12, 751) 97
(short) 0xcaef, // (12, 2799) 98
(short) 0xa28f, // (10, 655) 99
(short) 0xc6ef, // (12, 1775) 100
(short) 0xceef, // (12, 3823) 101
(short) 0xc1ef, // (12, 495) 102
(short) 0xa18f, // (10, 399) 103
(short) 0xc9ef, // (12, 2543) 104
(short) 0xc5ef, // (12, 1519) 105
(short) 0xcdef, // (12, 3567) 106
(short) 0xb02f, // (11, 47) 107
(short) 0xc3ef, // (12, 1007) 108
(short) 0xcbef, // (12, 3055) 109
(short) 0xc7ef, // (12, 2031) 110
(short) 0xb42f, // (11, 1071) 111
(short) 0xcfef, // (12, 4079) 112
(short) 0xc01f, // (12, 31) 113
(short) 0xc81f, // (12, 2079) 114
(short) 0xc41f, // (12, 1055) 115
(short) 0xcc1f, // (12, 3103) 116
(short) 0xc21f, // (12, 543) 117
(short) 0xca1f, // (12, 2591) 118
(short) 0xc61f, // (12, 1567) 119
(short) 0xce1f, // (12, 3615) 120
(short) 0xc11f, // (12, 287) 121
(short) 0xc91f, // (12, 2335) 122
(short) 0xc51f, // (12, 1311) 123
(short) 0xcd1f, // (12, 3359) 124
(short) 0xc31f, // (12, 799) 125
(short) 0xcb1f, // (12, 2847) 126
(short) 0xc71f, // (12, 1823) 127
(short) 0xcf1f, // (12, 3871) 128
(short) 0xa38f, // (10, 911) 129
(short) 0xc09f, // (12, 159) 130
(short) 0x8067, // ( 8, 103) 131
(short) 0xc89f, // (12, 2207) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xc49f, // (12, 1183) 134
(short) 0x80e7, // ( 8, 231) 135
(short) 0xcc9f, // (12, 3231) 136
(short) 0xb22f, // (11, 559) 137
(short) 0xc29f, // (12, 671) 138
(short) 0x91b7, // ( 9, 439) 139
(short) 0xca9f, // (12, 2719) 140
(short) 0xb62f, // (11, 1583) 141
(short) 0xc69f, // (12, 1695) 142
(short) 0x9077, // ( 9, 119) 143
(short) 0xce9f, // (12, 3743) 144
(short) 0xc19f, // (12, 415) 145
(short) 0xc99f, // (12, 2463) 146
(short) 0xa24f, // (10, 591) 147
(short) 0xc59f, // (12, 1439) 148
(short) 0xcd9f, // (12, 3487) 149
(short) 0xc39f, // (12, 927) 150
(short) 0xa14f, // (10, 335) 151
(short) 0xcb9f, // (12, 2975) 152
(short) 0xc79f, // (12, 1951) 153
(short) 0xcf9f, // (12, 3999) 154
(short) 0xb12f, // (11, 303) 155
(short) 0xc05f, // (12, 95) 156
(short) 0xc85f, // (12, 2143) 157
(short) 0xc45f, // (12, 1119) 158
(short) 0xb52f, // (11, 1327) 159
(short) 0xcc5f, // (12, 3167) 160
(short) 0xc25f, // (12, 607) 161
(short) 0xca5f, // (12, 2655) 162
(short) 0xb32f, // (11, 815) 163
(short) 0xc65f, // (12, 1631) 164
(short) 0xce5f, // (12, 3679) 165
(short) 0xc15f, // (12, 351) 166
(short) 0xb72f, // (11, 1839) 167
(short) 0xc95f, // (12, 2399) 168
(short) 0xc55f, // (12, 1375) 169
(short) 0xcd5f, // (12, 3423) 170
(short) 0xc35f, // (12, 863) 171
(short) 0xcb5f, // (12, 2911) 172
(short) 0xc75f, // (12, 1887) 173
(short) 0xcf5f, // (12, 3935) 174
(short) 0xb0af, // (11, 175) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 2 of 22) (steady 2 of 16) (phase = 0.156250000 = 5.0 / 32.0)
// entropy: 4.4520619712441886762
// avg_length: 4.5253989110544479146; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0xa177, // (10, 375) 0
(short) 0x5009, // ( 5, 9) 1
(short) 0x803b, // ( 8, 59) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0xa377, // (10, 887) 4
(short) 0x5019, // ( 5, 25) 5
(short) 0x80bb, // ( 8, 187) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xb34f, // (11, 847) 8
(short) 0x601d, // ( 6, 29) 9
(short) 0x9057, // ( 9, 87) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xb74f, // (11, 1871) 12
(short) 0x603d, // ( 6, 61) 13
(short) 0x807b, // ( 8, 123) 14
(short) 0x3006, // ( 3, 6) 15
(short) 0xc72f, // (12, 1839) 16
(short) 0x700b, // ( 7, 11) 17
(short) 0xa0f7, // (10, 247) 18
(short) 0x5005, // ( 5, 5) 19
(short) 0xcf2f, // (12, 3887) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0xa2f7, // (10, 759) 22
(short) 0x5015, // ( 5, 21) 23
(short) 0xc0af, // (12, 175) 24
(short) 0x80fb, // ( 8, 251) 25
(short) 0xb0cf, // (11, 207) 26
(short) 0x6003, // ( 6, 3) 27
(short) 0xc8af, // (12, 2223) 28
(short) 0x8007, // ( 8, 7) 29
(short) 0xa1f7, // (10, 503) 30
(short) 0x500d, // ( 5, 13) 31
(short) 0xc4af, // (12, 1199) 32
(short) 0x8087, // ( 8, 135) 33
(short) 0xb4cf, // (11, 1231) 34
(short) 0x6023, // ( 6, 35) 35
(short) 0xccaf, // (12, 3247) 36
(short) 0x8047, // ( 8, 71) 37
(short) 0xb2cf, // (11, 719) 38
(short) 0x6013, // ( 6, 19) 39
(short) 0xc2af, // (12, 687) 40
(short) 0x9157, // ( 9, 343) 41
(short) 0xcaaf, // (12, 2735) 42
(short) 0x702b, // ( 7, 43) 43
(short) 0xc6af, // (12, 1711) 44
(short) 0x90d7, // ( 9, 215) 45
(short) 0xceaf, // (12, 3759) 46
(short) 0x6033, // ( 6, 51) 47
(short) 0xc1af, // (12, 431) 48
(short) 0xa3f7, // (10, 1015) 49
(short) 0xc9af, // (12, 2479) 50
(short) 0x80c7, // ( 8, 199) 51
(short) 0xc5af, // (12, 1455) 52
(short) 0xa00f, // (10, 15) 53
(short) 0xcdaf, // (12, 3503) 54
(short) 0x8027, // ( 8, 39) 55
(short) 0xc3af, // (12, 943) 56
(short) 0xb6cf, // (11, 1743) 57
(short) 0xcbaf, // (12, 2991) 58
(short) 0x91d7, // ( 9, 471) 59
(short) 0xc7af, // (12, 1967) 60
(short) 0xb1cf, // (11, 463) 61
(short) 0xcfaf, // (12, 4015) 62
(short) 0x80a7, // ( 8, 167) 63
(short) 0xc06f, // (12, 111) 64
(short) 0x9037, // ( 9, 55) 65
(short) 0xc86f, // (12, 2159) 66
(short) 0x706b, // ( 7, 107) 67
(short) 0xc46f, // (12, 1135) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xcc6f, // (12, 3183) 70
(short) 0x701b, // ( 7, 27) 71
(short) 0xc26f, // (12, 623) 72
(short) 0xa20f, // (10, 527) 73
(short) 0xca6f, // (12, 2671) 74
(short) 0x8067, // ( 8, 103) 75
(short) 0xc66f, // (12, 1647) 76
(short) 0xa10f, // (10, 271) 77
(short) 0xce6f, // (12, 3695) 78
(short) 0x705b, // ( 7, 91) 79
(short) 0xc16f, // (12, 367) 80
(short) 0xb5cf, // (11, 1487) 81
(short) 0xc96f, // (12, 2415) 82
(short) 0x90b7, // ( 9, 183) 83
(short) 0xc56f, // (12, 1391) 84
(short) 0xb3cf, // (11, 975) 85
(short) 0xcd6f, // (12, 3439) 86
(short) 0x91b7, // ( 9, 439) 87
(short) 0xc36f, // (12, 879) 88
(short) 0xcb6f, // (12, 2927) 89
(short) 0xc76f, // (12, 1903) 90
(short) 0xa30f, // (10, 783) 91
(short) 0xcf6f, // (12, 3951) 92
(short) 0xc0ef, // (12, 239) 93
(short) 0xc8ef, // (12, 2287) 94
(short) 0xa08f, // (10, 143) 95
(short) 0xc4ef, // (12, 1263) 96
(short) 0xccef, // (12, 3311) 97
(short) 0xc2ef, // (12, 751) 98
(short) 0xa28f, // (10, 655) 99
(short) 0xcaef, // (12, 2799) 100
(short) 0xc6ef, // (12, 1775) 101
(short) 0xceef, // (12, 3823) 102
(short) 0xa18f, // (10, 399) 103
(short) 0xc1ef, // (12, 495) 104
(short) 0xc9ef, // (12, 2543) 105
(short) 0xc5ef, // (12, 1519) 106
(short) 0xb7cf, // (11, 1999) 107
(short) 0xcdef, // (12, 3567) 108
(short) 0xc3ef, // (12, 1007) 109
(short) 0xcbef, // (12, 3055) 110
(short) 0xb02f, // (11, 47) 111
(short) 0xc7ef, // (12, 2031) 112
(short) 0xcfef, // (12, 4079) 113
(short) 0xc01f, // (12, 31) 114
(short) 0xc81f, // (12, 2079) 115
(short) 0xc41f, // (12, 1055) 116
(short) 0xcc1f, // (12, 3103) 117
(short) 0xc21f, // (12, 543) 118
(short) 0xca1f, // (12, 2591) 119
(short) 0xc61f, // (12, 1567) 120
(short) 0xce1f, // (12, 3615) 121
(short) 0xc11f, // (12, 287) 122
(short) 0xc91f, // (12, 2335) 123
(short) 0xc51f, // (12, 1311) 124
(short) 0xcd1f, // (12, 3359) 125
(short) 0xc31f, // (12, 799) 126
(short) 0xcb1f, // (12, 2847) 127
(short) 0xc71f, // (12, 1823) 128
(short) 0xa38f, // (10, 911) 129
(short) 0xcf1f, // (12, 3871) 130
(short) 0x80e7, // ( 8, 231) 131
(short) 0xc09f, // (12, 159) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xc89f, // (12, 2207) 134
(short) 0x8017, // ( 8, 23) 135
(short) 0xc49f, // (12, 1183) 136
(short) 0xb42f, // (11, 1071) 137
(short) 0xcc9f, // (12, 3231) 138
(short) 0x9077, // ( 9, 119) 139
(short) 0xc29f, // (12, 671) 140
(short) 0xb22f, // (11, 559) 141
(short) 0xca9f, // (12, 2719) 142
(short) 0x8097, // ( 8, 151) 143
(short) 0xc69f, // (12, 1695) 144
(short) 0xce9f, // (12, 3743) 145
(short) 0xc19f, // (12, 415) 146
(short) 0xa24f, // (10, 591) 147
(short) 0xc99f, // (12, 2463) 148
(short) 0xc59f, // (12, 1439) 149
(short) 0xcd9f, // (12, 3487) 150
(short) 0xa14f, // (10, 335) 151
(short) 0xc39f, // (12, 927) 152
(short) 0xcb9f, // (12, 2975) 153
(short) 0xc79f, // (12, 1951) 154
(short) 0xb62f, // (11, 1583) 155
(short) 0xcf9f, // (12, 3999) 156
(short) 0xc05f, // (12, 95) 157
(short) 0xc85f, // (12, 2143) 158
(short) 0xb12f, // (11, 303) 159
(short) 0xc45f, // (12, 1119) 160
(short) 0xcc5f, // (12, 3167) 161
(short) 0xc25f, // (12, 607) 162
(short) 0xb52f, // (11, 1327) 163
(short) 0xca5f, // (12, 2655) 164
(short) 0xc65f, // (12, 1631) 165
(short) 0xce5f, // (12, 3679) 166
(short) 0xb32f, // (11, 815) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 3 of 22) (steady 3 of 16) (phase = 0.218750000 = 7.0 / 32.0)
// entropy: 4.4457680500675866853
// avg_length: 4.5181192844586535173; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0xb24f, // (11, 591) 0
(short) 0x601d, // ( 6, 29) 1
(short) 0x9097, // ( 9, 151) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0xa1f7, // (10, 503) 4
(short) 0x5005, // ( 5, 5) 5
(short) 0x807b, // ( 8, 123) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xc52f, // (12, 1327) 8
(short) 0x603d, // ( 6, 61) 9
(short) 0x9197, // ( 9, 407) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xb64f, // (11, 1615) 12
(short) 0x6003, // ( 6, 3) 13
(short) 0x9057, // ( 9, 87) 14
(short) 0x3006, // ( 3, 6) 15
(short) 0xcd2f, // (12, 3375) 16
(short) 0x80fb, // ( 8, 251) 17
(short) 0xb14f, // (11, 335) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xc32f, // (12, 815) 20
(short) 0x702b, // ( 7, 43) 21
(short) 0xa3f7, // (10, 1015) 22
(short) 0x4009, // ( 4, 9) 23
(short) 0xcb2f, // (12, 2863) 24
(short) 0x8007, // ( 8, 7) 25
(short) 0xb54f, // (11, 1359) 26
(short) 0x6023, // ( 6, 35) 27
(short) 0xc72f, // (12, 1839) 28
(short) 0x8087, // ( 8, 135) 29
(short) 0xb34f, // (11, 847) 30
(short) 0x500d, // ( 5, 13) 31
(short) 0xcf2f, // (12, 3887) 32
(short) 0x9157, // ( 9, 343) 33
(short) 0xc0af, // (12, 175) 34
(short) 0x6013, // ( 6, 19) 35
(short) 0xc8af, // (12, 2223) 36
(short) 0x8047, // ( 8, 71) 37
(short) 0xb74f, // (11, 1871) 38
(short) 0x6033, // ( 6, 51) 39
(short) 0xc4af, // (12, 1199) 40
(short) 0x90d7, // ( 9, 215) 41
(short) 0xccaf, // (12, 3247) 42
(short) 0x706b, // ( 7, 107) 43
(short) 0xc2af, // (12, 687) 44
(short) 0x91d7, // ( 9, 471) 45
(short) 0xcaaf, // (12, 2735) 46
(short) 0x600b, // ( 6, 11) 47
(short) 0xc6af, // (12, 1711) 48
(short) 0xb0cf, // (11, 207) 49
(short) 0xceaf, // (12, 3759) 50
(short) 0x80c7, // ( 8, 199) 51
(short) 0xc1af, // (12, 431) 52
(short) 0xa00f, // (10, 15) 53
(short) 0xc9af, // (12, 2479) 54
(short) 0x8027, // ( 8, 39) 55
(short) 0xc5af, // (12, 1455) 56
(short) 0xb4cf, // (11, 1231) 57
(short) 0xcdaf, // (12, 3503) 58
(short) 0x9037, // ( 9, 55) 59
(short) 0xc3af, // (12, 943) 60
(short) 0xb2cf, // (11, 719) 61
(short) 0xcbaf, // (12, 2991) 62
(short) 0x80a7, // ( 8, 167) 63
(short) 0xc7af, // (12, 1967) 64
(short) 0xa20f, // (10, 527) 65
(short) 0xcfaf, // (12, 4015) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xc06f, // (12, 111) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xc86f, // (12, 2159) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xc46f, // (12, 1135) 72
(short) 0xb6cf, // (11, 1743) 73
(short) 0xcc6f, // (12, 3183) 74
(short) 0x8067, // ( 8, 103) 75
(short) 0xc26f, // (12, 623) 76
(short) 0xa10f, // (10, 271) 77
(short) 0xca6f, // (12, 2671) 78
(short) 0x703b, // ( 7, 59) 79
(short) 0xc66f, // (12, 1647) 80
(short) 0xce6f, // (12, 3695) 81
(short) 0xc16f, // (12, 367) 82
(short) 0x90b7, // ( 9, 183) 83
(short) 0xc96f, // (12, 2415) 84
(short) 0xb1cf, // (11, 463) 85
(short) 0xc56f, // (12, 1391) 86
(short) 0x91b7, // ( 9, 439) 87
(short) 0xcd6f, // (12, 3439) 88
(short) 0xc36f, // (12, 879) 89
(short) 0xcb6f, // (12, 2927) 90
(short) 0xa30f, // (10, 783) 91
(short) 0xc76f, // (12, 1903) 92
(short) 0xcf6f, // (12, 3951) 93
(short) 0xc0ef, // (12, 239) 94
(short) 0x9077, // ( 9, 119) 95
(short) 0xc8ef, // (12, 2287) 96
(short) 0xc4ef, // (12, 1263) 97
(short) 0xccef, // (12, 3311) 98
(short) 0xa08f, // (10, 143) 99
(short) 0xc2ef, // (12, 751) 100
(short) 0xcaef, // (12, 2799) 101
(short) 0xc6ef, // (12, 1775) 102
(short) 0xa28f, // (10, 655) 103
(short) 0xceef, // (12, 3823) 104
(short) 0xc1ef, // (12, 495) 105
(short) 0xc9ef, // (12, 2543) 106
(short) 0xb5cf, // (11, 1487) 107
(short) 0xc5ef, // (12, 1519) 108
(short) 0xcdef, // (12, 3567) 109
(short) 0xc3ef, // (12, 1007) 110
(short) 0xb3cf, // (11, 975) 111
(short) 0xcbef, // (12, 3055) 112
(short) 0xc7ef, // (12, 2031) 113
(short) 0xcfef, // (12, 4079) 114
(short) 0xc01f, // (12, 31) 115
(short) 0xc81f, // (12, 2079) 116
(short) 0xc41f, // (12, 1055) 117
(short) 0xcc1f, // (12, 3103) 118
(short) 0xc21f, // (12, 543) 119
(short) 0xca1f, // (12, 2591) 120
(short) 0xc61f, // (12, 1567) 121
(short) 0xce1f, // (12, 3615) 122
(short) 0xc11f, // (12, 287) 123
(short) 0xc91f, // (12, 2335) 124
(short) 0xc51f, // (12, 1311) 125
(short) 0xcd1f, // (12, 3359) 126
(short) 0xc31f, // (12, 799) 127
(short) 0xcb1f, // (12, 2847) 128
(short) 0xb7cf, // (11, 1999) 129
(short) 0xc71f, // (12, 1823) 130
(short) 0x80e7, // ( 8, 231) 131
(short) 0xcf1f, // (12, 3871) 132
(short) 0xa18f, // (10, 399) 133
(short) 0xc09f, // (12, 159) 134
(short) 0x8017, // ( 8, 23) 135
(short) 0xc89f, // (12, 2207) 136
(short) 0xc49f, // (12, 1183) 137
(short) 0xcc9f, // (12, 3231) 138
(short) 0x9177, // ( 9, 375) 139
(short) 0xc29f, // (12, 671) 140
(short) 0xb02f, // (11, 47) 141
(short) 0xca9f, // (12, 2719) 142
(short) 0x90f7, // ( 9, 247) 143
(short) 0xc69f, // (12, 1695) 144
(short) 0xce9f, // (12, 3743) 145
(short) 0xc19f, // (12, 415) 146
(short) 0xa38f, // (10, 911) 147
(short) 0xc99f, // (12, 2463) 148
(short) 0xc59f, // (12, 1439) 149
(short) 0xcd9f, // (12, 3487) 150
(short) 0xa04f, // (10, 79) 151
(short) 0xc39f, // (12, 927) 152
(short) 0xcb9f, // (12, 2975) 153
(short) 0xc79f, // (12, 1951) 154
(short) 0xb42f, // (11, 1071) 155
(short) 0xcf9f, // (12, 3999) 156
(short) 0xc05f, // (12, 95) 157
(short) 0xc85f, // (12, 2143) 158
(short) 0xb22f, // (11, 559) 159
(short) 0xc45f, // (12, 1119) 160
(short) 0xcc5f, // (12, 3167) 161
(short) 0xc25f, // (12, 607) 162
(short) 0xb62f, // (11, 1583) 163
(short) 0xca5f, // (12, 2655) 164
(short) 0xc65f, // (12, 1631) 165
(short) 0xce5f, // (12, 3679) 166
(short) 0xb12f, // (11, 303) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 4 of 22) (steady 4 of 16) (phase = 0.281250000 = 9.0 / 32.0)
// entropy: 4.4386754570568340839
// avg_length: 4.5071584786605640716; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0xb24f, // (11, 591) 0
(short) 0x601d, // ( 6, 29) 1
(short) 0x9057, // ( 9, 87) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0xb64f, // (11, 1615) 4
(short) 0x5005, // ( 5, 5) 5
(short) 0x807b, // ( 8, 123) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xc32f, // (12, 815) 8
(short) 0x700b, // ( 7, 11) 9
(short) 0xa0f7, // (10, 247) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xb14f, // (11, 335) 12
(short) 0x603d, // ( 6, 61) 13
(short) 0x9157, // ( 9, 343) 14
(short) 0x3006, // ( 3, 6) 15
(short) 0xcb2f, // (12, 2863) 16
(short) 0x80fb, // ( 8, 251) 17
(short) 0xb54f, // (11, 1359) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xc72f, // (12, 1839) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0xa2f7, // (10, 759) 22
(short) 0x4009, // ( 4, 9) 23
(short) 0xcf2f, // (12, 3887) 24
(short) 0x8007, // ( 8, 7) 25
(short) 0xb34f, // (11, 847) 26
(short) 0x6003, // ( 6, 3) 27
(short) 0xc0af, // (12, 175) 28
(short) 0x8087, // ( 8, 135) 29
(short) 0xb74f, // (11, 1871) 30
(short) 0x500d, // ( 5, 13) 31
(short) 0xc8af, // (12, 2223) 32
(short) 0x90d7, // ( 9, 215) 33
(short) 0xc4af, // (12, 1199) 34
(short) 0x6023, // ( 6, 35) 35
(short) 0xccaf, // (12, 3247) 36
(short) 0x8047, // ( 8, 71) 37
(short) 0xb0cf, // (11, 207) 38
(short) 0x6013, // ( 6, 19) 39
(short) 0xc2af, // (12, 687) 40
(short) 0xa1f7, // (10, 503) 41
(short) 0xcaaf, // (12, 2735) 42
(short) 0x702b, // ( 7, 43) 43
(short) 0xc6af, // (12, 1711) 44
(short) 0x91d7, // ( 9, 471) 45
(short) 0xceaf, // (12, 3759) 46
(short) 0x6033, // ( 6, 51) 47
(short) 0xc1af, // (12, 431) 48
(short) 0xb4cf, // (11, 1231) 49
(short) 0xc9af, // (12, 2479) 50
(short) 0x80c7, // ( 8, 199) 51
(short) 0xc5af, // (12, 1455) 52
(short) 0xa3f7, // (10, 1015) 53
(short) 0xcdaf, // (12, 3503) 54
(short) 0x706b, // ( 7, 107) 55
(short) 0xc3af, // (12, 943) 56
(short) 0xb2cf, // (11, 719) 57
(short) 0xcbaf, // (12, 2991) 58
(short) 0x9037, // ( 9, 55) 59
(short) 0xc7af, // (12, 1967) 60
(short) 0xb6cf, // (11, 1743) 61
(short) 0xcfaf, // (12, 4015) 62
(short) 0x8027, // ( 8, 39) 63
(short) 0xc06f, // (12, 111) 64
(short) 0xa00f, // (10, 15) 65
(short) 0xc86f, // (12, 2159) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xc46f, // (12, 1135) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xcc6f, // (12, 3183) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xc26f, // (12, 623) 72
(short) 0xb1cf, // (11, 463) 73
(short) 0xca6f, // (12, 2671) 74
(short) 0x80a7, // ( 8, 167) 75
(short) 0xc66f, // (12, 1647) 76
(short) 0xa20f, // (10, 527) 77
(short) 0xce6f, // (12, 3695) 78
(short) 0x703b, // ( 7, 59) 79
(short) 0xc16f, // (12, 367) 80
(short) 0xc96f, // (12, 2415) 81
(short) 0xc56f, // (12, 1391) 82
(short) 0x90b7, // ( 9, 183) 83
(short) 0xcd6f, // (12, 3439) 84
(short) 0xb5cf, // (11, 1487) 85
(short) 0xc36f, // (12, 879) 86
(short) 0x8067, // ( 8, 103) 87
(short) 0xcb6f, // (12, 2927) 88
(short) 0xc76f, // (12, 1903) 89
(short) 0xcf6f, // (12, 3951) 90
(short) 0xa10f, // (10, 271) 91
(short) 0xc0ef, // (12, 239) 92
(short) 0xc8ef, // (12, 2287) 93
(short) 0xc4ef, // (12, 1263) 94
(short) 0x91b7, // ( 9, 439) 95
(short) 0xccef, // (12, 3311) 96
(short) 0xc2ef, // (12, 751) 97
(short) 0xcaef, // (12, 2799) 98
(short) 0xa30f, // (10, 783) 99
(short) 0xc6ef, // (12, 1775) 100
(short) 0xceef, // (12, 3823) 101
(short) 0xc1ef, // (12, 495) 102
(short) 0xa08f, // (10, 143) 103
(short) 0xc9ef, // (12, 2543) 104
(short) 0xc5ef, // (12, 1519) 105
(short) 0xcdef, // (12, 3567) 106
(short) 0xb3cf, // (11, 975) 107
(short) 0xc3ef, // (12, 1007) 108
(short) 0xcbef, // (12, 3055) 109
(short) 0xc7ef, // (12, 2031) 110
(short) 0xa28f, // (10, 655) 111
(short) 0xcfef, // (12, 4079) 112
(short) 0xc01f, // (12, 31) 113
(short) 0xc81f, // (12, 2079) 114
(short) 0xc41f, // (12, 1055) 115
(short) 0xcc1f, // (12, 3103) 116
(short) 0xc21f, // (12, 543) 117
(short) 0xca1f, // (12, 2591) 118
(short) 0xb7cf, // (11, 1999) 119
(short) 0xc61f, // (12, 1567) 120
(short) 0xce1f, // (12, 3615) 121
(short) 0xc11f, // (12, 287) 122
(short) 0xc91f, // (12, 2335) 123
(short) 0xc51f, // (12, 1311) 124
(short) 0xcd1f, // (12, 3359) 125
(short) 0xc31f, // (12, 799) 126
(short) 0xcb1f, // (12, 2847) 127
(short) 0xc71f, // (12, 1823) 128
(short) 0xb02f, // (11, 47) 129
(short) 0xcf1f, // (12, 3871) 130
(short) 0x80e7, // ( 8, 231) 131
(short) 0xc09f, // (12, 159) 132
(short) 0xa18f, // (10, 399) 133
(short) 0xc89f, // (12, 2207) 134
(short) 0x8017, // ( 8, 23) 135
(short) 0xc49f, // (12, 1183) 136
(short) 0xcc9f, // (12, 3231) 137
(short) 0xc29f, // (12, 671) 138
(short) 0x9077, // ( 9, 119) 139
(short) 0xca9f, // (12, 2719) 140
(short) 0xb42f, // (11, 1071) 141
(short) 0xc69f, // (12, 1695) 142
(short) 0x8097, // ( 8, 151) 143
(short) 0xce9f, // (12, 3743) 144
(short) 0xc19f, // (12, 415) 145
(short) 0xc99f, // (12, 2463) 146
(short) 0xa38f, // (10, 911) 147
(short) 0xc59f, // (12, 1439) 148
(short) 0xcd9f, // (12, 3487) 149
(short) 0xc39f, // (12, 927) 150
(short) 0x9177, // ( 9, 375) 151
(short) 0xcb9f, // (12, 2975) 152
(short) 0xc79f, // (12, 1951) 153
(short) 0xcf9f, // (12, 3999) 154
(short) 0xb22f, // (11, 559) 155
(short) 0xc05f, // (12, 95) 156
(short) 0xc85f, // (12, 2143) 157
(short) 0xc45f, // (12, 1119) 158
(short) 0xa04f, // (10, 79) 159
(short) 0xcc5f, // (12, 3167) 160
(short) 0xc25f, // (12, 607) 161
(short) 0xca5f, // (12, 2655) 162
(short) 0xb62f, // (11, 1583) 163
(short) 0xc65f, // (12, 1631) 164
(short) 0xce5f, // (12, 3679) 165
(short) 0xc15f, // (12, 351) 166
(short) 0xb12f, // (11, 303) 167
(short) 0xc95f, // (12, 2399) 168
(short) 0xc55f, // (12, 1375) 169
(short) 0xcd5f, // (12, 3423) 170
(short) 0xc35f, // (12, 863) 171
(short) 0xcb5f, // (12, 2911) 172
(short) 0xc75f, // (12, 1887) 173
(short) 0xcf5f, // (12, 3935) 174
(short) 0xb52f, // (11, 1327) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 5 of 22) (steady 5 of 16) (phase = 0.343750000 = 11.0 / 32.0)
// entropy: 4.4308578632493116345
// avg_length: 4.4996166821663301505; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0xc12f, // (12, 303) 0
(short) 0x601d, // ( 6, 29) 1
(short) 0x9057, // ( 9, 87) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0xb14f, // (11, 335) 4
(short) 0x5005, // ( 5, 5) 5
(short) 0x807b, // ( 8, 123) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xc92f, // (12, 2351) 8
(short) 0x700b, // ( 7, 11) 9
(short) 0xa1f7, // (10, 503) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xc52f, // (12, 1327) 12
(short) 0x603d, // ( 6, 61) 13
(short) 0x9157, // ( 9, 343) 14
(short) 0x3006, // ( 3, 6) 15
(short) 0xcd2f, // (12, 3375) 16
(short) 0x80fb, // ( 8, 251) 17
(short) 0xb54f, // (11, 1359) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xc32f, // (12, 815) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0xa3f7, // (10, 1015) 22
(short) 0x4009, // ( 4, 9) 23
(short) 0xcb2f, // (12, 2863) 24
(short) 0x8007, // ( 8, 7) 25
(short) 0xc72f, // (12, 1839) 26
(short) 0x6003, // ( 6, 3) 27
(short) 0xcf2f, // (12, 3887) 28
(short) 0x8087, // ( 8, 135) 29
(short) 0xb34f, // (11, 847) 30
(short) 0x500d, // ( 5, 13) 31
(short) 0xc0af, // (12, 175) 32
(short) 0x90d7, // ( 9, 215) 33
(short) 0xc8af, // (12, 2223) 34
(short) 0x6023, // ( 6, 35) 35
(short) 0xc4af, // (12, 1199) 36
(short) 0x8047, // ( 8, 71) 37
(short) 0xb74f, // (11, 1871) 38
(short) 0x6013, // ( 6, 19) 39
(short) 0xccaf, // (12, 3247) 40
(short) 0xa00f, // (10, 15) 41
(short) 0xc2af, // (12, 687) 42
(short) 0x702b, // ( 7, 43) 43
(short) 0xcaaf, // (12, 2735) 44
(short) 0x91d7, // ( 9, 471) 45
(short) 0xc6af, // (12, 1711) 46
(short) 0x6033, // ( 6, 51) 47
(short) 0xceaf, // (12, 3759) 48
(short) 0xb0cf, // (11, 207) 49
(short) 0xc1af, // (12, 431) 50
(short) 0x80c7, // ( 8, 199) 51
(short) 0xc9af, // (12, 2479) 52
(short) 0xa20f, // (10, 527) 53
(short) 0xc5af, // (12, 1455) 54
(short) 0x706b, // ( 7, 107) 55
(short) 0xcdaf, // (12, 3503) 56
(short) 0xc3af, // (12, 943) 57
(short) 0xcbaf, // (12, 2991) 58
(short) 0x9037, // ( 9, 55) 59
(short) 0xc7af, // (12, 1967) 60
(short) 0xb4cf, // (11, 1231) 61
(short) 0xcfaf, // (12, 4015) 62
(short) 0x8027, // ( 8, 39) 63
(short) 0xc06f, // (12, 111) 64
(short) 0xa10f, // (10, 271) 65
(short) 0xc86f, // (12, 2159) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xc46f, // (12, 1135) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xcc6f, // (12, 3183) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xc26f, // (12, 623) 72
(short) 0xb2cf, // (11, 719) 73
(short) 0xca6f, // (12, 2671) 74
(short) 0x80a7, // ( 8, 167) 75
(short) 0xc66f, // (12, 1647) 76
(short) 0xa30f, // (10, 783) 77
(short) 0xce6f, // (12, 3695) 78
(short) 0x703b, // ( 7, 59) 79
(short) 0xc16f, // (12, 367) 80
(short) 0xc96f, // (12, 2415) 81
(short) 0xc56f, // (12, 1391) 82
(short) 0x90b7, // ( 9, 183) 83
(short) 0xcd6f, // (12, 3439) 84
(short) 0xb6cf, // (11, 1743) 85
(short) 0xc36f, // (12, 879) 86
(short) 0x8067, // ( 8, 103) 87
(short) 0xcb6f, // (12, 2927) 88
(short) 0xc76f, // (12, 1903) 89
(short) 0xcf6f, // (12, 3951) 90
(short) 0xa08f, // (10, 143) 91
(short) 0xc0ef, // (12, 239) 92
(short) 0xc8ef, // (12, 2287) 93
(short) 0xc4ef, // (12, 1263) 94
(short) 0x91b7, // ( 9, 439) 95
(short) 0xccef, // (12, 3311) 96
(short) 0xc2ef, // (12, 751) 97
(short) 0xcaef, // (12, 2799) 98
(short) 0xa28f, // (10, 655) 99
(short) 0xc6ef, // (12, 1775) 100
(short) 0xceef, // (12, 3823) 101
(short) 0xc1ef, // (12, 495) 102
(short) 0x9077, // ( 9, 119) 103
(short) 0xc9ef, // (12, 2543) 104
(short) 0xc5ef, // (12, 1519) 105
(short) 0xcdef, // (12, 3567) 106
(short) 0xb1cf, // (11, 463) 107
(short) 0xc3ef, // (12, 1007) 108
(short) 0xcbef, // (12, 3055) 109
(short) 0xc7ef, // (12, 2031) 110
(short) 0xa18f, // (10, 399) 111
(short) 0xcfef, // (12, 4079) 112
(short) 0xc01f, // (12, 31) 113
(short) 0xc81f, // (12, 2079) 114
(short) 0xc41f, // (12, 1055) 115
(short) 0xcc1f, // (12, 3103) 116
(short) 0xc21f, // (12, 543) 117
(short) 0xca1f, // (12, 2591) 118
(short) 0xb5cf, // (11, 1487) 119
(short) 0xc61f, // (12, 1567) 120
(short) 0xce1f, // (12, 3615) 121
(short) 0xc11f, // (12, 287) 122
(short) 0xc91f, // (12, 2335) 123
(short) 0xc51f, // (12, 1311) 124
(short) 0xcd1f, // (12, 3359) 125
(short) 0xc31f, // (12, 799) 126
(short) 0xcb1f, // (12, 2847) 127
(short) 0xc71f, // (12, 1823) 128
(short) 0xb3cf, // (11, 975) 129
(short) 0xcf1f, // (12, 3871) 130
(short) 0x80e7, // ( 8, 231) 131
(short) 0xc09f, // (12, 159) 132
(short) 0xa38f, // (10, 911) 133
(short) 0xc89f, // (12, 2207) 134
(short) 0x8017, // ( 8, 23) 135
(short) 0xc49f, // (12, 1183) 136
(short) 0xcc9f, // (12, 3231) 137
(short) 0xc29f, // (12, 671) 138
(short) 0x9177, // ( 9, 375) 139
(short) 0xca9f, // (12, 2719) 140
(short) 0xb7cf, // (11, 1999) 141
(short) 0xc69f, // (12, 1695) 142
(short) 0x8097, // ( 8, 151) 143
(short) 0xce9f, // (12, 3743) 144
(short) 0xc19f, // (12, 415) 145
(short) 0xc99f, // (12, 2463) 146
(short) 0xa04f, // (10, 79) 147
(short) 0xc59f, // (12, 1439) 148
(short) 0xcd9f, // (12, 3487) 149
(short) 0xc39f, // (12, 927) 150
(short) 0x90f7, // ( 9, 247) 151
(short) 0xcb9f, // (12, 2975) 152
(short) 0xc79f, // (12, 1951) 153
(short) 0xcf9f, // (12, 3999) 154
(short) 0xb02f, // (11, 47) 155
(short) 0xc05f, // (12, 95) 156
(short) 0xc85f, // (12, 2143) 157
(short) 0xc45f, // (12, 1119) 158
(short) 0xa24f, // (10, 591) 159
(short) 0xcc5f, // (12, 3167) 160
(short) 0xc25f, // (12, 607) 161
(short) 0xca5f, // (12, 2655) 162
(short) 0xb42f, // (11, 1071) 163
(short) 0xc65f, // (12, 1631) 164
(short) 0xce5f, // (12, 3679) 165
(short) 0xc15f, // (12, 351) 166
(short) 0xb22f, // (11, 559) 167
(short) 0xc95f, // (12, 2399) 168
(short) 0xc55f, // (12, 1375) 169
(short) 0xcd5f, // (12, 3423) 170
(short) 0xc35f, // (12, 863) 171
(short) 0xcb5f, // (12, 2911) 172
(short) 0xc75f, // (12, 1887) 173
(short) 0xcf5f, // (12, 3935) 174
(short) 0xb62f, // (11, 1583) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 6 of 22) (steady 6 of 16) (phase = 0.406250000 = 13.0 / 32.0)
// entropy: 4.4310364988500126060
// avg_length: 4.5051134111084252254; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x601d, // ( 6, 29) 0
(short) 0x3002, // ( 3, 2) 1
(short) 0x603d, // ( 6, 61) 2
(short) 0x2000, // ( 2, 0) 3
(short) 0x700b, // ( 7, 11) 4
(short) 0x4001, // ( 4, 1) 5
(short) 0x6003, // ( 6, 3) 6
(short) 0x3006, // ( 3, 6) 7
(short) 0x807b, // ( 8, 123) 8
(short) 0x5005, // ( 5, 5) 9
(short) 0x704b, // ( 7, 75) 10
(short) 0x4009, // ( 4, 9) 11
(short) 0x9097, // ( 9, 151) 12
(short) 0x6023, // ( 6, 35) 13
(short) 0x80fb, // ( 8, 251) 14
(short) 0x5015, // ( 5, 21) 15
(short) 0x9197, // ( 9, 407) 16
(short) 0x6013, // ( 6, 19) 17
(short) 0x8007, // ( 8, 7) 18
(short) 0x500d, // ( 5, 13) 19
(short) 0xa0f7, // (10, 247) 20
(short) 0x702b, // ( 7, 43) 21
(short) 0x9057, // ( 9, 87) 22
(short) 0x6033, // ( 6, 51) 23
(short) 0xb14f, // (11, 335) 24
(short) 0x8087, // ( 8, 135) 25
(short) 0xa2f7, // (10, 759) 26
(short) 0x706b, // ( 7, 107) 27
(short) 0xb54f, // (11, 1359) 28
(short) 0x9157, // ( 9, 343) 29
(short) 0xa1f7, // (10, 503) 30
(short) 0x8047, // ( 8, 71) 31
(short) 0xa3f7, // (10, 1015) 32
(short) 0x701b, // ( 7, 27) 33
(short) 0x90d7, // ( 9, 215) 34
(short) 0x705b, // ( 7, 91) 35
(short) 0xb34f, // (11, 847) 36
(short) 0x80c7, // ( 8, 199) 37
(short) 0xa00f, // (10, 15) 38
(short) 0x703b, // ( 7, 59) 39
(short) 0xc32f, // (12, 815) 40
(short) 0x91d7, // ( 9, 471) 41
(short) 0xb74f, // (11, 1871) 42
(short) 0x8027, // ( 8, 39) 43
(short) 0xcb2f, // (12, 2863) 44
(short) 0xa20f, // (10, 527) 45
(short) 0xb0cf, // (11, 207) 46
(short) 0x9037, // ( 9, 55) 47
(short) 0xc72f, // (12, 1839) 48
(short) 0xa10f, // (10, 271) 49
(short) 0xcf2f, // (12, 3887) 50
(short) 0x9137, // ( 9, 311) 51
(short) 0xc0af, // (12, 175) 52
(short) 0xb4cf, // (11, 1231) 53
(short) 0xc8af, // (12, 2223) 54
(short) 0xa30f, // (10, 783) 55
(short) 0xc4af, // (12, 1199) 56
(short) 0xccaf, // (12, 3247) 57
(short) 0xc2af, // (12, 687) 58
(short) 0xb2cf, // (11, 719) 59
(short) 0xcaaf, // (12, 2735) 60
(short) 0xc6af, // (12, 1711) 61
(short) 0xceaf, // (12, 3759) 62
(short) 0xb6cf, // (11, 1743) 63
(short) 0xb1cf, // (11, 463) 64
(short) 0x80a7, // ( 8, 167) 65
(short) 0xa08f, // (10, 143) 66
(short) 0x8067, // ( 8, 103) 67
(short) 0xc1af, // (12, 431) 68
(short) 0x90b7, // ( 9, 183) 69
(short) 0xb5cf, // (11, 1487) 70
(short) 0x80e7, // ( 8, 231) 71
(short) 0xc9af, // (12, 2479) 72
(short) 0xa28f, // (10, 655) 73
(short) 0xc5af, // (12, 1455) 74
(short) 0x91b7, // ( 9, 439) 75
(short) 0xcdaf, // (12, 3503) 76
(short) 0xb3cf, // (11, 975) 77
(short) 0xc3af, // (12, 943) 78
(short) 0xa18f, // (10, 399) 79
(short) 0xcbaf, // (12, 2991) 80
(short) 0xb7cf, // (11, 1999) 81
(short) 0xc7af, // (12, 1967) 82
(short) 0xa38f, // (10, 911) 83
(short) 0xcfaf, // (12, 4015) 84
(short) 0xc06f, // (12, 111) 85
(short) 0xc86f, // (12, 2159) 86
(short) 0xb02f, // (11, 47) 87
(short) 0xc46f, // (12, 1135) 88
(short) 0xcc6f, // (12, 3183) 89
(short) 0xc26f, // (12, 623) 90
(short) 0xca6f, // (12, 2671) 91
(short) 0xc66f, // (12, 1647) 92
(short) 0xce6f, // (12, 3695) 93
(short) 0xc16f, // (12, 367) 94
(short) 0xc96f, // (12, 2415) 95
(short) 0xc56f, // (12, 1391) 96
(short) 0xcd6f, // (12, 3439) 97
(short) 0xc36f, // (12, 879) 98
(short) 0xb42f, // (11, 1071) 99
(short) 0xcb6f, // (12, 2927) 100
(short) 0xc76f, // (12, 1903) 101
(short) 0xcf6f, // (12, 3951) 102
(short) 0xc0ef, // (12, 239) 103
(short) 0xc8ef, // (12, 2287) 104
(short) 0xc4ef, // (12, 1263) 105
(short) 0xccef, // (12, 3311) 106
(short) 0xc2ef, // (12, 751) 107
(short) 0xcaef, // (12, 2799) 108
(short) 0xc6ef, // (12, 1775) 109
(short) 0xceef, // (12, 3823) 110
(short) 0xc1ef, // (12, 495) 111
(short) 0xc9ef, // (12, 2543) 112
(short) 0xc5ef, // (12, 1519) 113
(short) 0xcdef, // (12, 3567) 114
(short) 0xc3ef, // (12, 1007) 115
(short) 0xcbef, // (12, 3055) 116
(short) 0xc7ef, // (12, 2031) 117
(short) 0xcfef, // (12, 4079) 118
(short) 0xc01f, // (12, 31) 119
(short) 0xc81f, // (12, 2079) 120
(short) 0xc41f, // (12, 1055) 121
(short) 0xcc1f, // (12, 3103) 122
(short) 0xc21f, // (12, 543) 123
(short) 0xca1f, // (12, 2591) 124
(short) 0xc61f, // (12, 1567) 125
(short) 0xce1f, // (12, 3615) 126
(short) 0xc11f, // (12, 287) 127
(short) 0xc91f, // (12, 2335) 128
(short) 0x9077, // ( 9, 119) 129
(short) 0xb22f, // (11, 559) 130
(short) 0x8017, // ( 8, 23) 131
(short) 0xc51f, // (12, 1311) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xcd1f, // (12, 3359) 134
(short) 0x9177, // ( 9, 375) 135
(short) 0xc31f, // (12, 799) 136
(short) 0xb62f, // (11, 1583) 137
(short) 0xcb1f, // (12, 2847) 138
(short) 0xa24f, // (10, 591) 139
(short) 0xc71f, // (12, 1823) 140
(short) 0xcf1f, // (12, 3871) 141
(short) 0xc09f, // (12, 159) 142
(short) 0xb12f, // (11, 303) 143
(short) 0xc89f, // (12, 2207) 144
(short) 0xc49f, // (12, 1183) 145
(short) 0xcc9f, // (12, 3231) 146
(short) 0xb52f, // (11, 1327) 147
(short) 0xc29f, // (12, 671) 148
(short) 0xca9f, // (12, 2719) 149
(short) 0xc69f, // (12, 1695) 150
(short) 0xce9f, // (12, 3743) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 7 of 22) (steady 7 of 16) (phase = 0.468750000 = 15.0 / 32.0)
// entropy: 4.4417871821766841123
// avg_length: 4.5206419191518980583; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x700b, // ( 7, 11) 0
(short) 0x3002, // ( 3, 2) 1
(short) 0x601d, // ( 6, 29) 2
(short) 0x2000, // ( 2, 0) 3
(short) 0x704b, // ( 7, 75) 4
(short) 0x4001, // ( 4, 1) 5
(short) 0x603d, // ( 6, 61) 6
(short) 0x3006, // ( 3, 6) 7
(short) 0x8007, // ( 8, 7) 8
(short) 0x5005, // ( 5, 5) 9
(short) 0x702b, // ( 7, 43) 10
(short) 0x4009, // ( 4, 9) 11
(short) 0x9097, // ( 9, 151) 12
(short) 0x6003, // ( 6, 3) 13
(short) 0x8087, // ( 8, 135) 14
(short) 0x5015, // ( 5, 21) 15
(short) 0x9197, // ( 9, 407) 16
(short) 0x6023, // ( 6, 35) 17
(short) 0x8047, // ( 8, 71) 18
(short) 0x500d, // ( 5, 13) 19
(short) 0xa0f7, // (10, 247) 20
(short) 0x706b, // ( 7, 107) 21
(short) 0x9057, // ( 9, 87) 22
(short) 0x6013, // ( 6, 19) 23
(short) 0xb14f, // (11, 335) 24
(short) 0x80c7, // ( 8, 199) 25
(short) 0xa2f7, // (10, 759) 26
(short) 0x701b, // ( 7, 27) 27
(short) 0xc52f, // (12, 1327) 28
(short) 0x9157, // ( 9, 343) 29
(short) 0xb54f, // (11, 1359) 30
(short) 0x8027, // ( 8, 39) 31
(short) 0xa1f7, // (10, 503) 32
(short) 0x705b, // ( 7, 91) 33
(short) 0x90d7, // ( 9, 215) 34
(short) 0x6033, // ( 6, 51) 35
(short) 0xb34f, // (11, 847) 36
(short) 0x80a7, // ( 8, 167) 37
(short) 0xa3f7, // (10, 1015) 38
(short) 0x703b, // ( 7, 59) 39
(short) 0xcd2f, // (12, 3375) 40
(short) 0x91d7, // ( 9, 471) 41
(short) 0xb74f, // (11, 1871) 42
(short) 0x8067, // ( 8, 103) 43
(short) 0xc32f, // (12, 815) 44
(short) 0xa00f, // (10, 15) 45
(short) 0xcb2f, // (12, 2863) 46
(short) 0x9037, // ( 9, 55) 47
(short) 0xc72f, // (12, 1839) 48
(short) 0xa20f, // (10, 527) 49
(short) 0xcf2f, // (12, 3887) 50
(short) 0x9137, // ( 9, 311) 51
(short) 0xc0af, // (12, 175) 52
(short) 0xb0cf, // (11, 207) 53
(short) 0xc8af, // (12, 2223) 54
(short) 0xa10f, // (10, 271) 55
(short) 0xc4af, // (12, 1199) 56
(short) 0xccaf, // (12, 3247) 57
(short) 0xc2af, // (12, 687) 58
(short) 0xb4cf, // (11, 1231) 59
(short) 0xcaaf, // (12, 2735) 60
(short) 0xc6af, // (12, 1711) 61
(short) 0xceaf, // (12, 3759) 62
(short) 0xb2cf, // (11, 719) 63
(short) 0xb6cf, // (11, 1743) 64
(short) 0x80e7, // ( 8, 231) 65
(short) 0xa30f, // (10, 783) 66
(short) 0x707b, // ( 7, 123) 67
(short) 0xc1af, // (12, 431) 68
(short) 0x90b7, // ( 9, 183) 69
(short) 0xb1cf, // (11, 463) 70
(short) 0x8017, // ( 8, 23) 71
(short) 0xc9af, // (12, 2479) 72
(short) 0xa08f, // (10, 143) 73
(short) 0xc5af, // (12, 1455) 74
(short) 0x91b7, // ( 9, 439) 75
(short) 0xcdaf, // (12, 3503) 76
(short) 0xb5cf, // (11, 1487) 77
(short) 0xc3af, // (12, 943) 78
(short) 0xa28f, // (10, 655) 79
(short) 0xcbaf, // (12, 2991) 80
(short) 0xb3cf, // (11, 975) 81
(short) 0xc7af, // (12, 1967) 82
(short) 0xa18f, // (10, 399) 83
(short) 0xcfaf, // (12, 4015) 84
(short) 0xc06f, // (12, 111) 85
(short) 0xc86f, // (12, 2159) 86
(short) 0xb7cf, // (11, 1999) 87
(short) 0xc46f, // (12, 1135) 88
(short) 0xcc6f, // (12, 3183) 89
(short) 0xc26f, // (12, 623) 90
(short) 0xca6f, // (12, 2671) 91
(short) 0xc66f, // (12, 1647) 92
(short) 0xce6f, // (12, 3695) 93
(short) 0xc16f, // (12, 367) 94
(short) 0xc96f, // (12, 2415) 95
(short) 0xc56f, // (12, 1391) 96
(short) 0xcd6f, // (12, 3439) 97
(short) 0xc36f, // (12, 879) 98
(short) 0xb02f, // (11, 47) 99
(short) 0xcb6f, // (12, 2927) 100
(short) 0xc76f, // (12, 1903) 101
(short) 0xcf6f, // (12, 3951) 102
(short) 0xc0ef, // (12, 239) 103
(short) 0xc8ef, // (12, 2287) 104
(short) 0xc4ef, // (12, 1263) 105
(short) 0xccef, // (12, 3311) 106
(short) 0xc2ef, // (12, 751) 107
(short) 0xcaef, // (12, 2799) 108
(short) 0xc6ef, // (12, 1775) 109
(short) 0xceef, // (12, 3823) 110
(short) 0xc1ef, // (12, 495) 111
(short) 0xc9ef, // (12, 2543) 112
(short) 0xc5ef, // (12, 1519) 113
(short) 0xcdef, // (12, 3567) 114
(short) 0xc3ef, // (12, 1007) 115
(short) 0xcbef, // (12, 3055) 116
(short) 0xc7ef, // (12, 2031) 117
(short) 0xcfef, // (12, 4079) 118
(short) 0xc01f, // (12, 31) 119
(short) 0xc81f, // (12, 2079) 120
(short) 0xc41f, // (12, 1055) 121
(short) 0xcc1f, // (12, 3103) 122
(short) 0xc21f, // (12, 543) 123
(short) 0xca1f, // (12, 2591) 124
(short) 0xc61f, // (12, 1567) 125
(short) 0xce1f, // (12, 3615) 126
(short) 0xc11f, // (12, 287) 127
(short) 0xc91f, // (12, 2335) 128
(short) 0xa38f, // (10, 911) 129
(short) 0xb42f, // (11, 1071) 130
(short) 0x9077, // ( 9, 119) 131
(short) 0xc51f, // (12, 1311) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xcd1f, // (12, 3359) 134
(short) 0x9177, // ( 9, 375) 135
(short) 0xc31f, // (12, 799) 136
(short) 0xb22f, // (11, 559) 137
(short) 0xcb1f, // (12, 2847) 138
(short) 0xa24f, // (10, 591) 139
(short) 0xc71f, // (12, 1823) 140
(short) 0xcf1f, // (12, 3871) 141
(short) 0xc09f, // (12, 159) 142
(short) 0xb62f, // (11, 1583) 143
(short) 0xc89f, // (12, 2207) 144
(short) 0xc49f, // (12, 1183) 145
(short) 0xcc9f, // (12, 3231) 146
(short) 0xb12f, // (11, 303) 147
(short) 0xc29f, // (12, 671) 148
(short) 0xca9f, // (12, 2719) 149
(short) 0xc69f, // (12, 1695) 150
(short) 0xce9f, // (12, 3743) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 8 of 22) (steady 8 of 16) (phase = 0.531250000 = 17.0 / 32.0)
// entropy: 4.4505873338397474726
// avg_length: 4.5270058771550303334; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x7033, // ( 7, 51) 0
(short) 0x4006, // ( 4, 6) 1
(short) 0x601d, // ( 6, 29) 2
(short) 0x2000, // ( 2, 0) 3
(short) 0x7073, // ( 7, 115) 4
(short) 0x400e, // ( 4, 14) 5
(short) 0x603d, // ( 6, 61) 6
(short) 0x3002, // ( 3, 2) 7
(short) 0x807b, // ( 8, 123) 8
(short) 0x5005, // ( 5, 5) 9
(short) 0x700b, // ( 7, 11) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0x9097, // ( 9, 151) 12
(short) 0x5015, // ( 5, 21) 13
(short) 0x80fb, // ( 8, 251) 14
(short) 0x4009, // ( 4, 9) 15
(short) 0xa0f7, // (10, 247) 16
(short) 0x6003, // ( 6, 3) 17
(short) 0x8007, // ( 8, 7) 18
(short) 0x500d, // ( 5, 13) 19
(short) 0xa2f7, // (10, 759) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0x9197, // ( 9, 407) 22
(short) 0x6023, // ( 6, 35) 23
(short) 0xb34f, // (11, 847) 24
(short) 0x8087, // ( 8, 135) 25
(short) 0xa1f7, // (10, 503) 26
(short) 0x702b, // ( 7, 43) 27
(short) 0xb74f, // (11, 1871) 28
(short) 0x8047, // ( 8, 71) 29
(short) 0xa3f7, // (10, 1015) 30
(short) 0x706b, // ( 7, 107) 31
(short) 0xb0cf, // (11, 207) 32
(short) 0x701b, // ( 7, 27) 33
(short) 0x9057, // ( 9, 87) 34
(short) 0x6013, // ( 6, 19) 35
(short) 0xb4cf, // (11, 1231) 36
(short) 0x80c7, // ( 8, 199) 37
(short) 0xa00f, // (10, 15) 38
(short) 0x705b, // ( 7, 91) 39
(short) 0xc72f, // (12, 1839) 40
(short) 0x9157, // ( 9, 343) 41
(short) 0xb2cf, // (11, 719) 42
(short) 0x8027, // ( 8, 39) 43
(short) 0xcf2f, // (12, 3887) 44
(short) 0x90d7, // ( 9, 215) 45
(short) 0xb6cf, // (11, 1743) 46
(short) 0x80a7, // ( 8, 167) 47
(short) 0xc0af, // (12, 175) 48
(short) 0xa20f, // (10, 527) 49
(short) 0xc8af, // (12, 2223) 50
(short) 0x91d7, // ( 9, 471) 51
(short) 0xc4af, // (12, 1199) 52
(short) 0xa10f, // (10, 271) 53
(short) 0xccaf, // (12, 3247) 54
(short) 0x9037, // ( 9, 55) 55
(short) 0xc2af, // (12, 687) 56
(short) 0xcaaf, // (12, 2735) 57
(short) 0xc6af, // (12, 1711) 58
(short) 0xb1cf, // (11, 463) 59
(short) 0xceaf, // (12, 3759) 60
(short) 0xc1af, // (12, 431) 61
(short) 0xc9af, // (12, 2479) 62
(short) 0xb5cf, // (11, 1487) 63
(short) 0xc5af, // (12, 1455) 64
(short) 0x8067, // ( 8, 103) 65
(short) 0xa30f, // (10, 783) 66
(short) 0x703b, // ( 7, 59) 67
(short) 0xcdaf, // (12, 3503) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xb3cf, // (11, 975) 70
(short) 0x80e7, // ( 8, 231) 71
(short) 0xc3af, // (12, 943) 72
(short) 0xa08f, // (10, 143) 73
(short) 0xcbaf, // (12, 2991) 74
(short) 0x90b7, // ( 9, 183) 75
(short) 0xc7af, // (12, 1967) 76
(short) 0xa28f, // (10, 655) 77
(short) 0xcfaf, // (12, 4015) 78
(short) 0x91b7, // ( 9, 439) 79
(short) 0xc06f, // (12, 111) 80
(short) 0xb7cf, // (11, 1999) 81
(short) 0xc86f, // (12, 2159) 82
(short) 0xa18f, // (10, 399) 83
(short) 0xc46f, // (12, 1135) 84
(short) 0xb02f, // (11, 47) 85
(short) 0xcc6f, // (12, 3183) 86
(short) 0xa38f, // (10, 911) 87
(short) 0xc26f, // (12, 623) 88
(short) 0xca6f, // (12, 2671) 89
(short) 0xc66f, // (12, 1647) 90
(short) 0xce6f, // (12, 3695) 91
(short) 0xc16f, // (12, 367) 92
(short) 0xc96f, // (12, 2415) 93
(short) 0xc56f, // (12, 1391) 94
(short) 0xcd6f, // (12, 3439) 95
(short) 0xc36f, // (12, 879) 96
(short) 0xcb6f, // (12, 2927) 97
(short) 0xc76f, // (12, 1903) 98
(short) 0xb42f, // (11, 1071) 99
(short) 0xcf6f, // (12, 3951) 100
(short) 0xc0ef, // (12, 239) 101
(short) 0xc8ef, // (12, 2287) 102
(short) 0xb22f, // (11, 559) 103
(short) 0xc4ef, // (12, 1263) 104
(short) 0xccef, // (12, 3311) 105
(short) 0xc2ef, // (12, 751) 106
(short) 0xcaef, // (12, 2799) 107
(short) 0xc6ef, // (12, 1775) 108
(short) 0xceef, // (12, 3823) 109
(short) 0xc1ef, // (12, 495) 110
(short) 0xc9ef, // (12, 2543) 111
(short) 0xc5ef, // (12, 1519) 112
(short) 0xcdef, // (12, 3567) 113
(short) 0xc3ef, // (12, 1007) 114
(short) 0xcbef, // (12, 3055) 115
(short) 0xc7ef, // (12, 2031) 116
(short) 0xcfef, // (12, 4079) 117
(short) 0xc01f, // (12, 31) 118
(short) 0xc81f, // (12, 2079) 119
(short) 0xc41f, // (12, 1055) 120
(short) 0xcc1f, // (12, 3103) 121
(short) 0xc21f, // (12, 543) 122
(short) 0xca1f, // (12, 2591) 123
(short) 0xc61f, // (12, 1567) 124
(short) 0xce1f, // (12, 3615) 125
(short) 0xc11f, // (12, 287) 126
(short) 0xc91f, // (12, 2335) 127
(short) 0xc51f, // (12, 1311) 128
(short) 0x9077, // ( 9, 119) 129
(short) 0xcd1f, // (12, 3359) 130
(short) 0x8017, // ( 8, 23) 131
(short) 0xc31f, // (12, 799) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xcb1f, // (12, 2847) 134
(short) 0x9177, // ( 9, 375) 135
(short) 0xc71f, // (12, 1823) 136
(short) 0xb62f, // (11, 1583) 137
(short) 0xcf1f, // (12, 3871) 138
(short) 0xa24f, // (10, 591) 139
(short) 0xc09f, // (12, 159) 140
(short) 0xb12f, // (11, 303) 141
(short) 0xc89f, // (12, 2207) 142
(short) 0xa14f, // (10, 335) 143
(short) 0xc49f, // (12, 1183) 144
(short) 0xcc9f, // (12, 3231) 145
(short) 0xc29f, // (12, 671) 146
(short) 0xb52f, // (11, 1327) 147
(short) 0xca9f, // (12, 2719) 148
(short) 0xc69f, // (12, 1695) 149
(short) 0xce9f, // (12, 3743) 150
(short) 0xb32f, // (11, 815) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 9 of 22) (steady 9 of 16) (phase = 0.593750000 = 19.0 / 32.0)
// entropy: 4.4575203029748040606
// avg_length: 4.5315465600684730063; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x7033, // ( 7, 51) 0
(short) 0x4006, // ( 4, 6) 1
(short) 0x601d, // ( 6, 29) 2
(short) 0x2000, // ( 2, 0) 3
(short) 0x7073, // ( 7, 115) 4
(short) 0x400e, // ( 4, 14) 5
(short) 0x603d, // ( 6, 61) 6
(short) 0x3002, // ( 3, 2) 7
(short) 0x9097, // ( 9, 151) 8
(short) 0x5005, // ( 5, 5) 9
(short) 0x700b, // ( 7, 11) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0x9197, // ( 9, 407) 12
(short) 0x6003, // ( 6, 3) 13
(short) 0x807b, // ( 8, 123) 14
(short) 0x4009, // ( 4, 9) 15
(short) 0xa0f7, // (10, 247) 16
(short) 0x6023, // ( 6, 35) 17
(short) 0x80fb, // ( 8, 251) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xa2f7, // (10, 759) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0x9057, // ( 9, 87) 22
(short) 0x500d, // ( 5, 13) 23
(short) 0xb34f, // (11, 847) 24
(short) 0x8007, // ( 8, 7) 25
(short) 0xa1f7, // (10, 503) 26
(short) 0x702b, // ( 7, 43) 27
(short) 0xc72f, // (12, 1839) 28
(short) 0x8087, // ( 8, 135) 29
(short) 0xa3f7, // (10, 1015) 30
(short) 0x706b, // ( 7, 107) 31
(short) 0xb74f, // (11, 1871) 32
(short) 0x701b, // ( 7, 27) 33
(short) 0x9157, // ( 9, 343) 34
(short) 0x6013, // ( 6, 19) 35
(short) 0xb0cf, // (11, 207) 36
(short) 0x8047, // ( 8, 71) 37
(short) 0xa00f, // (10, 15) 38
(short) 0x705b, // ( 7, 91) 39
(short) 0xcf2f, // (12, 3887) 40
(short) 0x90d7, // ( 9, 215) 41
(short) 0xb4cf, // (11, 1231) 42
(short) 0x80c7, // ( 8, 199) 43
(short) 0xc0af, // (12, 175) 44
(short) 0x91d7, // ( 9, 471) 45
(short) 0xb2cf, // (11, 719) 46
(short) 0x8027, // ( 8, 39) 47
(short) 0xc8af, // (12, 2223) 48
(short) 0xa20f, // (10, 527) 49
(short) 0xc4af, // (12, 1199) 50
(short) 0x9037, // ( 9, 55) 51
(short) 0xccaf, // (12, 3247) 52
(short) 0xa10f, // (10, 271) 53
(short) 0xc2af, // (12, 687) 54
(short) 0x9137, // ( 9, 311) 55
(short) 0xcaaf, // (12, 2735) 56
(short) 0xc6af, // (12, 1711) 57
(short) 0xceaf, // (12, 3759) 58
(short) 0xa30f, // (10, 783) 59
(short) 0xc1af, // (12, 431) 60
(short) 0xc9af, // (12, 2479) 61
(short) 0xc5af, // (12, 1455) 62
(short) 0xb6cf, // (11, 1743) 63
(short) 0xcdaf, // (12, 3503) 64
(short) 0x80a7, // ( 8, 167) 65
(short) 0xb1cf, // (11, 463) 66
(short) 0x703b, // ( 7, 59) 67
(short) 0xc3af, // (12, 943) 68
(short) 0x90b7, // ( 9, 183) 69
(short) 0xb5cf, // (11, 1487) 70
(short) 0x8067, // ( 8, 103) 71
(short) 0xcbaf, // (12, 2991) 72
(short) 0xa08f, // (10, 143) 73
(short) 0xc7af, // (12, 1967) 74
(short) 0x91b7, // ( 9, 439) 75
(short) 0xcfaf, // (12, 4015) 76
(short) 0xa28f, // (10, 655) 77
(short) 0xc06f, // (12, 111) 78
(short) 0x9077, // ( 9, 119) 79
(short) 0xc86f, // (12, 2159) 80
(short) 0xb3cf, // (11, 975) 81
(short) 0xc46f, // (12, 1135) 82
(short) 0xa18f, // (10, 399) 83
(short) 0xcc6f, // (12, 3183) 84
(short) 0xb7cf, // (11, 1999) 85
(short) 0xc26f, // (12, 623) 86
(short) 0xa38f, // (10, 911) 87
(short) 0xca6f, // (12, 2671) 88
(short) 0xc66f, // (12, 1647) 89
(short) 0xce6f, // (12, 3695) 90
(short) 0xb02f, // (11, 47) 91
(short) 0xc16f, // (12, 367) 92
(short) 0xc96f, // (12, 2415) 93
(short) 0xc56f, // (12, 1391) 94
(short) 0xcd6f, // (12, 3439) 95
(short) 0xc36f, // (12, 879) 96
(short) 0xcb6f, // (12, 2927) 97
(short) 0xc76f, // (12, 1903) 98
(short) 0xb42f, // (11, 1071) 99
(short) 0xcf6f, // (12, 3951) 100
(short) 0xc0ef, // (12, 239) 101
(short) 0xc8ef, // (12, 2287) 102
(short) 0xb22f, // (11, 559) 103
(short) 0xc4ef, // (12, 1263) 104
(short) 0xccef, // (12, 3311) 105
(short) 0xc2ef, // (12, 751) 106
(short) 0xcaef, // (12, 2799) 107
(short) 0xc6ef, // (12, 1775) 108
(short) 0xceef, // (12, 3823) 109
(short) 0xc1ef, // (12, 495) 110
(short) 0xc9ef, // (12, 2543) 111
(short) 0xc5ef, // (12, 1519) 112
(short) 0xcdef, // (12, 3567) 113
(short) 0xc3ef, // (12, 1007) 114
(short) 0xcbef, // (12, 3055) 115
(short) 0xc7ef, // (12, 2031) 116
(short) 0xcfef, // (12, 4079) 117
(short) 0xc01f, // (12, 31) 118
(short) 0xc81f, // (12, 2079) 119
(short) 0xc41f, // (12, 1055) 120
(short) 0xcc1f, // (12, 3103) 121
(short) 0xc21f, // (12, 543) 122
(short) 0xca1f, // (12, 2591) 123
(short) 0xc61f, // (12, 1567) 124
(short) 0xce1f, // (12, 3615) 125
(short) 0xc11f, // (12, 287) 126
(short) 0xc91f, // (12, 2335) 127
(short) 0xc51f, // (12, 1311) 128
(short) 0x9177, // ( 9, 375) 129
(short) 0xcd1f, // (12, 3359) 130
(short) 0x80e7, // ( 8, 231) 131
(short) 0xc31f, // (12, 799) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xcb1f, // (12, 2847) 134
(short) 0x8017, // ( 8, 23) 135
(short) 0xc71f, // (12, 1823) 136
(short) 0xb62f, // (11, 1583) 137
(short) 0xcf1f, // (12, 3871) 138
(short) 0xa24f, // (10, 591) 139
(short) 0xc09f, // (12, 159) 140
(short) 0xb12f, // (11, 303) 141
(short) 0xc89f, // (12, 2207) 142
(short) 0xa14f, // (10, 335) 143
(short) 0xc49f, // (12, 1183) 144
(short) 0xcc9f, // (12, 3231) 145
(short) 0xc29f, // (12, 671) 146
(short) 0xb52f, // (11, 1327) 147
(short) 0xca9f, // (12, 2719) 148
(short) 0xc69f, // (12, 1695) 149
(short) 0xce9f, // (12, 3743) 150
(short) 0xb32f, // (11, 815) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 10 of 22) (steady 10 of 16) (phase = 0.656250000 = 21.0 / 32.0)
// entropy: 4.4626765653088611430
// avg_length: 4.5373141251902122661; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x700b, // ( 7, 11) 0
(short) 0x4006, // ( 4, 6) 1
(short) 0x601d, // ( 6, 29) 2
(short) 0x2000, // ( 2, 0) 3
(short) 0x807b, // ( 8, 123) 4
(short) 0x400e, // ( 4, 14) 5
(short) 0x603d, // ( 6, 61) 6
(short) 0x3002, // ( 3, 2) 7
(short) 0x9017, // ( 9, 23) 8
(short) 0x5005, // ( 5, 5) 9
(short) 0x704b, // ( 7, 75) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0x9117, // ( 9, 279) 12
(short) 0x6003, // ( 6, 3) 13
(short) 0x80fb, // ( 8, 251) 14
(short) 0x4009, // ( 4, 9) 15
(short) 0xa177, // (10, 375) 16
(short) 0x6023, // ( 6, 35) 17
(short) 0x9097, // ( 9, 151) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xa377, // (10, 887) 20
(short) 0x702b, // ( 7, 43) 21
(short) 0x9197, // ( 9, 407) 22
(short) 0x500d, // ( 5, 13) 23
(short) 0xb34f, // (11, 847) 24
(short) 0x8007, // ( 8, 7) 25
(short) 0xa0f7, // (10, 247) 26
(short) 0x706b, // ( 7, 107) 27
(short) 0xc0af, // (12, 175) 28
(short) 0x8087, // ( 8, 135) 29
(short) 0xa2f7, // (10, 759) 30
(short) 0x701b, // ( 7, 27) 31
(short) 0xb74f, // (11, 1871) 32
(short) 0x8047, // ( 8, 71) 33
(short) 0xa1f7, // (10, 503) 34
(short) 0x6013, // ( 6, 19) 35
(short) 0xb0cf, // (11, 207) 36
(short) 0x80c7, // ( 8, 199) 37
(short) 0xa3f7, // (10, 1015) 38
(short) 0x6033, // ( 6, 51) 39
(short) 0xc8af, // (12, 2223) 40
(short) 0x9057, // ( 9, 87) 41
(short) 0xb4cf, // (11, 1231) 42
(short) 0x8027, // ( 8, 39) 43
(short) 0xc4af, // (12, 1199) 44
(short) 0x9157, // ( 9, 343) 45
(short) 0xb2cf, // (11, 719) 46
(short) 0x80a7, // ( 8, 167) 47
(short) 0xccaf, // (12, 3247) 48
(short) 0xa00f, // (10, 15) 49
(short) 0xc2af, // (12, 687) 50
(short) 0x90d7, // ( 9, 215) 51
(short) 0xcaaf, // (12, 2735) 52
(short) 0xa20f, // (10, 527) 53
(short) 0xc6af, // (12, 1711) 54
(short) 0x91d7, // ( 9, 471) 55
(short) 0xceaf, // (12, 3759) 56
(short) 0xb6cf, // (11, 1743) 57
(short) 0xc1af, // (12, 431) 58
(short) 0xa10f, // (10, 271) 59
(short) 0xc9af, // (12, 2479) 60
(short) 0xc5af, // (12, 1455) 61
(short) 0xcdaf, // (12, 3503) 62
(short) 0xa30f, // (10, 783) 63
(short) 0xc3af, // (12, 943) 64
(short) 0x9037, // ( 9, 55) 65
(short) 0xb1cf, // (11, 463) 66
(short) 0x705b, // ( 7, 91) 67
(short) 0xcbaf, // (12, 2991) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xb5cf, // (11, 1487) 70
(short) 0x703b, // ( 7, 59) 71
(short) 0xc7af, // (12, 1967) 72
(short) 0xa08f, // (10, 143) 73
(short) 0xcfaf, // (12, 4015) 74
(short) 0x90b7, // ( 9, 183) 75
(short) 0xc06f, // (12, 111) 76
(short) 0xa28f, // (10, 655) 77
(short) 0xc86f, // (12, 2159) 78
(short) 0x91b7, // ( 9, 439) 79
(short) 0xc46f, // (12, 1135) 80
(short) 0xb3cf, // (11, 975) 81
(short) 0xcc6f, // (12, 3183) 82
(short) 0xa18f, // (10, 399) 83
(short) 0xc26f, // (12, 623) 84
(short) 0xb7cf, // (11, 1999) 85
(short) 0xca6f, // (12, 2671) 86
(short) 0xa38f, // (10, 911) 87
(short) 0xc66f, // (12, 1647) 88
(short) 0xce6f, // (12, 3695) 89
(short) 0xc16f, // (12, 367) 90
(short) 0xb02f, // (11, 47) 91
(short) 0xc96f, // (12, 2415) 92
(short) 0xc56f, // (12, 1391) 93
(short) 0xcd6f, // (12, 3439) 94
(short) 0xb42f, // (11, 1071) 95
(short) 0xc36f, // (12, 879) 96
(short) 0xcb6f, // (12, 2927) 97
(short) 0xc76f, // (12, 1903) 98
(short) 0xb22f, // (11, 559) 99
(short) 0xcf6f, // (12, 3951) 100
(short) 0xc0ef, // (12, 239) 101
(short) 0xc8ef, // (12, 2287) 102
(short) 0xb62f, // (11, 1583) 103
(short) 0xc4ef, // (12, 1263) 104
(short) 0xccef, // (12, 3311) 105
(short) 0xc2ef, // (12, 751) 106
(short) 0xcaef, // (12, 2799) 107
(short) 0xc6ef, // (12, 1775) 108
(short) 0xceef, // (12, 3823) 109
(short) 0xc1ef, // (12, 495) 110
(short) 0xc9ef, // (12, 2543) 111
(short) 0xc5ef, // (12, 1519) 112
(short) 0xcdef, // (12, 3567) 113
(short) 0xc3ef, // (12, 1007) 114
(short) 0xcbef, // (12, 3055) 115
(short) 0xc7ef, // (12, 2031) 116
(short) 0xcfef, // (12, 4079) 117
(short) 0xc01f, // (12, 31) 118
(short) 0xc81f, // (12, 2079) 119
(short) 0xc41f, // (12, 1055) 120
(short) 0xcc1f, // (12, 3103) 121
(short) 0xc21f, // (12, 543) 122
(short) 0xca1f, // (12, 2591) 123
(short) 0xc61f, // (12, 1567) 124
(short) 0xce1f, // (12, 3615) 125
(short) 0xc11f, // (12, 287) 126
(short) 0xc91f, // (12, 2335) 127
(short) 0xc51f, // (12, 1311) 128
(short) 0x9077, // ( 9, 119) 129
(short) 0xcd1f, // (12, 3359) 130
(short) 0x8067, // ( 8, 103) 131
(short) 0xc31f, // (12, 799) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xcb1f, // (12, 2847) 134
(short) 0x80e7, // ( 8, 231) 135
(short) 0xc71f, // (12, 1823) 136
(short) 0xb12f, // (11, 303) 137
(short) 0xcf1f, // (12, 3871) 138
(short) 0xa24f, // (10, 591) 139
(short) 0xc09f, // (12, 159) 140
(short) 0xb52f, // (11, 1327) 141
(short) 0xc89f, // (12, 2207) 142
(short) 0xa14f, // (10, 335) 143
(short) 0xc49f, // (12, 1183) 144
(short) 0xcc9f, // (12, 3231) 145
(short) 0xc29f, // (12, 671) 146
(short) 0xb32f, // (11, 815) 147
(short) 0xca9f, // (12, 2719) 148
(short) 0xc69f, // (12, 1695) 149
(short) 0xce9f, // (12, 3743) 150
(short) 0xb72f, // (11, 1839) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 11 of 22) (steady 11 of 16) (phase = 0.718750000 = 23.0 / 32.0)
// entropy: 4.4661524304421691411
// avg_length: 4.5443750890419041255; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x803b, // ( 8, 59) 0
(short) 0x4006, // ( 4, 6) 1
(short) 0x601d, // ( 6, 29) 2
(short) 0x2000, // ( 2, 0) 3
(short) 0x80bb, // ( 8, 187) 4
(short) 0x400e, // ( 4, 14) 5
(short) 0x603d, // ( 6, 61) 6
(short) 0x3002, // ( 3, 2) 7
(short) 0x9017, // ( 9, 23) 8
(short) 0x5005, // ( 5, 5) 9
(short) 0x807b, // ( 8, 123) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0x9117, // ( 9, 279) 12
(short) 0x6003, // ( 6, 3) 13
(short) 0x80fb, // ( 8, 251) 14
(short) 0x4009, // ( 4, 9) 15
(short) 0xa177, // (10, 375) 16
(short) 0x6023, // ( 6, 35) 17
(short) 0x9097, // ( 9, 151) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xa377, // (10, 887) 20
(short) 0x702b, // ( 7, 43) 21
(short) 0x9197, // ( 9, 407) 22
(short) 0x500d, // ( 5, 13) 23
(short) 0xb34f, // (11, 847) 24
(short) 0x8007, // ( 8, 7) 25
(short) 0xa0f7, // (10, 247) 26
(short) 0x6013, // ( 6, 19) 27
(short) 0xc0af, // (12, 175) 28
(short) 0x8087, // ( 8, 135) 29
(short) 0xa2f7, // (10, 759) 30
(short) 0x706b, // ( 7, 107) 31
(short) 0xb74f, // (11, 1871) 32
(short) 0x8047, // ( 8, 71) 33
(short) 0xa1f7, // (10, 503) 34
(short) 0x6033, // ( 6, 51) 35
(short) 0xb0cf, // (11, 207) 36
(short) 0x80c7, // ( 8, 199) 37
(short) 0xa3f7, // (10, 1015) 38
(short) 0x600b, // ( 6, 11) 39
(short) 0xc8af, // (12, 2223) 40
(short) 0x9057, // ( 9, 87) 41
(short) 0xb4cf, // (11, 1231) 42
(short) 0x8027, // ( 8, 39) 43
(short) 0xc4af, // (12, 1199) 44
(short) 0x9157, // ( 9, 343) 45
(short) 0xb2cf, // (11, 719) 46
(short) 0x80a7, // ( 8, 167) 47
(short) 0xccaf, // (12, 3247) 48
(short) 0xa00f, // (10, 15) 49
(short) 0xc2af, // (12, 687) 50
(short) 0x90d7, // ( 9, 215) 51
(short) 0xcaaf, // (12, 2735) 52
(short) 0xa20f, // (10, 527) 53
(short) 0xc6af, // (12, 1711) 54
(short) 0x91d7, // ( 9, 471) 55
(short) 0xceaf, // (12, 3759) 56
(short) 0xb6cf, // (11, 1743) 57
(short) 0xc1af, // (12, 431) 58
(short) 0xa10f, // (10, 271) 59
(short) 0xc9af, // (12, 2479) 60
(short) 0xc5af, // (12, 1455) 61
(short) 0xcdaf, // (12, 3503) 62
(short) 0xa30f, // (10, 783) 63
(short) 0xc3af, // (12, 943) 64
(short) 0x9037, // ( 9, 55) 65
(short) 0xb1cf, // (11, 463) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xcbaf, // (12, 2991) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xb5cf, // (11, 1487) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xc7af, // (12, 1967) 72
(short) 0xa08f, // (10, 143) 73
(short) 0xcfaf, // (12, 4015) 74
(short) 0x90b7, // ( 9, 183) 75
(short) 0xc06f, // (12, 111) 76
(short) 0xa28f, // (10, 655) 77
(short) 0xc86f, // (12, 2159) 78
(short) 0x91b7, // ( 9, 439) 79
(short) 0xc46f, // (12, 1135) 80
(short) 0xb3cf, // (11, 975) 81
(short) 0xcc6f, // (12, 3183) 82
(short) 0xa18f, // (10, 399) 83
(short) 0xc26f, // (12, 623) 84
(short) 0xb7cf, // (11, 1999) 85
(short) 0xca6f, // (12, 2671) 86
(short) 0xa38f, // (10, 911) 87
(short) 0xc66f, // (12, 1647) 88
(short) 0xce6f, // (12, 3695) 89
(short) 0xc16f, // (12, 367) 90
(short) 0xb02f, // (11, 47) 91
(short) 0xc96f, // (12, 2415) 92
(short) 0xc56f, // (12, 1391) 93
(short) 0xcd6f, // (12, 3439) 94
(short) 0xb42f, // (11, 1071) 95
(short) 0xc36f, // (12, 879) 96
(short) 0xcb6f, // (12, 2927) 97
(short) 0xc76f, // (12, 1903) 98
(short) 0xb22f, // (11, 559) 99
(short) 0xcf6f, // (12, 3951) 100
(short) 0xc0ef, // (12, 239) 101
(short) 0xc8ef, // (12, 2287) 102
(short) 0xb62f, // (11, 1583) 103
(short) 0xc4ef, // (12, 1263) 104
(short) 0xccef, // (12, 3311) 105
(short) 0xc2ef, // (12, 751) 106
(short) 0xcaef, // (12, 2799) 107
(short) 0xc6ef, // (12, 1775) 108
(short) 0xceef, // (12, 3823) 109
(short) 0xc1ef, // (12, 495) 110
(short) 0xc9ef, // (12, 2543) 111
(short) 0xc5ef, // (12, 1519) 112
(short) 0xcdef, // (12, 3567) 113
(short) 0xc3ef, // (12, 1007) 114
(short) 0xcbef, // (12, 3055) 115
(short) 0xc7ef, // (12, 2031) 116
(short) 0xcfef, // (12, 4079) 117
(short) 0xc01f, // (12, 31) 118
(short) 0xc81f, // (12, 2079) 119
(short) 0xc41f, // (12, 1055) 120
(short) 0xcc1f, // (12, 3103) 121
(short) 0xc21f, // (12, 543) 122
(short) 0xca1f, // (12, 2591) 123
(short) 0xc61f, // (12, 1567) 124
(short) 0xce1f, // (12, 3615) 125
(short) 0xc11f, // (12, 287) 126
(short) 0xc91f, // (12, 2335) 127
(short) 0xc51f, // (12, 1311) 128
(short) 0xa04f, // (10, 79) 129
(short) 0xcd1f, // (12, 3359) 130
(short) 0x8067, // ( 8, 103) 131
(short) 0xc31f, // (12, 799) 132
(short) 0xa24f, // (10, 591) 133
(short) 0xcb1f, // (12, 2847) 134
(short) 0x80e7, // ( 8, 231) 135
(short) 0xc71f, // (12, 1823) 136
(short) 0xb12f, // (11, 303) 137
(short) 0xcf1f, // (12, 3871) 138
(short) 0x9077, // ( 9, 119) 139
(short) 0xc09f, // (12, 159) 140
(short) 0xb52f, // (11, 1327) 141
(short) 0xc89f, // (12, 2207) 142
(short) 0xa14f, // (10, 335) 143
(short) 0xc49f, // (12, 1183) 144
(short) 0xcc9f, // (12, 3231) 145
(short) 0xc29f, // (12, 671) 146
(short) 0xb32f, // (11, 815) 147
(short) 0xca9f, // (12, 2719) 148
(short) 0xc69f, // (12, 1695) 149
(short) 0xce9f, // (12, 3743) 150
(short) 0xb72f, // (11, 1839) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 12 of 22) (steady 12 of 16) (phase = 0.781250000 = 25.0 / 32.0)
// entropy: 4.4680486273043946710
// avg_length: 4.5521643785256946657; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x807b, // ( 8, 123) 0
(short) 0x4006, // ( 4, 6) 1
(short) 0x601d, // ( 6, 29) 2
(short) 0x2000, // ( 2, 0) 3
(short) 0x80fb, // ( 8, 251) 4
(short) 0x400e, // ( 4, 14) 5
(short) 0x700b, // ( 7, 11) 6
(short) 0x3002, // ( 3, 2) 7
(short) 0x9097, // ( 9, 151) 8
(short) 0x5005, // ( 5, 5) 9
(short) 0x8007, // ( 8, 7) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0x9197, // ( 9, 407) 12
(short) 0x603d, // ( 6, 61) 13
(short) 0x8087, // ( 8, 135) 14
(short) 0x4009, // ( 4, 9) 15
(short) 0xa177, // (10, 375) 16
(short) 0x704b, // ( 7, 75) 17
(short) 0x9057, // ( 9, 87) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xb34f, // (11, 847) 20
(short) 0x702b, // ( 7, 43) 21
(short) 0x9157, // ( 9, 343) 22
(short) 0x500d, // ( 5, 13) 23
(short) 0xc72f, // (12, 1839) 24
(short) 0x8047, // ( 8, 71) 25
(short) 0xa377, // (10, 887) 26
(short) 0x6003, // ( 6, 3) 27
(short) 0xcf2f, // (12, 3887) 28
(short) 0x80c7, // ( 8, 199) 29
(short) 0xa0f7, // (10, 247) 30
(short) 0x6023, // ( 6, 35) 31
(short) 0xc0af, // (12, 175) 32
(short) 0x8027, // ( 8, 39) 33
(short) 0xa2f7, // (10, 759) 34
(short) 0x6013, // ( 6, 19) 35
(short) 0xc8af, // (12, 2223) 36
(short) 0x80a7, // ( 8, 167) 37
(short) 0xa1f7, // (10, 503) 38
(short) 0x6033, // ( 6, 51) 39
(short) 0xc4af, // (12, 1199) 40
(short) 0x90d7, // ( 9, 215) 41
(short) 0xb74f, // (11, 1871) 42
(short) 0x706b, // ( 7, 107) 43
(short) 0xccaf, // (12, 3247) 44
(short) 0x91d7, // ( 9, 471) 45
(short) 0xb0cf, // (11, 207) 46
(short) 0x701b, // ( 7, 27) 47
(short) 0xc2af, // (12, 687) 48
(short) 0xa3f7, // (10, 1015) 49
(short) 0xcaaf, // (12, 2735) 50
(short) 0x9037, // ( 9, 55) 51
(short) 0xc6af, // (12, 1711) 52
(short) 0xa00f, // (10, 15) 53
(short) 0xceaf, // (12, 3759) 54
(short) 0x9137, // ( 9, 311) 55
(short) 0xc1af, // (12, 431) 56
(short) 0xb4cf, // (11, 1231) 57
(short) 0xc9af, // (12, 2479) 58
(short) 0xa20f, // (10, 527) 59
(short) 0xc5af, // (12, 1455) 60
(short) 0xb2cf, // (11, 719) 61
(short) 0xcdaf, // (12, 3503) 62
(short) 0xa10f, // (10, 271) 63
(short) 0xc3af, // (12, 943) 64
(short) 0x90b7, // ( 9, 183) 65
(short) 0xb6cf, // (11, 1743) 66
(short) 0x705b, // ( 7, 91) 67
(short) 0xcbaf, // (12, 2991) 68
(short) 0x91b7, // ( 9, 439) 69
(short) 0xb1cf, // (11, 463) 70
(short) 0x703b, // ( 7, 59) 71
(short) 0xc7af, // (12, 1967) 72
(short) 0xa30f, // (10, 783) 73
(short) 0xcfaf, // (12, 4015) 74
(short) 0x8067, // ( 8, 103) 75
(short) 0xc06f, // (12, 111) 76
(short) 0xa08f, // (10, 143) 77
(short) 0xc86f, // (12, 2159) 78
(short) 0x9077, // ( 9, 119) 79
(short) 0xc46f, // (12, 1135) 80
(short) 0xb5cf, // (11, 1487) 81
(short) 0xcc6f, // (12, 3183) 82
(short) 0xa28f, // (10, 655) 83
(short) 0xc26f, // (12, 623) 84
(short) 0xb3cf, // (11, 975) 85
(short) 0xca6f, // (12, 2671) 86
(short) 0xa18f, // (10, 399) 87
(short) 0xc66f, // (12, 1647) 88
(short) 0xce6f, // (12, 3695) 89
(short) 0xc16f, // (12, 367) 90
(short) 0xb7cf, // (11, 1999) 91
(short) 0xc96f, // (12, 2415) 92
(short) 0xc56f, // (12, 1391) 93
(short) 0xcd6f, // (12, 3439) 94
(short) 0xb02f, // (11, 47) 95
(short) 0xc36f, // (12, 879) 96
(short) 0xcb6f, // (12, 2927) 97
(short) 0xc76f, // (12, 1903) 98
(short) 0xb42f, // (11, 1071) 99
(short) 0xcf6f, // (12, 3951) 100
(short) 0xc0ef, // (12, 239) 101
(short) 0xc8ef, // (12, 2287) 102
(short) 0xb22f, // (11, 559) 103
(short) 0xc4ef, // (12, 1263) 104
(short) 0xccef, // (12, 3311) 105
(short) 0xc2ef, // (12, 751) 106
(short) 0xcaef, // (12, 2799) 107
(short) 0xc6ef, // (12, 1775) 108
(short) 0xceef, // (12, 3823) 109
(short) 0xc1ef, // (12, 495) 110
(short) 0xc9ef, // (12, 2543) 111
(short) 0xc5ef, // (12, 1519) 112
(short) 0xcdef, // (12, 3567) 113
(short) 0xc3ef, // (12, 1007) 114
(short) 0xcbef, // (12, 3055) 115
(short) 0xc7ef, // (12, 2031) 116
(short) 0xcfef, // (12, 4079) 117
(short) 0xc01f, // (12, 31) 118
(short) 0xc81f, // (12, 2079) 119
(short) 0xc41f, // (12, 1055) 120
(short) 0xcc1f, // (12, 3103) 121
(short) 0xc21f, // (12, 543) 122
(short) 0xca1f, // (12, 2591) 123
(short) 0xc61f, // (12, 1567) 124
(short) 0xce1f, // (12, 3615) 125
(short) 0xc11f, // (12, 287) 126
(short) 0xc91f, // (12, 2335) 127
(short) 0xc51f, // (12, 1311) 128
(short) 0xa38f, // (10, 911) 129
(short) 0xcd1f, // (12, 3359) 130
(short) 0x80e7, // ( 8, 231) 131
(short) 0xc31f, // (12, 799) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xcb1f, // (12, 2847) 134
(short) 0x8017, // ( 8, 23) 135
(short) 0xc71f, // (12, 1823) 136
(short) 0xb62f, // (11, 1583) 137
(short) 0xcf1f, // (12, 3871) 138
(short) 0xa24f, // (10, 591) 139
(short) 0xc09f, // (12, 159) 140
(short) 0xb12f, // (11, 303) 141
(short) 0xc89f, // (12, 2207) 142
(short) 0xa14f, // (10, 335) 143
(short) 0xc49f, // (12, 1183) 144
(short) 0xcc9f, // (12, 3231) 145
(short) 0xc29f, // (12, 671) 146
(short) 0xb52f, // (11, 1327) 147
(short) 0xca9f, // (12, 2719) 148
(short) 0xc69f, // (12, 1695) 149
(short) 0xce9f, // (12, 3743) 150
(short) 0xb32f, // (11, 815) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 13 of 22) (steady 13 of 16) (phase = 0.843750000 = 27.0 / 32.0)
// entropy: 4.4684687952964843305
// avg_length: 4.5509169030369793774; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x803b, // ( 8, 59) 0
(short) 0x4006, // ( 4, 6) 1
(short) 0x7033, // ( 7, 51) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0x80bb, // ( 8, 187) 4
(short) 0x400e, // ( 4, 14) 5
(short) 0x7073, // ( 7, 115) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xa0f7, // (10, 247) 8
(short) 0x601d, // ( 6, 29) 9
(short) 0x807b, // ( 8, 123) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xa2f7, // (10, 759) 12
(short) 0x5005, // ( 5, 5) 13
(short) 0x80fb, // ( 8, 251) 14
(short) 0x4009, // ( 4, 9) 15
(short) 0xb34f, // (11, 847) 16
(short) 0x700b, // ( 7, 11) 17
(short) 0x9057, // ( 9, 87) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xb74f, // (11, 1871) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0x9157, // ( 9, 343) 22
(short) 0x500d, // ( 5, 13) 23
(short) 0xc72f, // (12, 1839) 24
(short) 0x8007, // ( 8, 7) 25
(short) 0xa1f7, // (10, 503) 26
(short) 0x603d, // ( 6, 61) 27
(short) 0xcf2f, // (12, 3887) 28
(short) 0x8087, // ( 8, 135) 29
(short) 0xa3f7, // (10, 1015) 30
(short) 0x6003, // ( 6, 3) 31
(short) 0xc0af, // (12, 175) 32
(short) 0x8047, // ( 8, 71) 33
(short) 0xa00f, // (10, 15) 34
(short) 0x6023, // ( 6, 35) 35
(short) 0xc8af, // (12, 2223) 36
(short) 0x80c7, // ( 8, 199) 37
(short) 0xa20f, // (10, 527) 38
(short) 0x6013, // ( 6, 19) 39
(short) 0xc4af, // (12, 1199) 40
(short) 0x90d7, // ( 9, 215) 41
(short) 0xb0cf, // (11, 207) 42
(short) 0x702b, // ( 7, 43) 43
(short) 0xccaf, // (12, 3247) 44
(short) 0x91d7, // ( 9, 471) 45
(short) 0xb4cf, // (11, 1231) 46
(short) 0x706b, // ( 7, 107) 47
(short) 0xc2af, // (12, 687) 48
(short) 0xa10f, // (10, 271) 49
(short) 0xcaaf, // (12, 2735) 50
(short) 0x8027, // ( 8, 39) 51
(short) 0xc6af, // (12, 1711) 52
(short) 0xa30f, // (10, 783) 53
(short) 0xceaf, // (12, 3759) 54
(short) 0x80a7, // ( 8, 167) 55
(short) 0xc1af, // (12, 431) 56
(short) 0xb2cf, // (11, 719) 57
(short) 0xc9af, // (12, 2479) 58
(short) 0xa08f, // (10, 143) 59
(short) 0xc5af, // (12, 1455) 60
(short) 0xb6cf, // (11, 1743) 61
(short) 0xcdaf, // (12, 3503) 62
(short) 0xa28f, // (10, 655) 63
(short) 0xc3af, // (12, 943) 64
(short) 0x9037, // ( 9, 55) 65
(short) 0xb1cf, // (11, 463) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xcbaf, // (12, 2991) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xb5cf, // (11, 1487) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xc7af, // (12, 1967) 72
(short) 0xa18f, // (10, 399) 73
(short) 0xcfaf, // (12, 4015) 74
(short) 0x8067, // ( 8, 103) 75
(short) 0xc06f, // (12, 111) 76
(short) 0xa38f, // (10, 911) 77
(short) 0xc86f, // (12, 2159) 78
(short) 0x80e7, // ( 8, 231) 79
(short) 0xc46f, // (12, 1135) 80
(short) 0xb3cf, // (11, 975) 81
(short) 0xcc6f, // (12, 3183) 82
(short) 0x90b7, // ( 9, 183) 83
(short) 0xc26f, // (12, 623) 84
(short) 0xb7cf, // (11, 1999) 85
(short) 0xca6f, // (12, 2671) 86
(short) 0x91b7, // ( 9, 439) 87
(short) 0xc66f, // (12, 1647) 88
(short) 0xce6f, // (12, 3695) 89
(short) 0xc16f, // (12, 367) 90
(short) 0xb02f, // (11, 47) 91
(short) 0xc96f, // (12, 2415) 92
(short) 0xc56f, // (12, 1391) 93
(short) 0xcd6f, // (12, 3439) 94
(short) 0xb42f, // (11, 1071) 95
(short) 0xc36f, // (12, 879) 96
(short) 0xcb6f, // (12, 2927) 97
(short) 0xc76f, // (12, 1903) 98
(short) 0xb22f, // (11, 559) 99
(short) 0xcf6f, // (12, 3951) 100
(short) 0xc0ef, // (12, 239) 101
(short) 0xc8ef, // (12, 2287) 102
(short) 0xb62f, // (11, 1583) 103
(short) 0xc4ef, // (12, 1263) 104
(short) 0xccef, // (12, 3311) 105
(short) 0xc2ef, // (12, 751) 106
(short) 0xcaef, // (12, 2799) 107
(short) 0xc6ef, // (12, 1775) 108
(short) 0xceef, // (12, 3823) 109
(short) 0xc1ef, // (12, 495) 110
(short) 0xc9ef, // (12, 2543) 111
(short) 0xc5ef, // (12, 1519) 112
(short) 0xcdef, // (12, 3567) 113
(short) 0xc3ef, // (12, 1007) 114
(short) 0xcbef, // (12, 3055) 115
(short) 0xc7ef, // (12, 2031) 116
(short) 0xcfef, // (12, 4079) 117
(short) 0xc01f, // (12, 31) 118
(short) 0xc81f, // (12, 2079) 119
(short) 0xc41f, // (12, 1055) 120
(short) 0xcc1f, // (12, 3103) 121
(short) 0xc21f, // (12, 543) 122
(short) 0xca1f, // (12, 2591) 123
(short) 0xc61f, // (12, 1567) 124
(short) 0xce1f, // (12, 3615) 125
(short) 0xc11f, // (12, 287) 126
(short) 0xc91f, // (12, 2335) 127
(short) 0xc51f, // (12, 1311) 128
(short) 0xa04f, // (10, 79) 129
(short) 0xcd1f, // (12, 3359) 130
(short) 0x8017, // ( 8, 23) 131
(short) 0xc31f, // (12, 799) 132
(short) 0xa24f, // (10, 591) 133
(short) 0xcb1f, // (12, 2847) 134
(short) 0x8097, // ( 8, 151) 135
(short) 0xc71f, // (12, 1823) 136
(short) 0xb12f, // (11, 303) 137
(short) 0xcf1f, // (12, 3871) 138
(short) 0x9077, // ( 9, 119) 139
(short) 0xc09f, // (12, 159) 140
(short) 0xb52f, // (11, 1327) 141
(short) 0xc89f, // (12, 2207) 142
(short) 0x9177, // ( 9, 375) 143
(short) 0xc49f, // (12, 1183) 144
(short) 0xcc9f, // (12, 3231) 145
(short) 0xc29f, // (12, 671) 146
(short) 0xb32f, // (11, 815) 147
(short) 0xca9f, // (12, 2719) 148
(short) 0xc69f, // (12, 1695) 149
(short) 0xce9f, // (12, 3743) 150
(short) 0xa14f, // (10, 335) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 14 of 22) (steady 14 of 16) (phase = 0.906250000 = 29.0 / 32.0)
// entropy: 4.4675179140944036860
// avg_length: 4.5477235350841240802; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x9017, // ( 9, 23) 0
(short) 0x4006, // ( 4, 6) 1
(short) 0x7033, // ( 7, 51) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0x9117, // ( 9, 279) 4
(short) 0x400e, // ( 4, 14) 5
(short) 0x7073, // ( 7, 115) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xa177, // (10, 375) 8
(short) 0x601d, // ( 6, 29) 9
(short) 0x803b, // ( 8, 59) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xa377, // (10, 887) 12
(short) 0x5005, // ( 5, 5) 13
(short) 0x80bb, // ( 8, 187) 14
(short) 0x4009, // ( 4, 9) 15
(short) 0xb0cf, // (11, 207) 16
(short) 0x700b, // ( 7, 11) 17
(short) 0x9097, // ( 9, 151) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xb4cf, // (11, 1231) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0x9197, // ( 9, 407) 22
(short) 0x500d, // ( 5, 13) 23
(short) 0xc4af, // (12, 1199) 24
(short) 0x807b, // ( 8, 123) 25
(short) 0xa0f7, // (10, 247) 26
(short) 0x603d, // ( 6, 61) 27
(short) 0xccaf, // (12, 3247) 28
(short) 0x80fb, // ( 8, 251) 29
(short) 0xa2f7, // (10, 759) 30
(short) 0x6003, // ( 6, 3) 31
(short) 0xc2af, // (12, 687) 32
(short) 0x8007, // ( 8, 7) 33
(short) 0xa1f7, // (10, 503) 34
(short) 0x6023, // ( 6, 35) 35
(short) 0xcaaf, // (12, 2735) 36
(short) 0x8087, // ( 8, 135) 37
(short) 0xa3f7, // (10, 1015) 38
(short) 0x6013, // ( 6, 19) 39
(short) 0xc6af, // (12, 1711) 40
(short) 0x9057, // ( 9, 87) 41
(short) 0xb2cf, // (11, 719) 42
(short) 0x702b, // ( 7, 43) 43
(short) 0xceaf, // (12, 3759) 44
(short) 0x9157, // ( 9, 343) 45
(short) 0xb6cf, // (11, 1743) 46
(short) 0x706b, // ( 7, 107) 47
(short) 0xc1af, // (12, 431) 48
(short) 0xa00f, // (10, 15) 49
(short) 0xc9af, // (12, 2479) 50
(short) 0x8047, // ( 8, 71) 51
(short) 0xc5af, // (12, 1455) 52
(short) 0xa20f, // (10, 527) 53
(short) 0xcdaf, // (12, 3503) 54
(short) 0x80c7, // ( 8, 199) 55
(short) 0xc3af, // (12, 943) 56
(short) 0xb1cf, // (11, 463) 57
(short) 0xcbaf, // (12, 2991) 58
(short) 0xa10f, // (10, 271) 59
(short) 0xc7af, // (12, 1967) 60
(short) 0xb5cf, // (11, 1487) 61
(short) 0xcfaf, // (12, 4015) 62
(short) 0x90d7, // ( 9, 215) 63
(short) 0xc06f, // (12, 111) 64
(short) 0x91d7, // ( 9, 471) 65
(short) 0xb3cf, // (11, 975) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xc86f, // (12, 2159) 68
(short) 0x9037, // ( 9, 55) 69
(short) 0xb7cf, // (11, 1999) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xc46f, // (12, 1135) 72
(short) 0xa30f, // (10, 783) 73
(short) 0xcc6f, // (12, 3183) 74
(short) 0x8027, // ( 8, 39) 75
(short) 0xc26f, // (12, 623) 76
(short) 0xa08f, // (10, 143) 77
(short) 0xca6f, // (12, 2671) 78
(short) 0x80a7, // ( 8, 167) 79
(short) 0xc66f, // (12, 1647) 80
(short) 0xb02f, // (11, 47) 81
(short) 0xce6f, // (12, 3695) 82
(short) 0x9137, // ( 9, 311) 83
(short) 0xc16f, // (12, 367) 84
(short) 0xb42f, // (11, 1071) 85
(short) 0xc96f, // (12, 2415) 86
(short) 0x90b7, // ( 9, 183) 87
(short) 0xc56f, // (12, 1391) 88
(short) 0xcd6f, // (12, 3439) 89
(short) 0xc36f, // (12, 879) 90
(short) 0xb22f, // (11, 559) 91
(short) 0xcb6f, // (12, 2927) 92
(short) 0xc76f, // (12, 1903) 93
(short) 0xcf6f, // (12, 3951) 94
(short) 0xa28f, // (10, 655) 95
(short) 0xc0ef, // (12, 239) 96
(short) 0xc8ef, // (12, 2287) 97
(short) 0xc4ef, // (12, 1263) 98
(short) 0xa18f, // (10, 399) 99
(short) 0xccef, // (12, 3311) 100
(short) 0xc2ef, // (12, 751) 101
(short) 0xcaef, // (12, 2799) 102
(short) 0xa38f, // (10, 911) 103
(short) 0xc6ef, // (12, 1775) 104
(short) 0xceef, // (12, 3823) 105
(short) 0xc1ef, // (12, 495) 106
(short) 0xc9ef, // (12, 2543) 107
(short) 0xc5ef, // (12, 1519) 108
(short) 0xcdef, // (12, 3567) 109
(short) 0xc3ef, // (12, 1007) 110
(short) 0xb62f, // (11, 1583) 111
(short) 0xcbef, // (12, 3055) 112
(short) 0xc7ef, // (12, 2031) 113
(short) 0xcfef, // (12, 4079) 114
(short) 0xc01f, // (12, 31) 115
(short) 0xc81f, // (12, 2079) 116
(short) 0xc41f, // (12, 1055) 117
(short) 0xcc1f, // (12, 3103) 118
(short) 0xc21f, // (12, 543) 119
(short) 0xca1f, // (12, 2591) 120
(short) 0xc61f, // (12, 1567) 121
(short) 0xce1f, // (12, 3615) 122
(short) 0xc11f, // (12, 287) 123
(short) 0xc91f, // (12, 2335) 124
(short) 0xc51f, // (12, 1311) 125
(short) 0xcd1f, // (12, 3359) 126
(short) 0xc31f, // (12, 799) 127
(short) 0xcb1f, // (12, 2847) 128
(short) 0xa04f, // (10, 79) 129
(short) 0xc71f, // (12, 1823) 130
(short) 0x8067, // ( 8, 103) 131
(short) 0xcf1f, // (12, 3871) 132
(short) 0xa24f, // (10, 591) 133
(short) 0xc09f, // (12, 159) 134
(short) 0x80e7, // ( 8, 231) 135
(short) 0xc89f, // (12, 2207) 136
(short) 0xb12f, // (11, 303) 137
(short) 0xc49f, // (12, 1183) 138
(short) 0x91b7, // ( 9, 439) 139
(short) 0xcc9f, // (12, 3231) 140
(short) 0xb52f, // (11, 1327) 141
(short) 0xc29f, // (12, 671) 142
(short) 0x9077, // ( 9, 119) 143
(short) 0xca9f, // (12, 2719) 144
(short) 0xc69f, // (12, 1695) 145
(short) 0xce9f, // (12, 3743) 146
(short) 0xa14f, // (10, 335) 147
(short) 0xc19f, // (12, 415) 148
(short) 0xc99f, // (12, 2463) 149
(short) 0xc59f, // (12, 1439) 150
(short) 0xa34f, // (10, 847) 151
(short) 0xcd9f, // (12, 3487) 152
(short) 0xc39f, // (12, 927) 153
(short) 0xcb9f, // (12, 2975) 154
(short) 0xc79f, // (12, 1951) 155
(short) 0xcf9f, // (12, 3999) 156
(short) 0xc05f, // (12, 95) 157
(short) 0xc85f, // (12, 2143) 158
(short) 0xb32f, // (11, 815) 159
(short) 0xc45f, // (12, 1119) 160
(short) 0xcc5f, // (12, 3167) 161
(short) 0xc25f, // (12, 607) 162
(short) 0xb72f, // (11, 1839) 163
(short) 0xca5f, // (12, 2655) 164
(short) 0xc65f, // (12, 1631) 165
(short) 0xce5f, // (12, 3679) 166
(short) 0xb0af, // (11, 175) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 15 of 22) (steady 15 of 16) (phase = 0.968750000 = 31.0 / 32.0)
// entropy: 4.4653007097343397902
// avg_length: 4.5480722016259509388; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x9017, // ( 9, 23) 0
(short) 0x4006, // ( 4, 6) 1
(short) 0x7033, // ( 7, 51) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0x9117, // ( 9, 279) 4
(short) 0x400e, // ( 4, 14) 5
(short) 0x7073, // ( 7, 115) 6
(short) 0x2000, // ( 2, 0) 7
(short) 0xa0f7, // (10, 247) 8
(short) 0x601d, // ( 6, 29) 9
(short) 0x803b, // ( 8, 59) 10
(short) 0x4001, // ( 4, 1) 11
(short) 0xa2f7, // (10, 759) 12
(short) 0x5005, // ( 5, 5) 13
(short) 0x80bb, // ( 8, 187) 14
(short) 0x4009, // ( 4, 9) 15
(short) 0xb0cf, // (11, 207) 16
(short) 0x700b, // ( 7, 11) 17
(short) 0x9097, // ( 9, 151) 18
(short) 0x5015, // ( 5, 21) 19
(short) 0xb4cf, // (11, 1231) 20
(short) 0x704b, // ( 7, 75) 21
(short) 0x9197, // ( 9, 407) 22
(short) 0x500d, // ( 5, 13) 23
(short) 0xc0af, // (12, 175) 24
(short) 0x807b, // ( 8, 123) 25
(short) 0xb2cf, // (11, 719) 26
(short) 0x603d, // ( 6, 61) 27
(short) 0xc8af, // (12, 2223) 28
(short) 0x80fb, // ( 8, 251) 29
(short) 0xa1f7, // (10, 503) 30
(short) 0x6003, // ( 6, 3) 31
(short) 0xc4af, // (12, 1199) 32
(short) 0x8007, // ( 8, 7) 33
(short) 0xb6cf, // (11, 1743) 34
(short) 0x6023, // ( 6, 35) 35
(short) 0xccaf, // (12, 3247) 36
(short) 0x8087, // ( 8, 135) 37
(short) 0xa3f7, // (10, 1015) 38
(short) 0x6013, // ( 6, 19) 39
(short) 0xc2af, // (12, 687) 40
(short) 0x9057, // ( 9, 87) 41
(short) 0xcaaf, // (12, 2735) 42
(short) 0x702b, // ( 7, 43) 43
(short) 0xc6af, // (12, 1711) 44
(short) 0x9157, // ( 9, 343) 45
(short) 0xb1cf, // (11, 463) 46
(short) 0x706b, // ( 7, 107) 47
(short) 0xceaf, // (12, 3759) 48
(short) 0xa00f, // (10, 15) 49
(short) 0xc1af, // (12, 431) 50
(short) 0x8047, // ( 8, 71) 51
(short) 0xc9af, // (12, 2479) 52
(short) 0xa20f, // (10, 527) 53
(short) 0xc5af, // (12, 1455) 54
(short) 0x80c7, // ( 8, 199) 55
(short) 0xcdaf, // (12, 3503) 56
(short) 0xb5cf, // (11, 1487) 57
(short) 0xc3af, // (12, 943) 58
(short) 0x90d7, // ( 9, 215) 59
(short) 0xcbaf, // (12, 2991) 60
(short) 0xb3cf, // (11, 975) 61
(short) 0xc7af, // (12, 1967) 62
(short) 0x91d7, // ( 9, 471) 63
(short) 0xcfaf, // (12, 4015) 64
(short) 0x9037, // ( 9, 55) 65
(short) 0xc06f, // (12, 111) 66
(short) 0x701b, // ( 7, 27) 67
(short) 0xc86f, // (12, 2159) 68
(short) 0x9137, // ( 9, 311) 69
(short) 0xb7cf, // (11, 1999) 70
(short) 0x705b, // ( 7, 91) 71
(short) 0xc46f, // (12, 1135) 72
(short) 0xa10f, // (10, 271) 73
(short) 0xcc6f, // (12, 3183) 74
(short) 0x8027, // ( 8, 39) 75
(short) 0xc26f, // (12, 623) 76
(short) 0xa30f, // (10, 783) 77
(short) 0xca6f, // (12, 2671) 78
(short) 0x80a7, // ( 8, 167) 79
(short) 0xc66f, // (12, 1647) 80
(short) 0xb02f, // (11, 47) 81
(short) 0xce6f, // (12, 3695) 82
(short) 0x90b7, // ( 9, 183) 83
(short) 0xc16f, // (12, 367) 84
(short) 0xb42f, // (11, 1071) 85
(short) 0xc96f, // (12, 2415) 86
(short) 0x91b7, // ( 9, 439) 87
(short) 0xc56f, // (12, 1391) 88
(short) 0xcd6f, // (12, 3439) 89
(short) 0xc36f, // (12, 879) 90
(short) 0xa08f, // (10, 143) 91
(short) 0xcb6f, // (12, 2927) 92
(short) 0xc76f, // (12, 1903) 93
(short) 0xcf6f, // (12, 3951) 94
(short) 0xa28f, // (10, 655) 95
(short) 0xc0ef, // (12, 239) 96
(short) 0xc8ef, // (12, 2287) 97
(short) 0xc4ef, // (12, 1263) 98
(short) 0xa18f, // (10, 399) 99
(short) 0xccef, // (12, 3311) 100
(short) 0xc2ef, // (12, 751) 101
(short) 0xcaef, // (12, 2799) 102
(short) 0xa38f, // (10, 911) 103
(short) 0xc6ef, // (12, 1775) 104
(short) 0xceef, // (12, 3823) 105
(short) 0xc1ef, // (12, 495) 106
(short) 0xc9ef, // (12, 2543) 107
(short) 0xc5ef, // (12, 1519) 108
(short) 0xcdef, // (12, 3567) 109
(short) 0xc3ef, // (12, 1007) 110
(short) 0xb22f, // (11, 559) 111
(short) 0xcbef, // (12, 3055) 112
(short) 0xc7ef, // (12, 2031) 113
(short) 0xcfef, // (12, 4079) 114
(short) 0xc01f, // (12, 31) 115
(short) 0xc81f, // (12, 2079) 116
(short) 0xc41f, // (12, 1055) 117
(short) 0xcc1f, // (12, 3103) 118
(short) 0xc21f, // (12, 543) 119
(short) 0xca1f, // (12, 2591) 120
(short) 0xc61f, // (12, 1567) 121
(short) 0xce1f, // (12, 3615) 122
(short) 0xc11f, // (12, 287) 123
(short) 0xc91f, // (12, 2335) 124
(short) 0xc51f, // (12, 1311) 125
(short) 0xcd1f, // (12, 3359) 126
(short) 0xc31f, // (12, 799) 127
(short) 0xcb1f, // (12, 2847) 128
(short) 0xa04f, // (10, 79) 129
(short) 0xc71f, // (12, 1823) 130
(short) 0x8067, // ( 8, 103) 131
(short) 0xcf1f, // (12, 3871) 132
(short) 0xa24f, // (10, 591) 133
(short) 0xc09f, // (12, 159) 134
(short) 0x80e7, // ( 8, 231) 135
(short) 0xc89f, // (12, 2207) 136
(short) 0xb62f, // (11, 1583) 137
(short) 0xc49f, // (12, 1183) 138
(short) 0x9077, // ( 9, 119) 139
(short) 0xcc9f, // (12, 3231) 140
(short) 0xb12f, // (11, 303) 141
(short) 0xc29f, // (12, 671) 142
(short) 0x9177, // ( 9, 375) 143
(short) 0xca9f, // (12, 2719) 144
(short) 0xc69f, // (12, 1695) 145
(short) 0xce9f, // (12, 3743) 146
(short) 0xa14f, // (10, 335) 147
(short) 0xc19f, // (12, 415) 148
(short) 0xc99f, // (12, 2463) 149
(short) 0xc59f, // (12, 1439) 150
(short) 0xa34f, // (10, 847) 151
(short) 0xcd9f, // (12, 3487) 152
(short) 0xc39f, // (12, 927) 153
(short) 0xcb9f, // (12, 2975) 154
(short) 0xc79f, // (12, 1951) 155
(short) 0xcf9f, // (12, 3999) 156
(short) 0xc05f, // (12, 95) 157
(short) 0xc85f, // (12, 2143) 158
(short) 0xb52f, // (11, 1327) 159
(short) 0xc45f, // (12, 1119) 160
(short) 0xcc5f, // (12, 3167) 161
(short) 0xc25f, // (12, 607) 162
(short) 0xb32f, // (11, 815) 163
(short) 0xca5f, // (12, 2655) 164
(short) 0xc65f, // (12, 1631) 165
(short) 0xce5f, // (12, 3679) 166
(short) 0xb72f, // (11, 1839) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// Six Encoding Tables for the Midrange.
// (table 16 of 22) (midrange 0 of 6) (c/k = 0.500000000 = 3.0 / 6.0)
// entropy: 2.1627885076675394949
// avg_length: 2.2704182849800043087; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x1000, // ( 1, 0) 0
(short) 0x2001, // ( 2, 1) 1
(short) 0x4003, // ( 4, 3) 2
(short) 0x500b, // ( 5, 11) 3
(short) 0x501b, // ( 5, 27) 4
(short) 0x6007, // ( 6, 7) 5
(short) 0x8057, // ( 8, 87) 6
(short) 0x9077, // ( 9, 119) 7
(short) 0x6027, // ( 6, 39) 8
(short) 0x80d7, // ( 8, 215) 9
(short) 0x9177, // ( 9, 375) 10
(short) 0xa1f7, // (10, 503) 11
(short) 0xa3f7, // (10, 1015) 12
(short) 0xb08f, // (11, 143) 13
(short) 0xc58f, // (12, 1423) 14
(short) 0xcd8f, // (12, 3471) 15
(short) 0x7017, // ( 7, 23) 16
(short) 0x8037, // ( 8, 55) 17
(short) 0xa00f, // (10, 15) 18
(short) 0xb48f, // (11, 1167) 19
(short) 0xb28f, // (11, 655) 20
(short) 0xc38f, // (12, 911) 21
(short) 0xcb8f, // (12, 2959) 22
(short) 0xc78f, // (12, 1935) 23
(short) 0xcf8f, // (12, 3983) 24
(short) 0xc04f, // (12, 79) 25
(short) 0xc84f, // (12, 2127) 26
(short) 0xc44f, // (12, 1103) 27
(short) 0xcc4f, // (12, 3151) 28
(short) 0xc24f, // (12, 591) 29
(short) 0xca4f, // (12, 2639) 30
(short) 0xc64f, // (12, 1615) 31
(short) 0x80b7, // ( 8, 183) 32
(short) 0xa20f, // (10, 527) 33
(short) 0xb68f, // (11, 1679) 34
(short) 0xce4f, // (12, 3663) 35
(short) 0xc14f, // (12, 335) 36
(short) 0xc94f, // (12, 2383) 37
(short) 0xc54f, // (12, 1359) 38
(short) 0xcd4f, // (12, 3407) 39
(short) 0xc34f, // (12, 847) 40
(short) 0xcb4f, // (12, 2895) 41
(short) 0xc74f, // (12, 1871) 42
(short) 0xcf4f, // (12, 3919) 43
(short) 0xc0cf, // (12, 207) 44
(short) 0xc8cf, // (12, 2255) 45
(short) 0xc4cf, // (12, 1231) 46
(short) 0xcccf, // (12, 3279) 47
(short) 0xc2cf, // (12, 719) 48
(short) 0xcacf, // (12, 2767) 49
(short) 0xc6cf, // (12, 1743) 50
(short) 0xcecf, // (12, 3791) 51
(short) 0xc1cf, // (12, 463) 52
(short) 0xc9cf, // (12, 2511) 53
(short) 0xc5cf, // (12, 1487) 54
(short) 0xcdcf, // (12, 3535) 55
(short) 0xc3cf, // (12, 975) 56
(short) 0xcbcf, // (12, 3023) 57
(short) 0xc7cf, // (12, 1999) 58
(short) 0xcfcf, // (12, 4047) 59
(short) 0xc02f, // (12, 47) 60
(short) 0xc82f, // (12, 2095) 61
(short) 0xc42f, // (12, 1071) 62
(short) 0xcc2f, // (12, 3119) 63
(short) 0x90f7, // ( 9, 247) 64
(short) 0xa10f, // (10, 271) 65
(short) 0xc22f, // (12, 559) 66
(short) 0xca2f, // (12, 2607) 67
(short) 0xc62f, // (12, 1583) 68
(short) 0xce2f, // (12, 3631) 69
(short) 0xc12f, // (12, 303) 70
(short) 0xc92f, // (12, 2351) 71
(short) 0xc52f, // (12, 1327) 72
(short) 0xcd2f, // (12, 3375) 73
(short) 0xc32f, // (12, 815) 74
(short) 0xcb2f, // (12, 2863) 75
(short) 0xc72f, // (12, 1839) 76
(short) 0xcf2f, // (12, 3887) 77
(short) 0xc0af, // (12, 175) 78
(short) 0xc8af, // (12, 2223) 79
(short) 0xc4af, // (12, 1199) 80
(short) 0xccaf, // (12, 3247) 81
(short) 0xc2af, // (12, 687) 82
(short) 0xcaaf, // (12, 2735) 83
(short) 0xc6af, // (12, 1711) 84
(short) 0xceaf, // (12, 3759) 85
(short) 0xc1af, // (12, 431) 86
(short) 0xc9af, // (12, 2479) 87
(short) 0xc5af, // (12, 1455) 88
(short) 0xcdaf, // (12, 3503) 89
(short) 0xc3af, // (12, 943) 90
(short) 0xcbaf, // (12, 2991) 91
(short) 0xc7af, // (12, 1967) 92
(short) 0xcfaf, // (12, 4015) 93
(short) 0xc06f, // (12, 111) 94
(short) 0xc86f, // (12, 2159) 95
(short) 0xc46f, // (12, 1135) 96
(short) 0xcc6f, // (12, 3183) 97
(short) 0xc26f, // (12, 623) 98
(short) 0xca6f, // (12, 2671) 99
(short) 0xc66f, // (12, 1647) 100
(short) 0xce6f, // (12, 3695) 101
(short) 0xc16f, // (12, 367) 102
(short) 0xc96f, // (12, 2415) 103
(short) 0xc56f, // (12, 1391) 104
(short) 0xcd6f, // (12, 3439) 105
(short) 0xc36f, // (12, 879) 106
(short) 0xcb6f, // (12, 2927) 107
(short) 0xc76f, // (12, 1903) 108
(short) 0xcf6f, // (12, 3951) 109
(short) 0xc0ef, // (12, 239) 110
(short) 0xc8ef, // (12, 2287) 111
(short) 0xc4ef, // (12, 1263) 112
(short) 0xccef, // (12, 3311) 113
(short) 0xc2ef, // (12, 751) 114
(short) 0xcaef, // (12, 2799) 115
(short) 0xc6ef, // (12, 1775) 116
(short) 0xceef, // (12, 3823) 117
(short) 0xc1ef, // (12, 495) 118
(short) 0xc9ef, // (12, 2543) 119
(short) 0xc5ef, // (12, 1519) 120
(short) 0xcdef, // (12, 3567) 121
(short) 0xc3ef, // (12, 1007) 122
(short) 0xcbef, // (12, 3055) 123
(short) 0xc7ef, // (12, 2031) 124
(short) 0xcfef, // (12, 4079) 125
(short) 0xc01f, // (12, 31) 126
(short) 0xc81f, // (12, 2079) 127
(short) 0xa30f, // (10, 783) 128
(short) 0xb18f, // (11, 399) 129
(short) 0xc41f, // (12, 1055) 130
(short) 0xcc1f, // (12, 3103) 131
(short) 0xc21f, // (12, 543) 132
(short) 0xca1f, // (12, 2591) 133
(short) 0xc61f, // (12, 1567) 134
(short) 0xce1f, // (12, 3615) 135
(short) 0xc11f, // (12, 287) 136
(short) 0xc91f, // (12, 2335) 137
(short) 0xc51f, // (12, 1311) 138
(short) 0xcd1f, // (12, 3359) 139
(short) 0xc31f, // (12, 799) 140
(short) 0xcb1f, // (12, 2847) 141
(short) 0xc71f, // (12, 1823) 142
(short) 0xcf1f, // (12, 3871) 143
(short) 0xc09f, // (12, 159) 144
(short) 0xc89f, // (12, 2207) 145
(short) 0xc49f, // (12, 1183) 146
(short) 0xcc9f, // (12, 3231) 147
(short) 0xc29f, // (12, 671) 148
(short) 0xca9f, // (12, 2719) 149
(short) 0xc69f, // (12, 1695) 150
(short) 0xce9f, // (12, 3743) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 17 of 22) (midrange 1 of 6) (c/k = 0.833333333 = 5.0 / 6.0)
// entropy: 2.9553294756640680063
// avg_length: 3.0766035704232641557; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x2000, // ( 2, 0) 0
(short) 0x2002, // ( 2, 2) 1
(short) 0x3001, // ( 3, 1) 2
(short) 0x4005, // ( 4, 5) 3
(short) 0x400d, // ( 4, 13) 4
(short) 0x5003, // ( 5, 3) 5
(short) 0x600b, // ( 6, 11) 6
(short) 0x602b, // ( 6, 43) 7
(short) 0x5013, // ( 5, 19) 8
(short) 0x601b, // ( 6, 27) 9
(short) 0x7007, // ( 7, 7) 10
(short) 0x7047, // ( 7, 71) 11
(short) 0x8017, // ( 8, 23) 12
(short) 0x90b7, // ( 9, 183) 13
(short) 0xa1f7, // (10, 503) 14
(short) 0xa3f7, // (10, 1015) 15
(short) 0x603b, // ( 6, 59) 16
(short) 0x7027, // ( 7, 39) 17
(short) 0x8097, // ( 8, 151) 18
(short) 0x8057, // ( 8, 87) 19
(short) 0x91b7, // ( 9, 439) 20
(short) 0xa00f, // (10, 15) 21
(short) 0xb18f, // (11, 399) 22
(short) 0xb58f, // (11, 1423) 23
(short) 0xa20f, // (10, 527) 24
(short) 0xb38f, // (11, 911) 25
(short) 0xc54f, // (12, 1359) 26
(short) 0xcd4f, // (12, 3407) 27
(short) 0xc34f, // (12, 847) 28
(short) 0xcb4f, // (12, 2895) 29
(short) 0xc74f, // (12, 1871) 30
(short) 0xcf4f, // (12, 3919) 31
(short) 0x7067, // ( 7, 103) 32
(short) 0x80d7, // ( 8, 215) 33
(short) 0x9077, // ( 9, 119) 34
(short) 0xa10f, // (10, 271) 35
(short) 0xa30f, // (10, 783) 36
(short) 0xb78f, // (11, 1935) 37
(short) 0xc0cf, // (12, 207) 38
(short) 0xc8cf, // (12, 2255) 39
(short) 0xb04f, // (11, 79) 40
(short) 0xc4cf, // (12, 1231) 41
(short) 0xcccf, // (12, 3279) 42
(short) 0xc2cf, // (12, 719) 43
(short) 0xcacf, // (12, 2767) 44
(short) 0xc6cf, // (12, 1743) 45
(short) 0xcecf, // (12, 3791) 46
(short) 0xc1cf, // (12, 463) 47
(short) 0xc9cf, // (12, 2511) 48
(short) 0xc5cf, // (12, 1487) 49
(short) 0xcdcf, // (12, 3535) 50
(short) 0xc3cf, // (12, 975) 51
(short) 0xcbcf, // (12, 3023) 52
(short) 0xc7cf, // (12, 1999) 53
(short) 0xcfcf, // (12, 4047) 54
(short) 0xc02f, // (12, 47) 55
(short) 0xc82f, // (12, 2095) 56
(short) 0xc42f, // (12, 1071) 57
(short) 0xcc2f, // (12, 3119) 58
(short) 0xc22f, // (12, 559) 59
(short) 0xca2f, // (12, 2607) 60
(short) 0xc62f, // (12, 1583) 61
(short) 0xce2f, // (12, 3631) 62
(short) 0xc12f, // (12, 303) 63
(short) 0x8037, // ( 8, 55) 64
(short) 0x9177, // ( 9, 375) 65
(short) 0xa08f, // (10, 143) 66
(short) 0xb44f, // (11, 1103) 67
(short) 0xb24f, // (11, 591) 68
(short) 0xc92f, // (12, 2351) 69
(short) 0xc52f, // (12, 1327) 70
(short) 0xcd2f, // (12, 3375) 71
(short) 0xc32f, // (12, 815) 72
(short) 0xcb2f, // (12, 2863) 73
(short) 0xc72f, // (12, 1839) 74
(short) 0xcf2f, // (12, 3887) 75
(short) 0xc0af, // (12, 175) 76
(short) 0xc8af, // (12, 2223) 77
(short) 0xc4af, // (12, 1199) 78
(short) 0xccaf, // (12, 3247) 79
(short) 0xc2af, // (12, 687) 80
(short) 0xcaaf, // (12, 2735) 81
(short) 0xc6af, // (12, 1711) 82
(short) 0xceaf, // (12, 3759) 83
(short) 0xc1af, // (12, 431) 84
(short) 0xc9af, // (12, 2479) 85
(short) 0xc5af, // (12, 1455) 86
(short) 0xcdaf, // (12, 3503) 87
(short) 0xc3af, // (12, 943) 88
(short) 0xcbaf, // (12, 2991) 89
(short) 0xc7af, // (12, 1967) 90
(short) 0xcfaf, // (12, 4015) 91
(short) 0xc06f, // (12, 111) 92
(short) 0xc86f, // (12, 2159) 93
(short) 0xc46f, // (12, 1135) 94
(short) 0xcc6f, // (12, 3183) 95
(short) 0xc26f, // (12, 623) 96
(short) 0xca6f, // (12, 2671) 97
(short) 0xc66f, // (12, 1647) 98
(short) 0xce6f, // (12, 3695) 99
(short) 0xc16f, // (12, 367) 100
(short) 0xc96f, // (12, 2415) 101
(short) 0xc56f, // (12, 1391) 102
(short) 0xcd6f, // (12, 3439) 103
(short) 0xc36f, // (12, 879) 104
(short) 0xcb6f, // (12, 2927) 105
(short) 0xc76f, // (12, 1903) 106
(short) 0xcf6f, // (12, 3951) 107
(short) 0xc0ef, // (12, 239) 108
(short) 0xc8ef, // (12, 2287) 109
(short) 0xc4ef, // (12, 1263) 110
(short) 0xccef, // (12, 3311) 111
(short) 0xc2ef, // (12, 751) 112
(short) 0xcaef, // (12, 2799) 113
(short) 0xc6ef, // (12, 1775) 114
(short) 0xceef, // (12, 3823) 115
(short) 0xc1ef, // (12, 495) 116
(short) 0xc9ef, // (12, 2543) 117
(short) 0xc5ef, // (12, 1519) 118
(short) 0xcdef, // (12, 3567) 119
(short) 0xc3ef, // (12, 1007) 120
(short) 0xcbef, // (12, 3055) 121
(short) 0xc7ef, // (12, 2031) 122
(short) 0xcfef, // (12, 4079) 123
(short) 0xc01f, // (12, 31) 124
(short) 0xc81f, // (12, 2079) 125
(short) 0xc41f, // (12, 1055) 126
(short) 0xcc1f, // (12, 3103) 127
(short) 0x90f7, // ( 9, 247) 128
(short) 0xa28f, // (10, 655) 129
(short) 0xb64f, // (11, 1615) 130
(short) 0xb14f, // (11, 335) 131
(short) 0xc21f, // (12, 543) 132
(short) 0xca1f, // (12, 2591) 133
(short) 0xc61f, // (12, 1567) 134
(short) 0xce1f, // (12, 3615) 135
(short) 0xc11f, // (12, 287) 136
(short) 0xc91f, // (12, 2335) 137
(short) 0xc51f, // (12, 1311) 138
(short) 0xcd1f, // (12, 3359) 139
(short) 0xc31f, // (12, 799) 140
(short) 0xcb1f, // (12, 2847) 141
(short) 0xc71f, // (12, 1823) 142
(short) 0xcf1f, // (12, 3871) 143
(short) 0xc09f, // (12, 159) 144
(short) 0xc89f, // (12, 2207) 145
(short) 0xc49f, // (12, 1183) 146
(short) 0xcc9f, // (12, 3231) 147
(short) 0xc29f, // (12, 671) 148
(short) 0xca9f, // (12, 2719) 149
(short) 0xc69f, // (12, 1695) 150
(short) 0xce9f, // (12, 3743) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 18 of 22) (midrange 2 of 6) (c/k = 1.166666667 = 7.0 / 6.0)
// entropy: 3.5218672531711128215
// avg_length: 3.6153551492375441967; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x2000, // ( 2, 0) 0
(short) 0x2002, // ( 2, 2) 1
(short) 0x4005, // ( 4, 5) 2
(short) 0x3001, // ( 3, 1) 3
(short) 0x5003, // ( 5, 3) 4
(short) 0x400d, // ( 4, 13) 5
(short) 0x600b, // ( 6, 11) 6
(short) 0x602b, // ( 6, 43) 7
(short) 0x601b, // ( 6, 27) 8
(short) 0x5013, // ( 5, 19) 9
(short) 0x703b, // ( 7, 59) 10
(short) 0x707b, // ( 7, 123) 11
(short) 0x8067, // ( 8, 103) 12
(short) 0x80e7, // ( 8, 231) 13
(short) 0x90d7, // ( 9, 215) 14
(short) 0x91d7, // ( 9, 471) 15
(short) 0x7007, // ( 7, 7) 16
(short) 0x7047, // ( 7, 71) 17
(short) 0x8017, // ( 8, 23) 18
(short) 0x8097, // ( 8, 151) 19
(short) 0x9037, // ( 9, 55) 20
(short) 0x9137, // ( 9, 311) 21
(short) 0xa1f7, // (10, 503) 22
(short) 0xa3f7, // (10, 1015) 23
(short) 0xa00f, // (10, 15) 24
(short) 0xa20f, // (10, 527) 25
(short) 0xb38f, // (11, 911) 26
(short) 0xb78f, // (11, 1935) 27
(short) 0xc0cf, // (12, 207) 28
(short) 0xc8cf, // (12, 2255) 29
(short) 0xc4cf, // (12, 1231) 30
(short) 0xcccf, // (12, 3279) 31
(short) 0x8057, // ( 8, 87) 32
(short) 0x7027, // ( 7, 39) 33
(short) 0x90b7, // ( 9, 183) 34
(short) 0x91b7, // ( 9, 439) 35
(short) 0xa10f, // (10, 271) 36
(short) 0xa30f, // (10, 783) 37
(short) 0xb04f, // (11, 79) 38
(short) 0xb44f, // (11, 1103) 39
(short) 0xb24f, // (11, 591) 40
(short) 0xb64f, // (11, 1615) 41
(short) 0xc2cf, // (12, 719) 42
(short) 0xcacf, // (12, 2767) 43
(short) 0xc6cf, // (12, 1743) 44
(short) 0xcecf, // (12, 3791) 45
(short) 0xc1cf, // (12, 463) 46
(short) 0xc9cf, // (12, 2511) 47
(short) 0xc5cf, // (12, 1487) 48
(short) 0xcdcf, // (12, 3535) 49
(short) 0xc3cf, // (12, 975) 50
(short) 0xcbcf, // (12, 3023) 51
(short) 0xc7cf, // (12, 1999) 52
(short) 0xcfcf, // (12, 4047) 53
(short) 0xc02f, // (12, 47) 54
(short) 0xc82f, // (12, 2095) 55
(short) 0xc42f, // (12, 1071) 56
(short) 0xcc2f, // (12, 3119) 57
(short) 0xc22f, // (12, 559) 58
(short) 0xca2f, // (12, 2607) 59
(short) 0xc62f, // (12, 1583) 60
(short) 0xce2f, // (12, 3631) 61
(short) 0xc12f, // (12, 303) 62
(short) 0xc92f, // (12, 2351) 63
(short) 0x9077, // ( 9, 119) 64
(short) 0x9177, // ( 9, 375) 65
(short) 0xa08f, // (10, 143) 66
(short) 0xa28f, // (10, 655) 67
(short) 0xb14f, // (11, 335) 68
(short) 0xb54f, // (11, 1359) 69
(short) 0xc52f, // (12, 1327) 70
(short) 0xcd2f, // (12, 3375) 71
(short) 0xc32f, // (12, 815) 72
(short) 0xcb2f, // (12, 2863) 73
(short) 0xc72f, // (12, 1839) 74
(short) 0xcf2f, // (12, 3887) 75
(short) 0xc0af, // (12, 175) 76
(short) 0xc8af, // (12, 2223) 77
(short) 0xc4af, // (12, 1199) 78
(short) 0xccaf, // (12, 3247) 79
(short) 0xc2af, // (12, 687) 80
(short) 0xcaaf, // (12, 2735) 81
(short) 0xc6af, // (12, 1711) 82
(short) 0xceaf, // (12, 3759) 83
(short) 0xc1af, // (12, 431) 84
(short) 0xc9af, // (12, 2479) 85
(short) 0xc5af, // (12, 1455) 86
(short) 0xcdaf, // (12, 3503) 87
(short) 0xc3af, // (12, 943) 88
(short) 0xcbaf, // (12, 2991) 89
(short) 0xc7af, // (12, 1967) 90
(short) 0xcfaf, // (12, 4015) 91
(short) 0xc06f, // (12, 111) 92
(short) 0xc86f, // (12, 2159) 93
(short) 0xc46f, // (12, 1135) 94
(short) 0xcc6f, // (12, 3183) 95
(short) 0xc26f, // (12, 623) 96
(short) 0xca6f, // (12, 2671) 97
(short) 0xc66f, // (12, 1647) 98
(short) 0xce6f, // (12, 3695) 99
(short) 0xc16f, // (12, 367) 100
(short) 0xc96f, // (12, 2415) 101
(short) 0xc56f, // (12, 1391) 102
(short) 0xcd6f, // (12, 3439) 103
(short) 0xc36f, // (12, 879) 104
(short) 0xcb6f, // (12, 2927) 105
(short) 0xc76f, // (12, 1903) 106
(short) 0xcf6f, // (12, 3951) 107
(short) 0xc0ef, // (12, 239) 108
(short) 0xc8ef, // (12, 2287) 109
(short) 0xc4ef, // (12, 1263) 110
(short) 0xccef, // (12, 3311) 111
(short) 0xc2ef, // (12, 751) 112
(short) 0xcaef, // (12, 2799) 113
(short) 0xc6ef, // (12, 1775) 114
(short) 0xceef, // (12, 3823) 115
(short) 0xc1ef, // (12, 495) 116
(short) 0xc9ef, // (12, 2543) 117
(short) 0xc5ef, // (12, 1519) 118
(short) 0xcdef, // (12, 3567) 119
(short) 0xc3ef, // (12, 1007) 120
(short) 0xcbef, // (12, 3055) 121
(short) 0xc7ef, // (12, 2031) 122
(short) 0xcfef, // (12, 4079) 123
(short) 0xc01f, // (12, 31) 124
(short) 0xc81f, // (12, 2079) 125
(short) 0xc41f, // (12, 1055) 126
(short) 0xcc1f, // (12, 3103) 127
(short) 0xa18f, // (10, 399) 128
(short) 0x90f7, // ( 9, 247) 129
(short) 0xb34f, // (11, 847) 130
(short) 0xb74f, // (11, 1871) 131
(short) 0xc21f, // (12, 543) 132
(short) 0xca1f, // (12, 2591) 133
(short) 0xc61f, // (12, 1567) 134
(short) 0xce1f, // (12, 3615) 135
(short) 0xc11f, // (12, 287) 136
(short) 0xc91f, // (12, 2335) 137
(short) 0xc51f, // (12, 1311) 138
(short) 0xcd1f, // (12, 3359) 139
(short) 0xc31f, // (12, 799) 140
(short) 0xcb1f, // (12, 2847) 141
(short) 0xc71f, // (12, 1823) 142
(short) 0xcf1f, // (12, 3871) 143
(short) 0xc09f, // (12, 159) 144
(short) 0xc89f, // (12, 2207) 145
(short) 0xc49f, // (12, 1183) 146
(short) 0xcc9f, // (12, 3231) 147
(short) 0xc29f, // (12, 671) 148
(short) 0xca9f, // (12, 2719) 149
(short) 0xc69f, // (12, 1695) 150
(short) 0xce9f, // (12, 3743) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 19 of 22) (midrange 3 of 6) (c/k = 1.500000000 = 9.0 / 6.0)
// entropy: 3.9228873257934386842
// avg_length: 3.9989687586992346269; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x3002, // ( 3, 2) 0
(short) 0x2000, // ( 2, 0) 1
(short) 0x4001, // ( 4, 1) 2
(short) 0x3006, // ( 3, 6) 3
(short) 0x500d, // ( 5, 13) 4
(short) 0x4009, // ( 4, 9) 5
(short) 0x501d, // ( 5, 29) 6
(short) 0x4005, // ( 4, 5) 7
(short) 0x6013, // ( 6, 19) 8
(short) 0x5003, // ( 5, 3) 9
(short) 0x6033, // ( 6, 51) 10
(short) 0x600b, // ( 6, 11) 11
(short) 0x8027, // ( 8, 39) 12
(short) 0x701b, // ( 7, 27) 13
(short) 0x80a7, // ( 8, 167) 14
(short) 0x705b, // ( 7, 91) 15
(short) 0x703b, // ( 7, 59) 16
(short) 0x602b, // ( 6, 43) 17
(short) 0x707b, // ( 7, 123) 18
(short) 0x7007, // ( 7, 7) 19
(short) 0x90d7, // ( 9, 215) 20
(short) 0x8067, // ( 8, 103) 21
(short) 0x91d7, // ( 9, 471) 22
(short) 0x80e7, // ( 8, 231) 23
(short) 0xa1f7, // (10, 503) 24
(short) 0x9037, // ( 9, 55) 25
(short) 0xa3f7, // (10, 1015) 26
(short) 0xa00f, // (10, 15) 27
(short) 0xc5cf, // (12, 1487) 28
(short) 0xb04f, // (11, 79) 29
(short) 0xcdcf, // (12, 3535) 30
(short) 0xb44f, // (11, 1103) 31
(short) 0x8017, // ( 8, 23) 32
(short) 0x7047, // ( 7, 71) 33
(short) 0x9137, // ( 9, 311) 34
(short) 0x8097, // ( 8, 151) 35
(short) 0xa20f, // (10, 527) 36
(short) 0x90b7, // ( 9, 183) 37
(short) 0xa10f, // (10, 271) 38
(short) 0x91b7, // ( 9, 439) 39
(short) 0xb24f, // (11, 591) 40
(short) 0xa30f, // (10, 783) 41
(short) 0xb64f, // (11, 1615) 42
(short) 0xb14f, // (11, 335) 43
(short) 0xc3cf, // (12, 975) 44
(short) 0xcbcf, // (12, 3023) 45
(short) 0xc7cf, // (12, 1999) 46
(short) 0xcfcf, // (12, 4047) 47
(short) 0xc02f, // (12, 47) 48
(short) 0xb54f, // (11, 1359) 49
(short) 0xc82f, // (12, 2095) 50
(short) 0xc42f, // (12, 1071) 51
(short) 0xcc2f, // (12, 3119) 52
(short) 0xc22f, // (12, 559) 53
(short) 0xca2f, // (12, 2607) 54
(short) 0xc62f, // (12, 1583) 55
(short) 0xce2f, // (12, 3631) 56
(short) 0xc12f, // (12, 303) 57
(short) 0xc92f, // (12, 2351) 58
(short) 0xc52f, // (12, 1327) 59
(short) 0xcd2f, // (12, 3375) 60
(short) 0xc32f, // (12, 815) 61
(short) 0xcb2f, // (12, 2863) 62
(short) 0xc72f, // (12, 1839) 63
(short) 0x9077, // ( 9, 119) 64
(short) 0x8057, // ( 8, 87) 65
(short) 0xa08f, // (10, 143) 66
(short) 0x9177, // ( 9, 375) 67
(short) 0xb34f, // (11, 847) 68
(short) 0xa28f, // (10, 655) 69
(short) 0xb74f, // (11, 1871) 70
(short) 0xb0cf, // (11, 207) 71
(short) 0xcf2f, // (12, 3887) 72
(short) 0xb4cf, // (11, 1231) 73
(short) 0xc0af, // (12, 175) 74
(short) 0xc8af, // (12, 2223) 75
(short) 0xc4af, // (12, 1199) 76
(short) 0xccaf, // (12, 3247) 77
(short) 0xc2af, // (12, 687) 78
(short) 0xcaaf, // (12, 2735) 79
(short) 0xc6af, // (12, 1711) 80
(short) 0xceaf, // (12, 3759) 81
(short) 0xc1af, // (12, 431) 82
(short) 0xc9af, // (12, 2479) 83
(short) 0xc5af, // (12, 1455) 84
(short) 0xcdaf, // (12, 3503) 85
(short) 0xc3af, // (12, 943) 86
(short) 0xcbaf, // (12, 2991) 87
(short) 0xc7af, // (12, 1967) 88
(short) 0xcfaf, // (12, 4015) 89
(short) 0xc06f, // (12, 111) 90
(short) 0xc86f, // (12, 2159) 91
(short) 0xc46f, // (12, 1135) 92
(short) 0xcc6f, // (12, 3183) 93
(short) 0xc26f, // (12, 623) 94
(short) 0xca6f, // (12, 2671) 95
(short) 0xc66f, // (12, 1647) 96
(short) 0xce6f, // (12, 3695) 97
(short) 0xc16f, // (12, 367) 98
(short) 0xc96f, // (12, 2415) 99
(short) 0xc56f, // (12, 1391) 100
(short) 0xcd6f, // (12, 3439) 101
(short) 0xc36f, // (12, 879) 102
(short) 0xcb6f, // (12, 2927) 103
(short) 0xc76f, // (12, 1903) 104
(short) 0xcf6f, // (12, 3951) 105
(short) 0xc0ef, // (12, 239) 106
(short) 0xc8ef, // (12, 2287) 107
(short) 0xc4ef, // (12, 1263) 108
(short) 0xccef, // (12, 3311) 109
(short) 0xc2ef, // (12, 751) 110
(short) 0xcaef, // (12, 2799) 111
(short) 0xc6ef, // (12, 1775) 112
(short) 0xceef, // (12, 3823) 113
(short) 0xc1ef, // (12, 495) 114
(short) 0xc9ef, // (12, 2543) 115
(short) 0xc5ef, // (12, 1519) 116
(short) 0xcdef, // (12, 3567) 117
(short) 0xc3ef, // (12, 1007) 118
(short) 0xcbef, // (12, 3055) 119
(short) 0xc7ef, // (12, 2031) 120
(short) 0xcfef, // (12, 4079) 121
(short) 0xc01f, // (12, 31) 122
(short) 0xc81f, // (12, 2079) 123
(short) 0xc41f, // (12, 1055) 124
(short) 0xcc1f, // (12, 3103) 125
(short) 0xc21f, // (12, 543) 126
(short) 0xca1f, // (12, 2591) 127
(short) 0xa18f, // (10, 399) 128
(short) 0x90f7, // ( 9, 247) 129
(short) 0xb2cf, // (11, 719) 130
(short) 0xa38f, // (10, 911) 131
(short) 0xc61f, // (12, 1567) 132
(short) 0xb6cf, // (11, 1743) 133
(short) 0xce1f, // (12, 3615) 134
(short) 0xb1cf, // (11, 463) 135
(short) 0xc11f, // (12, 287) 136
(short) 0xc91f, // (12, 2335) 137
(short) 0xc51f, // (12, 1311) 138
(short) 0xcd1f, // (12, 3359) 139
(short) 0xc31f, // (12, 799) 140
(short) 0xcb1f, // (12, 2847) 141
(short) 0xc71f, // (12, 1823) 142
(short) 0xcf1f, // (12, 3871) 143
(short) 0xc09f, // (12, 159) 144
(short) 0xc89f, // (12, 2207) 145
(short) 0xc49f, // (12, 1183) 146
(short) 0xcc9f, // (12, 3231) 147
(short) 0xc29f, // (12, 671) 148
(short) 0xca9f, // (12, 2719) 149
(short) 0xc69f, // (12, 1695) 150
(short) 0xce9f, // (12, 3743) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 20 of 22) (midrange 4 of 6) (c/k = 1.833333333 = 11.0 / 6.0)
// entropy: 4.1937026483207340277
// avg_length: 4.2809622975207295426; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x4006, // ( 4, 6) 0
(short) 0x2000, // ( 2, 0) 1
(short) 0x400e, // ( 4, 14) 2
(short) 0x3002, // ( 3, 2) 3
(short) 0x5005, // ( 5, 5) 4
(short) 0x4001, // ( 4, 1) 5
(short) 0x5015, // ( 5, 21) 6
(short) 0x4009, // ( 4, 9) 7
(short) 0x6003, // ( 6, 3) 8
(short) 0x500d, // ( 5, 13) 9
(short) 0x6023, // ( 6, 35) 10
(short) 0x501d, // ( 5, 29) 11
(short) 0x8047, // ( 8, 71) 12
(short) 0x6013, // ( 6, 19) 13
(short) 0x80c7, // ( 8, 199) 14
(short) 0x6033, // ( 6, 51) 15
(short) 0x701b, // ( 7, 27) 16
(short) 0x600b, // ( 6, 11) 17
(short) 0x8027, // ( 8, 39) 18
(short) 0x602b, // ( 6, 43) 19
(short) 0x90d7, // ( 9, 215) 20
(short) 0x705b, // ( 7, 91) 21
(short) 0x91d7, // ( 9, 471) 22
(short) 0x703b, // ( 7, 59) 23
(short) 0xa1f7, // (10, 503) 24
(short) 0x80a7, // ( 8, 167) 25
(short) 0xa3f7, // (10, 1015) 26
(short) 0x8067, // ( 8, 103) 27
(short) 0xb24f, // (11, 591) 28
(short) 0xa00f, // (10, 15) 29
(short) 0xb64f, // (11, 1615) 30
(short) 0xa20f, // (10, 527) 31
(short) 0x9037, // ( 9, 55) 32
(short) 0x707b, // ( 7, 123) 33
(short) 0x9137, // ( 9, 311) 34
(short) 0x7007, // ( 7, 7) 35
(short) 0xa10f, // (10, 271) 36
(short) 0x80e7, // ( 8, 231) 37
(short) 0xa30f, // (10, 783) 38
(short) 0x8017, // ( 8, 23) 39
(short) 0xb14f, // (11, 335) 40
(short) 0x90b7, // ( 9, 183) 41
(short) 0xb54f, // (11, 1359) 42
(short) 0xa08f, // (10, 143) 43
(short) 0xc02f, // (12, 47) 44
(short) 0xb34f, // (11, 847) 45
(short) 0xc82f, // (12, 2095) 46
(short) 0xb74f, // (11, 1871) 47
(short) 0xc42f, // (12, 1071) 48
(short) 0xb0cf, // (11, 207) 49
(short) 0xcc2f, // (12, 3119) 50
(short) 0xb4cf, // (11, 1231) 51
(short) 0xc22f, // (12, 559) 52
(short) 0xca2f, // (12, 2607) 53
(short) 0xc62f, // (12, 1583) 54
(short) 0xce2f, // (12, 3631) 55
(short) 0xc12f, // (12, 303) 56
(short) 0xc92f, // (12, 2351) 57
(short) 0xc52f, // (12, 1327) 58
(short) 0xcd2f, // (12, 3375) 59
(short) 0xc32f, // (12, 815) 60
(short) 0xcb2f, // (12, 2863) 61
(short) 0xc72f, // (12, 1839) 62
(short) 0xcf2f, // (12, 3887) 63
(short) 0xa28f, // (10, 655) 64
(short) 0x8097, // ( 8, 151) 65
(short) 0xa18f, // (10, 399) 66
(short) 0x8057, // ( 8, 87) 67
(short) 0xb2cf, // (11, 719) 68
(short) 0x91b7, // ( 9, 439) 69
(short) 0xb6cf, // (11, 1743) 70
(short) 0x9077, // ( 9, 119) 71
(short) 0xc0af, // (12, 175) 72
(short) 0xb1cf, // (11, 463) 73
(short) 0xc8af, // (12, 2223) 74
(short) 0xb5cf, // (11, 1487) 75
(short) 0xc4af, // (12, 1199) 76
(short) 0xccaf, // (12, 3247) 77
(short) 0xc2af, // (12, 687) 78
(short) 0xcaaf, // (12, 2735) 79
(short) 0xc6af, // (12, 1711) 80
(short) 0xceaf, // (12, 3759) 81
(short) 0xc1af, // (12, 431) 82
(short) 0xc9af, // (12, 2479) 83
(short) 0xc5af, // (12, 1455) 84
(short) 0xcdaf, // (12, 3503) 85
(short) 0xc3af, // (12, 943) 86
(short) 0xcbaf, // (12, 2991) 87
(short) 0xc7af, // (12, 1967) 88
(short) 0xcfaf, // (12, 4015) 89
(short) 0xc06f, // (12, 111) 90
(short) 0xc86f, // (12, 2159) 91
(short) 0xc46f, // (12, 1135) 92
(short) 0xcc6f, // (12, 3183) 93
(short) 0xc26f, // (12, 623) 94
(short) 0xca6f, // (12, 2671) 95
(short) 0xc66f, // (12, 1647) 96
(short) 0xce6f, // (12, 3695) 97
(short) 0xc16f, // (12, 367) 98
(short) 0xc96f, // (12, 2415) 99
(short) 0xc56f, // (12, 1391) 100
(short) 0xcd6f, // (12, 3439) 101
(short) 0xc36f, // (12, 879) 102
(short) 0xcb6f, // (12, 2927) 103
(short) 0xc76f, // (12, 1903) 104
(short) 0xcf6f, // (12, 3951) 105
(short) 0xc0ef, // (12, 239) 106
(short) 0xc8ef, // (12, 2287) 107
(short) 0xc4ef, // (12, 1263) 108
(short) 0xccef, // (12, 3311) 109
(short) 0xc2ef, // (12, 751) 110
(short) 0xcaef, // (12, 2799) 111
(short) 0xc6ef, // (12, 1775) 112
(short) 0xceef, // (12, 3823) 113
(short) 0xc1ef, // (12, 495) 114
(short) 0xc9ef, // (12, 2543) 115
(short) 0xc5ef, // (12, 1519) 116
(short) 0xcdef, // (12, 3567) 117
(short) 0xc3ef, // (12, 1007) 118
(short) 0xcbef, // (12, 3055) 119
(short) 0xc7ef, // (12, 2031) 120
(short) 0xcfef, // (12, 4079) 121
(short) 0xc01f, // (12, 31) 122
(short) 0xc81f, // (12, 2079) 123
(short) 0xc41f, // (12, 1055) 124
(short) 0xcc1f, // (12, 3103) 125
(short) 0xc21f, // (12, 543) 126
(short) 0xca1f, // (12, 2591) 127
(short) 0xb3cf, // (11, 975) 128
(short) 0x9177, // ( 9, 375) 129
(short) 0xb7cf, // (11, 1999) 130
(short) 0x90f7, // ( 9, 247) 131
(short) 0xc61f, // (12, 1567) 132
(short) 0xa38f, // (10, 911) 133
(short) 0xce1f, // (12, 3615) 134
(short) 0xa04f, // (10, 79) 135
(short) 0xc11f, // (12, 287) 136
(short) 0xc91f, // (12, 2335) 137
(short) 0xc51f, // (12, 1311) 138
(short) 0xcd1f, // (12, 3359) 139
(short) 0xc31f, // (12, 799) 140
(short) 0xcb1f, // (12, 2847) 141
(short) 0xc71f, // (12, 1823) 142
(short) 0xcf1f, // (12, 3871) 143
(short) 0xc09f, // (12, 159) 144
(short) 0xc89f, // (12, 2207) 145
(short) 0xc49f, // (12, 1183) 146
(short) 0xcc9f, // (12, 3231) 147
(short) 0xc29f, // (12, 671) 148
(short) 0xca9f, // (12, 2719) 149
(short) 0xc69f, // (12, 1695) 150
(short) 0xce9f, // (12, 3743) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
},
// (table 21 of 22) (midrange 5 of 6) (c/k = 2.166666667 = 13.0 / 6.0)
// entropy: 4.3601926041863263706
// avg_length: 4.4384101723259572481; max_length = 12; num_symbols = 256
{
//table, // (4 bits, 12 bits) symbol
//entry, // (length, codeword) [byte]
(short) 0x5009, // ( 5, 9) 0
(short) 0x3002, // ( 3, 2) 1
(short) 0x5019, // ( 5, 25) 2
(short) 0x2000, // ( 2, 0) 3
(short) 0x6003, // ( 6, 3) 4
(short) 0x4001, // ( 4, 1) 5
(short) 0x5005, // ( 5, 5) 6
(short) 0x3006, // ( 3, 6) 7
(short) 0x702b, // ( 7, 43) 8
(short) 0x5015, // ( 5, 21) 9
(short) 0x706b, // ( 7, 107) 10
(short) 0x500d, // ( 5, 13) 11
(short) 0x8007, // ( 8, 7) 12
(short) 0x6023, // ( 6, 35) 13
(short) 0x8087, // ( 8, 135) 14
(short) 0x501d, // ( 5, 29) 15
(short) 0x8047, // ( 8, 71) 16
(short) 0x6013, // ( 6, 19) 17
(short) 0x80c7, // ( 8, 199) 18
(short) 0x6033, // ( 6, 51) 19
(short) 0x9097, // ( 9, 151) 20
(short) 0x701b, // ( 7, 27) 21
(short) 0x9197, // ( 9, 407) 22
(short) 0x600b, // ( 6, 11) 23
(short) 0xa0f7, // (10, 247) 24
(short) 0x8027, // ( 8, 39) 25
(short) 0xa2f7, // (10, 759) 26
(short) 0x80a7, // ( 8, 167) 27
(short) 0xb14f, // (11, 335) 28
(short) 0x9057, // ( 9, 87) 29
(short) 0xb54f, // (11, 1359) 30
(short) 0x9157, // ( 9, 343) 31
(short) 0x90d7, // ( 9, 215) 32
(short) 0x705b, // ( 7, 91) 33
(short) 0x91d7, // ( 9, 471) 34
(short) 0x703b, // ( 7, 59) 35
(short) 0xa1f7, // (10, 503) 36
(short) 0x8067, // ( 8, 103) 37
(short) 0xa3f7, // (10, 1015) 38
(short) 0x707b, // ( 7, 123) 39
(short) 0xb34f, // (11, 847) 40
(short) 0x9037, // ( 9, 55) 41
(short) 0xb74f, // (11, 1871) 42
(short) 0x9137, // ( 9, 311) 43
(short) 0xc12f, // (12, 303) 44
(short) 0xa00f, // (10, 15) 45
(short) 0xc92f, // (12, 2351) 46
(short) 0xa20f, // (10, 527) 47
(short) 0xc52f, // (12, 1327) 48
(short) 0xa10f, // (10, 271) 49
(short) 0xcd2f, // (12, 3375) 50
(short) 0xa30f, // (10, 783) 51
(short) 0xc32f, // (12, 815) 52
(short) 0xb0cf, // (11, 207) 53
(short) 0xcb2f, // (12, 2863) 54
(short) 0xb4cf, // (11, 1231) 55
(short) 0xc72f, // (12, 1839) 56
(short) 0xcf2f, // (12, 3887) 57
(short) 0xc0af, // (12, 175) 58
(short) 0xc8af, // (12, 2223) 59
(short) 0xc4af, // (12, 1199) 60
(short) 0xccaf, // (12, 3247) 61
(short) 0xc2af, // (12, 687) 62
(short) 0xcaaf, // (12, 2735) 63
(short) 0xa08f, // (10, 143) 64
(short) 0x80e7, // ( 8, 231) 65
(short) 0xa28f, // (10, 655) 66
(short) 0x8017, // ( 8, 23) 67
(short) 0xb2cf, // (11, 719) 68
(short) 0x90b7, // ( 9, 183) 69
(short) 0xb6cf, // (11, 1743) 70
(short) 0x91b7, // ( 9, 439) 71
(short) 0xc6af, // (12, 1711) 72
(short) 0xa18f, // (10, 399) 73
(short) 0xceaf, // (12, 3759) 74
(short) 0xa38f, // (10, 911) 75
(short) 0xc1af, // (12, 431) 76
(short) 0xb1cf, // (11, 463) 77
(short) 0xc9af, // (12, 2479) 78
(short) 0xb5cf, // (11, 1487) 79
(short) 0xc5af, // (12, 1455) 80
(short) 0xb3cf, // (11, 975) 81
(short) 0xcdaf, // (12, 3503) 82
(short) 0xb7cf, // (11, 1999) 83
(short) 0xc3af, // (12, 943) 84
(short) 0xcbaf, // (12, 2991) 85
(short) 0xc7af, // (12, 1967) 86
(short) 0xcfaf, // (12, 4015) 87
(short) 0xc06f, // (12, 111) 88
(short) 0xc86f, // (12, 2159) 89
(short) 0xc46f, // (12, 1135) 90
(short) 0xcc6f, // (12, 3183) 91
(short) 0xc26f, // (12, 623) 92
(short) 0xca6f, // (12, 2671) 93
(short) 0xc66f, // (12, 1647) 94
(short) 0xce6f, // (12, 3695) 95
(short) 0xc16f, // (12, 367) 96
(short) 0xc96f, // (12, 2415) 97
(short) 0xc56f, // (12, 1391) 98
(short) 0xcd6f, // (12, 3439) 99
(short) 0xc36f, // (12, 879) 100
(short) 0xcb6f, // (12, 2927) 101
(short) 0xc76f, // (12, 1903) 102
(short) 0xcf6f, // (12, 3951) 103
(short) 0xc0ef, // (12, 239) 104
(short) 0xc8ef, // (12, 2287) 105
(short) 0xc4ef, // (12, 1263) 106
(short) 0xccef, // (12, 3311) 107
(short) 0xc2ef, // (12, 751) 108
(short) 0xcaef, // (12, 2799) 109
(short) 0xc6ef, // (12, 1775) 110
(short) 0xceef, // (12, 3823) 111
(short) 0xc1ef, // (12, 495) 112
(short) 0xc9ef, // (12, 2543) 113
(short) 0xc5ef, // (12, 1519) 114
(short) 0xcdef, // (12, 3567) 115
(short) 0xc3ef, // (12, 1007) 116
(short) 0xcbef, // (12, 3055) 117
(short) 0xc7ef, // (12, 2031) 118
(short) 0xcfef, // (12, 4079) 119
(short) 0xc01f, // (12, 31) 120
(short) 0xc81f, // (12, 2079) 121
(short) 0xc41f, // (12, 1055) 122
(short) 0xcc1f, // (12, 3103) 123
(short) 0xc21f, // (12, 543) 124
(short) 0xca1f, // (12, 2591) 125
(short) 0xc61f, // (12, 1567) 126
(short) 0xce1f, // (12, 3615) 127
(short) 0xb02f, // (11, 47) 128
(short) 0x9077, // ( 9, 119) 129
(short) 0xb42f, // (11, 1071) 130
(short) 0x9177, // ( 9, 375) 131
(short) 0xc11f, // (12, 287) 132
(short) 0xa04f, // (10, 79) 133
(short) 0xc91f, // (12, 2335) 134
(short) 0xa24f, // (10, 591) 135
(short) 0xc51f, // (12, 1311) 136
(short) 0xb22f, // (11, 559) 137
(short) 0xcd1f, // (12, 3359) 138
(short) 0xb62f, // (11, 1583) 139
(short) 0xc31f, // (12, 799) 140
(short) 0xcb1f, // (12, 2847) 141
(short) 0xc71f, // (12, 1823) 142
(short) 0xcf1f, // (12, 3871) 143
(short) 0xc09f, // (12, 159) 144
(short) 0xc89f, // (12, 2207) 145
(short) 0xc49f, // (12, 1183) 146
(short) 0xcc9f, // (12, 3231) 147
(short) 0xc29f, // (12, 671) 148
(short) 0xca9f, // (12, 2719) 149
(short) 0xc69f, // (12, 1695) 150
(short) 0xce9f, // (12, 3743) 151
(short) 0xc19f, // (12, 415) 152
(short) 0xc99f, // (12, 2463) 153
(short) 0xc59f, // (12, 1439) 154
(short) 0xcd9f, // (12, 3487) 155
(short) 0xc39f, // (12, 927) 156
(short) 0xcb9f, // (12, 2975) 157
(short) 0xc79f, // (12, 1951) 158
(short) 0xcf9f, // (12, 3999) 159
(short) 0xc05f, // (12, 95) 160
(short) 0xc85f, // (12, 2143) 161
(short) 0xc45f, // (12, 1119) 162
(short) 0xcc5f, // (12, 3167) 163
(short) 0xc25f, // (12, 607) 164
(short) 0xca5f, // (12, 2655) 165
(short) 0xc65f, // (12, 1631) 166
(short) 0xce5f, // (12, 3679) 167
(short) 0xc15f, // (12, 351) 168
(short) 0xc95f, // (12, 2399) 169
(short) 0xc55f, // (12, 1375) 170
(short) 0xcd5f, // (12, 3423) 171
(short) 0xc35f, // (12, 863) 172
(short) 0xcb5f, // (12, 2911) 173
(short) 0xc75f, // (12, 1887) 174
(short) 0xcf5f, // (12, 3935) 175
(short) 0xc0df, // (12, 223) 176
(short) 0xc8df, // (12, 2271) 177
(short) 0xc4df, // (12, 1247) 178
(short) 0xccdf, // (12, 3295) 179
(short) 0xc2df, // (12, 735) 180
(short) 0xcadf, // (12, 2783) 181
(short) 0xc6df, // (12, 1759) 182
(short) 0xcedf, // (12, 3807) 183
(short) 0xc1df, // (12, 479) 184
(short) 0xc9df, // (12, 2527) 185
(short) 0xc5df, // (12, 1503) 186
(short) 0xcddf, // (12, 3551) 187
(short) 0xc3df, // (12, 991) 188
(short) 0xcbdf, // (12, 3039) 189
(short) 0xc7df, // (12, 2015) 190
(short) 0xcfdf, // (12, 4063) 191
(short) 0xc03f, // (12, 63) 192
(short) 0xc83f, // (12, 2111) 193
(short) 0xc43f, // (12, 1087) 194
(short) 0xcc3f, // (12, 3135) 195
(short) 0xc23f, // (12, 575) 196
(short) 0xca3f, // (12, 2623) 197
(short) 0xc63f, // (12, 1599) 198
(short) 0xce3f, // (12, 3647) 199
(short) 0xc13f, // (12, 319) 200
(short) 0xc93f, // (12, 2367) 201
(short) 0xc53f, // (12, 1343) 202
(short) 0xcd3f, // (12, 3391) 203
(short) 0xc33f, // (12, 831) 204
(short) 0xcb3f, // (12, 2879) 205
(short) 0xc73f, // (12, 1855) 206
(short) 0xcf3f, // (12, 3903) 207
(short) 0xc0bf, // (12, 191) 208
(short) 0xc8bf, // (12, 2239) 209
(short) 0xc4bf, // (12, 1215) 210
(short) 0xccbf, // (12, 3263) 211
(short) 0xc2bf, // (12, 703) 212
(short) 0xcabf, // (12, 2751) 213
(short) 0xc6bf, // (12, 1727) 214
(short) 0xcebf, // (12, 3775) 215
(short) 0xc1bf, // (12, 447) 216
(short) 0xc9bf, // (12, 2495) 217
(short) 0xc5bf, // (12, 1471) 218
(short) 0xcdbf, // (12, 3519) 219
(short) 0xc3bf, // (12, 959) 220
(short) 0xcbbf, // (12, 3007) 221
(short) 0xc7bf, // (12, 1983) 222
(short) 0xcfbf, // (12, 4031) 223
(short) 0xc07f, // (12, 127) 224
(short) 0xc87f, // (12, 2175) 225
(short) 0xc47f, // (12, 1151) 226
(short) 0xcc7f, // (12, 3199) 227
(short) 0xc27f, // (12, 639) 228
(short) 0xca7f, // (12, 2687) 229
(short) 0xc67f, // (12, 1663) 230
(short) 0xce7f, // (12, 3711) 231
(short) 0xc17f, // (12, 383) 232
(short) 0xc97f, // (12, 2431) 233
(short) 0xc57f, // (12, 1407) 234
(short) 0xcd7f, // (12, 3455) 235
(short) 0xc37f, // (12, 895) 236
(short) 0xcb7f, // (12, 2943) 237
(short) 0xc77f, // (12, 1919) 238
(short) 0xcf7f, // (12, 3967) 239
(short) 0xc0ff, // (12, 255) 240
(short) 0xc8ff, // (12, 2303) 241
(short) 0xc4ff, // (12, 1279) 242
(short) 0xccff, // (12, 3327) 243
(short) 0xc2ff, // (12, 767) 244
(short) 0xcaff, // (12, 2815) 245
(short) 0xc6ff, // (12, 1791) 246
(short) 0xceff, // (12, 3839) 247
(short) 0xc1ff, // (12, 511) 248
(short) 0xc9ff, // (12, 2559) 249
(short) 0xc5ff, // (12, 1535) 250
(short) 0xcdff, // (12, 3583) 251
(short) 0xc3ff, // (12, 1023) 252
(short) 0xcbff, // (12, 3071) 253
(short) 0xc7ff, // (12, 2047) 254
(short) 0xcfff // (12, 4095) 255
}
};
/**
* Notice that there are only 65 symbols here, which is different from our
* usual 8 to 12 coding scheme which handles 256 symbols.
*/
static short[] lengthLimitedUnaryDecodingTable65 = null;
static short[] lengthLimitedUnaryEncodingTable65 = new short[] //[65]
{
// Length-limited "unary" code with 65 symbols.
// entropy: 2.0
// avg_length: 2.0249023437500000000; max_length = 12; num_symbols = 65
//table, (4 bits, 12 bits) symbol
//entry, (length, codeword) [byte]
(short) 0x1000, // ( 1, 0) 0
(short) 0x2001, // ( 2, 1) 1
(short) 0x3003, // ( 3, 3) 2
(short) 0x4007, // ( 4, 7) 3
(short) 0x500f, // ( 5, 15) 4
(short) 0x701f, // ( 7, 31) 5
(short) 0x805f, // ( 8, 95) 6
(short) 0x80df, // ( 8, 223) 7
(short) 0xa03f, // (10, 63) 8
(short) 0xa23f, // (10, 575) 9
(short) 0xb13f, // (11, 319) 10
(short) 0xc53f, // (12, 1343) 11
(short) 0xcd3f, // (12, 3391) 12
(short) 0xc33f, // (12, 831) 13
(short) 0xcb3f, // (12, 2879) 14
(short) 0xc73f, // (12, 1855) 15
(short) 0xcf3f, // (12, 3903) 16
(short) 0xc0bf, // (12, 191) 17
(short) 0xc8bf, // (12, 2239) 18
(short) 0xc4bf, // (12, 1215) 19
(short) 0xccbf, // (12, 3263) 20
(short) 0xc2bf, // (12, 703) 21
(short) 0xcabf, // (12, 2751) 22
(short) 0xc6bf, // (12, 1727) 23
(short) 0xcebf, // (12, 3775) 24
(short) 0xc1bf, // (12, 447) 25
(short) 0xc9bf, // (12, 2495) 26
(short) 0xc5bf, // (12, 1471) 27
(short) 0xcdbf, // (12, 3519) 28
(short) 0xc3bf, // (12, 959) 29
(short) 0xcbbf, // (12, 3007) 30
(short) 0xc7bf, // (12, 1983) 31
(short) 0xcfbf, // (12, 4031) 32
(short) 0xc07f, // (12, 127) 33
(short) 0xc87f, // (12, 2175) 34
(short) 0xc47f, // (12, 1151) 35
(short) 0xcc7f, // (12, 3199) 36
(short) 0xc27f, // (12, 639) 37
(short) 0xca7f, // (12, 2687) 38
(short) 0xc67f, // (12, 1663) 39
(short) 0xce7f, // (12, 3711) 40
(short) 0xc17f, // (12, 383) 41
(short) 0xc97f, // (12, 2431) 42
(short) 0xc57f, // (12, 1407) 43
(short) 0xcd7f, // (12, 3455) 44
(short) 0xc37f, // (12, 895) 45
(short) 0xcb7f, // (12, 2943) 46
(short) 0xc77f, // (12, 1919) 47
(short) 0xcf7f, // (12, 3967) 48
(short) 0xc0ff, // (12, 255) 49
(short) 0xc8ff, // (12, 2303) 50
(short) 0xc4ff, // (12, 1279) 51
(short) 0xccff, // (12, 3327) 52
(short) 0xc2ff, // (12, 767) 53
(short) 0xcaff, // (12, 2815) 54
(short) 0xc6ff, // (12, 1791) 55
(short) 0xceff, // (12, 3839) 56
(short) 0xc1ff, // (12, 511) 57
(short) 0xc9ff, // (12, 2559) 58
(short) 0xc5ff, // (12, 1535) 59
(short) 0xcdff, // (12, 3583) 60
(short) 0xc3ff, // (12, 1023) 61
(short) 0xcbff, // (12, 3071) 62
(short) 0xc7ff, // (12, 2047) 63
(short) 0xcfff // (12, 4095) 64
};
/**
* Note: these column permutations are part of the encoding scheme for sketches where
* C ≥ 3.375 * K.
* In each row, we identify the (0-based) column indices of all surprising bits
* outside of the high-entropy byte.
*
* <p>These indices are "rotated right" via the formula
* new = (old - (8+shift_by) + 64) mod 64 = (old + 56 - shift_by) mod 64.
* resulting in canonicalized indices between 0 and 55 inclusive.
*
* <p>These are then mapped through the forwards permutation specified below (and selected
* by the phase of C / K). Finally, the remapped indices are encoding with a unary code
* (with delta encoding for rows containing more than one surprising bit).
*/
static byte[][] columnPermutationsForDecoding = new byte[16][]; //[16][56]
/**
* These permutations were created by
* the ocaml program "generatePermutationsForSLIDING.ml".
*/
static final byte[][] columnPermutationsForEncoding = new byte[][] //[16] [56]
{
// for phase = 1 / 32
{0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 34, 14, 4},
// for phase = 3 / 32
{0, 1, 2, 3, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 35, 15, 4},
// for phase = 5 / 32
{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 37, 16, 5},
// for phase = 7 / 32
{0, 1, 2, 3, 4, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 39, 17, 5},
// for phase = 9 / 32
{0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 41, 18, 6},
// for phase = 11 / 32
{0, 1, 2, 3, 4, 5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39,
40, 41, 42, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 43, 19, 6},
// for phase = 13 / 32
{1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 21, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 45, 20, 7, 0},
// for phase = 15 / 32
{1, 2, 3, 4, 5, 6, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 22,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 48, 49, 50, 51, 52, 53, 54, 55, 47, 21, 7, 0},
// for phase = 17 / 32
{1, 2, 3, 4, 5, 6, 7, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 51, 52, 53, 54, 55, 50, 22, 8, 0},
// for phase = 19 / 32
{0, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 53, 54, 55, 52, 23, 9, 1},
// for phase = 21 / 32
{0, 2, 3, 4, 5, 6, 7, 8, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 25, 9, 1},
// for phase = 23 / 32
{0, 2, 3, 4, 5, 6, 7, 8, 9, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 26, 10, 1},
// for phase = 25 / 32
{0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 27, 11, 2},
// for phase = 27 / 32
{0, 1, 3, 4, 5, 6, 7, 8, 9, 10, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 29, 11, 2},
// for phase = 29 / 32
{0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 13, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 30, 12, 3},
// for phase = 31 / 32
{0, 1, 2, 4, 5, 6, 7, 8, 9, 10, 11, 12, 14, 15, 16, 17, 18, 19, 20, 21,
22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 33, 34, 35, 36, 37, 38, 39, 40,
41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 32, 13, 3}
};
//Initialize this class
static {
makeTheDecodingTables();
}
}
| 2,743 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/TestUtil.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static java.lang.Math.pow;
import static java.lang.Math.round;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssert;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssertEquals;
/**
* @author Lee Rhodes
*/
public class TestUtil {
static final double pwrLaw10NextDouble(final int ppb, final double curPoint) {
final double cur = (curPoint < 1.0) ? 1.0 : curPoint;
double gi = round(Math.log10(cur) * ppb); //current generating index
double next;
do {
next = round(pow(10.0, ++gi / ppb));
} while (next <= curPoint);
return next;
}
static boolean specialEquals(final CpcSketch sk1, final CpcSketch sk2,
final boolean sk1wasMerged, final boolean sk2wasMerged) {
rtAssertEquals(sk1.seed, sk2.seed);
rtAssertEquals(sk1.lgK, sk2.lgK);
rtAssertEquals(sk1.numCoupons, sk2.numCoupons);
rtAssertEquals(sk1.windowOffset, sk2.windowOffset);
rtAssertEquals(sk1.slidingWindow, sk2.slidingWindow);
PairTable.equals(sk1.pairTable, sk2.pairTable);
// fiCol is only updated occasionally while stream processing,
// therefore, the stream sketch could be behind the merged sketch.
// So we have to recalculate the FiCol on the stream sketch.
final int ficolA = sk1.fiCol;
final int ficolB = sk2.fiCol;
if (!sk1wasMerged && sk2wasMerged) {
rtAssert(!sk1.mergeFlag && sk2.mergeFlag);
final int fiCol1 = calculateFirstInterestingColumn(sk1);
rtAssertEquals(fiCol1, sk2.fiCol);
} else if (sk1wasMerged && !sk2wasMerged) {
rtAssert(sk1.mergeFlag && !sk2.mergeFlag);
final int fiCol2 = calculateFirstInterestingColumn(sk2);
rtAssertEquals(fiCol2,sk1.fiCol);
} else {
rtAssertEquals(sk1.mergeFlag, sk2.mergeFlag);
rtAssertEquals(ficolA, ficolB);
rtAssertEquals(sk1.kxp, sk2.kxp, .01 * sk1.kxp); //1% tolerance
rtAssertEquals(sk1.hipEstAccum, sk2.hipEstAccum, 01 * sk1.hipEstAccum); //1% tolerance
}
return true;
}
static int calculateFirstInterestingColumn(final CpcSketch sketch) {
final int offset = sketch.windowOffset;
if (offset == 0) {
return 0;
}
final PairTable table = sketch.pairTable;
assert (table != null);
final int[] slots = table.getSlotsArr();
final int numSlots = 1 << table.getLgSizeInts();
int i;
int result = offset;
for (i = 0; i < numSlots; i++) {
final int rowCol = slots[i];
if (rowCol != -1) {
final int col = rowCol & 63;
if (col < result) { result = col; }
}
}
return result;
}
}
| 2,744 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CpcCompression.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.cpc.CompressionData.columnPermutationsForDecoding;
import static org.apache.datasketches.cpc.CompressionData.columnPermutationsForEncoding;
import static org.apache.datasketches.cpc.CompressionData.decodingTablesForHighEntropyByte;
import static org.apache.datasketches.cpc.CompressionData.encodingTablesForHighEntropyByte;
import static org.apache.datasketches.cpc.CompressionData.lengthLimitedUnaryDecodingTable65;
import static org.apache.datasketches.cpc.CompressionData.lengthLimitedUnaryEncodingTable65;
import static org.apache.datasketches.cpc.PairTable.introspectiveInsertionSort;
//import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssertEquals;
/**
* @author Lee Rhodes
* @author Kevin Lang
*/
final class CpcCompression {
//visible for test
static final int NEXT_WORD_IDX = 0; //ptrArr[NEXT_WORD_IDX]
static final int BIT_BUF = 1; //ptrArr[BIT_BUF]
static final int BUF_BITS = 2; //ptrArr[BUF_BITS]
//visible for test
static void writeUnary(
final int[] compressedWords,
final long[] ptrArr,
final int theValue) {
int nextWordIndex = (int) ptrArr[NEXT_WORD_IDX]; //must be int
assert (nextWordIndex == ptrArr[NEXT_WORD_IDX]); //catch truncation error
long bitBuf = ptrArr[BIT_BUF]; //must be long
int bufBits = (int) ptrArr[BUF_BITS]; //could be byte
assert (compressedWords != null);
assert (nextWordIndex >= 0);
assert (bitBuf >= 0);
assert ((bufBits >= 0) && (bufBits <= 31));
int remaining = theValue;
while (remaining >= 16) {
remaining -= 16;
// Here we output 16 zeros, but we don't need to physically write them into bitbuf
// because it already contains zeros in that region.
bufBits += 16; // Record the fact that 16 bits of output have occurred.
//MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
if (bufBits >= 32) {
compressedWords[nextWordIndex++] = (int) bitBuf;
bitBuf >>>= 32;
bufBits -= 32;
}
}
assert (remaining >= 0) && (remaining <= 15);
final long theUnaryCode = 1L << remaining; //must be a long
bitBuf |= theUnaryCode << bufBits;
bufBits += (1 + remaining);
//MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
if (bufBits >= 32) {
compressedWords[nextWordIndex++] = (int) bitBuf;
bitBuf >>>= 32;
bufBits -= 32;
}
ptrArr[NEXT_WORD_IDX] = nextWordIndex;
assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch sign extension error
ptrArr[BIT_BUF] = bitBuf;
ptrArr[BUF_BITS] = bufBits;
}
//visible for test
static long readUnary(
final int[] compressedWords,
final long[] ptrArr) {
int nextWordIndex = (int) ptrArr[NEXT_WORD_IDX]; //must be int
assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch truncation error
long bitBuf = ptrArr[BIT_BUF];
int bufBits = (int) ptrArr[BUF_BITS];
assert compressedWords != null;
assert nextWordIndex >= 0;
assert bitBuf >= 0;
assert bufBits >= 0;
long subTotal = 0;
int trailingZeros;
//readUnaryLoop:
while (true) {
//MAYBE_FILL_BITBUF(compressedWords,nextWordIndex,8); // ensure 8 bits in bit buffer
if (bufBits < 8) { // Prepare for an 8-bit peek into the bitstream.
bitBuf |= ((compressedWords[nextWordIndex++] & 0XFFFF_FFFFL) << bufBits);
bufBits += 32;
}
// These 8 bits include either all or part of the Unary codeword.
final int peek8 = (int) (bitBuf & 0XFFL);
trailingZeros = Math.min(8, Integer.numberOfTrailingZeros(peek8));
assert ((trailingZeros >= 0) && (trailingZeros <= 8)) : "TZ+ " + trailingZeros;
if (trailingZeros == 8) { // The codeword was partial, so read some more.
subTotal += 8;
bufBits -= 8;
bitBuf >>>= 8;
continue;
}
break;
}
bufBits -= (1 + trailingZeros);
bitBuf >>>= (1 + trailingZeros);
ptrArr[NEXT_WORD_IDX] = nextWordIndex;
assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch sign extension error
ptrArr[BIT_BUF] = bitBuf;
ptrArr[BUF_BITS] = bufBits;
return subTotal + trailingZeros;
}
/**
* This returns the number of compressedWords that were actually used.
* @param byteArray input
* @param numBytesToEncode input
* @param encodingTable input
* @param compressedWords output
* @return the number of compressedWords that were actually used.
*/
//visible for test
//It is the caller's responsibility to ensure that the compressedWords array is long enough.
static int lowLevelCompressBytes(
final byte[] byteArray, // input
final int numBytesToEncode, // input, must be an int
final short[] encodingTable, // input
final int[] compressedWords) { // output
int nextWordIndex = 0;
long bitBuf = 0; // bits are packed into this first, then are flushed to compressedWords
int bufBits = 0; // number of bits currently in bitbuf; must be between 0 and 31
for (int byteIndex = 0; byteIndex < numBytesToEncode; byteIndex++) {
final int theByte = byteArray[byteIndex] & 0XFF;
final long codeInfo = (encodingTable[theByte] & 0XFFFFL);
final long codeVal = codeInfo & 0XFFFL;
final int codeWordLength = (int) (codeInfo >>> 12);
bitBuf |= (codeVal << bufBits);
bufBits += codeWordLength;
//MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
if (bufBits >= 32) {
compressedWords[nextWordIndex++] = (int) bitBuf;
bitBuf >>>= 32;
bufBits -= 32;
}
}
//Pad the bitstream with 11 zero-bits so that the decompressor's 12-bit peek
// can't overrun its input.
bufBits += 11;
//MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
if (bufBits >= 32) {
compressedWords[nextWordIndex++] = (int) bitBuf;
bitBuf >>>= 32;
bufBits -= 32;
}
if (bufBits > 0) { // We are done encoding now, so we flush the bit buffer.
assert (bufBits < 32);
compressedWords[nextWordIndex++] = (int) bitBuf;
}
return nextWordIndex;
}
//visible for test
static void lowLevelUncompressBytes(
final byte[] byteArray, // output
final int numBytesToDecode, // input (but refers to the output)
final short[] decodingTable, // input
final int[] compressedWords, // input
final long numCompressedWords) { // input
int byteIndex = 0;
int nextWordIndex = 0;
long bitBuf = 0;
int bufBits = 0;
assert (byteArray != null);
assert (decodingTable != null);
assert (compressedWords != null);
for (byteIndex = 0; byteIndex < numBytesToDecode; byteIndex++) {
//MAYBE_FILL_BITBUF(compressedWords,wordIndex,12); // ensure 12 bits in bit buffer
if (bufBits < 12) { // Prepare for a 12-bit peek into the bitstream.
bitBuf |= ((compressedWords[nextWordIndex++] & 0XFFFF_FFFFL) << bufBits);
bufBits += 32;
}
// These 12 bits will include an entire Huffman codeword.
final int peek12 = (int) (bitBuf & 0XFFFL);
final int lookup = decodingTable[peek12] & 0XFFFF;
final int codeWordLength = lookup >>> 8;
final byte decodedByte = (byte) (lookup & 0XFF);
byteArray[byteIndex] = decodedByte;
bitBuf >>>= codeWordLength;
bufBits -= codeWordLength;
}
// Buffer over-run should be impossible unless there is a bug.
// However, we might as well check here.
assert (nextWordIndex <= numCompressedWords);
}
/**
* Here "pairs" refers to row/column pairs that specify the positions of surprising values in
* the bit matrix.
* @param pairArray input
* @param numPairsToEncode input
* @param numBaseBits input
* @param compressedWords output
* @return the number of compressedWords actually used
*/
//visible for test
static long lowLevelCompressPairs(
final int[] pairArray, // input
final int numPairsToEncode, // input
final int numBaseBits, // input //cannot exceed 63 or 6 bits, could be byte
final int[] compressedWords) { // output
int pairIndex = 0;
final long[] ptrArr = new long[3];
int nextWordIndex = 0; //must be int
long bitBuf = 0; //must be long
int bufBits = 0; //could be byte
final long golombLoMask = (1L << numBaseBits) - 1L;
int predictedRowIndex = 0;
int predictedColIndex = 0;
for (pairIndex = 0; pairIndex < numPairsToEncode; pairIndex++) {
final int rowCol = pairArray[pairIndex];
final int rowIndex = rowCol >>> 6;
final int colIndex = rowCol & 0X3F; //63
if (rowIndex != predictedRowIndex) { predictedColIndex = 0; }
assert (rowIndex >= predictedRowIndex);
assert (colIndex >= predictedColIndex);
final long yDelta = rowIndex - predictedRowIndex; //cannot exceed 2^26
final int xDelta = colIndex - predictedColIndex; //cannot exceed 65
predictedRowIndex = rowIndex;
predictedColIndex = colIndex + 1;
final long codeInfo = lengthLimitedUnaryEncodingTable65[xDelta] & 0XFFFFL;
final long codeVal = codeInfo & 0XFFFL;
final int codeLen = (int) (codeInfo >>> 12);
bitBuf |= (codeVal << bufBits);
bufBits += codeLen;
//MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
if (bufBits >= 32) {
compressedWords[nextWordIndex++] = (int) bitBuf;
bitBuf >>>= 32;
bufBits -= 32;
}
final long golombLo = yDelta & golombLoMask; //long for bitBuf
final long golombHi = yDelta >>> numBaseBits; //cannot exceed 2^26
//TODO Inline WriteUnary
ptrArr[NEXT_WORD_IDX] = nextWordIndex;
ptrArr[BIT_BUF] = bitBuf;
ptrArr[BUF_BITS] = bufBits;
assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch sign extension error
writeUnary(compressedWords, ptrArr, (int) golombHi);
nextWordIndex = (int) ptrArr[NEXT_WORD_IDX];
bitBuf = ptrArr[BIT_BUF];
bufBits = (int) ptrArr[BUF_BITS];
assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch truncation error
//END Inline WriteUnary
bitBuf |= golombLo << bufBits;
bufBits += numBaseBits;
//MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
if (bufBits >= 32) {
compressedWords[nextWordIndex++] = (int) bitBuf;
bitBuf >>>= 32;
bufBits -= 32;
}
}
// Pad the bitstream so that the decompressor's 12-bit peek can't overrun its input.
int padding = 10 - numBaseBits;
if (padding < 0) { padding = 0; }
bufBits += padding;
//MAYBE_FLUSH_BITBUF(compressedWords, nextWordIndex);
if (bufBits >= 32) {
compressedWords[nextWordIndex++] = (int) bitBuf;
bitBuf >>>= 32;
bufBits -= 32;
}
if (bufBits > 0) { // We are done encoding now, so we flush the bit buffer.
assert (bufBits < 32);
compressedWords[nextWordIndex++] = (int) bitBuf;
//bitBuf = 0;
//bufBits = 0; // not really necessary
}
return nextWordIndex;
}
//visible for test
static void lowLevelUncompressPairs(
final int[] pairArray, // output
final int numPairsToDecode, // input, size of output, must be int
final int numBaseBits, // input, cannot exceed 6 bits
final int[] compressedWords, // input
final long numCompressedWords) { // input
int pairIndex = 0;
final long[] ptrArr = new long[3];
int nextWordIndex = 0;
long bitBuf = 0;
int bufBits = 0;
final long golombLoMask = (1L << numBaseBits) - 1L;
int predictedRowIndex = 0;
int predictedColIndex = 0;
// for each pair we need to read:
// xDelta (12-bit length-limited unary)
// yDeltaHi (unary)
// yDeltaLo (basebits)
for (pairIndex = 0; pairIndex < numPairsToDecode; pairIndex++) {
//MAYBE_FILL_BITBUF(compressedWords,wordIndex,12); // ensure 12 bits in bit buffer
if (bufBits < 12) { // Prepare for a 12-bit peek into the bitstream.
bitBuf |= ((compressedWords[nextWordIndex++] & 0XFFFF_FFFFL) << bufBits);
bufBits += 32;
}
final int peek12 = (int) (bitBuf & 0XFFFL);
final int lookup = lengthLimitedUnaryDecodingTable65[peek12] & 0XFFFF;
final int codeWordLength = lookup >>> 8;
final int xDelta = lookup & 0XFF;
bitBuf >>>= codeWordLength;
bufBits -= codeWordLength;
//TODO Inline ReadUnary
ptrArr[NEXT_WORD_IDX] = nextWordIndex;
ptrArr[BIT_BUF] = bitBuf;
ptrArr[BUF_BITS] = bufBits;
assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch sign extension error
final long golombHi = readUnary(compressedWords, ptrArr);
nextWordIndex = (int) ptrArr[NEXT_WORD_IDX];
bitBuf = ptrArr[BIT_BUF];
bufBits = (int) ptrArr[BUF_BITS];
assert nextWordIndex == ptrArr[NEXT_WORD_IDX]; //catch truncation error
//END Inline ReadUnary
//MAYBE_FILL_BITBUF(compressedWords,wordIndex,numBaseBits); // ensure numBaseBits in bit buffer
if (bufBits < numBaseBits) { // Prepare for a numBaseBits peek into the bitstream.
bitBuf |= ((compressedWords[nextWordIndex++] & 0XFFFF_FFFFL) << bufBits);
bufBits += 32;
}
final long golombLo = bitBuf & golombLoMask;
bitBuf >>>= numBaseBits;
bufBits -= numBaseBits;
final long yDelta = (golombHi << numBaseBits) | golombLo;
// Now that we have yDelta and xDelta, we can compute the pair's row and column.
if (yDelta > 0) { predictedColIndex = 0; }
final int rowIndex = predictedRowIndex + (int) yDelta;
final int colIndex = predictedColIndex + xDelta;
final int rowCol = (rowIndex << 6) | colIndex;
pairArray[pairIndex] = rowCol;
predictedRowIndex = rowIndex;
predictedColIndex = colIndex + 1;
}
// check for buffer over-run
assert (nextWordIndex <= numCompressedWords)
: "nextWdIdx: " + nextWordIndex + ", #CompWds: " + numCompressedWords;
}
private static int safeLengthForCompressedPairBuf(
final long k, final long numPairs, final long numBaseBits) {
assert (numPairs > 0);
// long ybits = k + numPairs; // simpler and safer UB
// The following tighter UB on ybits is based on page 198
// of the textbook "Managing Gigabytes" by Witten, Moffat, and Bell.
// Notice that if numBaseBits == 0 it coincides with (k + numPairs).
final long ybits = (numPairs * (1L + numBaseBits)) + (k >>> numBaseBits);
final long xbits = 12 * numPairs;
long padding = 10L - numBaseBits;
if (padding < 0) { padding = 0; }
final long bits = xbits + ybits + padding;
//final long words = divideLongsRoundingUp(bits, 32);
final long words = CpcCompression.divideBy32RoundingUp(bits);
assert words < (1L << 31);
return (int) words;
}
// Explanation of padding: we write
// 1) xdelta (huffman, provides at least 1 bit, requires 12-bit lookahead)
// 2) ydeltaGolombHi (unary, provides at least 1 bit, requires 8-bit lookahead)
// 3) ydeltaGolombLo (straight B bits).
// So the 12-bit lookahead is the tight constraint, but there are at least (2 + B) bits emitted,
// so we would be safe with max (0, 10 - B) bits of padding at the end of the bitstream.
private static int safeLengthForCompressedWindowBuf(final long k) { // measured in 32-bit words
// 11 bits of padding, due to 12-bit lookahead, with 1 bit certainly present.
final long bits = (12 * k) + 11;
//cannot exceed Integer.MAX_VALUE
//return (int) (divideLongsRoundingUp(bits, 32));
return (int) CpcCompression.divideBy32RoundingUp(bits);
}
private static int determinePseudoPhase(final int lgK, final long numCoupons) {
final long k = 1L << lgK;
final long c = numCoupons;
// This midrange logic produces pseudo-phases. They are used to select encoding tables.
// The thresholds were chosen by hand after looking at plots of measured compression.
if ((1000 * c) < (2375 * k)) {
if ( (4 * c) < (3 * k)) { return ( 16 + 0 ); } // midrange table
else if ( (10 * c) < (11 * k)) { return ( 16 + 1 ); } // midrange table
else if ( (100 * c) < (132 * k)) { return ( 16 + 2 ); } // midrange table
else if ( (3 * c) < (5 * k)) { return ( 16 + 3 ); } // midrange table
else if ((1000 * c) < (1965 * k)) { return ( 16 + 4 ); } // midrange table
else if ((1000 * c) < (2275 * k)) { return ( 16 + 5 ); } // midrange table
else { return 6; } // steady-state table employed before its actual phase
}
else {
// This steady-state logic produces true phases. They are used to select
// encoding tables, and also column permutations for the "Sliding" flavor.
assert lgK >= 4;
final long tmp = c >>> (lgK - 4);
final int phase = (int) (tmp & 15L);
assert (phase >= 0) && (phase < 16);
return phase;
}
}
private static void compressTheWindow(final CompressedState target, final CpcSketch source) {
final int srcLgK = source.lgK;
final int srcK = 1 << srcLgK;
final int windowBufLen = safeLengthForCompressedWindowBuf(srcK);
final int[] windowBuf = new int[windowBufLen];
final int pseudoPhase = determinePseudoPhase(srcLgK, source.numCoupons);
target.cwLengthInts = lowLevelCompressBytes(
source.slidingWindow,
srcK,
encodingTablesForHighEntropyByte[pseudoPhase],
windowBuf);
// At this point we free the unused portion of the compression output buffer.
// final int[] shorterBuf = Arrays.copyOf(windowBuf, target.cwLength);
// target.compressedWindow = shorterBuf;
target.cwStream = windowBuf; //avoid extra copy
}
private static void uncompressTheWindow(final CpcSketch target, final CompressedState source) {
final int srcLgK = source.lgK;
final int srcK = 1 << srcLgK;
final byte[] window = new byte[srcK];
// bzero ((void *) window, (size_t) k); // zeroing not needed here (unlike the Hybrid Flavor)
assert (target.slidingWindow == null);
target.slidingWindow = window;
final int pseudoPhase = determinePseudoPhase(srcLgK, source.numCoupons);
assert (source.cwStream != null);
lowLevelUncompressBytes(target.slidingWindow, srcK,
decodingTablesForHighEntropyByte[pseudoPhase],
source.cwStream,
source.cwLengthInts);
}
private static void compressTheSurprisingValues(final CompressedState target, final CpcSketch source,
final int[] pairs, final int numPairs) {
assert (numPairs > 0);
target.numCsv = numPairs;
final int srcK = 1 << source.lgK;
final int numBaseBits = CpcCompression.golombChooseNumberOfBaseBits(srcK + numPairs, numPairs);
final int pairBufLen = safeLengthForCompressedPairBuf(srcK, numPairs, numBaseBits);
final int[] pairBuf = new int[pairBufLen];
target.csvLengthInts = (int) lowLevelCompressPairs(pairs, numPairs, numBaseBits, pairBuf);
// At this point we free the unused portion of the compression output buffer.
// final int[] shorterBuf = Arrays.copyOf(pairBuf, target.csvLength);
// target.compressedWindow = shorterBuf;
target.csvStream = pairBuf; //avoid extra copy
}
//allocates and returns an array of uncompressed pairs.
//the length of this array is known to the source sketch.
private static int[] uncompressTheSurprisingValues(final CompressedState source) {
final int srcK = 1 << source.lgK;
final int numPairs = source.numCsv;
assert numPairs > 0;
final int[] pairs = new int[numPairs];
final int numBaseBits = CpcCompression.golombChooseNumberOfBaseBits(srcK + numPairs, numPairs);
lowLevelUncompressPairs(pairs, numPairs, numBaseBits, source.csvStream, source.csvLengthInts);
return pairs;
}
private static void compressSparseFlavor(final CompressedState target, final CpcSketch source) {
assert (source.slidingWindow == null); //there is no window to compress
final PairTable srcPairTable = source.pairTable;
final int srcNumPairs = srcPairTable.getNumPairs();
final int[] srcPairArr = PairTable.unwrappingGetItems(srcPairTable, srcNumPairs);
introspectiveInsertionSort(srcPairArr, 0, srcNumPairs - 1);
compressTheSurprisingValues(target, source, srcPairArr, srcNumPairs);
}
private static void uncompressSparseFlavor(final CpcSketch target, final CompressedState source) {
assert (source.cwStream == null);
assert (source.csvStream != null);
final int[] srcPairArr = uncompressTheSurprisingValues(source);
final int numPairs = source.numCsv;
final PairTable table = PairTable.newInstanceFromPairsArray(srcPairArr, numPairs, source.lgK);
target.pairTable = table;
}
//The empty space that this leaves at the beginning of the output array
// will be filled in later by the caller.
private static int[] trickyGetPairsFromWindow(final byte[] window, final int k, final int numPairsToGet,
final int emptySpace) {
final int outputLength = emptySpace + numPairsToGet;
final int[] pairs = new int[outputLength];
int rowIndex = 0;
int pairIndex = emptySpace;
for (rowIndex = 0; rowIndex < k; rowIndex++) {
int wByte = window[rowIndex] & 0XFF;
while (wByte != 0) {
final int colIndex = Integer.numberOfTrailingZeros(wByte);
// assert (colIndex < 8);
wByte ^= (1 << colIndex); // erase the 1
pairs[pairIndex++] = (rowIndex << 6) | colIndex;
}
}
assert (pairIndex == outputLength);
return (pairs);
}
//This is complicated because it effectively builds a Sparse version
//of a Pinned sketch before compressing it. Hence the name Hybrid.
private static void compressHybridFlavor(final CompressedState target, final CpcSketch source) {
final int srcK = 1 << source.lgK;
final PairTable srcPairTable = source.pairTable;
final int srcNumPairs = srcPairTable.getNumPairs();
final int[] srcPairArr = PairTable.unwrappingGetItems(srcPairTable, srcNumPairs);
introspectiveInsertionSort(srcPairArr, 0, srcNumPairs - 1);
final byte[] srcSlidingWindow = source.slidingWindow;
final int srcWindowOffset = source.windowOffset;
final long srcNumCoupons = source.numCoupons;
assert (srcSlidingWindow != null);
assert (srcWindowOffset == 0);
final long numPairs = srcNumCoupons - srcNumPairs; // because the window offset is zero
assert numPairs < Integer.MAX_VALUE;
final int numPairsFromArray = (int) numPairs;
assert (numPairsFromArray + srcNumPairs) == srcNumCoupons; //for test
final int[] allPairs
= trickyGetPairsFromWindow(srcSlidingWindow, srcK, numPairsFromArray, srcNumPairs);
PairTable.merge(srcPairArr, 0, srcNumPairs,
allPairs, srcNumPairs, numPairsFromArray,
allPairs, 0); // note the overlapping subarray trick
//FOR TESTING If needed
// for (int i = 0; i < (source.numCoupons - 1); i++) {
// assert (Integer.compareUnsigned(allPairs[i], allPairs[i + 1]) < 0); }
compressTheSurprisingValues(target, source, allPairs, (int) srcNumCoupons);
}
private static void uncompressHybridFlavor(final CpcSketch target, final CompressedState source) {
assert (source.cwStream == null);
assert (source.csvStream != null);
final int[] pairs = uncompressTheSurprisingValues(source); //fail path 3
final int numPairs = source.numCsv;
// In the hybrid flavor, some of these pairs actually
// belong in the window, so we will separate them out,
// moving the "true" pairs to the bottom of the array.
final int srcLgK = source.lgK;
final int k = 1 << srcLgK;
final byte[] window = new byte[k];
int nextTruePair = 0;
for (int i = 0; i < numPairs; i++) {
final int rowCol = pairs[i];
assert (rowCol != -1);
final int col = rowCol & 63;
if (col < 8) {
final int row = rowCol >>> 6;
window[row] |= (1 << col); // set the window bit
}
else {
pairs[nextTruePair++] = rowCol; // move true pair down
}
}
assert (source.getWindowOffset() == 0);
target.windowOffset = 0;
final PairTable table = PairTable.newInstanceFromPairsArray(pairs, nextTruePair, srcLgK);
target.pairTable = table;
target.slidingWindow = window;
}
private static void compressPinnedFlavor(final CompressedState target, final CpcSketch source) {
compressTheWindow(target, source);
final PairTable srcPairTable = source.pairTable;
final int numPairs = srcPairTable.getNumPairs();
if (numPairs > 0) {
final int[] pairs = PairTable.unwrappingGetItems(srcPairTable, numPairs);
// Here we subtract 8 from the column indices. Because they are stored in the low 6 bits
// of each rowCol pair, and because no column index is less than 8 for a "Pinned" sketch,
// I believe we can simply subtract 8 from the pairs themselves.
// shift the columns over by 8 positions before compressing (because of the window)
for (int i = 0; i < numPairs; i++) {
assert (pairs[i] & 63) >= 8;
pairs[i] -= 8;
}
introspectiveInsertionSort(pairs, 0, numPairs - 1);
compressTheSurprisingValues(target, source, pairs, numPairs);
}
}
private static void uncompressPinnedFlavor(final CpcSketch target, final CompressedState source) {
assert (source.cwStream != null);
uncompressTheWindow(target, source);
final int srcLgK = source.lgK;
final int numPairs = source.numCsv;
if (numPairs == 0) {
target.pairTable = new PairTable(2, 6 + srcLgK);
}
else {
assert numPairs > 0;
assert source.csvStream != null;
final int[] pairs = uncompressTheSurprisingValues(source);
// undo the compressor's 8-column shift
for (int i = 0; i < numPairs; i++) {
assert (pairs[i] & 63) < 56;
pairs[i] += 8;
}
final PairTable table = PairTable.newInstanceFromPairsArray(pairs, numPairs, srcLgK);
target.pairTable = table;
}
}
//Complicated by the existence of both a left fringe and a right fringe.
private static void compressSlidingFlavor(final CompressedState target, final CpcSketch source) {
compressTheWindow(target, source);
final PairTable srcPairTable = source.pairTable;
final int numPairs = srcPairTable.getNumPairs();
if (numPairs > 0) {
final int[] pairs = PairTable.unwrappingGetItems(srcPairTable, numPairs);
// Here we apply a complicated transformation to the column indices, which
// changes the implied ordering of the pairs, so we must do it before sorting.
final int pseudoPhase = determinePseudoPhase(source.lgK, source.numCoupons); // NB
assert (pseudoPhase < 16);
final byte[] permutation = columnPermutationsForEncoding[pseudoPhase];
final int offset = source.windowOffset;
assert ((offset > 0) && (offset <= 56));
for (int i = 0; i < numPairs; i++) {
final int rowCol = pairs[i];
final int row = rowCol >>> 6;
int col = (rowCol & 63);
// first rotate the columns into a canonical configuration:
// new = ((old - (offset+8)) + 64) mod 64
col = ((col + 56) - offset) & 63;
assert (col >= 0) && (col < 56);
// then apply the permutation
col = permutation[col];
pairs[i] = (row << 6) | col;
}
introspectiveInsertionSort(pairs, 0, numPairs - 1);
compressTheSurprisingValues(target, source, pairs, numPairs);
}
}
private static void uncompressSlidingFlavor(final CpcSketch target, final CompressedState source) {
assert (source.cwStream != null);
uncompressTheWindow(target, source);
final int srcLgK = source.lgK;
final int numPairs = source.numCsv;
if (numPairs == 0) {
target.pairTable = new PairTable(2, 6 + srcLgK);
}
else {
assert (numPairs > 0);
assert (source.csvStream != null);
final int[] pairs = uncompressTheSurprisingValues(source);
final int pseudoPhase = determinePseudoPhase(srcLgK, source.numCoupons); // NB
assert (pseudoPhase < 16);
final byte[] permutation = columnPermutationsForDecoding[pseudoPhase];
final int offset = source.getWindowOffset();
assert (offset > 0) && (offset <= 56);
for (int i = 0; i < numPairs; i++) {
final int rowCol = pairs[i];
final int row = rowCol >>> 6;
int col = rowCol & 63;
// first undo the permutation
col = permutation[col];
// then undo the rotation: old = (new + (offset+8)) mod 64
col = (col + (offset + 8)) & 63;
pairs[i] = (row << 6) | col;
}
final PairTable table = PairTable.newInstanceFromPairsArray(pairs, numPairs, srcLgK);
target.pairTable = table;
}
}
static CompressedState compress(final CpcSketch source, final CompressedState target) {
final Flavor srcFlavor = source.getFlavor();
switch (srcFlavor) {
case EMPTY: break;
case SPARSE:
compressSparseFlavor(target, source);
assert (target.cwStream == null);
assert (target.csvStream != null);
break;
case HYBRID:
compressHybridFlavor(target, source);
assert (target.cwStream == null);
assert (target.csvStream != null);
break;
case PINNED:
compressPinnedFlavor(target, source);
assert (target.cwStream != null);
break;
case SLIDING:
compressSlidingFlavor(target, source);
assert (target.cwStream != null);
break;
//default: not possible
}
return target;
}
static CpcSketch uncompress(final CompressedState source, final CpcSketch target) {
assert (target != null);
final Flavor srcFlavor = source.getFlavor();
switch (srcFlavor) {
case EMPTY: break;
case SPARSE:
assert (source.cwStream == null);
uncompressSparseFlavor(target, source);
break;
case HYBRID:
uncompressHybridFlavor(target, source);
break;
case PINNED:
assert (source.cwStream != null);
uncompressPinnedFlavor(target, source);
break;
case SLIDING:
uncompressSlidingFlavor(target, source);
break;
//default: not possible
}
return target;
}
private static int golombChooseNumberOfBaseBits(final int k, final long count) {
assert k >= 1L;
assert count >= 1L;
final long quotient = (k - count) / count; // integer division
if (quotient == 0) { return 0; }
return (int) floorLog2ofLong(quotient);
}
private static long floorLog2ofLong(final long x) { //not a good name
assert (x >= 1L);
long p = 0;
long y = 1;
while (true) {
if (y == x) { return p; }
if (y > x) { return p - 1; }
p += 1;
y <<= 1;
}
}
private static long divideBy32RoundingUp(final long x) {
final long tmp = x >>> 5;
return ((tmp << 5) == x) ? tmp : tmp + 1;
}
}
| 2,745 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/PairTable.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssert;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssertEquals;
import java.util.Arrays;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesStateException;
/**
* Note: Definition of
* <a href="{@docRoot}/resources/dictionary.html#SnowPlow">Snow Plow Effect</a>.
* @author Lee Rhodes
* @author Kevin Lang
*/
final class PairTable {
private static final String LS = System.getProperty("line.separator");
private static final int upsizeNumer = 3;
private static final int upsizeDenom = 4;
private static final int downsizeNumer = 1;
private static final int downsizeDenom = 4;
private int lgSizeInts;
private final int validBits;
private int numPairs;
private int[] slotsArr;
PairTable(final int lgSizeInts, final int numValidBits) {
checkLgSizeInts(lgSizeInts);
this.lgSizeInts = lgSizeInts;
final int numSlots = 1 << lgSizeInts;
validBits = numValidBits;
numPairs = 0;
slotsArr = new int[numSlots];
for (int i = 0; i < numSlots; i++) { slotsArr[i] = -1; }
}
//Factory
static PairTable newInstanceFromPairsArray(final int[] pairs, final int numPairs, final int lgK) {
int lgNumSlots = 2;
while ((upsizeDenom * numPairs) > (upsizeNumer * (1 << lgNumSlots))) {
lgNumSlots++;
}
final PairTable table = new PairTable(lgNumSlots, 6 + lgK);
/* Note: there is a possible
* <a href="{@docRoot}/resources/dictionary.html#SnowPlow">Snow Plow Effect</a> here because
* the caller is passing in a sorted pairs array. However, we are starting out with the correct
* final table size, so the problem is not likely to occur.
*/
for (int i = 0; i < numPairs; i++) {
mustInsert(table, pairs[i]);
}
table.numPairs = numPairs;
return table;
}
PairTable clear() {
Arrays.fill(slotsArr, -1);
numPairs = 0;
return this;
}
PairTable copy() {
final PairTable copy = new PairTable(lgSizeInts, validBits);
copy.numPairs = numPairs;
copy.slotsArr = slotsArr.clone(); //slotsArr can never be null
return copy;
}
int getLgSizeInts() {
return lgSizeInts;
}
int getNumPairs() {
return numPairs;
}
int[] getSlotsArr() {
return slotsArr;
}
int getValidBits() {
return validBits;
}
/**
* Rebuilds to a larger size. NumItems and validBits remain unchanged.
* @param newLgSizeInts the new size
* @return a larger PairTable
*/
PairTable rebuild(final int newLgSizeInts) {
checkLgSizeInts(newLgSizeInts);
final int newSize = 1 << newLgSizeInts;
final int oldSize = 1 << lgSizeInts;
rtAssert(newSize > numPairs);
final int[] oldSlotsArr = slotsArr;
slotsArr = new int[newSize];
Arrays.fill(slotsArr, -1);
lgSizeInts = newLgSizeInts;
for (int i = 0; i < oldSize; i++) {
final int item = oldSlotsArr[i];
if (item != -1) { mustInsert(this, item); }
}
return this;
}
@Override
public String toString() {
return toString(false);
}
private static void mustInsert(final PairTable table, final int item) {
//SHARED CODE (implemented as a macro in C and expanded here)
final int lgSizeInts = table.lgSizeInts;
final int sizeInts = 1 << lgSizeInts;
final int mask = sizeInts - 1;
final int shift = table.validBits - lgSizeInts;
rtAssert(shift > 0);
int probe = item >>> shift; //extract high tablesize bits
rtAssert((probe >= 0) && (probe <= mask));
final int[] arr = table.slotsArr;
int fetched = arr[probe];
while ((fetched != item) && (fetched != -1)) {
probe = (probe + 1) & mask;
fetched = arr[probe];
}
//END SHARED CODE
if (fetched == item) { throw new SketchesStateException("PairTable mustInsert() failed"); }
else {
assert (fetched == -1);
arr[probe] = item;
// counts and resizing must be handled by the caller.
}
}
static boolean maybeInsert(final PairTable table, final int item) {
//SHARED CODE (implemented as a macro in C and expanded here)
final int lgSizeInts = table.lgSizeInts;
final int sizeInts = 1 << lgSizeInts;
final int mask = sizeInts - 1;
final int shift = table.validBits - lgSizeInts;
rtAssert(shift > 0);
int probe = item >>> shift;
rtAssert((probe >= 0) && (probe <= mask));
final int[] arr = table.slotsArr;
int fetched = arr[probe];
while ((fetched != item) && (fetched != -1)) {
probe = (probe + 1) & mask;
fetched = arr[probe];
}
//END SHARED CODE
if (fetched == item) { return false; }
else {
assert (fetched == -1);
arr[probe] = item;
table.numPairs += 1;
while ((upsizeDenom * table.numPairs) > (upsizeNumer * (1 << table.lgSizeInts))) {
table.rebuild(table.lgSizeInts + 1);
}
return true;
}
}
static boolean maybeDelete(final PairTable table, final int item) {
//SHARED CODE (implemented as a macro in C and expanded here)
final int lgSizeInts = table.lgSizeInts;
final int sizeInts = 1 << lgSizeInts;
final int mask = sizeInts - 1;
final int shift = table.validBits - lgSizeInts;
rtAssert(shift > 0);
int probe = item >>> shift;
rtAssert((probe >= 0) && (probe <= mask));
final int[] arr = table.slotsArr;
int fetched = arr[probe];
while ((fetched != item) && (fetched != -1)) {
probe = (probe + 1) & mask;
fetched = arr[probe];
}
//END SHARED CODE
if (fetched == -1) { return false; }
else {
assert (fetched == item);
// delete the item
arr[probe] = -1;
table.numPairs -= 1; assert (table.numPairs >= 0);
// re-insert all items between the freed slot and the next empty slot
probe = (probe + 1) & mask; fetched = arr[probe];
while (fetched != -1) {
arr[probe] = -1;
mustInsert(table, fetched);
probe = (probe + 1) & mask; fetched = arr[probe];
}
// shrink if necessary
while (((downsizeDenom * table.numPairs)
< (downsizeNumer * (1 << table.lgSizeInts))) && (table.lgSizeInts > 2)) {
table.rebuild(table.lgSizeInts - 1);
}
return true;
}
}
/**
* While extracting the items from a linear probing hashtable,
* this will usually undo the wrap-around provided that the table
* isn't too full. Experiments suggest that for sufficiently large tables
* the load factor would have to be over 90 percent before this would fail frequently,
* and even then the subsequent sort would fix things up.
* @param table the given table to unwrap
* @param numPairs the number of valid pairs in the table
* @return the unwrapped table
*/
static int[] unwrappingGetItems(final PairTable table, final int numPairs) {
if (numPairs < 1) { return null; }
final int[] slotsArr = table.slotsArr;
final int tableSize = 1 << table.lgSizeInts;
final int[] result = new int[numPairs];
int i = 0;
int l = 0;
int r = numPairs - 1;
// Special rules for the region before the first empty slot.
final int hiBit = 1 << (table.validBits - 1);
while ((i < tableSize) && (slotsArr[i] != -1)) {
final int item = slotsArr[i++];
if ((item & hiBit) != 0) { result[r--] = item; } // This item was probably wrapped, so move to end.
else { result[l++] = item; }
}
// The rest of the table is processed normally.
while (i < tableSize) {
final int look = slotsArr[i++];
if (look != -1) { result[l++] = look; }
}
assert l == (r + 1);
return result;
}
/**
* In applications where the input array is already nearly sorted,
* insertion sort runs in linear time with a very small constant.
* This introspective version of insertion sort protects against
* the quadratic cost of sorting bad input arrays.
* It keeps track of how much work has been done, and if that exceeds a
* constant times the array length, it switches to a different sorting algorithm.
* @param a the array to sort
* @param l points AT the leftmost element, i.e., inclusive.
* @param r points AT the rightmost element, i.e., inclusive.
*/
static void introspectiveInsertionSort(final int[] a, final int l, final int r) {
final int length = (r - l) + 1;
long cost = 0;
final long costLimit = 8L * length;
for (int i = l + 1; i <= r; i++) {
int j = i;
final long v = a[i] & 0XFFFF_FFFFL; //v must be long
while ((j >= (l + 1)) && (v < ((a[j - 1]) & 0XFFFF_FFFFL))) {
a[j] = a[j - 1];
j -= 1;
}
a[j] = (int) v;
cost += (i - j); // distance moved is a measure of work
if (cost > costLimit) {
//we need an unsigned sort, but it is linear time and very rarely occurs
final long[] b = new long[a.length];
for (int m = 0; m < a.length; m++) { b[m] = a[m] & 0XFFFF_FFFFL; }
Arrays.sort(b, l, r + 1);
for (int m = 0; m < a.length; m++) { a[m] = (int) b[m]; }
// The following sanity check can be used during development
//int bad = 0;
//for (int m = l; m < (r - 1); m++) {
// final long b1 = a[m] & 0XFFFF_FFFFL;
// final long b2 = a[m + 1] & 0XFFFF_FFFFL;
// if (b1 > b2) { bad++; }
//}
//assert (bad == 0);
return;
}
}
// The following sanity check can be used during development
// int bad = 0;
// for (int m = l; m < (r - 1); m++) {
// final long b1 = a[m] & 0XFFFF_FFFFL;
// final long b2 = a[m + 1] & 0XFFFF_FFFFL;
// if (b1 > b2) { bad++; }
// }
// assert (bad == 0);
}
static void merge(
final int[] arrA, final int startA, final int lengthA, //input
final int[] arrB, final int startB, final int lengthB, //input
final int[] arrC, final int startC) { //output
final int lengthC = lengthA + lengthB;
final int limA = startA + lengthA;
final int limB = startB + lengthB;
final int limC = startC + lengthC;
int a = startA;
int b = startB;
int c = startC;
for ( ; c < limC ; c++) {
if (b >= limB) { arrC[c] = arrA[a++]; }
else if (a >= limA) { arrC[c] = arrB[b++]; }
else {
final long aa = arrA[a] & 0XFFFF_FFFFL;
final long bb = arrB[b] & 0XFFFF_FFFFL;
if (aa < bb) { arrC[c] = arrA[a++]; }
else { arrC[c] = arrB[b++]; }
}
}
assert (a == limA);
assert (b == limB);
}
static boolean equals(final PairTable a, final PairTable b) {
if ((a == null) && (b == null)) { return true; }
if ((a == null) || (b == null)) {
throw new SketchesArgumentException("PairTable " + ((a == null) ? "a" : "b") + " is null");
}
//Note: lgSize array sizes may not be equal, but contents still can be equal
rtAssertEquals(a.validBits, b.validBits);
final int numPairsA = a.numPairs;
final int numPairsB = b.numPairs;
rtAssertEquals(numPairsA, numPairsB);
final int[] pairsA = PairTable.unwrappingGetItems(a, numPairsA);
final int[] pairsB = PairTable.unwrappingGetItems(b, numPairsB);
PairTable.introspectiveInsertionSort(pairsA, 0, numPairsA - 1);
PairTable.introspectiveInsertionSort(pairsB, 0, numPairsB - 1);
rtAssertEquals(pairsA, pairsB);
return true;
}
String toString(final boolean detail) {
final StringBuilder sb = new StringBuilder();
final int sizeInts = 1 << lgSizeInts;
sb.append("PairTable").append(LS);
sb.append(" Lg Size Ints : ").append(lgSizeInts).append(LS);
sb.append(" Size Ints : ").append(sizeInts).append(LS);
sb.append(" Valid Bits : ").append(validBits).append(LS);
sb.append(" Num Pairs : ").append(numPairs).append(LS);
if (detail) {
sb.append(" DATA (hex) : ").append(LS);
final String hdr = String.format("%9s %9s %9s %4s", "Index","Word","Row","Col");
sb.append(hdr).append(LS);
for (int i = 0; i < sizeInts; i++) {
final int word = slotsArr[i];
if (word == -1) { //empty
final String h = String.format("%9d %9s", i, "--");
sb.append(h).append(LS);
} else { //data
final int row = word >>> 6;
final int col = word & 0X3F;
final String wordStr = Long.toHexString(word & 0XFFFF_FFFFL);
final String data = String.format("%9d %9s %9d %4d", i, wordStr, row, col);
sb.append(data).append(LS);
}
}
}
return sb.toString();
}
private static void checkLgSizeInts(final int lgSizeInts) {
if ((lgSizeInts < 2) || (lgSizeInts > 26)) {
throw new SketchesArgumentException("Illegal LgSizeInts: " + lgSizeInts);
}
}
}
| 2,746 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/CpcUnion.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.common.Util.INVERSE_GOLDEN;
import static org.apache.datasketches.cpc.CpcUtil.countBitsSetInMatrix;
import static org.apache.datasketches.cpc.Flavor.EMPTY;
import static org.apache.datasketches.cpc.Flavor.SPARSE;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesStateException;
import org.apache.datasketches.thetacommon.ThetaUtil;
/*
* The merging logic is somewhat involved, so it will be summarized here.
*
* <p>First, we compare the K values of the union and the source sketch.
*
* <p>If (source.K < union.K), we reduce the union's K to match, which
* requires downsampling the union's internal sketch.
*
* <p>Here is how to perform the downsampling.
*
* <p>If the union contains a bitMatrix, downsample it by row-wise OR'ing.
*
* <p>If the union contains a sparse sketch, then create a new empty
* sketch, and walk the old target sketch updating the new one (with modulo).
* At the end, check whether the new target
* sketch is still in sparse mode (it might not be, because downsampling
* densifies the set of collected coupons). If it is NOT in sparse mode,
* immediately convert it to a bitmatrix.
*
* <p>At this point, we have source.K ≥ union.K.
* [We won't keep mentioning this, but in all of the following the
* source's row indices are used mod union.K while updating the union's sketch.
* That takes care of the situation where source.K < union.K.]
*
* <p>Case A: union is Sparse and source is Sparse. We walk the source sketch
* updating the union's sketch. At the end, if the union's sketch
* is no longer in sparse mode, we convert it to a bitmatrix.
*
* <p>Case B: union is bitmatrix and source is Sparse. We walk the source sketch,
* setting bits in the bitmatrix.
*
* <p>In the remaining cases, we have flavor(source) > Sparse, so we immediately convert the
* union's sketch to a bitmatrix (even if the union contains very few coupons). Then:
*
* <p>Case C: union is bitmatrix and source is Hybrid or Pinned. Then we OR the source's
* sliding window into the bitmatrix, and walk the source's table, setting bits in the bitmatrix.
*
* <p>Case D: union is bitmatrix, and source is Sliding. Then we convert the source into
* a bitmatrix, and OR it into the union's bitmatrix. [Important note; merely walking the source
* wouldn't work because of the partially inverted Logic in the Sliding flavor, where the presence of
* coupons is sometimes indicated by the ABSENCE of rowCol pairs in the surprises table.]
*
* <p>How does getResult work?
*
* <p>If the union is using its accumulator field, make a copy of that sketch.
*
* <p>If the union is using its bitMatrix field, then we have to convert the
* bitMatrix back into a sketch, which requires doing some extra work to
* figure out the values of numCoupons, offset, fiCol, and KxQ.
*
*/
/**
* The union (merge) operation for the CPC sketches.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
public class CpcUnion {
private final long seed;
private int lgK;
// Note: at most one of bitMatrix and accumulator will be non-null at any given moment.
// accumulator is a sketch object that is employed until it graduates out of Sparse mode.
// At that point, it is converted into a full-sized bitMatrix, which is mathematically a sketch,
// but doesn't maintain any of the "extra" fields of our sketch objects, so some additional work
// is required when getResult is called at the end.
private long[] bitMatrix;
private CpcSketch accumulator; //can only be empty or sparse Flavor
/**
* Construct this unioning object with the default LgK and the default update seed.
*/
public CpcUnion() {
this(CpcSketch.DEFAULT_LG_K, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Construct this unioning object with LgK and the default update seed.
* @param lgK The given log2 of K.
*/
public CpcUnion(final int lgK) {
this(lgK, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Construct this unioning object with LgK and a given seed.
* @param lgK The given log2 of K.
* @param seed The given seed.
*/
public CpcUnion(final int lgK, final long seed) {
this.seed = seed;
this.lgK = lgK;
bitMatrix = null;
// We begin with the accumulator holding an EMPTY_MERGED sketch object.
// As an optimization the accumulator could start as NULL, but that would require changes elsewhere.
accumulator = new CpcSketch(lgK);
}
/**
* Update this union with a CpcSketch.
* @param sketch the given CpcSketch.
*/
public void update(final CpcSketch sketch) {
mergeInto(this, sketch);
}
/**
* Returns the result of union operations as a CPC sketch.
* @return the result of union operations as a CPC sketch.
*/
public CpcSketch getResult() {
return getResult(this);
}
/**
* Returns the current value of Log_base2 of K. Note that due to merging with source sketches that
* may have a lower value of LgK, this value can be less than what the union object was configured
* with.
*
* @return the current value of Log_base2 of K.
*/
public int getLgK() {
return lgK;
}
/**
* Return the DataSketches identifier for this CPC family of sketches.
* @return the DataSketches identifier for this CPC family of sketches.
*/
public static Family getFamily() {
return Family.CPC;
}
//used for testing only
long getNumCoupons() {
if (bitMatrix != null) {
return countBitsSetInMatrix(bitMatrix);
}
return accumulator.numCoupons;
}
//used for testing only
static long[] getBitMatrix(final CpcUnion union) {
checkUnionState(union);
return (union.bitMatrix != null)
? union.bitMatrix
: CpcUtil.bitMatrixOfSketch(union.accumulator);
}
private static void walkTableUpdatingSketch(final CpcSketch dest, final PairTable table) {
final int[] slots = table.getSlotsArr();
final int numSlots = (1 << table.getLgSizeInts());
assert dest.lgK <= 26;
final int destMask = (((1 << dest.lgK) - 1) << 6) | 63; //downsamples when destlgK < srcLgK
/* Using the inverse golden ratio stride fixes the
* <a href="{@docRoot}/resources/dictionary.html#SnowPlow">Snow Plow Effect</a>.
*/
int stride = (int) (INVERSE_GOLDEN * numSlots);
assert stride >= 2;
if (stride == ((stride >>> 1) << 1)) { stride += 1; } //force the stride to be odd
assert (stride >= 3) && (stride < numSlots);
for (int i = 0, j = 0; i < numSlots; i++, j += stride) {
j &= (numSlots - 1);
final int rowCol = slots[j];
if (rowCol != -1) {
dest.rowColUpdate(rowCol & destMask);
}
}
}
private static void orTableIntoMatrix(final long[] bitMatrix, final int destLgK, final PairTable table) {
final int[] slots = table.getSlotsArr();
final int numSlots = 1 << table.getLgSizeInts();
final int destMask = (1 << destLgK) - 1; // downsamples when destlgK < srcLgK
for (int i = 0; i < numSlots; i++) {
final int rowCol = slots[i];
if (rowCol != -1) {
final int col = rowCol & 63;
final int row = rowCol >>> 6;
bitMatrix[row & destMask] |= (1L << col); // Set the bit.
}
}
}
private static void orWindowIntoMatrix(final long[] destMatrix, final int destLgK,
final byte[] srcWindow, final int srcOffset, final int srcLgK) {
assert (destLgK <= srcLgK);
final int destMask = (1 << destLgK) - 1; // downsamples when destlgK < srcLgK
final int srcK = 1 << srcLgK;
for (int srcRow = 0; srcRow < srcK; srcRow++) {
destMatrix[srcRow & destMask] |= ((srcWindow[srcRow] & 0XFFL) << srcOffset);
}
}
private static void orMatrixIntoMatrix(final long[] destMatrix, final int destLgK,
final long[] srcMatrix, final int srcLgK) {
assert (destLgK <= srcLgK);
final int destMask = (1 << destLgK) - 1; // downsamples when destlgK < srcLgK
final int srcK = 1 << srcLgK;
for (int srcRow = 0; srcRow < srcK; srcRow++) {
destMatrix[srcRow & destMask] |= srcMatrix[srcRow];
}
}
private static void reduceUnionK(final CpcUnion union, final int newLgK) {
assert (newLgK < union.lgK);
if (union.bitMatrix != null) { // downsample the union's bit matrix
final int newK = 1 << newLgK;
final long[] newMatrix = new long[newK];
orMatrixIntoMatrix(newMatrix, newLgK, union.bitMatrix, union.lgK);
union.bitMatrix = newMatrix;
union.lgK = newLgK;
}
else { // downsample the union's accumulator
final CpcSketch oldSketch = union.accumulator;
if (oldSketch.numCoupons == 0) {
union.accumulator = new CpcSketch(newLgK, oldSketch.seed);
union.lgK = newLgK;
return;
}
final CpcSketch newSketch = new CpcSketch(newLgK, oldSketch.seed);
walkTableUpdatingSketch(newSketch, oldSketch.pairTable);
final Flavor finalNewFlavor = newSketch.getFlavor();
assert (finalNewFlavor != EMPTY); //SV table had to have something in it
if (finalNewFlavor == SPARSE) {
union.accumulator = newSketch;
union.lgK = newLgK;
return;
}
// the new sketch has graduated beyond sparse, so convert to bitMatrix
union.accumulator = null;
union.bitMatrix = CpcUtil.bitMatrixOfSketch(newSketch);
union.lgK = newLgK;
}
}
private static void mergeInto(final CpcUnion union, final CpcSketch source) {
if (source == null) { return; }
checkSeeds(union.seed, source.seed);
final int sourceFlavorOrd = source.getFlavor().ordinal();
if (sourceFlavorOrd == 0) { return; } //EMPTY
//Accumulator and bitMatrix must be mutually exclusive,
//so bitMatrix != null => accumulator == null and visa versa
//if (Accumulator != null) union must be EMPTY or SPARSE,
checkUnionState(union);
if (source.lgK < union.lgK) { reduceUnionK(union, source.lgK); }
// if source is past SPARSE mode, make sure that union is a bitMatrix.
if ((sourceFlavorOrd > 1) && (union.accumulator != null)) {
union.bitMatrix = CpcUtil.bitMatrixOfSketch(union.accumulator);
union.accumulator = null;
}
final int state = ((sourceFlavorOrd - 1) << 1) | ((union.bitMatrix != null) ? 1 : 0);
switch (state) {
case 0 : { //A: Sparse, bitMatrix == null, accumulator valid
if (union.accumulator == null) {
//CodeQL could not figure this out so I have to insert this.
throw new SketchesStateException("union.accumulator can never be null here.");
}
if ((union.accumulator.getFlavor() == EMPTY)
&& (union.lgK == source.lgK)) {
union.accumulator = source.copy();
break;
}
walkTableUpdatingSketch(union.accumulator, source.pairTable);
// if the accumulator has graduated beyond sparse, switch union to a bitMatrix
if (union.accumulator.getFlavor().ordinal() > 1) {
union.bitMatrix = CpcUtil.bitMatrixOfSketch(union.accumulator);
union.accumulator = null;
}
break;
}
case 1 : { //B: Sparse, bitMatrix valid, accumulator == null
orTableIntoMatrix(union.bitMatrix, union.lgK, source.pairTable);
break;
}
case 3 : //C: Hybrid, bitMatrix valid, accumulator == null
case 5 : { //C: Pinned, bitMatrix valid, accumulator == null
orWindowIntoMatrix(union.bitMatrix, union.lgK, source.slidingWindow,
source.windowOffset, source.lgK);
orTableIntoMatrix(union.bitMatrix, union.lgK, source.pairTable);
break;
}
case 7 : { //D: Sliding, bitMatrix valid, accumulator == null
// SLIDING mode involves inverted logic, so we can't just walk the source sketch.
// Instead, we convert it to a bitMatrix that can be OR'ed into the destination.
final long[] sourceMatrix = CpcUtil.bitMatrixOfSketch(source);
orMatrixIntoMatrix(union.bitMatrix, union.lgK, sourceMatrix, source.lgK);
break;
}
default: throw new SketchesStateException("Illegal Union state: " + state);
}
}
private static CpcSketch getResult(final CpcUnion union) {
checkUnionState(union);
if (union.accumulator != null) { // start of case where union contains a sketch
if (union.accumulator.numCoupons == 0) {
final CpcSketch result = new CpcSketch(union.lgK, union.accumulator.seed);
result.mergeFlag = true;
return (result);
}
assert (SPARSE == union.accumulator.getFlavor());
final CpcSketch result = union.accumulator.copy();
result.mergeFlag = true;
return (result);
} // end of case where union contains a sketch
// start of case where union contains a bitMatrix
final long[] matrix = union.bitMatrix;
final int lgK = union.lgK;
final CpcSketch result = new CpcSketch(union.lgK, union.seed);
final long numCoupons = countBitsSetInMatrix(matrix);
result.numCoupons = numCoupons;
final Flavor flavor = CpcUtil.determineFlavor(lgK, numCoupons);
assert ((flavor.ordinal() > SPARSE.ordinal()) );
final int offset = CpcUtil.determineCorrectOffset(lgK, numCoupons);
result.windowOffset = offset;
//Build the window and pair table
final int k = 1 << lgK;
final byte[] window = new byte[k];
result.slidingWindow = window;
// LgSize = K/16; in some cases this will end up being oversized
final int newTableLgSize = Math.max(lgK - 4, 2);
final PairTable table = new PairTable(newTableLgSize, 6 + lgK);
result.pairTable = table;
// The following works even when the offset is zero.
final long maskForClearingWindow = (0XFFL << offset) ^ -1L;
final long maskForFlippingEarlyZone = (1L << offset) - 1L;
long allSurprisesORed = 0;
/* using a sufficiently large hash table avoids the
* <a href="{@docRoot}/resources/dictionary.html#SnowPlow">Snow Plow Effect</a>
*/
for (int i = 0; i < k; i++) {
long pattern = matrix[i];
window[i] = (byte) ((pattern >>> offset) & 0XFFL);
pattern &= maskForClearingWindow;
pattern ^= maskForFlippingEarlyZone; // This flipping converts surprising 0's to 1's.
allSurprisesORed |= pattern;
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;
}
}
// At this point we could shrink an oversize hash table, but the relative waste isn't very big.
result.fiCol = Long.numberOfTrailingZeros(allSurprisesORed);
if (result.fiCol > offset) {
result.fiCol = offset;
} // corner case
// NB: the HIP-related fields will contain bogus values, but that is okay.
result.mergeFlag = true;
return result;
// end of case where union contains a bitMatrix
}
private static void checkSeeds(final long seedA, final long seedB) {
if (seedA != seedB) {
throw new SketchesArgumentException("Hash Seeds do not match.");
}
}
private static void checkUnionState(final CpcUnion union) {
if (union == null) {
throw new SketchesStateException("union cannot be null");
}
final CpcSketch accumulator = union.accumulator;
if ( !((accumulator != null) ^ (union.bitMatrix != null)) ) {
throw new SketchesStateException(
"accumulator and bitMatrix cannot be both valid or both null: "
+ "accumValid = " + (accumulator != null)
+ ", bitMatrixValid = " + (union.bitMatrix != null));
}
if (accumulator != null) { //must be SPARSE or EMPTY
if (accumulator.numCoupons > 0) { //SPARSE
if ( !((accumulator.slidingWindow == null) && (accumulator.pairTable != null)) ) {
throw new SketchesStateException(
"Non-empty union accumulator must be SPARSE: " + accumulator.getFlavor());
}
} //else EMPTY
if (union.lgK != accumulator.lgK) {
throw new SketchesStateException("union LgK must equal accumulator LgK");
}
}
}
}
| 2,747 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/IconPolynomialCoefficients.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.cpc.CpcUtil.maxLgK;
import static org.apache.datasketches.cpc.CpcUtil.minLgK;
/**
* @author Lee Rhodes
* @author Kevin Lang
*/
final class IconPolynomialCoefficients {
static final int iconPolynomialDegree = 19;
static final int iconPolynomialNumCoefficients = 1 + iconPolynomialDegree;
static final int iconTableSize = iconPolynomialNumCoefficients * ((1 + maxLgK) - minLgK);
//CHECKSTYLE.OFF: LineLength
static final double[] iconPolynomialCoefficents = new double[] {
// log K = 4
0.9895027971889700513, 0.3319496644645180128, 0.1242818722715769986, -0.03324149686026930256, -0.2985637298081619817,
1.366555923595830002, -4.705499366260569971, 11.61506432505530029, -21.11254986175579873, 28.89421695078809904,
-30.1383659011730991, 24.11946778830730054, -14.83391445199539938, 6.983088767267210173, -2.48964120264876998,
0.6593243603602499947, -0.125493534558034997, 0.01620971672896159843, -0.001271267679036929953, 4.567178653294529745e-05,
// log K = 5
0.9947713741300230339, 0.3326559581620939787, 0.1250050661634889981, -0.04130073804472530336, -0.2584095537451129854,
1.218050389433120051, -4.319106696095399656, 10.87175052045090062, -20.0184979022142997, 27.63210188163320069,
-28.97950009664030091, 23.26740804691930009, -14.33375703270860058, 6.751281271241110105, -2.406363094133439962,
0.6367414734718820357, -0.1210468076141379967, 0.01561196698118279963, -0.001222335432128580056, 4.383502970318410206e-05,
// log K = 6
0.9973904854982870161, 0.3330148852217920119, 0.125251536589509993, -0.04434075124043219962, -0.2436238890691720116,
1.163293254754570016, -4.177758779777369647, 10.60301981340099964, -19.6274507428828997, 27.18420839597660077,
-28.56827214174580121, 22.96268674086600114, -14.15234202220280046, 6.665700662642549901, -2.375043356720739851,
0.6280993991240929608, -0.119319019358031006, 0.01537674055733759954, -0.001202881695730769916, 4.309894633186929849e-05,
// log K = 7
0.9986963310058679655, 0.3331956705633329907, 0.125337696770523005, -0.04546817338088020299, -0.2386752211125199863,
1.145927328111949972, -4.135694445582720036, 10.52805060502839929, -19.52408322548339825, 27.06921653903929936,
-28.46207532143190022, 22.88083524357429965, -14.10057147392659971, 6.63958754983273991, -2.364865219283200037,
0.6251341806425250169, -0.1186991327450530043, 0.0152892726403408008, -0.001195439764873199896, 4.281098416794090072e-05,
// log K = 8
0.999348600452531044, 0.3332480372393080148, 0.126666900963325002, -0.06495714694254159371, -0.08376282050638980681,
0.3760158094643630267, -1.568204791601850001, 4.483117719555970382, -9.119180124379150598, 13.65799293358900002,
-15.3100211234349004, 12.97546344654869976, -8.351661538536939489, 4.075022612435580172, -1.49387015887069996,
0.4040976870253379927, -0.07813232681879349328, 0.01020545649538820085, -0.0008063279210812720381, 2.909334976414100078e-05,
// log K = 9
0.9996743787297059924, 0.3332925779481850093, 0.1267124599259649986, -0.06550452970936600228, -0.08191738117533520214,
0.3773034458363569987, -1.604679509609959975, 4.636761898691969641, -9.487348609558699408, 14.25164235443030059,
-15.99674955529870068, 13.56353219046370029, -8.730194904342459594, 4.259010067932120336, -1.56106689792022002,
0.4222540912786589828, -0.08165296504921559784, 0.01066878484925220041, -0.0008433887618256910015, 3.045339724886519912e-05,
// log K = 10
0.999837191783945034, 0.3333142252339619804, 0.1267759538087240012, -0.06631005632753710077, -0.07692759158286699428,
0.3568943956395980166, -1.546598721379510044, 4.51595019978557044, -9.298431968763770428, 14.02586858080080034,
-15.78858959520439953, 13.41484931677589998, -8.647958125130809748, 4.22398017468472009, -1.549708891200570093,
0.419507410264540026, -0.08117411611046250475, 0.01061202286184199928, -0.000839300527596772007, 3.03185874520205985e-05,
// log K = 11
0.9999186020796150265, 0.3333249054574359826, 0.126791713589799987, -0.06662487271699729652, -0.07335552427910230211,
0.3316370184815959909, -1.434143797561290068, 4.180260309967409604, -8.593906870708760692, 12.95088874800289958,
-14.56876092520539956, 12.37074367531410068, -7.969152075707960137, 3.888774396648960074, -1.424923326506990051,
0.385084561785229984, -0.07435541911616409816, 0.009695363567476529554, -0.0007644375960047160388, 2.75156194717188011e-05,
// log K = 12
0.9999592955649559967, 0.3333310560725140093, 0.1267379744020450116, -0.06524495415766619344, -0.08854031542298740343,
0.4244320628874230228, -1.794077789033230008, 5.133875262768450298, -10.40149374917120007, 15.47808115629240078,
-17.2272296137545986, 14.5002173676463002, -9.274819801602760094, 4.500782540026570189, -1.642359389030050076,
0.442596113445525019, -0.0853226219238850947, 0.01111969379054169975, -0.0008771614088006969611, 3.161668519459719752e-05,
// log K = 13
0.9999796468102559732, 0.3333336602394039727, 0.126728089053198989, -0.06503798598282370391, -0.09050261023823169548,
0.4350609244189960201, -1.831274835815670077, 5.223387516985289913, -10.55574395269979959, 15.67359470222429962,
-17.41263416341029924, 14.63297400889229927, -9.346752431221359458, 4.530124905188380069, -1.651245566462089975,
0.444542549250713015, -0.08561720963336499901, 0.01114805146185449992, -0.0008786251203363140043, 3.16416341644572998e-05,
// log K = 14
0.9999898187060970445, 0.3333362579300819806, 0.1266984078369459976, -0.06464561179765909715, -0.09343280886228019777,
0.4490702549264070087, -1.878087608052450008, 5.338004322057390283, -10.76690603590630069, 15.97069195083200022,
-17.73440379943459888, 14.90212518309260048, -9.520506013770420495, 4.616238931978830173, -1.68364817877918993,
0.4536194960681350086, -0.087448605434800597, 0.01139929991331390009, -0.0008995891451622229631, 3.244407259782900338e-05,
// log K = 15
0.9999949072549390028, 0.3333376334705290267, 0.126665364358402005, -0.06411790034705669439, -0.09776009134670660128,
0.4704691112248470253, -1.948021675295769972, 5.497760972696490001, -11.03165645315390009, 16.29703330781000048,
-18.03851029448010124, 15.11836776139680083, -9.638205179917429533, 4.665122328753120051, -1.698980686525759953,
0.4571799506245269873, -0.08804011353783609828, 0.01146553155965330043, -0.0009040455800659569869, 3.257931866957050274e-05,
// log K = 16
0.9999974544793589493, 0.3333381337614599871, 0.1266524862971120102, -0.06391676499117690535, -0.09929616211306059592,
0.4771390820378790254, -1.965762451227349938, 5.526802350376460282, -11.05703067024660058, 16.29535848023060041,
-18.00114005075790047, 15.06214012231560062, -9.58874727382628933, 4.63537541652793017, -1.686222848555620102,
0.4532602373715179933, -0.08719448925964939923, 0.01134365425717459921, -0.0008934965241274289835, 3.216436244471380105e-05,
// log K = 17
0.9999987278278800185, 0.3333383411464330148, 0.126642761751724009, -0.06371042959073920653, -0.1013564516034080043,
0.4891311195679299839, -2.010971712051409899, 5.644390807952309963, -11.27697253921500042, 16.59957157207080058,
-18.31808338317799922, 15.31363518393730061, -9.741451446816620674, 4.706207545519429658, -1.711102469010010063,
0.4597587341089349744, -0.08841670767182820134, 0.01149999225097850068, -0.0009056651366963050422, 3.259910736274500059e-05,
// log K = 18
0.9999993637727100371, 0.3333385511608860097, 0.1266341580529160016, -0.06353272828164230335, -0.103139962850642003,
0.4996216017206500104, -2.05099128585287982, 5.749874086531799655, -11.47727638570349917, 16.88141587810320132,
-18.61744656177490143, 15.55634230427719977, -9.892350736128680211, 4.778033520984200422, -1.737045483861280104,
0.4667410882683730167, -0.08977256212421590165, 0.01167940146667079994, -0.0009201381242396030127, 3.313600701586759867e-05,
// log K = 19
0.9999996805376010212, 0.3333372324328989778, 0.1267104737214659882, -0.06504749929326139601, -0.0882341962464350954,
0.4131871162041140244, -1.725190703567099915, 4.900817515593920426, -9.883452720776510603, 14.6657081190816001,
-16.29398295135089825, 13.69805011761319946, -8.753475239465899449, 4.244072374564439976, -1.547202527706629915,
0.4164770109614310267, -0.08017596922092029565, 0.01043146101701039954, -0.00082124200571200305, 2.953319493719429935e-05,
// log K = 20
0.9999998390037539986, 0.3333365859956040067, 0.1267460211029839967, -0.06569456024647769843, -0.0823070353477164951,
0.3810826463303410017, -1.611983580241109992, 4.624520077758210057, -9.397308335633589138, 14.03184981378050011,
-15.6703191315401007, 13.22992718704790072, -8.484216393184780713, 4.125607133488029987, -1.507690650697159906,
0.4066678517577320129, -0.07842110121777939868, 0.01021780862225150042, -0.0008054065857047439754, 2.899431830426989844e-05,
// log K = 21
0.9999999207001479817, 0.3333384953015239849, 0.1266331480396669928, -0.06345750166298599892, -0.1042341210992499961,
0.5077112908497130039, -2.087398133609810191, 5.858842546192500222, -11.70620319777190055, 17.23103975433669888,
-19.01462552846669851, 15.89674059836560005, -10.11395134034419918, 4.88760796465891989, -1.777886770904629987,
0.4780200178339499839, -0.09200895321782050218, 0.01198029553244219989, -0.0009447283875782100165, 3.405716775824710232e-05,
// log K = 22
0.9999999606908690497, 0.3333383929524300071, 0.1266456445096819927, -0.06373504294081690225, -0.1012834291081849969,
0.4893810690172959998, -2.01391428223606983, 5.656430437473649597, -11.3067201537791, 16.64980594135310099,
-18.3792355790383013, 15.36879753115040081, -9.778831246425049528, 4.725308061988969577, -1.718423596500280093,
0.4618308177809870019, -0.08883675060799739454, 0.01155766944804260087, -0.0009104695617243750358, 3.278237729674439666e-05,
// log K = 23
0.9999999794683379628, 0.3333386441751680085, 0.1266463995182049995, -0.06376031920455070556, -0.1010799540803130059,
0.488540137426137, -2.012048323537570127, 5.654949475342659682, -11.31023240892979942, 16.66334675284959843,
-18.40241452866079896, 15.39443572867130072, -9.798844412838670692, 4.736683907539640082, -1.723168363744929987,
0.463270349018644001, -0.08914619066708899531, 0.01160235936257320022, -0.0009143600818183229709, 3.293669304679140117e-05,
// log K = 24
0.9999999911469820146, 0.3333376076934529975, 0.1266944349940530012, -0.06470524278387919381, -0.09189342220283110152,
0.4359182372694809793, -1.815980282951169977, 5.149474056470340066, -10.37086570678100017, 15.36962686758569951,
-17.05756384717849983, 14.32755177515199918, -9.149944050025640152, 4.434601894497260055, -1.616478926806520056,
0.4351979157055039793, -0.08381768225272340223, 0.01091321820476520016, -0.0008600264403629039739, 3.09667800347144002e-05,
// log K = 25
0.9999999968592140354, 0.3333379164881000167, 0.1266782495827009913, -0.06434163088961859789, -0.09575258124988890451,
0.4597843575354370049, -1.911374431241559924, 5.411856661251520428, -10.88850084646090011, 16.12298941380269923,
-17.88172178487259956, 15.01301780636859995, -9.585542896142529301, 4.645811872761620442, -1.693952293156189892,
0.4563143308861309921, -0.08795976148455289523, 0.01146560428011200033, -0.0009048442931930629528, 3.26358391497329992e-05,
// log K = 26
0.9999999970700530483, 0.333338329556315982, 0.126644753076394001, -0.06372365346512399997, -0.1012760856945769949,
0.4886852278576360176, -2.009005418394389952, 5.638119224137019714, -11.26276715335160006, 16.57640024218650154,
-18.29035093605569884, 15.28892246224570073, -9.724916375991760731, 4.6978877652334603, -1.707974125916829955,
0.4588937864564729963, -0.08824617586088029375, 0.01147732114826570046, -0.00090384524860747295, 3.253252703695579795e-05,
};
//CHECKSTYLE.ON: LineLength
}
| 2,748 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/IconEstimator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.cpc.CpcUtil.maxLgK;
import static org.apache.datasketches.cpc.CpcUtil.minLgK;
import static org.apache.datasketches.cpc.IconPolynomialCoefficients.iconPolynomialCoefficents;
import static org.apache.datasketches.cpc.IconPolynomialCoefficients.iconPolynomialNumCoefficients;
/**
* The ICON estimator for CPC sketches is defined by the arXiv paper.
*
* <p>The current file provides exact and approximate implementations of this estimator.
*
* <p>The exact version works for any value of K, but is quite slow.
*
* <p>The much faster approximate version works for K values that are powers of two
* ranging from 2^4 to 2^32.
*
* <p>At a high-level, this approximation can be described as using an
* exponential approximation when C > K * (5.6 or 5.7), while smaller
* values of C are handled by a degree-19 polynomial approximation of
* a pre-conditioned version of the true ICON mapping from C to N_hat.
*
* <p>This file also provides a validation procedure that compares its approximate
* and exact implementations of the CPC ICON estimator.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
final class IconEstimator {
static double evaluatePolynomial(final double[] coefficients, final int start, final int num,
final double x) {
final int end = (start + num) - 1;
double total = coefficients[end];
for (int j = end - 1; j >= start; j--) {
total *= x;
total += coefficients[j];
}
return total;
}
static double iconExponentialApproximation(final double k, final double c) {
return (0.7940236163830469 * k * Math.pow(2.0, c / k));
}
static double getIconEstimate(final int lgK, final long c) {
assert lgK >= minLgK;
assert lgK <= maxLgK;
if (c < 2L) { return ((c == 0L) ? 0.0 : 1.0); }
final int k = 1 << lgK;
final double doubleK = k;
final double doubleC = c;
// Differing thresholds ensure that the approximated estimator is monotonically increasing.
final double thresholdFactor = ((lgK < 14) ? 5.7 : 5.6);
if (doubleC > (thresholdFactor * doubleK)) {
return (iconExponentialApproximation(doubleK, doubleC));
}
final double factor = evaluatePolynomial(iconPolynomialCoefficents,
iconPolynomialNumCoefficients * (lgK - minLgK),
iconPolynomialNumCoefficients,
// The constant 2.0 is baked into the table iconPolynomialCoefficents[].
// This factor, although somewhat arbitrary, is based on extensive characterization studies
// and is considered a safe conservative factor.
doubleC / (2.0 * doubleK));
final double ratio = doubleC / doubleK;
// The constant 66.774757 is baked into the table iconPolynomialCoefficents[].
// This factor, although somewhat arbitrary, is based on extensive characterization studies
// and is considered a safe conservative factor.
final double term = 1.0 + ((ratio * ratio * ratio) / 66.774757);
final double result = doubleC * factor * term;
return (result >= doubleC) ? result : doubleC;
}
}
| 2,749 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/PreambleUtil.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.cpc;
import static org.apache.datasketches.common.Util.checkBounds;
import static org.apache.datasketches.common.Util.zeroPad;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssert;
import static org.apache.datasketches.cpc.RuntimeAsserts.rtAssertEquals;
import java.nio.ByteOrder;
import java.util.Objects;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesStateException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
//@formatter:off
/**
* All formats are illustrated as Big-Endian, LSB on the right.
*
* <pre>
* Format = EMPTY_MERGED/EMPTY_HIP: NoWindow, NoSV, HIP or NoHIP = 00X.
* The first 8 bytes are common for all Formats.
* PI = 2, FIcol = 0
* Long adr ||
* || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* 0 ||---SEED HASH-----|-Flags--|-FIcol--|---lgK--|-FamID--|-SerVer-|---PI---|
*
*
* Format = SPARSE_HYBRID_MERGED: {NoWindow, SV, NoHIP} = 2 = 010.
* PI = 4, FIcol = 0
* Long adr ||
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||-------------SV Length Ints--------|--------numCoupons = numSV---------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 || |----------Start SV bit stream------|
*
*
* Format = SPARSE_HYBRID_HIP: {NoWindow, SV, HIP} = 3 = 011
* PI = 8, FIcol = 0
* Long adr ||
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||-------------SV Length Ints--------|--------numCoupons = numSV---------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||----------------------------------KxP----------------------------------|
*
* || 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 |
* 3 ||-------------------------------HIP Accum-------------------------------|
*
* || 39 | 38 | 37 | 36 | 35 | 34 | 33 | 32 |
* 4 || |----------Start of SV stream-------|
*
*
* Format = PINNED_SLIDING_MERGED_NOSV: {Window, No SV, NoHIP} = 4 = 100
* PI = 4, FIcol = valid
* Long adr ||
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||----------Window Length Ints-------|------------numCoupons-------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 || |--------Start of Window stream-----|
*
*
* Format = PINNED_SLIDING_HIP_NOSV: {Window, No SV, HIP} = 5 = 101
* PI = 8, FIcol = valid
* Long adr ||
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||----------Window Length Ints-------|------------numCoupons-------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||----------------------------------KxP----------------------------------|
*
* || 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 |
* 3 ||-------------------------------HIP Accum-------------------------------|
*
* || 39 | 38 | 37 | 36 | 35 | 34 | 33 | 32 |
* 4 || |--------Start of Window stream-----|
*
*
* Format = PINNED_SLIDING_MERGED: {Window, SV, NoHIP} = 6 = 110
* PI = 6, FIcol = valid
* Long adr ||
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||---------------numSV---------------|------------numCoupons-------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||----------Window Length Ints-------|-------------SV Length Ints--------|
*
* || XX | XX | XX | XX | 27 | 26 | 25 | 24 |
* 3 ||--------Start of SV stream---------|--------Start of Window stream-----|
*
*
* Format = PINNED_SLIDING_HIP: {Window, SV, HIP} = 7 = 111
* PI = 10, FIcol = valid
* Long adr ||
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||---------------numSV---------------|------------numCoupons-------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||----------------------------------KxP----------------------------------|
*
* || 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 |
* 3 ||-------------------------------HIP Accum-------------------------------|
*
* || 39 | 38 | 37 | 36 | 35 | 34 | 33 | 32 |
* 4 ||----------Window Length Ints-------|-------------SV Length Ints--------|
*
* || XX | XX | XX | XX | 43 | 42 | 41 | 40 |
* 5 ||--------Start of SV stream---------|--------Start of Window stream-----|
* </pre>
*
* @author Lee Rhodes
* @author Kevin Lang
*/
final class PreambleUtil {
private PreambleUtil() {}
static {
if (ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN) {
throw new SketchesStateException("This sketch will not work on Big Endian CPUs.");
}
}
private static final String LS = System.getProperty("line.separator");
private static final String fmt = "%10d%10x";
/**
* The serialization version for the set of serialization formats defined in this class
*/
static final byte SER_VER = 1;
//Flag bit masks, Byte 5
static final int BIG_ENDIAN_FLAG_MASK = 1; //Reserved.
static final int COMPRESSED_FLAG_MASK = 2;
static final int HIP_FLAG_MASK = 4;
static final int SUP_VAL_FLAG_MASK = 8; //num Suprising Values > 0
static final int WINDOW_FLAG_MASK = 16;//window length > 0
//PREAMBLE SIZE
/**
* This defines the preamble space required by each of the formats in units of 4-byte integers.
*/
private static final byte[] preIntDefs = { 2, 2, 4, 8, 4, 8, 6, 10 };
/**
* Returns the defined size of the preamble in units of integers (4 bytes) given the
* <i>Format</i>.
* @param format the given <i>Format</i>.
* @return the defined size of the preamble in units of integers (4 bytes) given the <i>Format</i>.
*/
static byte getDefinedPreInts(final Format format) {
return preIntDefs[format.ordinal()];
}
//PREAMBLE LO_FIELD DEFINITIONS, OFFSETS, AND GETS
/**
* This defines the seven fields of the first eight bytes of the preamble.
* The ordinal of these values defines the byte offset.
* Do not change the order.
*/
enum LoField { PRE_INTS, SER_VERSION, FAMILY, LG_K, FI_COL, FLAGS, SEED_HASH }
/**
* Returns the defined byte offset from the start of the preamble given a <i>LoField</i>.
* This only applies to the first 8 bytes of the preamble.
* @param loField the given <i>LoField</i>.
* @return the defined byte offset from the start of the preamble given a <i>LoField</i>.
*/
static int getLoFieldOffset(final LoField loField) {
return loField.ordinal();
}
static int getPreInts(final Memory mem) {
return mem.getByte(getLoFieldOffset(LoField.PRE_INTS)) & 0XFF;
}
static int getSerVer(final Memory mem) {
return mem.getByte(getLoFieldOffset(LoField.SER_VERSION)) & 0XFF;
}
static Family getFamily(final Memory mem) {
final int fam = mem.getByte(getLoFieldOffset(LoField.FAMILY)) & 0XFF;
return Family.idToFamily(fam);
}
static int getLgK(final Memory mem) {
return mem.getByte(getLoFieldOffset(LoField.LG_K)) & 0XFF;
}
static int getFiCol(final Memory mem) {
return mem.getByte(getLoFieldOffset(LoField.FI_COL)) & 0XFF;
}
static int getFlags(final Memory mem) {
return mem.getByte(getLoFieldOffset(LoField.FLAGS)) & 0XFF;
}
static short getSeedHash(final Memory mem) {
return mem.getShort(getLoFieldOffset(LoField.SEED_HASH));
}
static int getFormatOrdinal(final Memory mem) {
final int flags = getFlags(mem);
return (flags >>> 2) & 0x7;
}
static Format getFormat(final Memory mem) {
final int ordinal = getFormatOrdinal(mem);
return Format.ordinalToFormat(ordinal);
}
static boolean hasHip(final Memory mem) {
return (getFlags(mem) & HIP_FLAG_MASK) > 0;
}
static final boolean hasSv(final Memory mem) {
return (getFlags(mem) & SUP_VAL_FLAG_MASK) > 0;
}
static final boolean hasWindow(final Memory mem) {
return (getFlags(mem) & WINDOW_FLAG_MASK) > 0;
}
static final boolean isCompressed(final Memory mem) {
return (getFlags(mem) & COMPRESSED_FLAG_MASK) > 0;
}
//PREAMBLE HI_FIELD DEFINITIONS
/**
* This defines the eight additional preamble fields located after the <i>LoField</i>.
* Do not change the order.
*
* <p>Note: NUM_SV has dual meanings: In sparse and hybrid flavors it is equivalent to
* numCoupons so it isn't stored separately. In pinned and sliding flavors is is the
* numSV of the PairTable, which stores only surprising values.</p>
*/
enum HiField { NUM_COUPONS, NUM_SV, KXP, HIP_ACCUM, SV_LENGTH_INTS, W_LENGTH_INTS, SV_STREAM,
W_STREAM }
//PREAMBLE HI_FIELD OFFSETS
/**
* This defines the byte offset for eac of the 8 <i>HiFields</i>
* given the Format ordinal (1st dimension) and the HiField ordinal (2nd dimension).
*/
private static final byte[][] hiFieldOffset = //[Format][HiField]
{ {0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{8, 0, 0, 0, 12, 0, 16, 0},
{8, 0, 16, 24, 12, 0, 32, 0},
{8, 0, 0, 0, 0, 12, 0, 16},
{8, 0, 16, 24, 0, 12, 0, 32},
{8, 12, 0, 0, 16, 20, 24, 24}, //the 2nd 24 is not used.
{8, 12, 16, 24, 32, 36, 40, 40} //the 2nd 40 is not used.
};
/**
* Returns the defined byte offset from the start of the preamble given the <i>HiField</i>
* and the <i>Format</i>.
* Note this can not be used to obtain the stream offsets.
* @param format the desired <i>Format</i>
* @param hiField the desired preamble <i>HiField</i> after the first eight bytes.
* @return the defined byte offset from the start of the preamble for the given <i>HiField</i>
* and the <i>Format</i>.
*/
static long getHiFieldOffset(final Format format, final HiField hiField) {
final int formatIdx = format.ordinal();
final int hiFieldIdx = hiField.ordinal();
final long fieldOffset = hiFieldOffset[formatIdx][hiFieldIdx] & 0xFF; //initially a byte
if (fieldOffset == 0) {
throw new SketchesStateException("Undefined preamble field given the Format: "
+ "Format: " + format.toString() + ", HiField: " + hiField.toString());
}
return fieldOffset;
}
//PREAMBLE HI_FIELD GETS
static int getNumCoupons(final Memory mem) {
final Format format = getFormat(mem);
final HiField hiField = HiField.NUM_COUPONS;
final long offset = getHiFieldOffset(format, hiField);
return mem.getInt(offset);
}
static int getNumSv(final Memory mem) {
final Format format = getFormat(mem);
final HiField hiField = HiField.NUM_SV;
final long offset = getHiFieldOffset(format, hiField);
return mem.getInt(offset);
}
static int getSvLengthInts(final Memory mem) {
final Format format = getFormat(mem);
final HiField hiField = HiField.SV_LENGTH_INTS;
final long offset = getHiFieldOffset(format, hiField);
return mem.getInt(offset);
}
static int getWLengthInts(final Memory mem) {
final Format format = getFormat(mem);
final HiField hiField = HiField.W_LENGTH_INTS;
final long offset = getHiFieldOffset(format, hiField);
return mem.getInt(offset);
}
static double getKxP(final Memory mem) {
final Format format = getFormat(mem);
final HiField hiField = HiField.KXP;
final long offset = getHiFieldOffset(format, hiField);
return mem.getDouble(offset);
}
static double getHipAccum(final Memory mem) {
final Format format = getFormat(mem);
final HiField hiField = HiField.HIP_ACCUM;
final long offset = getHiFieldOffset(format, hiField);
return mem.getDouble(offset);
}
static long getSvStreamOffset(final Memory mem) {
final Format format = getFormat(mem);
final HiField svLenField = HiField.SV_LENGTH_INTS;
if (!hasSv(mem)) {
fieldError(format, svLenField);
} else {
final long svLengthInts = mem.getInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS)) & 0XFFFF_FFFFL;
if (svLengthInts == 0) {
throw new SketchesStateException("svLengthInts cannot be zero");
}
}
long wLengthInts = 0;
if (hasWindow(mem)) {
wLengthInts = mem.getInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS)) & 0XFFFF_FFFFL;
if (wLengthInts == 0) {
throw new SketchesStateException("wLengthInts cannot be zero");
}
}
return (getPreInts(mem) + wLengthInts) << 2;
}
static long getWStreamOffset(final Memory mem) {
final Format format = getFormat(mem);
final HiField wLenField = HiField.W_LENGTH_INTS;
if (!hasWindow(mem)) { fieldError(format, wLenField); }
final long wLengthInts = mem.getInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS)) & 0XFFFF_FFFFL;
if (wLengthInts == 0) {
throw new SketchesStateException("wLengthInts cannot be zero");
}
return getPreInts(mem) << 2;
}
static int[] getSvStream(final Memory mem) {
final long offset = getSvStreamOffset(mem);
final int svLengthInts = getSvLengthInts(mem);
final int[] svStream = new int[svLengthInts];
mem.getIntArray(offset, svStream, 0, svLengthInts);
return svStream;
}
static int[] getWStream(final Memory mem) {
final long offset = getWStreamOffset(mem);
final int wLength = getWLengthInts(mem);
final int[] wStream = new int[wLength];
mem.getIntArray(offset, wStream, 0, wLength);
return wStream;
}
// PUT INTO MEMORY
static void putEmptyMerged(final WritableMemory wmem,
final int lgK,
final short seedHash) {
final Format format = Format.EMPTY_MERGED;
final byte preInts = getDefinedPreInts(format);
final byte fiCol = (byte) 0;
final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
checkCapacity(wmem.getCapacity(), 8);
putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash);
}
static void putEmptyHip(final WritableMemory wmem,
final int lgK,
final short seedHash) {
final Format format = Format.EMPTY_HIP;
final byte preInts = getDefinedPreInts(format);
final byte fiCol = (byte) 0;
final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
checkCapacity(wmem.getCapacity(), 8);
putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash);
}
static void putSparseHybridMerged(final WritableMemory wmem,
final int lgK,
final int numCoupons, //unsigned
final int svLengthInts,
final short seedHash,
final int[] svStream) {
final Format format = Format.SPARSE_HYBRID_MERGED;
final byte preInts = getDefinedPreInts(format);
final byte fiCol = (byte) 0;
final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
checkCapacity(wmem.getCapacity(), 4L * (preInts + svLengthInts));
putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash);
wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
wmem.putInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS), svLengthInts);
wmem.putIntArray(getSvStreamOffset(wmem), svStream, 0, svLengthInts);
}
static void putSparseHybridHip(final WritableMemory wmem,
final int lgK,
final int numCoupons, //unsigned
final int svLengthInts,
final double kxp,
final double hipAccum,
final short seedHash,
final int[] svStream) {
final Format format = Format.SPARSE_HYBRID_HIP;
final byte preInts = getDefinedPreInts(format);
final byte fiCol = (byte) 0;
final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
checkCapacity(wmem.getCapacity(), 4L * (preInts + svLengthInts));
putFirst8(wmem, preInts, (byte) lgK, fiCol, flags, seedHash);
wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
wmem.putInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS), svLengthInts);
wmem.putDouble(getHiFieldOffset(format, HiField.KXP), kxp);
wmem.putDouble(getHiFieldOffset(format, HiField.HIP_ACCUM), hipAccum);
wmem.putIntArray(getSvStreamOffset(wmem), svStream, 0, svLengthInts);
}
static void putPinnedSlidingMergedNoSv(final WritableMemory wmem,
final int lgK,
final int fiCol,
final int numCoupons, //unsigned
final int wLengthInts,
final short seedHash,
final int[] wStream) {
final Format format = Format.PINNED_SLIDING_MERGED_NOSV;
final byte preInts = getDefinedPreInts(format);
final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
checkCapacity(wmem.getCapacity(), 4L * (preInts + wLengthInts));
putFirst8(wmem, preInts, (byte) lgK, (byte) fiCol, flags, seedHash);
wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
wmem.putInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS), wLengthInts);
wmem.putIntArray(getWStreamOffset(wmem), wStream, 0, wLengthInts);
}
static void putPinnedSlidingHipNoSv(final WritableMemory wmem,
final int lgK,
final int fiCol,
final int numCoupons, //unsigned
final int wLengthInts,
final double kxp,
final double hipAccum,
final short seedHash,
final int[] wStream) {
final Format format = Format.PINNED_SLIDING_HIP_NOSV;
final byte preInts = getDefinedPreInts(format);
final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
checkCapacity(wmem.getCapacity(), 4L * (preInts + wLengthInts));
putFirst8(wmem, preInts, (byte) lgK, (byte) fiCol, flags, seedHash);
wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
wmem.putInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS), wLengthInts);
wmem.putDouble(getHiFieldOffset(format, HiField.KXP), kxp);
wmem.putDouble(getHiFieldOffset(format, HiField.HIP_ACCUM), hipAccum);
wmem.putIntArray(getWStreamOffset(wmem), wStream, 0, wLengthInts);
}
static void putPinnedSlidingMerged(final WritableMemory wmem,
final int lgK,
final int fiCol,
final int numCoupons, //unsigned
final int numSv,
final int svLengthInts,
final int wLengthInts,
final short seedHash,
final int[] svStream,
final int[] wStream) {
final Format format = Format.PINNED_SLIDING_MERGED;
final byte preInts = getDefinedPreInts(format);
final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
checkCapacity(wmem.getCapacity(), 4L * (preInts + svLengthInts + wLengthInts));
putFirst8(wmem, preInts, (byte) lgK, (byte) fiCol, flags, seedHash);
wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
wmem.putInt(getHiFieldOffset(format, HiField.NUM_SV), numSv);
wmem.putInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS), svLengthInts);
wmem.putInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS), wLengthInts);
wmem.putIntArray(getSvStreamOffset(wmem), svStream, 0, svLengthInts);
wmem.putIntArray(getWStreamOffset(wmem), wStream, 0, wLengthInts);
}
static void putPinnedSlidingHip(final WritableMemory wmem,
final int lgK,
final int fiCol,
final int numCoupons, //unsigned
final int numSv,
final double kxp,
final double hipAccum,
final int svLengthInts,
final int wLengthInts,
final short seedHash,
final int[] svStream,
final int[] wStream) {
final Format format = Format.PINNED_SLIDING_HIP;
final byte preInts = getDefinedPreInts(format);
final byte flags = (byte) ((format.ordinal() << 2) | COMPRESSED_FLAG_MASK);
checkCapacity(wmem.getCapacity(), 4L * (preInts + svLengthInts + wLengthInts));
putFirst8(wmem, preInts, (byte) lgK, (byte) fiCol, flags, seedHash);
wmem.putInt(getHiFieldOffset(format, HiField.NUM_COUPONS), numCoupons);
wmem.putInt(getHiFieldOffset(format, HiField.NUM_SV), numSv);
wmem.putDouble(getHiFieldOffset(format, HiField.KXP), kxp);
wmem.putDouble(getHiFieldOffset(format, HiField.HIP_ACCUM), hipAccum);
wmem.putInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS), svLengthInts);
wmem.putInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS), wLengthInts);
wmem.putIntArray(getSvStreamOffset(wmem), svStream, 0, svLengthInts);
wmem.putIntArray(getWStreamOffset(wmem), wStream, 0, wLengthInts);
}
private static void putFirst8(final WritableMemory wmem, final byte preInts, final byte lgK,
final byte fiCol, final byte flags, final short seedHash) {
wmem.clear(0L, 4L * preInts);
wmem.putByte(getLoFieldOffset(LoField.PRE_INTS), preInts);
wmem.putByte(getLoFieldOffset(LoField.SER_VERSION), SER_VER);
wmem.putByte(getLoFieldOffset(LoField.FAMILY), (byte) Family.CPC.getID());
wmem.putByte(getLoFieldOffset(LoField.LG_K), lgK);
wmem.putByte(getLoFieldOffset(LoField.FI_COL), fiCol);
wmem.putByte(getLoFieldOffset(LoField.FLAGS), flags);
wmem.putShort(getLoFieldOffset(LoField.SEED_HASH), seedHash);
}
//TO STRING
static String toString(final byte[] byteArr, final boolean detail) {
final Memory mem = Memory.wrap(byteArr);
return toString(mem, detail);
}
static String toString(final Memory mem, final boolean detail) {
final long capBytes = mem.getCapacity();
//Lo Fields Preamble, first 7 fields, first 8 bytes
final int preInts = mem.getByte(getLoFieldOffset(LoField.PRE_INTS)) & 0xFF;
final int serVer = mem.getByte(getLoFieldOffset(LoField.SER_VERSION)) & 0xFF;
final Family family = Family.idToFamily(mem.getByte(getLoFieldOffset(LoField.FAMILY)) & 0xFF);
final int lgK = mem.getByte(getLoFieldOffset(LoField.LG_K)) & 0xFF;
final int fiCol = mem.getByte(getLoFieldOffset(LoField.FI_COL)) & 0xFF;
final int flags = mem.getByte(getLoFieldOffset(LoField.FLAGS)) & 0XFF;
final int seedHash = mem.getShort(getLoFieldOffset(LoField.SEED_HASH)) & 0XFFFF;
final String seedHashStr = Integer.toHexString(seedHash);
//Flags of the Flags byte
final String flagsStr = zeroPad(Integer.toBinaryString(flags), 8) + ", " + (flags);
final boolean bigEndian = (flags & BIG_ENDIAN_FLAG_MASK) > 0;
final boolean compressed = (flags & COMPRESSED_FLAG_MASK) > 0;
final boolean hasHip = (flags & HIP_FLAG_MASK) > 0;
final boolean hasSV = (flags & SUP_VAL_FLAG_MASK) > 0;
final boolean hasWindow = (flags & WINDOW_FLAG_MASK) > 0;
final int formatOrdinal = (flags >>> 2) & 0x7;
final Format format = Format.ordinalToFormat(formatOrdinal);
final String nativeOrderStr = ByteOrder.nativeOrder().toString();
long numCoupons = 0;
long numSv = 0;
long winOffset = 0;
long svLengthInts = 0;
long wLengthInts = 0;
double kxp = 0;
double hipAccum = 0;
long svStreamStart = 0;
long wStreamStart = 0;
long reqBytes = 0;
final StringBuilder sb = new StringBuilder();
sb.append(LS);
sb.append("### CPC SKETCH IMAGE - PREAMBLE:").append(LS);
sb.append("Format : ").append(format.name()).append(LS);
sb.append("Byte 0: Preamble Ints : ").append(preInts).append(LS);
sb.append("Byte 1: SerVer : ").append(serVer).append(LS);
sb.append("Byte 2: Family : ").append(family).append(LS);
sb.append("Byte 3: lgK : ").append(lgK).append(LS);
sb.append("Byte 4: First Interesting Col : ").append(fiCol).append(LS);
sb.append("Byte 5: Flags : ").append(flagsStr).append(LS);
sb.append(" BIG_ENDIAN_STORAGE : ").append(bigEndian).append(LS);
sb.append(" (Native Byte Order) : ").append(nativeOrderStr).append(LS);
sb.append(" Compressed : ").append(compressed).append(LS);
sb.append(" Has HIP : ").append(hasHip).append(LS);
sb.append(" Has Surprising Values : ").append(hasSV).append(LS);
sb.append(" Has Window Values : ").append(hasWindow).append(LS);
sb.append("Byte 6, 7: Seed Hash : ").append(seedHashStr).append(LS);
final Flavor flavor;
switch (format) {
case EMPTY_MERGED :
case EMPTY_HIP : {
flavor = CpcUtil.determineFlavor(lgK, numCoupons);
sb.append("Flavor : ").append(flavor).append(LS);
break;
}
case SPARSE_HYBRID_MERGED : {
numCoupons = mem.getInt(getHiFieldOffset(format, HiField.NUM_COUPONS)) & 0xFFFF_FFFFL;
numSv = numCoupons;
svLengthInts = mem.getInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS)) & 0xFFFF_FFFFL;
svStreamStart = getSvStreamOffset(mem);
reqBytes = svStreamStart + (svLengthInts << 2);
flavor = CpcUtil.determineFlavor(lgK, numCoupons);
sb.append("Flavor : ").append(flavor).append(LS);
sb.append("Num Coupons : ").append(numCoupons).append(LS);
sb.append("Num SV : ").append(numSv).append(LS);
sb.append("SV Length Ints : ").append(svLengthInts).append(LS);
sb.append("SV Stream Start : ").append(svStreamStart).append(LS);
break;
}
case SPARSE_HYBRID_HIP : {
numCoupons = mem.getInt(getHiFieldOffset(format, HiField.NUM_COUPONS)) & 0xFFFF_FFFFL;
numSv = numCoupons;
svLengthInts = mem.getInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS)) & 0xFFFF_FFFFL;
svStreamStart = getSvStreamOffset(mem);
kxp = mem.getDouble(getHiFieldOffset(format, HiField.KXP));
hipAccum = mem.getDouble(getHiFieldOffset(format, HiField.HIP_ACCUM));
reqBytes = svStreamStart + (svLengthInts << 2);
flavor = CpcUtil.determineFlavor(lgK, numCoupons);
sb.append("Flavor : ").append(flavor).append(LS);
sb.append("Num Coupons : ").append(numCoupons).append(LS);
sb.append("Num SV : ").append(numSv).append(LS);
sb.append("SV Length Ints : ").append(svLengthInts).append(LS);
sb.append("SV Stream Start : ").append(svStreamStart).append(LS);
sb.append("KxP : ").append(kxp).append(LS);
sb.append("HipAccum : ").append(hipAccum).append(LS);
break;
}
case PINNED_SLIDING_MERGED_NOSV : {
numCoupons = mem.getInt(getHiFieldOffset(format, HiField.NUM_COUPONS)) & 0xFFFF_FFFFL;
winOffset = CpcUtil.determineCorrectOffset(lgK, numCoupons);
wLengthInts = mem.getInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS)) & 0xFFFF_FFFFL;
wStreamStart = getWStreamOffset(mem);
reqBytes = wStreamStart + (wLengthInts << 2);
flavor = CpcUtil.determineFlavor(lgK, numCoupons);
sb.append("Flavor : ").append(flavor).append(LS);
sb.append("Num Coupons : ").append(numCoupons).append(LS);
sb.append("Window Offset : ").append(winOffset).append(LS);
sb.append("Window Length Ints : ").append(wLengthInts).append(LS);
sb.append("Window Stream Start : ").append(wStreamStart).append(LS);
break;
}
case PINNED_SLIDING_HIP_NOSV : {
numCoupons = mem.getInt(getHiFieldOffset(format, HiField.NUM_COUPONS)) & 0xFFFF_FFFFL;
winOffset = CpcUtil.determineCorrectOffset(lgK, numCoupons);
wLengthInts = mem.getInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS)) & 0xFFFF_FFFFL;
wStreamStart = getWStreamOffset(mem);
kxp = mem.getDouble(getHiFieldOffset(format, HiField.KXP));
hipAccum = mem.getDouble(getHiFieldOffset(format, HiField.HIP_ACCUM));
reqBytes = wStreamStart + (wLengthInts << 2);
flavor = CpcUtil.determineFlavor(lgK, numCoupons);
sb.append("Flavor : ").append(flavor).append(LS);
sb.append("Num Coupons : ").append(numCoupons).append(LS);
sb.append("Window Offset : ").append(winOffset).append(LS);
sb.append("Window Length Ints : ").append(wLengthInts).append(LS);
sb.append("Window Stream Start : ").append(wStreamStart).append(LS);
sb.append("KxP : ").append(kxp).append(LS);
sb.append("HipAccum : ").append(hipAccum).append(LS);
break;
}
case PINNED_SLIDING_MERGED : {
numCoupons = mem.getInt(getHiFieldOffset(format, HiField.NUM_COUPONS) & 0xFFFF_FFFFL);
winOffset = CpcUtil.determineCorrectOffset(lgK, numCoupons);
wLengthInts = mem.getInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS)) & 0xFFFF_FFFFL;
numSv = mem.getInt(getHiFieldOffset(format, HiField.NUM_SV)) & 0xFFFF_FFFFL;
svLengthInts = mem.getInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS)) & 0xFFFF_FFFFL;
wStreamStart = getWStreamOffset(mem);
svStreamStart = getSvStreamOffset(mem);
reqBytes = svStreamStart + (svLengthInts << 2);
flavor = CpcUtil.determineFlavor(lgK, numCoupons);
sb.append("Flavor : ").append(flavor).append(LS);
sb.append("Num Coupons : ").append(numCoupons).append(LS);
sb.append("Num SV : ").append(numSv).append(LS);
sb.append("SV Length Ints : ").append(svLengthInts).append(LS);
sb.append("SV Stream Start : ").append(svStreamStart).append(LS);
sb.append("Window Offset : ").append(winOffset).append(LS);
sb.append("Window Length Ints : ").append(wLengthInts).append(LS);
sb.append("Window Stream Start : ").append(wStreamStart).append(LS);
break;
}
case PINNED_SLIDING_HIP : {
numCoupons = mem.getInt(getHiFieldOffset(format, HiField.NUM_COUPONS) & 0xFFFF_FFFFL);
winOffset = CpcUtil.determineCorrectOffset(lgK, numCoupons);
wLengthInts = mem.getInt(getHiFieldOffset(format, HiField.W_LENGTH_INTS)) & 0xFFFF_FFFFL;
numSv = mem.getInt(getHiFieldOffset(format, HiField.NUM_SV)) & 0xFFFF_FFFFL;
svLengthInts = mem.getInt(getHiFieldOffset(format, HiField.SV_LENGTH_INTS)) & 0xFFFF_FFFFL;
wStreamStart = getWStreamOffset(mem);
svStreamStart = getSvStreamOffset(mem);
kxp = mem.getDouble(getHiFieldOffset(format, HiField.KXP));
hipAccum = mem.getDouble(getHiFieldOffset(format, HiField.HIP_ACCUM));
reqBytes = svStreamStart + (svLengthInts << 2);
flavor = CpcUtil.determineFlavor(lgK, numCoupons);
sb.append("Flavor : ").append(flavor).append(LS);
sb.append("Num Coupons : ").append(numCoupons).append(LS);
sb.append("Num SV : ").append(numSv).append(LS);
sb.append("SV Length Ints : ").append(svLengthInts).append(LS);
sb.append("SV Stream Start : ").append(svStreamStart).append(LS);
sb.append("Window Offset : ").append(winOffset).append(LS);
sb.append("Window Length Ints : ").append(wLengthInts).append(LS);
sb.append("Window Stream Start : ").append(wStreamStart).append(LS);
sb.append("KxP : ").append(kxp).append(LS);
sb.append("HipAccum : ").append(hipAccum).append(LS);
break;
}
}
sb.append("Actual Bytes : ").append(capBytes).append(LS);
sb.append("Required Bytes : ").append(reqBytes).append(LS);
if (detail) {
sb.append(LS).append("### CPC SKETCH IMAGE - DATA").append(LS);
if (wLengthInts > 0) {
sb.append(LS).append("Window Stream:").append(LS);
listData(mem, wStreamStart, wLengthInts, sb);
}
if (svLengthInts > 0) {
sb.append(LS).append("SV Stream:").append(LS);
listData(mem, svStreamStart, svLengthInts, sb);
}
}
sb.append("### END CPC SKETCH IMAGE").append(LS);
return sb.toString();
} //end toString(mem)
private static void listData(final Memory mem, final long offsetBytes, final long lengthInts,
final StringBuilder sb) {
final long memCap = mem.getCapacity();
final long expectedCap = offsetBytes + (4L * lengthInts);
checkCapacity(memCap, expectedCap);
for (long i = 0; i < lengthInts; i++) {
sb.append(String.format(fmt, i, mem.getInt(offsetBytes + (4L * i)))).append(LS);
}
}
static void fieldError(final Format format, final HiField hiField) {
throw new SketchesArgumentException(
"Operation is illegal: Format = " + format.name() + ", HiField = " + hiField);
}
static void checkCapacity(final long memCap, final long expectedCap) {
if (memCap < expectedCap) {
throw new SketchesArgumentException(
"Insufficient Image Bytes = " + memCap + ", Expected = " + expectedCap);
}
}
//basic checks of SerVer, Format, preInts, Family, fiCol, lgK.
static void checkLoPreamble(final Memory mem) {
Objects.requireNonNull(mem, "Source Memory must not be null");
checkBounds(0, 8, mem.getCapacity()); //need min 8 bytes
rtAssertEquals(getSerVer(mem), SER_VER & 0XFF);
final Format fmat = getFormat(mem);
final int preIntsDef = getDefinedPreInts(fmat) & 0XFF;
rtAssertEquals(getPreInts(mem), preIntsDef);
final Family fam = getFamily(mem);
rtAssert(fam == Family.CPC);
final int lgK = getLgK(mem);
rtAssert((lgK >= 4) && (lgK <= 26));
final int fiCol = getFiCol(mem);
rtAssert((fiCol <= 63) && (fiCol >= 0));
}
}
//@formatter:on
| 2,750 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/cpc/package-info.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* Compressed Probabilistic Counting sketch family
*/
package org.apache.datasketches.cpc;
| 2,751 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/AnotBimpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Util.exactLog2OfLong;
import static org.apache.datasketches.thetacommon.HashOperations.convertToHashTable;
import static org.apache.datasketches.thetacommon.HashOperations.hashSearch;
import java.util.Arrays;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* Implements the A-and-not-B operations.
* @author Lee Rhodes
* @author Kevin Lang
*/
final class AnotBimpl extends AnotB {
private final short seedHash_;
private boolean empty_;
private long thetaLong_;
private long[] hashArr_ = new long[0]; //compact array w curCount_ entries
private int curCount_;
/**
* Construct a new AnotB SetOperation on the java heap. Called by SetOperation.Builder.
*
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
*/
AnotBimpl(final long seed) {
this(ThetaUtil.computeSeedHash(seed));
}
/**
* Construct a new AnotB SetOperation on the java heap.
*
* @param seedHash 16 bit hash of the chosen update seed.
*/
private AnotBimpl(final short seedHash) {
seedHash_ = seedHash;
reset();
}
@Override
public void setA(final Sketch skA) {
if (skA == null) {
reset();
throw new SketchesArgumentException("The input argument <i>A</i> must not be null");
}
if (skA.isEmpty()) {
reset();
return;
}
//skA is not empty
ThetaUtil.checkSeedHashes(seedHash_, skA.getSeedHash());
//process A
hashArr_ = getHashArrA(skA);
empty_ = false;
thetaLong_ = skA.getThetaLong();
curCount_ = hashArr_.length;
}
@Override
public void notB(final Sketch skB) {
if (empty_ || skB == null || skB.isEmpty()) { return; }
//local and skB is not empty
ThetaUtil.checkSeedHashes(seedHash_, skB.getSeedHash());
thetaLong_ = Math.min(thetaLong_, skB.getThetaLong());
//process B
hashArr_ = getResultHashArr(thetaLong_, curCount_, hashArr_, skB);
curCount_ = hashArr_.length;
empty_ = curCount_ == 0 && thetaLong_ == Long.MAX_VALUE;
}
@Override
public CompactSketch getResult(final boolean reset) {
return getResult(true, null, reset);
}
@Override
public CompactSketch getResult(final boolean dstOrdered, final WritableMemory dstMem,
final boolean reset) {
final CompactSketch result = CompactOperations.componentsToCompact(
thetaLong_, curCount_, seedHash_, empty_, true, false, dstOrdered, dstMem, hashArr_.clone());
if (reset) { reset(); }
return result;
}
@Override
public CompactSketch aNotB(final Sketch skA, final Sketch skB, final boolean dstOrdered,
final WritableMemory dstMem) {
if (skA == null || skB == null) {
throw new SketchesArgumentException("Neither argument may be null");
}
//Both skA & skB are not null
final long minThetaLong = Math.min(skA.getThetaLong(), skB.getThetaLong());
if (skA.isEmpty()) { return skA.compact(dstOrdered, dstMem); }
//A is not Empty
ThetaUtil.checkSeedHashes(skA.getSeedHash(), seedHash_);
if (skB.isEmpty()) {
return skA.compact(dstOrdered, dstMem);
}
ThetaUtil.checkSeedHashes(skB.getSeedHash(), seedHash_);
//Both skA & skB are not empty
//process A
final long[] hashArrA = getHashArrA(skA);
final int countA = hashArrA.length;
//process B
final long[] hashArrOut = getResultHashArr(minThetaLong, countA, hashArrA, skB); //out is clone
final int countOut = hashArrOut.length;
final boolean empty = countOut == 0 && minThetaLong == Long.MAX_VALUE;
final CompactSketch result = CompactOperations.componentsToCompact(
minThetaLong, countOut, seedHash_, empty, true, false, dstOrdered, dstMem, hashArrOut);
return result;
}
@Override
int getRetainedEntries() {
return curCount_;
}
@Override
public boolean isSameResource(final Memory that) {
return false;
}
//restricted
private static long[] getHashArrA(final Sketch skA) { //returns a new array
//Get skA cache as array
final CompactSketch cskA = skA.compact(false, null); //sorting not required
final long[] hashArrA = cskA.getCache().clone();
return hashArrA;
}
private static long[] getResultHashArr( //returns a new array
final long minThetaLong,
final int countA,
final long[] hashArrA,
final Sketch skB) {
//Rebuild/get hashtable of skB
final long[] hashTableB; //read only
final long[] thetaCache = skB.getCache();
final int countB = skB.getRetainedEntries(true);
if (skB instanceof CompactSketch) {
hashTableB = convertToHashTable(thetaCache, countB, minThetaLong, ThetaUtil.REBUILD_THRESHOLD);
} else {
hashTableB = thetaCache;
}
//build temporary result arrays of skA
final long[] tmpHashArrA = new long[countA];
//search for non matches and build temp arrays
final int lgHTBLen = exactLog2OfLong(hashTableB.length);
int nonMatches = 0;
for (int i = 0; i < countA; i++) {
final long hash = hashArrA[i];
if (hash != 0 && hash < minThetaLong) { //only allows hashes of A < minTheta
final int index = hashSearch(hashTableB, lgHTBLen, hash);
if (index == -1) {
tmpHashArrA[nonMatches] = hash;
nonMatches++;
}
}
}
return Arrays.copyOfRange(tmpHashArrA, 0, nonMatches);
}
private void reset() {
thetaLong_ = Long.MAX_VALUE;
empty_ = true;
hashArr_ = new long[0];
curCount_ = 0;
}
@Override
long[] getCache() {
return hashArr_.clone();
}
@Override
short getSeedHash() {
return seedHash_;
}
@Override
long getThetaLong() {
return thetaLong_;
}
@Override
boolean isEmpty() {
return empty_;
}
}
| 2,752 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/Union.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
/**
* Compute the union of two or more theta sketches.
* A new instance represents an empty set.
*
* @author Lee Rhodes
*/
public abstract class Union extends SetOperation {
/**
* Returns the number of storage bytes required for this union in its current state.
*
* @return the number of storage bytes required for this union in its current state.
*/
public abstract int getCurrentBytes();
@Override
public Family getFamily() {
return Family.UNION;
}
/**
* Returns the maximum required storage bytes for this union.
* @return the maximum required storage bytes for this union.
*/
public abstract int getMaxUnionBytes();
/**
* Gets the result of this operation as an ordered CompactSketch on the Java heap.
* This does not disturb the underlying data structure of the union.
* Therefore, it is OK to continue updating the union after this operation.
* @return the result of this operation as an ordered CompactSketch on the Java heap
*/
public abstract CompactSketch getResult();
/**
* Gets the result of this operation as a CompactSketch of the chosen form.
* This does not disturb the underlying data structure of the union.
* Therefore, it is OK to continue updating the union after this operation.
*
* @param dstOrdered
* <a href="{@docRoot}/resources/dictionary.html#dstOrdered">See Destination Ordered</a>
*
* @param dstMem
* <a href="{@docRoot}/resources/dictionary.html#dstMem">See Destination Memory</a>.
*
* @return the result of this operation as a CompactSketch of the chosen form
*/
public abstract CompactSketch getResult(boolean dstOrdered, WritableMemory dstMem);
/**
* Resets this Union. The seed remains intact, everything else reverts back to its virgin state.
*/
public abstract void reset();
/**
* Returns a byte array image of this Union object
* @return a byte array image of this Union object
*/
public abstract byte[] toByteArray();
/**
* This implements a stateless, pair-wise union operation. The returned sketch will be cut back to
* the smaller of the two k values if required.
*
* <p>Nulls and empty sketches are ignored.</p>
*
* @param sketchA The first argument
* @param sketchB The second argument
* @return the result ordered CompactSketch on the heap.
*/
public CompactSketch union(final Sketch sketchA, final Sketch sketchB) {
return union(sketchA, sketchB, true, null);
}
/**
* This implements a stateless, pair-wise union operation. The returned sketch will be cut back to
* k if required, similar to the regular Union operation.
*
* <p>Nulls and empty sketches are ignored.</p>
*
* @param sketchA The first argument
* @param sketchB The second argument
* @param dstOrdered If true, the returned CompactSketch will be ordered.
* @param dstMem If not null, the returned CompactSketch will be placed in this WritableMemory.
* @return the result CompactSketch.
*/
public abstract CompactSketch union(Sketch sketchA, Sketch sketchB, boolean dstOrdered,
WritableMemory dstMem);
/**
* Perform a Union operation with <i>this</i> union and the given on-heap sketch of the Theta Family.
* This method is not valid for the older SetSketch, which was prior to Open Source (August, 2015).
*
* <p>This method can be repeatedly called.
*
* <p>Nulls and empty sketches are ignored.</p>
*
* @param sketchIn The incoming sketch.
*/
public abstract void union(Sketch sketchIn);
/**
* Perform a Union operation with <i>this</i> union and the given Memory image of any sketch of the
* Theta Family. The input image may be from earlier versions of the Theta Compact Sketch,
* called the SetSketch (circa 2014), which was prior to Open Source and are compact and ordered.
*
* <p>This method can be repeatedly called.
*
* <p>Nulls and empty sketches are ignored.</p>
*
* @param mem Memory image of sketch to be merged
*/
public abstract void union(Memory mem);
/**
* Update <i>this</i> union with the given long data item.
*
* @param datum The given long datum.
*/
public abstract void update(long datum);
/**
* Update <i>this</i> union with the given double (or float) data item.
* The double will be converted to a long using Double.doubleToLongBits(datum),
* which normalizes all NaN values to a single NaN representation.
* Plus and minus zero will be normalized to plus zero.
* Each of the special floating-point values NaN and +/- Infinity are treated as distinct.
*
* @param datum The given double datum.
*/
public abstract void update(double datum);
/**
* Update <i>this</i> union with the with the given String data item.
* The string is converted to a byte array using UTF8 encoding.
* If the string is null or empty no update attempt is made and the method returns.
*
* <p>Note: this will not produce the same output hash values as the {@link #update(char[])}
* method and will generally be a little slower depending on the complexity of the UTF8 encoding.
* </p>
*
* <p>Note: this is not a Sketch Union operation. This treats the given string as a data item.</p>
*
* @param datum The given String.
*/
public abstract void update(String datum);
/**
* Update <i>this</i> union with the given byte array item.
* If the byte array is null or empty no update attempt is made and the method returns.
*
* <p>Note: this is not a Sketch Union operation. This treats the given byte array as a data
* item.</p>
*
* @param data The given byte array.
*/
public abstract void update(byte[] data);
/**
* Update <i>this</i> union with the given integer array item.
* If the integer array is null or empty no update attempt is made and the method returns.
*
* <p>Note: this is not a Sketch Union operation. This treats the given integer array as a data
* item.</p>
*
* @param data The given int array.
*/
public abstract void update(int[] data);
/**
* Update <i>this</i> union with the given char array item.
* If the char array is null or empty no update attempt is made and the method returns.
*
* <p>Note: this will not produce the same output hash values as the {@link #update(String)}
* method but will be a little faster as it avoids the complexity of the UTF8 encoding.</p>
*
* <p>Note: this is not a Sketch Union operation. This treats the given char array as a data
* item.</p>
*
* @param data The given char array.
*/
public abstract void update(char[] data);
/**
* Update <i>this</i> union with the given long array item.
* If the long array is null or empty no update attempt is made and the method returns.
*
* <p>Note: this is not a Sketch Union operation. This treats the given char array as a data
* item.</p>
*
* @param data The given long array.
*/
public abstract void update(long[] data);
}
| 2,753 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/ConcurrentHeapThetaBuffer.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.UpdateReturnState.ConcurrentBufferInserted;
import static org.apache.datasketches.theta.UpdateReturnState.ConcurrentPropagated;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedOverTheta;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.thetacommon.HashOperations;
/**
* This is a theta filtering, bounded size buffer that operates in the context of a single writing
* thread. When the buffer becomes full its content is propagated into the shared sketch, which
* may be on a different thread. The limit on the buffer size is configurable. A bound of size 1
* allows the combination of buffers and shared sketch to maintain an error bound in real-time
* that is close to the error bound of a sequential theta sketch. Allowing larger buffer sizes
* enables amortization of the cost propagations and substantially improves overall system throughput.
* The error caused by the buffering is essentially a perspective of time and synchronization
* and not really a true error. At the end of a stream, after all the buffers have synchronized with
* the shared sketch, there is no additional error.
* Propagation is done either synchronously by the updating thread, or asynchronously by a
* background propagation thread.
*
* <p>This is a buffer, not a sketch, and it extends the <i>HeapQuickSelectSketch</i>
* in order to leverage some of the sketch machinery to make its work simple. However, if this
* buffer receives a query, like <i>getEstimate()</i>, the correct answer does not come from the super
* <i>HeapQuickSelectSketch</i>, which knows nothing about the concurrency relationship to the
* shared concurrent sketch, it must come from the shared concurrent sketch. As a result nearly all
* of the inherited sketch methods are redirected to the shared concurrent sketch.
*
* @author eshcar
* @author Lee Rhodes
*/
final class ConcurrentHeapThetaBuffer extends HeapQuickSelectSketch {
// Shared sketch consisting of the global sample set and theta value.
private final ConcurrentSharedThetaSketch shared;
// A flag indicating whether the shared sketch is in shared mode and requires eager propagation
// Initially this is true. Once it is set to false (estimation mode) it never flips back.
private boolean isExactMode;
// A flag to indicate if we expect the propagated data to be ordered
private final boolean propagateOrderedCompact;
// Propagation flag is set to true while propagation is in progress (or pending).
// It is the synchronization primitive to coordinate the work with the propagation thread.
private final AtomicBoolean localPropagationInProgress;
ConcurrentHeapThetaBuffer(final int lgNomLongs, final long seed,
final ConcurrentSharedThetaSketch shared, final boolean propagateOrderedCompact,
final int maxNumLocalThreads) {
super(computeLogBufferSize(lgNomLongs, shared.getExactLimit(), maxNumLocalThreads),
seed, 1.0F, //p
ResizeFactor.X1, //rf
false); //not a union gadget
this.shared = shared;
isExactMode = true;
this.propagateOrderedCompact = propagateOrderedCompact;
localPropagationInProgress = new AtomicBoolean(false);
}
private static int computeLogBufferSize(final int lgNomLongs, final long exactSize,
final int maxNumLocalBuffers) {
return Math.min(lgNomLongs, (int)Math.log(Math.sqrt(exactSize) / (2 * maxNumLocalBuffers)));
}
//concurrent restricted methods
/**
* Propagates a single hash value to the shared sketch
*
* @param hash to be propagated
*/
private boolean propagateToSharedSketch(final long hash) {
//noinspection StatementWithEmptyBody
while (localPropagationInProgress.get()) {
} //busy wait until previous propagation completed
localPropagationInProgress.set(true);
final boolean res = shared.propagate(localPropagationInProgress, null, hash);
//in this case the parent empty_ and curCount_ were not touched
thetaLong_ = shared.getVolatileTheta();
return res;
}
/**
* Propagates the content of the buffer as a sketch to the shared sketch
*/
private void propagateToSharedSketch() {
//noinspection StatementWithEmptyBody
while (localPropagationInProgress.get()) {
} //busy wait until previous propagation completed
final CompactSketch compactSketch = compact(propagateOrderedCompact, null);
localPropagationInProgress.set(true);
shared.propagate(localPropagationInProgress, compactSketch,
ConcurrentSharedThetaSketch.NOT_SINGLE_HASH);
super.reset();
thetaLong_ = shared.getVolatileTheta();
}
//Public Sketch overrides proxies to shared concurrent sketch
@Override
public int getCompactBytes() {
return shared.getCompactBytes();
}
@Override
public int getCurrentBytes() {
return shared.getCurrentBytes();
}
@Override
public double getEstimate() {
return shared.getEstimate();
}
@Override
public double getLowerBound(final int numStdDev) {
return shared.getLowerBound(numStdDev);
}
@Override
public double getUpperBound(final int numStdDev) {
return shared.getUpperBound(numStdDev);
}
@Override
public boolean hasMemory() {
return shared.hasMemory();
}
@Override
public boolean isDirect() {
return shared.isDirect();
}
@Override
public boolean isEmpty() {
return shared.isEmpty();
}
@Override
public boolean isEstimationMode() {
return shared.isEstimationMode();
}
//End of proxies
@Override
public byte[] toByteArray() {
throw new UnsupportedOperationException("Local theta buffer need not be serialized");
}
//Public UpdateSketch overrides
@Override
public void reset() {
super.reset();
isExactMode = true;
localPropagationInProgress.set(false);
}
//Restricted UpdateSketch overrides
/**
* Updates buffer with given hash value.
* Triggers propagation to shared sketch if buffer is full.
*
* @param hash the given input hash value. A hash of zero or Long.MAX_VALUE is ignored.
* A negative hash value will throw an exception.
* @return
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
@Override
UpdateReturnState hashUpdate(final long hash) {
if (isExactMode) {
isExactMode = !shared.isEstimationMode();
}
HashOperations.checkHashCorruption(hash);
if ((getHashTableThreshold() == 0) || isExactMode ) {
//The over-theta and zero test
if (HashOperations.continueCondition(getThetaLong(), hash)) {
return RejectedOverTheta; //signal that hash was rejected due to theta or zero.
}
if (propagateToSharedSketch(hash)) {
return ConcurrentPropagated;
}
}
final UpdateReturnState state = super.hashUpdate(hash);
if (isOutOfSpace(getRetainedEntries(true) + 1)) {
propagateToSharedSketch();
return ConcurrentPropagated;
}
if (state == UpdateReturnState.InsertedCountIncremented) {
return ConcurrentBufferInserted;
}
return state;
}
}
| 2,754 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/CompactOperations.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.PreambleUtil.COMPACT_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.LG_NOM_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.ORDERED_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.READ_ONLY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER;
import static org.apache.datasketches.theta.PreambleUtil.SINGLEITEM_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractSeedHash;
import static org.apache.datasketches.theta.PreambleUtil.extractSerVer;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.insertCurCount;
import static org.apache.datasketches.theta.PreambleUtil.insertFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.insertFlags;
import static org.apache.datasketches.theta.PreambleUtil.insertP;
import static org.apache.datasketches.theta.PreambleUtil.insertPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertSeedHash;
import static org.apache.datasketches.theta.PreambleUtil.insertSerVer;
import static org.apache.datasketches.theta.PreambleUtil.insertThetaLong;
import java.util.Arrays;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesStateException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
/**
* @author Lee Rhodes
*/
final class CompactOperations {
private CompactOperations() {}
static CompactSketch componentsToCompact( //No error checking
final long thetaLong,
final int curCount,
final short seedHash,
final boolean srcEmpty,
final boolean srcCompact,
final boolean srcOrdered,
final boolean dstOrdered,
final WritableMemory dstMem,
final long[] hashArr) //may not be compacted, ordered or unordered, may be null
{
final boolean direct = dstMem != null;
final boolean empty = srcEmpty || ((curCount == 0) && (thetaLong == Long.MAX_VALUE));
final boolean single = (curCount == 1) && (thetaLong == Long.MAX_VALUE);
final long[] hashArrOut;
if (!srcCompact) {
hashArrOut = CompactOperations.compactCache(hashArr, curCount, thetaLong, dstOrdered);
} else {
hashArrOut = hashArr;
}
if (!srcOrdered && dstOrdered && !empty && !single) {
Arrays.sort(hashArrOut);
}
//Note: for empty or single we always output the ordered form.
final boolean dstOrderedOut = (empty || single) ? true : dstOrdered;
if (direct) {
final int preLongs = computeCompactPreLongs(empty, curCount, thetaLong);
int flags = READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK; //always LE
flags |= empty ? EMPTY_FLAG_MASK : 0;
flags |= dstOrderedOut ? ORDERED_FLAG_MASK : 0;
flags |= single ? SINGLEITEM_FLAG_MASK : 0;
final Memory mem =
loadCompactMemory(hashArrOut, seedHash, curCount, thetaLong, dstMem, (byte)flags, preLongs);
return new DirectCompactSketch(mem);
} else { //Heap
if (empty) {
return EmptyCompactSketch.getInstance();
}
if (single) {
return new SingleItemSketch(hashArrOut[0], seedHash);
}
return new HeapCompactSketch(hashArrOut, empty, seedHash, curCount, thetaLong, dstOrderedOut);
}
}
/**
* Heapify or convert a source Theta Sketch Memory image into a heap or target Memory CompactSketch.
* This assumes hashSeed is OK; serVer = 3.
* @param srcMem the given input source Memory image
* @param dstOrdered the desired ordering of the resulting CompactSketch
* @param dstMem Used for the target CompactSketch if it is Memory-based.
* @return a CompactSketch of the correct form.
*/
@SuppressWarnings("unused")
static CompactSketch memoryToCompact(
final Memory srcMem,
final boolean dstOrdered,
final WritableMemory dstMem)
{
//extract Pre0 fields and Flags from srcMem
final int srcPreLongs = extractPreLongs(srcMem);
final int srcSerVer = extractSerVer(srcMem); //not used
final int srcFamId = extractFamilyID(srcMem);
final int srcLgArrLongs = extractLgArrLongs(srcMem);
final int srcFlags = extractFlags(srcMem);
final short srcSeedHash = (short) extractSeedHash(srcMem);
//srcFlags
final boolean srcReadOnlyFlag = (srcFlags & READ_ONLY_FLAG_MASK) > 0;
final boolean srcEmptyFlag = (srcFlags & EMPTY_FLAG_MASK) > 0;
final boolean srcCompactFlag = (srcFlags & COMPACT_FLAG_MASK) > 0;
final boolean srcOrderedFlag = (srcFlags & ORDERED_FLAG_MASK) > 0;
final boolean srcSingleFlag = (srcFlags & SINGLEITEM_FLAG_MASK) > 0;
final boolean single = srcSingleFlag
|| SingleItemSketch.otherCheckForSingleItem(srcPreLongs, srcSerVer, srcFamId, srcFlags);
//extract pre1 and pre2 fields
final int curCount = single ? 1 : (srcPreLongs > 1) ? extractCurCount(srcMem) : 0;
final long thetaLong = (srcPreLongs > 2) ? extractThetaLong(srcMem) : Long.MAX_VALUE;
//do some basic checks ...
if (srcEmptyFlag) { assert (curCount == 0) && (thetaLong == Long.MAX_VALUE); }
if (single) { assert (curCount == 1) && (thetaLong == Long.MAX_VALUE); }
checkFamilyAndFlags(srcFamId, srcCompactFlag, srcReadOnlyFlag);
//dispatch empty and single cases
//Note: for empty and single we always output the ordered form.
final boolean dstOrderedOut = (srcEmptyFlag || single) ? true : dstOrdered;
if (srcEmptyFlag) {
if (dstMem != null) {
dstMem.putByteArray(0, EmptyCompactSketch.EMPTY_COMPACT_SKETCH_ARR, 0, 8);
return new DirectCompactSketch(dstMem);
} else {
return EmptyCompactSketch.getInstance();
}
}
if (single) {
final long hash = srcMem.getLong(srcPreLongs << 3);
final SingleItemSketch sis = new SingleItemSketch(hash, srcSeedHash);
if (dstMem != null) {
dstMem.putByteArray(0, sis.toByteArray(),0, 16);
return new DirectCompactSketch(dstMem);
} else { //heap
return sis;
}
}
//extract hashArr > 1
final long[] hashArr;
if (srcCompactFlag) {
hashArr = new long[curCount];
srcMem.getLongArray(srcPreLongs << 3, hashArr, 0, curCount);
} else { //update sketch, thus hashTable form
final int srcCacheLen = 1 << srcLgArrLongs;
final long[] tempHashArr = new long[srcCacheLen];
srcMem.getLongArray(srcPreLongs << 3, tempHashArr, 0, srcCacheLen);
hashArr = compactCache(tempHashArr, curCount, thetaLong, dstOrderedOut);
}
final int flagsOut = READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK
| ((dstOrderedOut) ? ORDERED_FLAG_MASK : 0);
//load the destination.
if (dstMem != null) {
final Memory tgtMem = loadCompactMemory(hashArr, srcSeedHash, curCount, thetaLong, dstMem,
(byte)flagsOut, srcPreLongs);
return new DirectCompactSketch(tgtMem);
} else { //heap
return new HeapCompactSketch(hashArr, srcEmptyFlag, srcSeedHash, curCount, thetaLong,
dstOrderedOut);
}
}
private static final void checkFamilyAndFlags(
final int srcFamId,
final boolean srcCompactFlag,
final boolean srcReadOnlyFlag) {
final Family srcFamily = Family.idToFamily(srcFamId);
if (srcCompactFlag) {
if ((srcFamily == Family.COMPACT) && srcReadOnlyFlag) { return; }
} else {
if (srcFamily == Family.ALPHA) { return; }
if (srcFamily == Family.QUICKSELECT) { return; }
}
throw new SketchesArgumentException(
"Possible Corruption: Family does not match flags: Family: "
+ srcFamily.toString()
+ ", Compact Flag: " + srcCompactFlag
+ ", ReadOnly Flag: " + srcReadOnlyFlag);
}
//All arguments must be valid and correct including flags.
// Used as helper to create byte arrays as well as loading Memory for direct compact sketches
static final Memory loadCompactMemory(
final long[] compactHashArr,
final short seedHash,
final int curCount,
final long thetaLong,
final WritableMemory dstMem,
final byte flags,
final int preLongs)
{
assert (dstMem != null) && (compactHashArr != 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();
//Caution: The following loads directly into Memory without creating a heap byte[] first,
// which would act as a pre-clearing, initialization mechanism. So it is important to make sure
// that all fields are initialized, even those that are not used by the CompactSketch.
// Otherwise, uninitialized fields could be filled with off-heap garbage, which could cause
// other problems downstream if those fields are not filtered out first.
// As written below, all fields are initialized avoiding an extra copy.
//The first 8 bytes (pre0)
insertPreLongs(dstMem, preLongs); //RF not used = 0
insertSerVer(dstMem, SER_VER);
insertFamilyID(dstMem, famID);
//The following initializes the lgNomLongs and lgArrLongs to 0.
//They are not used in CompactSketches.
dstMem.putShort(LG_NOM_LONGS_BYTE, (short)0);
insertFlags(dstMem, flags);
insertSeedHash(dstMem, seedHash);
if ((preLongs == 1) && (curCount == 1)) { //singleItem, theta = 1.0
dstMem.putLong(8, compactHashArr[0]);
return dstMem;
}
if (preLongs > 1) {
insertCurCount(dstMem, curCount);
insertP(dstMem, (float) 1.0);
}
if (preLongs > 2) {
insertThetaLong(dstMem, thetaLong);
}
if (curCount > 0) { //theta could be < 1.0.
dstMem.putLongArray(preLongs << 3, compactHashArr, 0, curCount);
}
return dstMem; //if prelongs == 3 & curCount == 0, theta could be < 1.0.
}
/**
* Copies then compacts, cleans, and may sort the resulting array.
* The source cache can be a hash table with interstitial zeros or
* "dirty" values, which are hash values greater than theta.
* These can be generated by the Alpha sketch.
* @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.
*/
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;
}
if (j < curCount) {
throw new SketchesStateException(
"Possible Corruption: curCount parameter is incorrect.");
}
if (dstOrdered && (curCount > 1)) {
Arrays.sort(cacheOut);
}
return cacheOut;
}
/*
* The truth table for empty, curCount and theta when compacting is as follows:
* <pre>
* Num Theta CurCount Empty State Name, Comments
* 0 1.0 0 T OK EMPTY: The Normal Empty State
* 1 1.0 0 F Internal This can occur internally as the result of an intersection of two exact,
* disjoint sets, or AnotB of two exact, identical sets. There is no probability
* distribution, so this is converted internally to EMPTY {1.0, 0, T}.
* This is handled in SetOperation.createCompactSketch().
* 2 1.0 !0 T Error Empty=T and curCount !0 should never coexist.
* This is checked in all compacting operations.
* 3 1.0 !0 F OK EXACT: This corresponds to a sketch in exact mode
* 4 <1.0 0 T Internal This can be an initial UpdateSketch state if p < 1.0,
* so change theta to 1.0. Return {Th = 1.0, 0, T}.
* This is handled in UpdateSketch.compact() and toByteArray().
* 5 <1.0 0 F OK This can result from set operations
* 6 <1.0 !0 T Error Empty=T and curCount !0 should never coexist.
* This is checked in all compacting operations.
* 7 <1.0 !0 F OK This corresponds to a sketch in estimation mode
* </pre>
* #4 is handled by <i>correctThetaOnCompat(boolean, int)</i> (below).
* #2 & #6 handled by <i>checkIllegalCurCountAndEmpty(boolean, int)</i>
*/
/**
* This corrects a temporary anomalous condition where compact() is called on an UpdateSketch
* that was initialized with p < 1.0 and update() was never called. In this case Theta < 1.0,
* curCount = 0, and empty = true. The correction is to change Theta to 1.0, which makes the
* returning sketch empty. This should only be used in the compaction or serialization of an
* UpdateSketch.
* @param empty the given empty state
* @param curCount the given curCount
* @param thetaLong the given thetaLong
* @return thetaLong
*/
static final long correctThetaOnCompact(final boolean empty, final int curCount,
final long thetaLong) { //handles #4 above
return (empty && (curCount == 0)) ? Long.MAX_VALUE : thetaLong;
}
/**
* This checks for the illegal condition where curCount > 0 and the state of
* empty = true. This check can be used anywhere a sketch is returned or a sketch is created
* from complete arguments.
* @param empty the given empty state
* @param curCount the given current count
*/ //This handles #2 and #6 above
static final void checkIllegalCurCountAndEmpty(final boolean empty, final int curCount) {
if (empty && (curCount != 0)) { //this handles #2 and #6 above
throw new SketchesStateException("Illegal State: Empty=true and Current Count != 0.");
}
}
/**
* This compute number of preamble longs for a compact sketch based on <i>empty</i>,
* <i>curCount</i> and <i>thetaLong</i>.
* This also accommodates for EmptyCompactSketch and SingleItemSketch.
* @param empty The given empty state
* @param curCount The given current count (retained entries)
* @param thetaLong the current thetaLong
* @return the number of preamble longs
*/
static final int computeCompactPreLongs(final boolean empty, final int curCount,
final long thetaLong) {
return (thetaLong < Long.MAX_VALUE) ? 3 : empty ? 1 : (curCount > 1) ? 2 : 1;
}
/**
* This checks for the singleItem Compact Sketch.
* @param empty the given empty state
* @param curCount the given curCount
* @param thetaLong the given thetaLong
* @return true if notEmpty, curCount = 1 and theta = 1.0;
*/
static final boolean isSingleItem(final boolean empty, final int curCount,
final long thetaLong) {
return !empty && (curCount == 1) && (thetaLong == Long.MAX_VALUE);
}
}
| 2,755 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/UnionImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static java.lang.Math.min;
import static org.apache.datasketches.theta.PreambleUtil.COMPACT_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.ORDERED_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.UNION_THETA_LONG;
import static org.apache.datasketches.theta.PreambleUtil.clearEmpty;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractSeedHash;
import static org.apache.datasketches.theta.PreambleUtil.extractSerVer;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.extractUnionThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.insertUnionThetaLong;
import static org.apache.datasketches.theta.SingleItemSketch.otherCheckForSingleItem;
import static org.apache.datasketches.thetacommon.QuickSelect.selectExcludingZeros;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.HashOperations;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* Shared code for the HeapUnion and DirectUnion implementations.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
final class UnionImpl extends Union {
/**
* Although the gadget object is initially an UpdateSketch, in the context of a Union it is used
* as a specialized buffer that happens to leverage much of the machinery of an UpdateSketch.
* However, in this context some of the key invariants of the sketch algorithm are intentionally
* violated as an optimization. As a result this object can not be considered as an UpdateSketch
* and should never be exported as an UpdateSketch. It's internal state is not necessarily
* finalized and may contain garbage. Also its internal concept of "nominal entries" or "k" can
* be meaningless. It is private for very good reasons.
*/
private final UpdateSketch gadget_;
private final short expectedSeedHash_; //eliminates having to compute the seedHash on every union.
private long unionThetaLong_; //when on-heap, this is the only copy
private boolean unionEmpty_; //when on-heap, this is the only copy
private UnionImpl(final UpdateSketch gadget, final long seed) {
gadget_ = gadget;
expectedSeedHash_ = ThetaUtil.computeSeedHash(seed);
}
/**
* 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
*/
static UnionImpl initNewHeapInstance(
final int lgNomLongs,
final long seed,
final float p,
final ResizeFactor rf) {
final UpdateSketch gadget = //create with UNION family
new HeapQuickSelectSketch(lgNomLongs, seed, p, rf, true);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = gadget.getThetaLong();
unionImpl.unionEmpty_ = gadget.isEmpty();
return unionImpl;
}
/**
* 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
*/
static UnionImpl initNewDirectInstance(
final int lgNomLongs,
final long seed,
final float p,
final ResizeFactor rf,
final MemoryRequestServer memReqSvr,
final WritableMemory dstMem) {
final UpdateSketch gadget = //create with UNION family
new DirectQuickSelectSketch(lgNomLongs, seed, p, rf, memReqSvr, dstMem, true);
final UnionImpl unionImpl = new UnionImpl(gadget, seed);
unionImpl.unionThetaLong_ = gadget.getThetaLong();
unionImpl.unionEmpty_ = gadget.isEmpty();
return unionImpl;
}
/**
* 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 expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return this class
*/
static UnionImpl heapifyInstance(final Memory srcMem, final long expectedSeed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = HeapQuickSelectSketch.heapifyInstance(srcMem, expectedSeed);
final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
return unionImpl;
}
/**
* 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 expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return this class
*/
static UnionImpl fastWrap(final Memory srcMem, final long expectedSeed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = DirectQuickSelectSketchR.fastReadOnlyWrap(srcMem, expectedSeed);
final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
return unionImpl;
}
/**
* Fast-wrap a Union object around a Union WritableMemory 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 expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return this class
*/
static UnionImpl fastWrap(final WritableMemory srcMem, final long expectedSeed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = DirectQuickSelectSketch.fastWritableWrap(srcMem, expectedSeed);
final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
return unionImpl;
}
/**
* 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 expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return this class
*/
static UnionImpl wrapInstance(final Memory srcMem, final long expectedSeed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = DirectQuickSelectSketchR.readOnlyWrap(srcMem, expectedSeed);
final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
return unionImpl;
}
/**
* Wrap a Union object around a Union WritableMemory object containing data.
* Called by SetOperation.
* @param srcMem The source Memory object.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return this class
*/
static UnionImpl wrapInstance(final WritableMemory srcMem, final long expectedSeed) {
Family.UNION.checkFamilyID(extractFamilyID(srcMem));
final UpdateSketch gadget = DirectQuickSelectSketch.writableWrap(srcMem, expectedSeed);
final UnionImpl unionImpl = new UnionImpl(gadget, expectedSeed);
unionImpl.unionThetaLong_ = extractUnionThetaLong(srcMem);
unionImpl.unionEmpty_ = PreambleUtil.isEmptyFlag(srcMem);
return unionImpl;
}
@Override
public int getCurrentBytes() {
return gadget_.getCurrentBytes();
}
@Override
public int getMaxUnionBytes() {
final int lgK = gadget_.getLgNomLongs();
return (16 << lgK) + (Family.UNION.getMaxPreLongs() << 3);
}
@Override
public CompactSketch getResult() {
return getResult(true, null);
}
@Override
public CompactSketch getResult(final boolean dstOrdered, final WritableMemory dstMem) {
final int gadgetCurCount = gadget_.getRetainedEntries(true);
final int k = 1 << gadget_.getLgNomLongs();
final long[] gadgetCacheCopy =
gadget_.hasMemory() ? gadget_.getCache() : gadget_.getCache().clone();
//Pull back to k
final long curGadgetThetaLong = gadget_.getThetaLong();
final long adjGadgetThetaLong = gadgetCurCount > k
? selectExcludingZeros(gadgetCacheCopy, gadgetCurCount, k + 1) : curGadgetThetaLong;
//Finalize Theta and curCount
final long unionThetaLong = gadget_.hasMemory()
? gadget_.getMemory().getLong(UNION_THETA_LONG) : unionThetaLong_;
final long minThetaLong = min(min(curGadgetThetaLong, adjGadgetThetaLong), unionThetaLong);
final int curCountOut = minThetaLong < curGadgetThetaLong
? HashOperations.count(gadgetCacheCopy, minThetaLong)
: gadgetCurCount;
//Compact the cache
final long[] compactCacheOut =
CompactOperations.compactCache(gadgetCacheCopy, curCountOut, minThetaLong, dstOrdered);
final boolean empty = gadget_.isEmpty() && unionEmpty_;
final short seedHash = gadget_.getSeedHash();
return CompactOperations.componentsToCompact(
minThetaLong, curCountOut, seedHash, empty, true, dstOrdered, dstOrdered, dstMem, compactCacheOut);
}
@Override
public boolean isSameResource(final Memory that) {
return gadget_ instanceof DirectQuickSelectSketchR
? gadget_.getMemory().isSameResource(that) : false;
}
@Override
public void reset() {
gadget_.reset();
unionThetaLong_ = gadget_.getThetaLong();
unionEmpty_ = gadget_.isEmpty();
}
@Override
public byte[] toByteArray() {
final byte[] gadgetByteArr = gadget_.toByteArray();
final WritableMemory mem = WritableMemory.writableWrap(gadgetByteArr);
insertUnionThetaLong(mem, unionThetaLong_);
if (gadget_.isEmpty() != unionEmpty_) {
clearEmpty(mem);
unionEmpty_ = false;
}
return gadgetByteArr;
}
@Override //Stateless Union
public CompactSketch union(final Sketch sketchA, final Sketch sketchB, final boolean dstOrdered,
final WritableMemory dstMem) {
reset();
union(sketchA);
union(sketchB);
final CompactSketch csk = getResult(dstOrdered, dstMem);
reset();
return csk;
}
@Override
public void union(final Sketch sketchIn) {
//UNION Empty Rule: AND the empty states.
if (sketchIn == null || sketchIn.isEmpty()) {
//null and empty is interpreted as (Theta = 1.0, count = 0, empty = T). Nothing changes
return;
}
//sketchIn is valid and not empty
ThetaUtil.checkSeedHashes(expectedSeedHash_, sketchIn.getSeedHash());
if (sketchIn instanceof SingleItemSketch) {
gadget_.hashUpdate(sketchIn.getCache()[0]);
return;
}
Sketch.checkSketchAndMemoryFlags(sketchIn);
unionThetaLong_ = min(min(unionThetaLong_, sketchIn.getThetaLong()), gadget_.getThetaLong()); //Theta rule
unionEmpty_ = false;
final int curCountIn = sketchIn.getRetainedEntries(true);
if (curCountIn > 0) {
if (sketchIn.isOrdered() && (sketchIn instanceof CompactSketch)) { //Use early stop
//Ordered, thus compact
if (sketchIn.hasMemory()) {
final Memory skMem = ((CompactSketch) sketchIn).getMemory();
final int preambleLongs = skMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
for (int i = 0; i < curCountIn; i++ ) {
final int offsetBytes = preambleLongs + i << 3;
final long hashIn = skMem.getLong(offsetBytes);
if (hashIn >= unionThetaLong_) { break; } // "early stop"
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
}
else { //sketchIn is on the Java Heap or has array
final long[] cacheIn = sketchIn.getCache(); //not a copy!
for (int i = 0; i < curCountIn; i++ ) {
final long hashIn = cacheIn[i];
if (hashIn >= unionThetaLong_) { break; } // "early stop"
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
}
}
} //End ordered, compact
else { //either not-ordered compact or Hash Table form. A HT may have dirty values.
final long[] cacheIn = sketchIn.getCache(); //if off-heap this will be a copy
final int arrLongs = cacheIn.length;
for (int i = 0, c = 0; i < arrLongs && c < curCountIn; i++ ) {
final long hashIn = cacheIn[i];
if (hashIn <= 0L || hashIn >= unionThetaLong_) { continue; } //rejects dirty values
gadget_.hashUpdate(hashIn); //backdoor update, hash function is bypassed
c++; //ensures against invalid state inside the incoming sketch
}
}
}
unionThetaLong_ = min(unionThetaLong_, gadget_.getThetaLong()); //Theta rule with gadget
if (gadget_.hasMemory()) {
final WritableMemory wmem = (WritableMemory)gadget_.getMemory();
PreambleUtil.insertUnionThetaLong(wmem, unionThetaLong_);
PreambleUtil.clearEmpty(wmem);
}
}
@Override
public void union(final Memory skMem) {
if (skMem == null) { return; }
final int cap = (int) skMem.getCapacity();
if (cap < 16) { return; } //empty or garbage
final int serVer = extractSerVer(skMem);
final int fam = extractFamilyID(skMem);
if (serVer == 4) { // compressed ordered compact
// performance can be improved by decompression while performing the union
// potentially only partial decompression might be needed
ThetaUtil.checkSeedHashes(expectedSeedHash_, (short) extractSeedHash(skMem));
final CompactSketch csk = CompactSketch.wrap(skMem);
union(csk);
return;
}
if (serVer == 3) { //The OpenSource sketches (Aug 4, 2015) starts with serVer = 3
if (fam < 1 || fam > 3) {
throw new SketchesArgumentException(
"Family must be Alpha, QuickSelect, or Compact: " + Family.idToFamily(fam));
}
processVer3(skMem);
return;
}
if (serVer == 2) { //older Sketch, which is compact and ordered
ThetaUtil.checkSeedHashes(expectedSeedHash_, (short)extractSeedHash(skMem));
final CompactSketch csk = ForwardCompatibility.heapify2to3(skMem, expectedSeedHash_);
union(csk);
return;
}
if (serVer == 1) { //much older Sketch, which is compact and ordered, no seedHash
final CompactSketch csk = ForwardCompatibility.heapify1to3(skMem, expectedSeedHash_);
union(csk);
return;
}
throw new SketchesArgumentException("SerVer is unknown: " + serVer);
}
//Has seedHash, p, could have 0 entries & theta < 1.0,
//could be unordered, ordered, compact, or not compact,
//could be Alpha, QuickSelect, or Compact.
private void processVer3(final Memory skMem) {
final int preLongs = extractPreLongs(skMem);
if (preLongs == 1) {
if (otherCheckForSingleItem(skMem)) {
final long hash = skMem.getLong(8);
gadget_.hashUpdate(hash);
return;
}
return; //empty
}
ThetaUtil.checkSeedHashes(expectedSeedHash_, (short)extractSeedHash(skMem));
final int curCountIn;
final long thetaLongIn;
if (preLongs == 2) { //exact mode
curCountIn = extractCurCount(skMem);
if (curCountIn == 0) { return; } //should be > 0, but if it is 0 return empty anyway.
thetaLongIn = Long.MAX_VALUE;
}
else { //prelongs == 3
//curCount may be 0 (e.g., from intersection); but sketch cannot be empty.
curCountIn = extractCurCount(skMem);
thetaLongIn = extractThetaLong(skMem);
}
unionThetaLong_ = min(min(unionThetaLong_, thetaLongIn), gadget_.getThetaLong()); //theta rule
unionEmpty_ = false;
final int flags = extractFlags(skMem);
final boolean ordered = (flags & ORDERED_FLAG_MASK) != 0;
if (ordered) { //must be compact
for (int i = 0; i < curCountIn; 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 = (flags & COMPACT_FLAG_MASK) != 0;
final int size = compact ? curCountIn : 1 << extractLgArrLongs(skMem);
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
if (gadget_.hasMemory()) {
final WritableMemory wmem = (WritableMemory)gadget_.getMemory();
PreambleUtil.insertUnionThetaLong(wmem, unionThetaLong_);
PreambleUtil.clearEmpty(wmem);
}
}
@Override
public void update(final long datum) {
gadget_.update(datum);
}
@Override
public void update(final double datum) {
gadget_.update(datum);
}
@Override
public void update(final String datum) {
gadget_.update(datum);
}
@Override
public void update(final byte[] data) {
gadget_.update(data);
}
@Override
public void update(final char[] data) {
gadget_.update(data);
}
@Override
public void update(final int[] data) {
gadget_.update(data);
}
@Override
public void update(final long[] data) {
gadget_.update(data);
}
//Restricted
@Override
long[] getCache() {
return gadget_.getCache();
}
@Override
int getRetainedEntries() {
return gadget_.getRetainedEntries(true);
}
@Override
short getSeedHash() {
return gadget_.getSeedHash();
}
@Override
long getThetaLong() {
return min(unionThetaLong_, gadget_.getThetaLong());
}
@Override
boolean isEmpty() {
return gadget_.isEmpty() && unionEmpty_;
}
}
| 2,756 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/SetOperation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Family.idToFamily;
import static org.apache.datasketches.common.Util.ceilingIntPowerOf2;
import static org.apache.datasketches.theta.PreambleUtil.FAMILY_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER_BYTE;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* The parent API for all Set Operations
*
* @author Lee Rhodes
*/
public abstract class SetOperation {
static final int CONST_PREAMBLE_LONGS = 3;
SetOperation() {}
/**
* Makes a new builder
*
* @return a new builder
*/
public static final SetOperationBuilder builder() {
return new SetOperationBuilder();
}
/**
* Heapify takes the SetOperations image in Memory and instantiates an on-heap
* SetOperation using the
* <a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update Seed</a>.
* The resulting SetOperation will not retain any link to the source Memory.
*
* <p>Note: Only certain set operators during stateful operations can be serialized and thus
* heapified.</p>
*
* @param srcMem an image of a SetOperation where the image seed hash matches the default seed hash.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a Heap-based SetOperation from the given Memory
*/
public static SetOperation heapify(final Memory srcMem) {
return heapify(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Heapify takes the SetOperation image in Memory and instantiates an on-heap
* SetOperation using the given expectedSeed.
* The resulting SetOperation will not retain any link to the source Memory.
*
* <p>Note: Only certain set operators during stateful operations can be serialized and thus
* heapified.</p>
*
* @param srcMem an image of a SetOperation where the hash of the given expectedSeed matches the image seed hash.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a Heap-based SetOperation from the given Memory
*/
public static SetOperation heapify(final Memory srcMem, final long expectedSeed) {
final byte famID = srcMem.getByte(FAMILY_BYTE);
final Family family = idToFamily(famID);
switch (family) {
case UNION : {
return UnionImpl.heapifyInstance(srcMem, expectedSeed);
}
case INTERSECTION : {
return IntersectionImpl.heapifyInstance(srcMem, expectedSeed);
}
default: {
throw new SketchesArgumentException("SetOperation cannot heapify family: "
+ family.toString());
}
}
}
/**
* Wrap takes the SetOperation image in Memory and refers to it directly.
* There is no data copying onto the java heap.
* This method assumes the
* <a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update Seed</a>.
*
* <p>Note: Only certain set operators during stateful operations can be serialized and thus
* wrapped.</p>
*
* @param srcMem an image of a SetOperation where the image seed hash matches the default seed hash.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a SetOperation backed by the given Memory
*/
public static SetOperation wrap(final Memory srcMem) {
return wrap(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Wrap takes the SetOperation image in Memory and refers to it directly.
* There is no data copying onto the java heap.
*
* <p>Note: Only certain set operators during stateful operations can be serialized and thus
* wrapped.</p>
*
* @param srcMem an image of a SetOperation where the hash of the given expectedSeed matches the image seed hash.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a SetOperation backed by the given Memory
*/
public static SetOperation wrap(final Memory srcMem, final long expectedSeed) {
final byte famID = srcMem.getByte(FAMILY_BYTE);
final Family family = idToFamily(famID);
final int serVer = srcMem.getByte(SER_VER_BYTE);
if (serVer != 3) {
throw new SketchesArgumentException("SerVer must be 3: " + serVer);
}
switch (family) {
case UNION : {
return UnionImpl.wrapInstance(srcMem, expectedSeed);
}
case INTERSECTION : {
return IntersectionImpl.wrapInstance((WritableMemory)srcMem, expectedSeed, true);
}
default:
throw new SketchesArgumentException("SetOperation cannot wrap family: " + family.toString());
}
}
/**
* Wrap takes the SetOperation image in Memory and refers to it directly.
* There is no data copying onto the java heap.
* This method assumes the
* <a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update Seed</a>.
*
* <p>Note: Only certain set operators during stateful operations can be serialized and thus
* wrapped.</p>
*
* @param srcMem an image of a SetOperation where the image seed hash matches the default seed hash.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a SetOperation backed by the given Memory
*/
public static SetOperation wrap(final WritableMemory srcMem) {
return wrap(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Wrap takes the SetOperation image in Memory and refers to it directly.
* There is no data copying onto the java heap.
*
* <p>Note: Only certain set operators during stateful operations can be serialized and thus
* wrapped.</p>
*
* @param srcMem an image of a SetOperation where the hash of the given expectedSeed matches the image seed hash.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a SetOperation backed by the given Memory
*/
public static SetOperation wrap(final WritableMemory srcMem, final long expectedSeed) {
final byte famID = srcMem.getByte(FAMILY_BYTE);
final Family family = idToFamily(famID);
final int serVer = srcMem.getByte(SER_VER_BYTE);
if (serVer != 3) {
throw new SketchesArgumentException("SerVer must be 3: " + serVer);
}
switch (family) {
case UNION : {
return UnionImpl.wrapInstance(srcMem, expectedSeed);
}
case INTERSECTION : {
return IntersectionImpl.wrapInstance(srcMem, expectedSeed, false);
}
default:
throw new SketchesArgumentException("SetOperation cannot wrap family: "
+ family.toString());
}
}
/**
* Returns the maximum required storage bytes given a nomEntries parameter for Union operations
* @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 the maximum required storage bytes given a nomEntries parameter
*/
public static int getMaxUnionBytes(final int nomEntries) {
final int nomEnt = ceilingIntPowerOf2(nomEntries);
return (nomEnt << 4) + (Family.UNION.getMaxPreLongs() << 3);
}
/**
* Returns the maximum required storage bytes given a nomEntries parameter for Intersection
* operations
* @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 the maximum required storage bytes given a nomEntries parameter
*/
public static int getMaxIntersectionBytes(final int nomEntries) {
final int nomEnt = ceilingIntPowerOf2(nomEntries);
final int bytes = (nomEnt << 4) + (Family.INTERSECTION.getMaxPreLongs() << 3);
return bytes;
}
/**
* Returns the maximum number of bytes for the returned CompactSketch, given the
* value of nomEntries of the first sketch A of AnotB.
* @param nomEntries this value must be a power of 2.
* @return the maximum number of bytes.
*/
public static int getMaxAnotBResultBytes(final int nomEntries) {
final int ceil = ceilingIntPowerOf2(nomEntries);
return 24 + (15 * ceil);
}
/**
* Gets the Family of this SetOperation
* @return the Family of this SetOperation
*/
public abstract Family getFamily();
/**
* Returns true if the backing resource of <i>this</i> is identical with the backing resource
* of <i>that</i>. The capacities must be the same. If <i>this</i> is a region,
* the region offset must also be the same.
*
* <p>Note: Only certain set operators during stateful operations can be serialized.
* Only when they are stored into Memory will this be relevant.</p>
*
* @param that A different non-null object
* @return true if the backing resource of <i>this</i> is the same as the backing resource
* of <i>that</i>.
*/
public abstract boolean isSameResource(Memory that);
//restricted
/**
* Gets the hash array in compact form.
* This is only useful during stateful operations.
* This should never be made public.
* @return the hash array
*/
abstract long[] getCache();
/**
* Gets the current count of retained entries.
* This is only useful during stateful operations.
* Intentionally not made public because behavior will be confusing to end user.
*
* @return Gets the current count of retained entries.
*/
abstract int getRetainedEntries();
/**
* Returns the seedHash established during class construction.
* @return the seedHash.
*/
abstract short getSeedHash();
/**
* Gets the current value of ThetaLong.
* Only useful during stateful operations.
* Intentionally not made public because behavior will be confusing to end user.
* @return the current value of ThetaLong.
*/
abstract long getThetaLong();
/**
* Returns true if this set operator is empty.
* Only useful during stateful operations.
* Intentionally not made public because behavior will be confusing to end user.
* @return true if this set operator is empty.
*/
abstract boolean isEmpty();
}
| 2,757 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/ConcurrentSharedThetaSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.datasketches.memory.WritableMemory;
/**
* An internal interface to define the API of a concurrent shared theta sketch.
* It reflects all data processed by a single or multiple update threads, and can serve queries at
* any time.
*
* @author eshcar
*/
interface ConcurrentSharedThetaSketch {
long NOT_SINGLE_HASH = -1L;
double MIN_ERROR = 0.0000001;
static long computeExactLimit(long k, double error) {
return 2 * Math.min(k, (long) Math.ceil(1.0 / Math.pow(Math.max(error,MIN_ERROR), 2.0)));
}
/**
* Returns flip point (number of updates) from exact to estimate mode.
* @return flip point from exact to estimate mode
*/
long getExactLimit();
/**
* Ensures mutual exclusion. No other thread can update the shared sketch while propagation is
* in progress
* @return true if eager propagation was started
*/
boolean startEagerPropagation();
/**
* Completes the propagation: end mutual exclusion block.
* Notifies the local thread the propagation is completed
*
* @param localPropagationInProgress the synchronization primitive through which propagator
* notifies local thread the propagation is completed
* @param isEager true if the propagation is in eager mode
*/
void endPropagation(AtomicBoolean localPropagationInProgress, boolean isEager);
/**
* Returns the value of the volatile theta manged by the shared sketch
* @return the value of the volatile theta manged by the shared sketch
*/
long getVolatileTheta();
/**
* Awaits termination of background (lazy) propagation tasks
*/
void awaitBgPropagationTermination();
/**
* Init background (lazy) propagation service
*/
void initBgPropagationService();
/**
* (Eager) Propagates the given sketch or hash value into this sketch
* @param localPropagationInProgress the flag to be updated when propagation is done
* @param sketchIn any Theta sketch with the data
* @param singleHash a single hash value
* @return true if propagation successfully started
*/
boolean propagate(final AtomicBoolean localPropagationInProgress, final Sketch sketchIn,
final long singleHash);
/**
* (Lazy/Eager) Propagates the given hash value into this sketch
* @param singleHash a single hash value
*/
void propagate(final long singleHash);
/**
* Updates the estimation of the number of unique entries by capturing a snapshot of the sketch
* data, namely, volatile theta and the num of valid entries in the sketch
*/
void updateEstimationSnapshot();
/**
* Updates the value of the volatile theta by extracting it from the underlying sketch managed
* by the shared sketch
*/
void updateVolatileTheta();
/**
* Validates the shared sketch is in the context of the given epoch
*
* @param epoch the epoch number to be validates
* @return true iff the shared sketch is in the context of the given epoch
*/
boolean validateEpoch(long epoch);
//The following mirrors are public methods that already exist on the "extends" side of the dual
// inheritance. They are provided here to allow casts to this interface access
// to these methods without having to cast back to the extended parent class.
//
//This allows an internal class to cast either the Concurrent Direct or Concurrent Heap
//shared class to this interface and have access to the above special concurrent methods as
//well as the methods below.
//
//For the external user all of the below methods can be obtained by casting the shared
//sketch to UpdateSketch. However, these methods here also act as an alias so that an
//attempt to access these methods from the local buffer will be divered to the shared
//sketch.
//From Sketch
int getCompactBytes();
int getCurrentBytes();
double getEstimate();
double getLowerBound(int numStdDev);
double getUpperBound(int numStdDev);
boolean hasMemory();
boolean isDirect();
boolean isEmpty();
boolean isEstimationMode();
byte[] toByteArray();
int getRetainedEntries(boolean valid);
CompactSketch compact();
CompactSketch compact(boolean ordered, WritableMemory wmem);
UpdateSketch rebuild();
void reset();
}
| 2,758 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/CompactSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Family.idToFamily;
import static org.apache.datasketches.theta.PreambleUtil.COMPACT_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.ORDERED_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.READ_ONLY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractSeedHash;
import static org.apache.datasketches.theta.PreambleUtil.extractSerVer;
import static org.apache.datasketches.theta.PreambleUtil.extractEntryBitsV4;
import static org.apache.datasketches.theta.PreambleUtil.extractNumEntriesBytesV4;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLongV4;
import static org.apache.datasketches.theta.SingleItemSketch.otherCheckForSingleItem;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* The parent class of all the CompactSketches. CompactSketches are never created directly.
* They are created as a result of the compact() method of an UpdateSketch, a result of a
* getResult() of a SetOperation, or from a heapify method.
*
* <p>A CompactSketch is the simplest form of a Theta Sketch. It consists of a compact list
* (i.e., no intervening spaces) of hash values, which may be ordered or not, a value for theta
* and a seed hash. A CompactSketch is immutable (read-only),
* and the space required when stored is only the space required for the hash values and 8 to 24
* bytes of preamble. An empty CompactSketch consumes only 8 bytes.</p>
*
* @author Lee Rhodes
*/
public abstract class CompactSketch extends Sketch {
/**
* Heapify takes a CompactSketch image in Memory and instantiates an on-heap CompactSketch.
*
* <p>The resulting sketch will not retain any link to the source Memory and all of its data will be
* copied to the heap CompactSketch.</p>
*
* <p>This method assumes that the sketch image was created with the correct hash seed, so it is not checked.
* The resulting on-heap CompactSketch will be given the seedHash derived from the given sketch image.
* However, Serial Version 1 sketch images do not have a seedHash field,
* so the resulting heapified CompactSketch will be given the hash of the DEFAULT_UPDATE_SEED.</p>
*
* @param srcMem an image of a CompactSketch.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>.
* @return a CompactSketch on the heap.
*/
public static CompactSketch heapify(final Memory srcMem) {
return heapify(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED, false);
}
/**
* Heapify takes a CompactSketch image in Memory and instantiates an on-heap CompactSketch.
*
* <p>The resulting sketch will not retain any link to the source Memory and all of its data will be
* copied to the heap CompactSketch.</p>
*
* <p>This method checks if the given expectedSeed was used to create the source Memory image.
* However, SerialVersion 1 sketch images cannot be checked as they don't have a seedHash field,
* so the resulting heapified CompactSketch will be given the hash of the expectedSeed.</p>
*
* @param srcMem an image of a CompactSketch that was created using the given expectedSeed.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>.
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a CompactSketch on the heap.
*/
public static CompactSketch heapify(final Memory srcMem, final long expectedSeed) {
return heapify(srcMem, expectedSeed, true);
}
private static CompactSketch heapify(final Memory srcMem, final long seed, final boolean enforceSeed) {
final int serVer = extractSerVer(srcMem);
final int familyID = extractFamilyID(srcMem);
final Family family = idToFamily(familyID);
if (family != Family.COMPACT) {
throw new IllegalArgumentException("Corrupted: " + family + " is not Compact!");
}
if (serVer == 4) {
return heapifyV4(srcMem, seed, enforceSeed);
}
if (serVer == 3) {
final int flags = extractFlags(srcMem);
final boolean srcOrdered = (flags & ORDERED_FLAG_MASK) != 0;
final boolean empty = (flags & EMPTY_FLAG_MASK) != 0;
if (enforceSeed && !empty) { PreambleUtil.checkMemorySeedHash(srcMem, seed); }
return CompactOperations.memoryToCompact(srcMem, srcOrdered, null);
}
//not SerVer 3, assume compact stored form
final short seedHash = ThetaUtil.computeSeedHash(seed);
if (serVer == 1) {
return ForwardCompatibility.heapify1to3(srcMem, seedHash);
}
if (serVer == 2) {
return ForwardCompatibility.heapify2to3(srcMem,
enforceSeed ? seedHash : (short) extractSeedHash(srcMem));
}
throw new SketchesArgumentException("Unknown Serialization Version: " + serVer);
}
/**
* Wrap takes the CompactSketch image in given Memory and refers to it directly.
* There is no data copying onto the java heap.
* The wrap operation enables fast read-only merging and access to all the public read-only API.
*
* <p>Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have
* been explicitly stored as direct sketches can be wrapped.
* Wrapping earlier serial version sketches will result in a heapify operation.
* These early versions were never designed to "wrap".</p>
*
* <p>Wrapping any subclass of this class that is empty or contains only a single item will
* result in heapified forms of empty and single item sketch respectively.
* This is actually faster and consumes less overall memory.</p>
*
* <p>This method assumes that the sketch image was created with the correct hash seed, so it is not checked.
* However, Serial Version 1 sketch images do not have a seedHash field,
* so the resulting on-heap CompactSketch will be given the hash of the DEFAULT_UPDATE_SEED.</p>
*
* @param srcMem an image of a Sketch.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>.
* @return a CompactSketch backed by the given Memory except as above.
*/
public static CompactSketch wrap(final Memory srcMem) {
return wrap(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED, false);
}
/**
* Wrap takes the sketch image in the given Memory and refers to it directly.
* There is no data copying onto the java heap.
* The wrap operation enables fast read-only merging and access to all the public read-only API.
*
* <p>Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have
* been explicitly stored as direct sketches can be wrapped.
* Wrapping earlier serial version sketches will result in a heapify operation.
* These early versions were never designed to "wrap".</p>
*
* <p>Wrapping any subclass of this class that is empty or contains only a single item will
* result in heapified forms of empty and single item sketch respectively.
* This is actually faster and consumes less overall memory.</p>
*
* <p>This method checks if the given expectedSeed was used to create the source Memory image.
* However, SerialVersion 1 sketches cannot be checked as they don't have a seedHash field,
* so the resulting heapified CompactSketch will be given the hash of the expectedSeed.</p>
*
* @param srcMem an image of a Sketch that was created using the given expectedSeed.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a CompactSketch backed by the given Memory except as above.
*/
public static CompactSketch wrap(final Memory srcMem, final long expectedSeed) {
return wrap(srcMem, expectedSeed, true);
}
private static CompactSketch wrap(final Memory srcMem, final long seed, final boolean enforceSeed) {
final int serVer = extractSerVer(srcMem);
final int familyID = extractFamilyID(srcMem);
final Family family = Family.idToFamily(familyID);
if (family != Family.COMPACT) {
throw new IllegalArgumentException("Corrupted: " + family + " is not Compact!");
}
final short seedHash = ThetaUtil.computeSeedHash(seed);
if (serVer == 4) {
// not wrapping the compressed format since currently we cannot take advantage of
// decompression during iteration because set operations reach into memory directly
return heapifyV4(srcMem, seed, enforceSeed);
}
else if (serVer == 3) {
if (PreambleUtil.isEmptyFlag(srcMem)) {
return EmptyCompactSketch.getHeapInstance(srcMem);
}
if (otherCheckForSingleItem(srcMem)) {
return SingleItemSketch.heapify(srcMem, enforceSeed ? seedHash : (short) extractSeedHash(srcMem));
}
//not empty & not singleItem
final int flags = extractFlags(srcMem);
final boolean compactFlag = (flags & COMPACT_FLAG_MASK) > 0;
if (!compactFlag) {
throw new SketchesArgumentException(
"Corrupted: COMPACT family sketch image must have compact flag set");
}
final boolean readOnly = (flags & READ_ONLY_FLAG_MASK) > 0;
if (!readOnly) {
throw new SketchesArgumentException(
"Corrupted: COMPACT family sketch image must have Read-Only flag set");
}
return DirectCompactSketch.wrapInstance(srcMem,
enforceSeed ? seedHash : (short) extractSeedHash(srcMem));
} //end of serVer 3
else if (serVer == 1) {
return ForwardCompatibility.heapify1to3(srcMem, seedHash);
}
else if (serVer == 2) {
return ForwardCompatibility.heapify2to3(srcMem,
enforceSeed ? seedHash : (short) extractSeedHash(srcMem));
}
throw new SketchesArgumentException(
"Corrupted: Serialization Version " + serVer + " not recognized.");
}
//Sketch Overrides
@Override
public abstract CompactSketch compact(final boolean dstOrdered, final WritableMemory dstMem);
@Override
public int getCompactBytes() {
return getCurrentBytes();
}
@Override
int getCurrentDataLongs() {
return getRetainedEntries(true);
}
@Override
public Family getFamily() {
return Family.COMPACT;
}
@Override
public boolean isCompact() {
return true;
}
public byte[] toByteArrayCompressed() {
if (!isOrdered() || getRetainedEntries() == 0 || (getRetainedEntries() == 1 && !isEstimationMode())) {
return toByteArray();
}
return toByteArrayV4();
}
private int computeMinLeadingZeros() {
// compression is based on leading zeros in deltas between ordered hash values
// assumes ordered sketch
long previous = 0;
long ored = 0;
final HashIterator it = iterator();
while (it.next()) {
final long delta = it.get() - previous;
ored |= delta;
previous = it.get();
}
return Long.numberOfLeadingZeros(ored);
}
private static int wholeBytesToHoldBits(final int bits) {
return (bits >>> 3) + ((bits & 7) > 0 ? 1 : 0);
}
private byte[] toByteArrayV4() {
final int preambleLongs = isEstimationMode() ? 2 : 1;
final int entryBits = 64 - computeMinLeadingZeros();
final int compressedBits = entryBits * getRetainedEntries();
// store num_entries as whole bytes since whole-byte blocks will follow (most probably)
final int numEntriesBytes = wholeBytesToHoldBits(32 - Integer.numberOfLeadingZeros(getRetainedEntries()));
final int size = preambleLongs * Long.BYTES + numEntriesBytes + wholeBytesToHoldBits(compressedBits);
final byte[] bytes = new byte[size];
final WritableMemory mem = WritableMemory.writableWrap(bytes);
int offsetBytes = 0;
mem.putByte(offsetBytes++, (byte) preambleLongs);
mem.putByte(offsetBytes++, (byte) 4); // to do: add constant
mem.putByte(offsetBytes++, (byte) Family.COMPACT.getID());
mem.putByte(offsetBytes++, (byte) entryBits);
mem.putByte(offsetBytes++, (byte) numEntriesBytes);
mem.putByte(offsetBytes++, (byte) (COMPACT_FLAG_MASK | READ_ONLY_FLAG_MASK | ORDERED_FLAG_MASK));
mem.putShort(offsetBytes, getSeedHash());
offsetBytes += Short.BYTES;
if (isEstimationMode()) {
mem.putLong(offsetBytes, getThetaLong());
offsetBytes += Long.BYTES;
}
int numEntries = getRetainedEntries();
for (int i = 0; i < numEntriesBytes; i++) {
mem.putByte(offsetBytes++, (byte) (numEntries & 0xff));
numEntries >>>= 8;
}
long previous = 0;
final long[] deltas = new long[8];
final HashIterator it = iterator();
int i;
for (i = 0; i + 7 < getRetainedEntries(); i += 8) {
for (int j = 0; j < 8; j++) {
it.next();
deltas[j] = it.get() - previous;
previous = it.get();
}
BitPacking.packBitsBlock8(deltas, 0, bytes, offsetBytes, entryBits);
offsetBytes += entryBits;
}
int offsetBits = 0;
for (; i < getRetainedEntries(); i++) {
it.next();
final long delta = it.get() - previous;
previous = it.get();
BitPacking.packBits(delta, entryBits, bytes, offsetBytes, offsetBits);
offsetBytes += (offsetBits + entryBits) >>> 3;
offsetBits = (offsetBits + entryBits) & 7;
}
return bytes;
}
private static CompactSketch heapifyV4(final Memory srcMem, final long seed, final boolean enforceSeed) {
final int preLongs = extractPreLongs(srcMem);
final int flags = extractFlags(srcMem);
final int entryBits = extractEntryBitsV4(srcMem);
final int numEntriesBytes = extractNumEntriesBytesV4(srcMem);
final short seedHash = (short) extractSeedHash(srcMem);
final boolean isEmpty = (flags & EMPTY_FLAG_MASK) > 0;
if (enforceSeed && !isEmpty) { PreambleUtil.checkMemorySeedHash(srcMem, seed); }
int offsetBytes = 8;
long theta = Long.MAX_VALUE;
if (preLongs > 1) {
theta = extractThetaLongV4(srcMem);
offsetBytes += Long.BYTES;
}
int numEntries = 0;
for (int i = 0; i < numEntriesBytes; i++) {
numEntries |= Byte.toUnsignedInt(srcMem.getByte(offsetBytes++)) << (i << 3);
}
final long[] entries = new long[numEntries];
final byte[] bytes = new byte[entryBits]; // temporary buffer for unpacking
int i;
for (i = 0; i + 7 < numEntries; i += 8) {
srcMem.getByteArray(offsetBytes, bytes, 0, entryBits);
BitPacking.unpackBitsBlock8(entries, i, bytes, 0, entryBits);
offsetBytes += entryBits;
}
if (i < numEntries) {
srcMem.getByteArray(offsetBytes, bytes, 0, wholeBytesToHoldBits((numEntries - i) * entryBits));
int offsetBits = 0;
offsetBytes = 0;
for (; i < numEntries; i++) {
BitPacking.unpackBits(entries, i, entryBits, bytes, offsetBytes, offsetBits);
offsetBytes += (offsetBits + entryBits) >>> 3;
offsetBits = (offsetBits + entryBits) & 7;
}
}
// undo deltas
long previous = 0;
for (i = 0; i < numEntries; i++) {
entries[i] += previous;
previous = entries[i];
}
return new HeapCompactSketch(entries, isEmpty, seedHash, numEntries, theta, true);
}
}
| 2,759 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/Rebuilder.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.PreambleUtil.LG_ARR_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.insertCurCount;
import static org.apache.datasketches.theta.PreambleUtil.insertLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertThetaLong;
import static org.apache.datasketches.thetacommon.QuickSelect.selectExcludingZeros;
import org.apache.datasketches.common.Util;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.HashOperations;
/**
* Handles common resize, rebuild and move operations.
* The Memory based operations assume a specific data structure that is unique to the theta sketches.
*
* @author Lee Rhodes
*/
final class Rebuilder {
private Rebuilder() {}
/**
* 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
*/
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);
}
/**
* Moves me (the entire sketch) to a new larger Memory location and rebuilds the hash table.
* This assumes a Memory preamble of standard form with the correct value of thetaLong.
* Afterwards, the caller must update the local Memory reference, lgArrLongs
* and hashTableThreshold from the dstMemory and free the source Memory.
*
* @param srcMem the source Memory
* @param preambleLongs size of preamble in longs
* @param srcLgArrLongs size (log_base2) of source hash table
* @param dstMem the destination Memory, which may be garbage
* @param dstLgArrLongs the destination hash table target size
* @param thetaLong theta as a long
*/
static final void moveAndResize(final Memory srcMem, final int preambleLongs,
final int srcLgArrLongs, final WritableMemory dstMem, final int dstLgArrLongs, final long thetaLong) {
//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.
//Move Preamble to destination memory
final int preBytes = preambleLongs << 3;
srcMem.copyTo(0, dstMem, 0, preBytes); //copy the preamble
//Bulk copy source to on-heap buffer
final int srcHTLen = 1 << srcLgArrLongs;
final long[] srcHTArr = new long[srcHTLen];
srcMem.getLongArray(preBytes, srcHTArr, 0, srcHTLen);
//Create destination buffer
final int dstHTLen = 1 << dstLgArrLongs;
final long[] dstHTArr = new long[dstHTLen];
//Rebuild hash table in destination buffer
HashOperations.hashArrayInsert(srcHTArr, dstHTArr, dstLgArrLongs, thetaLong);
//Bulk copy to destination memory
dstMem.putLongArray(preBytes, dstHTArr, 0, dstHTLen);
dstMem.putByte(LG_ARR_LONGS_BYTE, (byte)dstLgArrLongs); //update in dstMem
}
/**
* 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
*/
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
}
/**
* 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
*/
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;
}
}
| 2,760 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/BitPacking.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import org.apache.datasketches.common.SketchesArgumentException;
public class BitPacking {
public static void packBits(final long value, int bits, final byte[] buffer, int bufOffset,
final int bitOffset) {
if (bitOffset > 0) {
final int chunkBits = 8 - bitOffset;
final int mask = (1 << chunkBits) - 1;
if (bits < chunkBits) {
buffer[bufOffset] |= (value << (chunkBits - bits)) & mask;
return;
}
buffer[bufOffset++] |= (value >>> (bits - chunkBits)) & mask;
bits -= chunkBits;
}
while (bits >= 8) {
buffer[bufOffset++] = (byte)(value >>> (bits - 8));
bits -= 8;
}
if (bits > 0) {
buffer[bufOffset] = (byte)(value << (8 - bits));
}
}
public static void unpackBits(final long[] value, final int index, int bits, final byte[] buffer,
int bufOffset,final int bitOffset) {
final int availBits = 8 - bitOffset;
final int chunkBits = availBits <= bits ? availBits : bits;
final int mask = (1 << chunkBits) - 1;
value[index] = (buffer[bufOffset] >>> (availBits - chunkBits)) & mask;
bufOffset += availBits == chunkBits ? 1 : 0;
bits -= chunkBits;
while (bits >= 8) {
value[index] <<= 8;
value[index] |= (Byte.toUnsignedLong(buffer[bufOffset++]));
bits -= 8;
}
if (bits > 0) {
value[index] <<= bits;
value[index] |= Byte.toUnsignedLong(buffer[bufOffset]) >>> (8 - bits);
}
}
// pack given number of bits from a block of 8 64-bit values into bytes
// we don't need 0 and 64 bits
// we assume that higher bits (which we are not packing) are zeros
// this assumption allows to avoid masking operations
static void packBitsBlock8(final long[] values, final int i, final byte[] buf, final int off, final int bits) {
switch (bits) {
case 1: packBits1(values, i, buf, off); break;
case 2: packBits2(values, i, buf, off); break;
case 3: packBits3(values, i, buf, off); break;
case 4: packBits4(values, i, buf, off); break;
case 5: packBits5(values, i, buf, off); break;
case 6: packBits6(values, i, buf, off); break;
case 7: packBits7(values, i, buf, off); break;
case 8: packBits8(values, i, buf, off); break;
case 9: packBits9(values, i, buf, off); break;
case 10: packBits10(values, i, buf, off); break;
case 11: packBits11(values, i, buf, off); break;
case 12: packBits12(values, i, buf, off); break;
case 13: packBits13(values, i, buf, off); break;
case 14: packBits14(values, i, buf, off); break;
case 15: packBits15(values, i, buf, off); break;
case 16: packBits16(values, i, buf, off); break;
case 17: packBits17(values, i, buf, off); break;
case 18: packBits18(values, i, buf, off); break;
case 19: packBits19(values, i, buf, off); break;
case 20: packBits20(values, i, buf, off); break;
case 21: packBits21(values, i, buf, off); break;
case 22: packBits22(values, i, buf, off); break;
case 23: packBits23(values, i, buf, off); break;
case 24: packBits24(values, i, buf, off); break;
case 25: packBits25(values, i, buf, off); break;
case 26: packBits26(values, i, buf, off); break;
case 27: packBits27(values, i, buf, off); break;
case 28: packBits28(values, i, buf, off); break;
case 29: packBits29(values, i, buf, off); break;
case 30: packBits30(values, i, buf, off); break;
case 31: packBits31(values, i, buf, off); break;
case 32: packBits32(values, i, buf, off); break;
case 33: packBits33(values, i, buf, off); break;
case 34: packBits34(values, i, buf, off); break;
case 35: packBits35(values, i, buf, off); break;
case 36: packBits36(values, i, buf, off); break;
case 37: packBits37(values, i, buf, off); break;
case 38: packBits38(values, i, buf, off); break;
case 39: packBits39(values, i, buf, off); break;
case 40: packBits40(values, i, buf, off); break;
case 41: packBits41(values, i, buf, off); break;
case 42: packBits42(values, i, buf, off); break;
case 43: packBits43(values, i, buf, off); break;
case 44: packBits44(values, i, buf, off); break;
case 45: packBits45(values, i, buf, off); break;
case 46: packBits46(values, i, buf, off); break;
case 47: packBits47(values, i, buf, off); break;
case 48: packBits48(values, i, buf, off); break;
case 49: packBits49(values, i, buf, off); break;
case 50: packBits50(values, i, buf, off); break;
case 51: packBits51(values, i, buf, off); break;
case 52: packBits52(values, i, buf, off); break;
case 53: packBits53(values, i, buf, off); break;
case 54: packBits54(values, i, buf, off); break;
case 55: packBits55(values, i, buf, off); break;
case 56: packBits56(values, i, buf, off); break;
case 57: packBits57(values, i, buf, off); break;
case 58: packBits58(values, i, buf, off); break;
case 59: packBits59(values, i, buf, off); break;
case 60: packBits60(values, i, buf, off); break;
case 61: packBits61(values, i, buf, off); break;
case 62: packBits62(values, i, buf, off); break;
case 63: packBits63(values, i, buf, off); break;
default: throw new SketchesArgumentException("wrong number of bits " + bits);
}
}
static void unpackBitsBlock8(final long[] values, final int i, final byte[] buf, final int off, final int bits) {
switch (bits) {
case 1: unpackBits1(values, i, buf, off); break;
case 2: unpackBits2(values, i, buf, off); break;
case 3: unpackBits3(values, i, buf, off); break;
case 4: unpackBits4(values, i, buf, off); break;
case 5: unpackBits5(values, i, buf, off); break;
case 6: unpackBits6(values, i, buf, off); break;
case 7: unpackBits7(values, i, buf, off); break;
case 8: unpackBits8(values, i, buf, off); break;
case 9: unpackBits9(values, i, buf, off); break;
case 10: unpackBits10(values, i, buf, off); break;
case 11: unpackBits11(values, i, buf, off); break;
case 12: unpackBits12(values, i, buf, off); break;
case 13: unpackBits13(values, i, buf, off); break;
case 14: unpackBits14(values, i, buf, off); break;
case 15: unpackBits15(values, i, buf, off); break;
case 16: unpackBits16(values, i, buf, off); break;
case 17: unpackBits17(values, i, buf, off); break;
case 18: unpackBits18(values, i, buf, off); break;
case 19: unpackBits19(values, i, buf, off); break;
case 20: unpackBits20(values, i, buf, off); break;
case 21: unpackBits21(values, i, buf, off); break;
case 22: unpackBits22(values, i, buf, off); break;
case 23: unpackBits23(values, i, buf, off); break;
case 24: unpackBits24(values, i, buf, off); break;
case 25: unpackBits25(values, i, buf, off); break;
case 26: unpackBits26(values, i, buf, off); break;
case 27: unpackBits27(values, i, buf, off); break;
case 28: unpackBits28(values, i, buf, off); break;
case 29: unpackBits29(values, i, buf, off); break;
case 30: unpackBits30(values, i, buf, off); break;
case 31: unpackBits31(values, i, buf, off); break;
case 32: unpackBits32(values, i, buf, off); break;
case 33: unpackBits33(values, i, buf, off); break;
case 34: unpackBits34(values, i, buf, off); break;
case 35: unpackBits35(values, i, buf, off); break;
case 36: unpackBits36(values, i, buf, off); break;
case 37: unpackBits37(values, i, buf, off); break;
case 38: unpackBits38(values, i, buf, off); break;
case 39: unpackBits39(values, i, buf, off); break;
case 40: unpackBits40(values, i, buf, off); break;
case 41: unpackBits41(values, i, buf, off); break;
case 42: unpackBits42(values, i, buf, off); break;
case 43: unpackBits43(values, i, buf, off); break;
case 44: unpackBits44(values, i, buf, off); break;
case 45: unpackBits45(values, i, buf, off); break;
case 46: unpackBits46(values, i, buf, off); break;
case 47: unpackBits47(values, i, buf, off); break;
case 48: unpackBits48(values, i, buf, off); break;
case 49: unpackBits49(values, i, buf, off); break;
case 50: unpackBits50(values, i, buf, off); break;
case 51: unpackBits51(values, i, buf, off); break;
case 52: unpackBits52(values, i, buf, off); break;
case 53: unpackBits53(values, i, buf, off); break;
case 54: unpackBits54(values, i, buf, off); break;
case 55: unpackBits55(values, i, buf, off); break;
case 56: unpackBits56(values, i, buf, off); break;
case 57: unpackBits57(values, i, buf, off); break;
case 58: unpackBits58(values, i, buf, off); break;
case 59: unpackBits59(values, i, buf, off); break;
case 60: unpackBits60(values, i, buf, off); break;
case 61: unpackBits61(values, i, buf, off); break;
case 62: unpackBits62(values, i, buf, off); break;
case 63: unpackBits63(values, i, buf, off); break;
default: throw new SketchesArgumentException("wrong number of bits " + bits);
}
}
static void packBits1(final long[] values, final int i, final byte[] buf, final int off) {
buf[off] = (byte) (values[i + 0] << 7);
buf[off] |= values[i + 1] << 6;
buf[off] |= values[i + 2] << 5;
buf[off] |= values[i + 3] << 4;
buf[off] |= values[i + 4] << 3;
buf[off] |= values[i + 5] << 2;
buf[off] |= values[i + 6] << 1;
buf[off] |= values[i + 7];
}
static void packBits2(final long[] values, final int i, final byte[] buf, int off) {
buf[off] = (byte) (values[i + 0] << 6);
buf[off] |= values[i + 1] << 4;
buf[off] |= values[i + 2] << 2;
buf[off++] |= values[i + 3];
buf[off] = (byte) (values[i + 4] << 6);
buf[off] |= values[i + 5] << 4;
buf[off] |= values[i + 6] << 2;
buf[off] |= values[i + 7];
}
static void packBits3(final long[] values, final int i, final byte[] buf, int off) {
buf[off] = (byte) (values[i + 0] << 5);
buf[off] |= values[i + 1] << 2;
buf[off++] |= values[i + 2] >>> 1;
buf[off] = (byte) (values[i + 2] << 7);
buf[off] |= values[i + 3] << 4;
buf[off] |= values[i + 4] << 1;
buf[off++] |= values[i + 5] >>> 2;
buf[off] = (byte) (values[i + 5] << 6);
buf[off] |= values[i + 6] << 3;
buf[off] |= values[i + 7];
}
static void packBits4(final long[] values, final int i, final byte[] buf, int off) {
buf[off] = (byte) (values[i + 0] << 4);
buf[off++] |= values[i + 1];
buf[off] = (byte) (values[i + 2] << 4);
buf[off++] |= values[i + 3];
buf[off] = (byte) (values[i + 4] << 4);
buf[off++] |= values[i + 5];
buf[off] = (byte) (values[i + 6] << 4);
buf[off] |= values[i + 7];
}
static void packBits5(final long[] values, final int i, final byte[] buf, int off) {
buf[off] = (byte) (values[i + 0] << 3);
buf[off++] |= values[i + 1] >>> 2;
buf[off] = (byte) (values[i + 1] << 6);
buf[off] |= values[i + 2] << 1;
buf[off++] |= values[i + 3] >>> 4;
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 1;
buf[off] = (byte) (values[i + 4] << 7);
buf[off] |= values[i + 5] << 2;
buf[off++] |= values[i + 6] >>> 3;
buf[off] = (byte) (values[i + 6] << 5);
buf[off] |= values[i + 7];
}
static void packBits6(final long[] values, final int i, final byte[] buf, int off) {
buf[off] = (byte) (values[i + 0] << 2);
buf[off++] |= values[i + 1] >>> 4;
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 2;
buf[off] = (byte) (values[i + 2] << 6);
buf[off++] |= values[i + 3];
buf[off] = (byte) (values[i + 4] << 2);
buf[off++] |= values[i + 5] >>> 4;
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 2;
buf[off] = (byte) (values[i + 6] << 6);
buf[off] |= values[i + 7];
}
static void packBits7(final long[] values, final int i, final byte[] buf, int off) {
buf[off] = (byte) (values[i + 0] << 1);
buf[off++] |= values[i + 1] >>> 6;
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 5;
buf[off] = (byte) (values[i + 2] << 3);
buf[off++] |= values[i + 3] >>> 4;
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 3;
buf[off] = (byte) (values[i + 4] << 5);
buf[off++] |= values[i + 5] >>> 2;
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 1;
buf[off] = (byte) (values[i + 6] << 7);
buf[off] |= values[i + 7];
}
static void packBits8(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0]);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2]);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4]);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6]);
buf[off] = (byte) (values[i + 7]);
}
static void packBits9(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 1);
buf[off] = (byte) (values[i + 0] << 7);
buf[off++] |= values[i + 1] >>> 2;
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 3;
buf[off] = (byte) (values[i + 2] << 5);
buf[off++] |= values[i + 3] >>> 4;
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 5;
buf[off] = (byte) (values[i + 4] << 3);
buf[off++] |= values[i + 5] >>> 6;
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 7;
buf[off] = (byte) (values[i + 6] << 1);
buf[off++] |= values[i + 7] >>> 8;
buf[off] = (byte) (values[i + 7]);
}
static void packBits10(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 2);
buf[off] = (byte) (values[i + 0] << 6);
buf[off++] |= values[i + 1] >>> 4;
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 6;
buf[off] = (byte) (values[i + 2] << 2);
buf[off++] |= values[i + 3] >>> 8;
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 2);
buf[off] = (byte) (values[i + 4] << 6);
buf[off++] |= values[i + 5] >>> 4;
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 6;
buf[off] = (byte) (values[i + 6] << 2);
buf[off++] |= values[i + 7] >>> 8;
buf[off] = (byte) (values[i + 7]);
}
static void packBits11(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 3);
buf[off] = (byte) (values[i + 0] << 5);
buf[off++] |= values[i + 1] >>> 6;
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 9;
buf[off++] = (byte) (values[i + 2] >>> 1);
buf[off] = (byte) (values[i + 2] << 7);
buf[off++] |= values[i + 3] >>> 4;
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 7;
buf[off] = (byte) (values[i + 4] << 1);
buf[off++] |= values[i + 5] >>> 10;
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 5;
buf[off] = (byte) (values[i + 6] << 3);
buf[off++] |= values[i + 7] >>> 8;
buf[off] = (byte) (values[i + 7]);
}
static void packBits12(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 4);
buf[off] = (byte) (values[i + 0] << 4);
buf[off++] |= values[i + 1] >>> 8;
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 4);
buf[off] = (byte) (values[i + 2] << 4);
buf[off++] |= values[i + 3] >>> 8;
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 4);
buf[off] = (byte) (values[i + 4] << 4);
buf[off++] |= values[i + 5] >>> 8;
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 4);
buf[off] = (byte) (values[i + 6] << 4);
buf[off++] |= values[i + 7] >>> 8;
buf[off] = (byte) (values[i + 7]);
}
static void packBits13(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 5);
buf[off] = (byte) (values[i + 0] << 3);
buf[off++] |= values[i + 1] >>> 10;
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 7;
buf[off] = (byte) (values[i + 2] << 1);
buf[off++] |= values[i + 3] >>> 12;
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] >>> 4);
buf[off++] |= values[i + 4] >>> 9;
buf[off++] = (byte) (values[i + 4] >>> 1);
buf[off] = (byte) (values[i + 4] << 7);
buf[off++] |= values[i + 5] >>> 6;
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 11;
buf[off++] = (byte) (values[i + 6] >>> 3);
buf[off] = (byte) (values[i + 6] << 5);
buf[off++] |= values[i + 7] >>> 8;
buf[off] = (byte) (values[i + 7]);
}
static void packBits14(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 6);
buf[off] = (byte) (values[i + 0] << 2);
buf[off++] |= values[i + 1] >>> 12;
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 10;
buf[off++] = (byte) (values[i + 2] >>> 2);
buf[off] = (byte) (values[i + 2] << 6);
buf[off++] |= values[i + 3] >>> 8;
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 6);
buf[off] = (byte) (values[i + 4] << 2);
buf[off++] |= values[i + 5] >>> 12;
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 10;
buf[off++] = (byte) (values[i + 6] >>> 2);
buf[off] = (byte) (values[i + 6] << 6);
buf[off++] |= values[i + 7] >>> 8;
buf[off] = (byte) (values[i + 7]);
}
static void packBits15(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 7);
buf[off] = (byte) (values[i + 0] << 1);
buf[off++] |= values[i + 1] >>> 14;
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 13;
buf[off++] = (byte) (values[i + 2] >>> 5);
buf[off] = (byte) (values[i + 2] << 3);
buf[off++] |= values[i + 3] >>> 12;
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 11;
buf[off++] = (byte) (values[i + 4] >>> 3);
buf[off] = (byte) (values[i + 4] << 5);
buf[off++] |= values[i + 5] >>> 10;
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 9;
buf[off++] = (byte) (values[i + 6] >>> 1);
buf[off] = (byte) (values[i + 6] << 7);
buf[off++] |= values[i + 7] >>> 8;
buf[off] = (byte) (values[i + 7]);
}
static void packBits16(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 8);
buf[off++] = (byte) (values[i + 0]);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 8);
buf[off++] = (byte) (values[i + 2]);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 8);
buf[off++] = (byte) (values[i + 4]);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 8);
buf[off++] = (byte) (values[i + 6]);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits17(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 9);
buf[off++] = (byte) (values[i + 0] >>> 1);
buf[off] = (byte) (values[i + 0] << 7);
buf[off++] |= values[i + 1] >>> 10;
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 11;
buf[off++] = (byte) (values[i + 2] >>> 3);
buf[off] = (byte) (values[i + 2] << 5);
buf[off++] |= values[i + 3] >>> 12;
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 13;
buf[off++] = (byte) (values[i + 4] >>> 5);
buf[off] = (byte) (values[i + 4] << 3);
buf[off++] |= values[i + 5] >>> 14;
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 15;
buf[off++] = (byte) (values[i + 6] >>> 7);
buf[off] = (byte) (values[i + 6] << 1);
buf[off++] |= values[i + 7] >>> 16;
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits18(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 10);
buf[off++] = (byte) (values[i + 0] >>> 2);
buf[off] = (byte) (values[i + 0] << 6);
buf[off++] |= values[i + 1] >>> 12;
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 14;
buf[off++] = (byte) (values[i + 2] >>> 6);
buf[off] = (byte) (values[i + 2] << 2);
buf[off++] |= values[i + 3] >>> 16;
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 10);
buf[off++] = (byte) (values[i + 4] >>> 2);
buf[off] = (byte) (values[i + 4] << 6);
buf[off++] |= values[i + 5] >>> 12;
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 14;
buf[off++] = (byte) (values[i + 6] >>> 6);
buf[off] = (byte) (values[i + 6] << 2);
buf[off++] |= values[i + 7] >>> 16;
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits19(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 11);
buf[off++] = (byte) (values[i + 0] >>> 3);
buf[off] = (byte) (values[i + 0] << 5);
buf[off++] |= values[i + 1] >>> 14;
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 17;
buf[off++] = (byte) (values[i + 2] >>> 9);
buf[off++] = (byte) (values[i + 2] >>> 1);
buf[off] = (byte) (values[i + 2] << 7);
buf[off++] |= values[i + 3] >>> 12;
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 15;
buf[off++] |= values[i + 4] >>> 7;
buf[off] = (byte) (values[i + 4] << 1);
buf[off++] |= values[i + 5] >>> 18;
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 13;
buf[off++] = (byte) (values[i + 6] >>> 5);
buf[off] = (byte) (values[i + 6] << 3);
buf[off++] |= values[i + 7] >>> 16;
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits20(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 12);
buf[off++] = (byte) (values[i + 0] >>> 4);
buf[off] = (byte) (values[i + 0] << 4);
buf[off++] |= values[i + 1] >>> 16;
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 12);
buf[off++] = (byte) (values[i + 2] >>> 4);
buf[off] = (byte) (values[i + 2] << 4);
buf[off++] |= values[i + 3] >>> 16;
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 12);
buf[off++] = (byte) (values[i + 4] >>> 4);
buf[off] = (byte) (values[i + 4] << 4);
buf[off++] |= values[i + 5] >>> 16;
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 12);
buf[off++] = (byte) (values[i + 6] >>> 4);
buf[off] = (byte) (values[i + 6] << 4);
buf[off++] |= values[i + 7] >>> 16;
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits21(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 13);
buf[off++] = (byte) (values[i + 0] >>> 5);
buf[off] = (byte) (values[i + 0] << 3);
buf[off++] |= values[i + 1] >>> 18;
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 15;
buf[off++] = (byte) (values[i + 2] >>> 7);
buf[off] = (byte) (values[i + 2] << 1);
buf[off++] |= values[i + 3] >>> 20;
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 17;
buf[off++] = (byte) (values[i + 4] >>> 9);
buf[off++] = (byte) (values[i + 4] >>> 1);
buf[off] = (byte) (values[i + 4] << 7);
buf[off++] |= values[i + 5] >>> 14;
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 19;
buf[off++] = (byte) (values[i + 6] >>> 11);
buf[off++] = (byte) (values[i + 6] >>> 3);
buf[off] = (byte) (values[i + 6] << 5);
buf[off++] |= values[i + 7] >>> 16;
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits22(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 14);
buf[off++] = (byte) (values[i + 0] >>> 6);
buf[off] = (byte) (values[i + 0] << 2);
buf[off++] |= values[i + 1] >>> 20;
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 18;
buf[off++] = (byte) (values[i + 2] >>> 10);
buf[off++] = (byte) (values[i + 2] >>> 2);
buf[off] = (byte) (values[i + 2] << 6);
buf[off++] |= values[i + 3] >>> 16;
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 14);
buf[off++] = (byte) (values[i + 4] >>> 6);
buf[off] = (byte) (values[i + 4] << 2);
buf[off++] |= values[i + 5] >>> 20;
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 18;
buf[off++] = (byte) (values[i + 6] >>> 10);
buf[off++] = (byte) (values[i + 6] >>> 2);
buf[off] = (byte) (values[i + 6] << 6);
buf[off++] |= values[i + 7] >>> 16;
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits23(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 15);
buf[off++] = (byte) (values[i + 0] >>> 7);
buf[off] = (byte) (values[i + 0] << 1);
buf[off++] |= values[i + 1] >>> 22;
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 21;
buf[off++] = (byte) (values[i + 2] >>> 13);
buf[off++] = (byte) (values[i + 2] >>> 5);
buf[off] = (byte) (values[i + 2] << 3);
buf[off++] |= values[i + 3] >>> 20;
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 19;
buf[off++] = (byte) (values[i + 4] >>> 11);
buf[off++] = (byte) (values[i + 4] >>> 3);
buf[off] = (byte) (values[i + 4] << 5);
buf[off++] |= values[i + 5] >>> 18;
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 17;
buf[off++] = (byte) (values[i + 6] >>> 9);
buf[off++] = (byte) (values[i + 6] >>> 1);
buf[off] = (byte) (values[i + 6] << 7);
buf[off++] |= values[i + 7] >>> 16;
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits24(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 16);
buf[off++] = (byte) (values[i + 0] >>> 8);
buf[off++] = (byte) (values[i + 0]);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 16);
buf[off++] = (byte) (values[i + 2] >>> 8);
buf[off++] = (byte) (values[i + 2]);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 16);
buf[off++] = (byte) (values[i + 4] >>> 8);
buf[off++] = (byte) (values[i + 4]);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 16);
buf[off++] = (byte) (values[i + 6] >>> 8);
buf[off++] = (byte) (values[i + 6]);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits25(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 17);
buf[off++] = (byte) (values[i + 0] >>> 9);
buf[off++] = (byte) (values[i + 0] >>> 1);
buf[off] = (byte) (values[i + 0] << 7);
buf[off++] |= values[i + 1] >>> 18;
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 19;
buf[off++] = (byte) (values[i + 2] >>> 11);
buf[off++] = (byte) (values[i + 2] >>> 3);
buf[off] = (byte) (values[i + 2] << 5);
buf[off++] |= values[i + 3] >>> 20;
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 21;
buf[off++] = (byte) (values[i + 4] >>> 13);
buf[off++] = (byte) (values[i + 4] >>> 5);
buf[off] = (byte) (values[i + 4] << 3);
buf[off++] |= values[i + 5] >>> 22;
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 23;
buf[off++] = (byte) (values[i + 6] >>> 15);
buf[off++] = (byte) (values[i + 6] >>> 7);
buf[off] = (byte) (values[i + 6] << 1);
buf[off++] |= values[i + 7] >>> 24;
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits26(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 18);
buf[off++] = (byte) (values[i + 0] >>> 10);
buf[off++] = (byte) (values[i + 0] >>> 2);
buf[off] = (byte) (values[i + 0] << 6);
buf[off++] |= values[i + 1] >>> 20;
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 22;
buf[off++] = (byte) (values[i + 2] >>> 14);
buf[off++] = (byte) (values[i + 2] >>> 6);
buf[off] = (byte) (values[i + 2] << 2);
buf[off++] |= values[i + 3] >>> 24;
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 18);
buf[off++] = (byte) (values[i + 4] >>> 10);
buf[off++] = (byte) (values[i + 4] >>> 2);
buf[off] = (byte) (values[i + 4] << 6);
buf[off++] |= values[i + 5] >>> 20;
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 22;
buf[off++] = (byte) (values[i + 6] >>> 14);
buf[off++] = (byte) (values[i + 6] >>> 6);
buf[off] = (byte) (values[i + 6] << 2);
buf[off++] |= values[i + 7] >>> 24;
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits27(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 19);
buf[off++] = (byte) (values[i + 0] >>> 11);
buf[off++] = (byte) (values[i + 0] >>> 3);
buf[off] = (byte) (values[i + 0] << 5);
buf[off++] |= values[i + 1] >>> 22;
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 25;
buf[off++] = (byte) (values[i + 2] >>> 17);
buf[off++] = (byte) (values[i + 2] >>> 9);
buf[off++] = (byte) (values[i + 2] >>> 1);
buf[off] = (byte) (values[i + 2] << 7);
buf[off++] |= values[i + 3] >>> 20;
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 23;
buf[off++] = (byte) (values[i + 4] >>> 15);
buf[off++] = (byte) (values[i + 4] >>> 7);
buf[off] = (byte) (values[i + 4] << 1);
buf[off++] |= values[i + 5] >>> 26;
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 21;
buf[off++] = (byte) (values[i + 6] >>> 13);
buf[off++] = (byte) (values[i + 6] >>> 5);
buf[off] = (byte) (values[i + 6] << 3);
buf[off++] |= values[i + 7] >>> 24;
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits28(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 20);
buf[off++] = (byte) (values[i + 0] >>> 12);
buf[off++] = (byte) (values[i + 0] >>> 4);
buf[off] = (byte) (values[i + 0] << 4);
buf[off++] |= values[i + 1] >>> 24;
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 20);
buf[off++] = (byte) (values[i + 2] >>> 12);
buf[off++] = (byte) (values[i + 2] >>> 4);
buf[off] = (byte) (values[i + 2] << 4);
buf[off++] |= values[i + 3] >>> 24;
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 20);
buf[off++] = (byte) (values[i + 4] >>> 12);
buf[off++] = (byte) (values[i + 4] >>> 4);
buf[off] = (byte) (values[i + 4] << 4);
buf[off++] |= values[i + 5] >>> 24;
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 20);
buf[off++] = (byte) (values[i + 6] >>> 12);
buf[off++] = (byte) (values[i + 6] >>> 4);
buf[off] = (byte) (values[i + 6] << 4);
buf[off++] |= values[i + 7] >>> 24;
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits29(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 21);
buf[off++] = (byte) (values[i + 0] >>> 13);
buf[off++] = (byte) (values[i + 0] >>> 5);
buf[off] = (byte) (values[i + 0] << 3);
buf[off++] |= values[i + 1] >>> 26;
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 23;
buf[off++] = (byte) (values[i + 2] >>> 15);
buf[off++] = (byte) (values[i + 2] >>> 7);
buf[off] = (byte) (values[i + 2] << 1);
buf[off++] |= values[i + 3] >>> 28;
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 25;
buf[off++] = (byte) (values[i + 4] >>> 17);
buf[off++] = (byte) (values[i + 4] >>> 9);
buf[off++] = (byte) (values[i + 4] >>> 1);
buf[off] = (byte) (values[i + 4] << 7);
buf[off++] |= values[i + 5] >>> 22;
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 27;
buf[off++] = (byte) (values[i + 6] >>> 19);
buf[off++] = (byte) (values[i + 6] >>> 11);
buf[off++] = (byte) (values[i + 6] >>> 3);
buf[off] = (byte) (values[i + 6] << 5);
buf[off++] |= values[i + 7] >>> 24;
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits30(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 22);
buf[off++] = (byte) (values[i + 0] >>> 14);
buf[off++] = (byte) (values[i + 0] >>> 6);
buf[off] = (byte) (values[i + 0] << 2);
buf[off++] |= values[i + 1] >>> 28;
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 26;
buf[off++] = (byte) (values[i + 2] >>> 18);
buf[off++] = (byte) (values[i + 2] >>> 10);
buf[off++] = (byte) (values[i + 2] >>> 2);
buf[off] = (byte) (values[i + 2] << 6);
buf[off++] |= values[i + 3] >>> 24;
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 22);
buf[off++] = (byte) (values[i + 4] >>> 14);
buf[off++] = (byte) (values[i + 4] >>> 6);
buf[off] = (byte) (values[i + 4] << 2);
buf[off++] |= values[i + 5] >>> 28;
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 26;
buf[off++] = (byte) (values[i + 6] >>> 18);
buf[off++] = (byte) (values[i + 6] >>> 10);
buf[off++] = (byte) (values[i + 6] >>> 2);
buf[off] = (byte) (values[i + 6] << 6);
buf[off++] |= values[i + 7] >>> 24;
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits31(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 23);
buf[off++] = (byte) (values[i + 0] >>> 15);
buf[off++] = (byte) (values[i + 0] >>> 7);
buf[off] = (byte) (values[i + 0] << 1);
buf[off++] |= values[i + 1] >>> 30;
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 29;
buf[off++] = (byte) (values[i + 2] >>> 21);
buf[off++] = (byte) (values[i + 2] >>> 13);
buf[off++] = (byte) (values[i + 2] >>> 5);
buf[off] = (byte) (values[i + 2] << 3);
buf[off++] |= values[i + 3] >>> 28;
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 27;
buf[off++] = (byte) (values[i + 4] >>> 19);
buf[off++] = (byte) (values[i + 4] >>> 11);
buf[off++] = (byte) (values[i + 4] >>> 3);
buf[off] = (byte) (values[i + 4] << 5);
buf[off++] |= values[i + 5] >>> 26;
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 25;
buf[off++] = (byte) (values[i + 6] >>> 17);
buf[off++] = (byte) (values[i + 6] >>> 9);
buf[off++] = (byte) (values[i + 6] >>> 1);
buf[off] = (byte) (values[i + 6] << 7);
buf[off++] |= values[i + 7] >>> 24;
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits32(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 24);
buf[off++] = (byte) (values[i + 0] >>> 16);
buf[off++] = (byte) (values[i + 0] >>> 8);
buf[off++] = (byte) (values[i + 0]);
buf[off++] = (byte) (values[i + 1] >>> 24);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 24);
buf[off++] = (byte) (values[i + 2] >>> 16);
buf[off++] = (byte) (values[i + 2] >>> 8);
buf[off++] = (byte) (values[i + 2]);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 24);
buf[off++] = (byte) (values[i + 4] >>> 16);
buf[off++] = (byte) (values[i + 4] >>> 8);
buf[off++] = (byte) (values[i + 4]);
buf[off++] = (byte) (values[i + 5] >>> 24);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 24);
buf[off++] = (byte) (values[i + 6] >>> 16);
buf[off++] = (byte) (values[i + 6] >>> 8);
buf[off++] = (byte) (values[i + 6]);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits33(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 25);
buf[off++] = (byte) (values[i + 0] >>> 17);
buf[off++] = (byte) (values[i + 0] >>> 9);
buf[off++] = (byte) (values[i + 0] >>> 1);
buf[off] = (byte) (values[i + 0] << 7);
buf[off++] |= values[i + 1] >>> 26;
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 27;
buf[off++] = (byte) (values[i + 2] >>> 19);
buf[off++] = (byte) (values[i + 2] >>> 11);
buf[off++] = (byte) (values[i + 2] >>> 3);
buf[off] = (byte) (values[i + 2] << 5);
buf[off++] |= values[i + 3] >>> 28;
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 29;
buf[off++] = (byte) (values[i + 4] >>> 21);
buf[off++] = (byte) (values[i + 4] >>> 13);
buf[off++] = (byte) (values[i + 4] >>> 5);
buf[off] = (byte) (values[i + 4] << 3);
buf[off++] |= values[i + 5] >>> 30;
buf[off++] = (byte) (values[i + 5] >>> 22);
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 31;
buf[off++] = (byte) (values[i + 6] >>> 23);
buf[off++] = (byte) (values[i + 6] >>> 15);
buf[off++] = (byte) (values[i + 6] >>> 7);
buf[off] = (byte) (values[i + 6] << 1);
buf[off++] |= values[i + 7] >>> 32;
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits34(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 26);
buf[off++] = (byte) (values[i + 0] >>> 18);
buf[off++] = (byte) (values[i + 0] >>> 10);
buf[off++] = (byte) (values[i + 0] >>> 2);
buf[off] = (byte) (values[i + 0] << 6);
buf[off++] |= values[i + 1] >>> 28;
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 30;
buf[off++] = (byte) (values[i + 2] >>> 22);
buf[off++] = (byte) (values[i + 2] >>> 14);
buf[off++] = (byte) (values[i + 2] >>> 6);
buf[off] = (byte) (values[i + 2] << 2);
buf[off++] |= values[i + 3] >>> 32;
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 26);
buf[off++] = (byte) (values[i + 4] >>> 18);
buf[off++] = (byte) (values[i + 4] >>> 10);
buf[off++] = (byte) (values[i + 4] >>> 2);
buf[off] = (byte) (values[i + 4] << 6);
buf[off++] |= values[i + 5] >>> 28;
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 30;
buf[off++] = (byte) (values[i + 6] >>> 22);
buf[off++] = (byte) (values[i + 6] >>> 14);
buf[off++] = (byte) (values[i + 6] >>> 6);
buf[off] = (byte) (values[i + 6] << 2);
buf[off++] |= values[i + 7] >>> 32;
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits35(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 27);
buf[off++] = (byte) (values[i + 0] >>> 19);
buf[off++] = (byte) (values[i + 0] >>> 11);
buf[off++] = (byte) (values[i + 0] >>> 3);
buf[off] = (byte) (values[i + 0] << 5);
buf[off++] |= values[i + 1] >>> 30;
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 33;
buf[off++] = (byte) (values[i + 2] >>> 25);
buf[off++] = (byte) (values[i + 2] >>> 17);
buf[off++] = (byte) (values[i + 2] >>> 9);
buf[off++] = (byte) (values[i + 2] >>> 1);
buf[off] = (byte) (values[i + 2] << 7);
buf[off++] |= values[i + 3] >>> 28;
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 31;
buf[off++] = (byte) (values[i + 4] >>> 23);
buf[off++] = (byte) (values[i + 4] >>> 15);
buf[off++] = (byte) (values[i + 4] >>> 7);
buf[off] = (byte) (values[i + 4] << 1);
buf[off++] |= values[i + 5] >>> 34;
buf[off++] = (byte) (values[i + 5] >>> 26);
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 29;
buf[off++] = (byte) (values[i + 6] >>> 21);
buf[off++] = (byte) (values[i + 6] >>> 13);
buf[off++] = (byte) (values[i + 6] >>> 5);
buf[off] = (byte) (values[i + 6] << 3);
buf[off++] |= values[i + 7] >>> 32;
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits36(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 28);
buf[off++] = (byte) (values[i + 0] >>> 20);
buf[off++] = (byte) (values[i + 0] >>> 12);
buf[off++] = (byte) (values[i + 0] >>> 4);
buf[off] = (byte) (values[i + 0] << 4);
buf[off++] |= values[i + 1] >>> 32;
buf[off++] = (byte) (values[i + 1] >>> 24);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 28);
buf[off++] = (byte) (values[i + 2] >>> 20);
buf[off++] = (byte) (values[i + 2] >>> 12);
buf[off++] = (byte) (values[i + 2] >>> 4);
buf[off] = (byte) (values[i + 2] << 4);
buf[off++] |= values[i + 3] >>> 32;
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 28);
buf[off++] = (byte) (values[i + 4] >>> 20);
buf[off++] = (byte) (values[i + 4] >>> 12);
buf[off++] = (byte) (values[i + 4] >>> 4);
buf[off] = (byte) (values[i + 4] << 4);
buf[off++] |= values[i + 5] >>> 32;
buf[off++] = (byte) (values[i + 5] >>> 24);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 28);
buf[off++] = (byte) (values[i + 6] >>> 20);
buf[off++] = (byte) (values[i + 6] >>> 12);
buf[off++] = (byte) (values[i + 6] >>> 4);
buf[off] = (byte) (values[i + 6] << 4);
buf[off++] |= values[i + 7] >>> 32;
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits37(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 29);
buf[off++] = (byte) (values[i + 0] >>> 21);
buf[off++] = (byte) (values[i + 0] >>> 13);
buf[off++] = (byte) (values[i + 0] >>> 5);
buf[off] = (byte) (values[i + 0] << 3);
buf[off++] |= values[i + 1] >>> 34;
buf[off++] = (byte) (values[i + 1] >>> 26);
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 31;
buf[off++] = (byte) (values[i + 2] >>> 23);
buf[off++] = (byte) (values[i + 2] >>> 15);
buf[off++] = (byte) (values[i + 2] >>> 7);
buf[off] = (byte) (values[i + 2] << 1);
buf[off++] |= values[i + 3] >>> 36;
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 33;
buf[off++] = (byte) (values[i + 4] >>> 25);
buf[off++] = (byte) (values[i + 4] >>> 17);
buf[off++] = (byte) (values[i + 4] >>> 9);
buf[off++] = (byte) (values[i + 4] >>> 1);
buf[off] = (byte) (values[i + 4] << 7);
buf[off++] |= values[i + 5] >>> 30;
buf[off++] = (byte) (values[i + 5] >>> 22);
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 35;
buf[off++] = (byte) (values[i + 6] >>> 27);
buf[off++] = (byte) (values[i + 6] >>> 19);
buf[off++] = (byte) (values[i + 6] >>> 11);
buf[off++] = (byte) (values[i + 6] >>> 3);
buf[off] = (byte) (values[i + 6] << 5);
buf[off++] |= values[i + 7] >>> 32;
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits38(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 30);
buf[off++] = (byte) (values[i + 0] >>> 22);
buf[off++] = (byte) (values[i + 0] >>> 14);
buf[off++] = (byte) (values[i + 0] >>> 6);
buf[off] = (byte) (values[i + 0] << 2);
buf[off++] |= values[i + 1] >>> 36;
buf[off++] = (byte) (values[i + 1] >>> 28);
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 34;
buf[off++] = (byte) (values[i + 2] >>> 26);
buf[off++] = (byte) (values[i + 2] >>> 18);
buf[off++] = (byte) (values[i + 2] >>> 10);
buf[off++] = (byte) (values[i + 2] >>> 2);
buf[off] = (byte) (values[i + 2] << 6);
buf[off++] |= values[i + 3] >>> 32;
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 30);
buf[off++] = (byte) (values[i + 4] >>> 22);
buf[off++] = (byte) (values[i + 4] >>> 14);
buf[off++] = (byte) (values[i + 4] >>> 6);
buf[off] = (byte) (values[i + 4] << 2);
buf[off++] |= values[i + 5] >>> 36;
buf[off++] = (byte) (values[i + 5] >>> 28);
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 34;
buf[off++] = (byte) (values[i + 6] >>> 26);
buf[off++] = (byte) (values[i + 6] >>> 18);
buf[off++] = (byte) (values[i + 6] >>> 10);
buf[off++] = (byte) (values[i + 6] >>> 2);
buf[off] = (byte) (values[i + 6] << 6);
buf[off++] |= values[i + 7] >>> 32;
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits39(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 31);
buf[off++] = (byte) (values[i + 0] >>> 23);
buf[off++] = (byte) (values[i + 0] >>> 15);
buf[off++] = (byte) (values[i + 0] >>> 7);
buf[off] = (byte) (values[i + 0] << 1);
buf[off++] |= values[i + 1] >>> 38;
buf[off++] = (byte) (values[i + 1] >>> 30);
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 37;
buf[off++] = (byte) (values[i + 2] >>> 29);
buf[off++] = (byte) (values[i + 2] >>> 21);
buf[off++] = (byte) (values[i + 2] >>> 13);
buf[off++] = (byte) (values[i + 2] >>> 5);
buf[off] = (byte) (values[i + 2] << 3);
buf[off++] |= values[i + 3] >>> 36;
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 35;
buf[off++] = (byte) (values[i + 4] >>> 27);
buf[off++] = (byte) (values[i + 4] >>> 19);
buf[off++] = (byte) (values[i + 4] >>> 11);
buf[off++] = (byte) (values[i + 4] >>> 3);
buf[off] = (byte) (values[i + 4] << 5);
buf[off++] |= values[i + 5] >>> 34;
buf[off++] = (byte) (values[i + 5] >>> 26);
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 33;
buf[off++] = (byte) (values[i + 6] >>> 25);
buf[off++] = (byte) (values[i + 6] >>> 17);
buf[off++] = (byte) (values[i + 6] >>> 9);
buf[off++] = (byte) (values[i + 6] >>> 1);
buf[off] = (byte) (values[i + 6] << 7);
buf[off++] |= values[i + 7] >>> 32;
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits40(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 32);
buf[off++] = (byte) (values[i + 0] >>> 24);
buf[off++] = (byte) (values[i + 0] >>> 16);
buf[off++] = (byte) (values[i + 0] >>> 8);
buf[off++] = (byte) (values[i + 0]);
buf[off++] = (byte) (values[i + 1] >>> 32);
buf[off++] = (byte) (values[i + 1] >>> 24);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 32);
buf[off++] = (byte) (values[i + 2] >>> 24);
buf[off++] = (byte) (values[i + 2] >>> 16);
buf[off++] = (byte) (values[i + 2] >>> 8);
buf[off++] = (byte) (values[i + 2]);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 32);
buf[off++] = (byte) (values[i + 4] >>> 24);
buf[off++] = (byte) (values[i + 4] >>> 16);
buf[off++] = (byte) (values[i + 4] >>> 8);
buf[off++] = (byte) (values[i + 4]);
buf[off++] = (byte) (values[i + 5] >>> 32);
buf[off++] = (byte) (values[i + 5] >>> 24);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 32);
buf[off++] = (byte) (values[i + 6] >>> 24);
buf[off++] = (byte) (values[i + 6] >>> 16);
buf[off++] = (byte) (values[i + 6] >>> 8);
buf[off++] = (byte) (values[i + 6]);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits41(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 33);
buf[off++] = (byte) (values[i + 0] >>> 25);
buf[off++] = (byte) (values[i + 0] >>> 17);
buf[off++] = (byte) (values[i + 0] >>> 9);
buf[off++] = (byte) (values[i + 0] >>> 1);
buf[off] = (byte) (values[i + 0] << 7);
buf[off++] |= values[i + 1] >>> 34;
buf[off++] = (byte) (values[i + 1] >>> 26);
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 35;
buf[off++] = (byte) (values[i + 2] >>> 27);
buf[off++] = (byte) (values[i + 2] >>> 19);
buf[off++] = (byte) (values[i + 2] >>> 11);
buf[off++] = (byte) (values[i + 2] >>> 3);
buf[off] = (byte) (values[i + 2] << 5);
buf[off++] |= values[i + 3] >>> 36;
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 37;
buf[off++] = (byte) (values[i + 4] >>> 29);
buf[off++] = (byte) (values[i + 4] >>> 21);
buf[off++] = (byte) (values[i + 4] >>> 13);
buf[off++] = (byte) (values[i + 4] >>> 5);
buf[off] = (byte) (values[i + 4] << 3);
buf[off++] |= values[i + 5] >>> 38;
buf[off++] = (byte) (values[i + 5] >>> 30);
buf[off++] = (byte) (values[i + 5] >>> 22);
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 39;
buf[off++] = (byte) (values[i + 6] >>> 31);
buf[off++] = (byte) (values[i + 6] >>> 23);
buf[off++] = (byte) (values[i + 6] >>> 15);
buf[off++] = (byte) (values[i + 6] >>> 7);
buf[off] = (byte) (values[i + 6] << 1);
buf[off++] |= values[i + 7] >>> 40;
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits42(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 34);
buf[off++] = (byte) (values[i + 0] >>> 26);
buf[off++] = (byte) (values[i + 0] >>> 18);
buf[off++] = (byte) (values[i + 0] >>> 10);
buf[off++] = (byte) (values[i + 0] >>> 2);
buf[off] = (byte) (values[i + 0] << 6);
buf[off++] |= values[i + 1] >>> 36;
buf[off++] = (byte) (values[i + 1] >>> 28);
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 38;
buf[off++] = (byte) (values[i + 2] >>> 30);
buf[off++] = (byte) (values[i + 2] >>> 22);
buf[off++] = (byte) (values[i + 2] >>> 14);
buf[off++] = (byte) (values[i + 2] >>> 6);
buf[off] = (byte) (values[i + 2] << 2);
buf[off++] |= values[i + 3] >>> 40;
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 34);
buf[off++] = (byte) (values[i + 4] >>> 26);
buf[off++] = (byte) (values[i + 4] >>> 18);
buf[off++] = (byte) (values[i + 4] >>> 10);
buf[off++] = (byte) (values[i + 4] >>> 2);
buf[off] = (byte) (values[i + 4] << 6);
buf[off++] |= values[i + 5] >>> 36;
buf[off++] = (byte) (values[i + 5] >>> 28);
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 38;
buf[off++] = (byte) (values[i + 6] >>> 30);
buf[off++] = (byte) (values[i + 6] >>> 22);
buf[off++] = (byte) (values[i + 6] >>> 14);
buf[off++] = (byte) (values[i + 6] >>> 6);
buf[off] = (byte) (values[i + 6] << 2);
buf[off++] |= values[i + 7] >>> 40;
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits43(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 35);
buf[off++] = (byte) (values[i + 0] >>> 27);
buf[off++] = (byte) (values[i + 0] >>> 19);
buf[off++] = (byte) (values[i + 0] >>> 11);
buf[off++] = (byte) (values[i + 0] >>> 3);
buf[off] = (byte) (values[i + 0] << 5);
buf[off++] |= values[i + 1] >>> 38;
buf[off++] = (byte) (values[i + 1] >>> 30);
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 41;
buf[off++] = (byte) (values[i + 2] >>> 33);
buf[off++] = (byte) (values[i + 2] >>> 25);
buf[off++] = (byte) (values[i + 2] >>> 17);
buf[off++] = (byte) (values[i + 2] >>> 9);
buf[off++] = (byte) (values[i + 2] >>> 1);
buf[off] = (byte) (values[i + 2] << 7);
buf[off++] |= values[i + 3] >>> 36;
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 39;
buf[off++] = (byte) (values[i + 4] >>> 31);
buf[off++] = (byte) (values[i + 4] >>> 23);
buf[off++] = (byte) (values[i + 4] >>> 15);
buf[off++] = (byte) (values[i + 4] >>> 7);
buf[off] = (byte) (values[i + 4] << 1);
buf[off++] |= values[i + 5] >>> 42;
buf[off++] = (byte) (values[i + 5] >>> 34);
buf[off++] = (byte) (values[i + 5] >>> 26);
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 37;
buf[off++] = (byte) (values[i + 6] >>> 29);
buf[off++] = (byte) (values[i + 6] >>> 21);
buf[off++] = (byte) (values[i + 6] >>> 13);
buf[off++] = (byte) (values[i + 6] >>> 5);
buf[off] = (byte) (values[i + 6] << 3);
buf[off++] |= values[i + 7] >>> 40;
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits44(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 36);
buf[off++] = (byte) (values[i + 0] >>> 28);
buf[off++] = (byte) (values[i + 0] >>> 20);
buf[off++] = (byte) (values[i + 0] >>> 12);
buf[off++] = (byte) (values[i + 0] >>> 4);
buf[off] = (byte) (values[i + 0] << 4);
buf[off++] |= values[i + 1] >>> 40;
buf[off++] = (byte) (values[i + 1] >>> 32);
buf[off++] = (byte) (values[i + 1] >>> 24);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 36);
buf[off++] = (byte) (values[i + 2] >>> 28);
buf[off++] = (byte) (values[i + 2] >>> 20);
buf[off++] = (byte) (values[i + 2] >>> 12);
buf[off++] = (byte) (values[i + 2] >>> 4);
buf[off] = (byte) (values[i + 2] << 4);
buf[off++] |= values[i + 3] >>> 40;
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 36);
buf[off++] = (byte) (values[i + 4] >>> 28);
buf[off++] = (byte) (values[i + 4] >>> 20);
buf[off++] = (byte) (values[i + 4] >>> 12);
buf[off++] = (byte) (values[i + 4] >>> 4);
buf[off] = (byte) (values[i + 4] << 4);
buf[off++] |= values[i + 5] >>> 40;
buf[off++] = (byte) (values[i + 5] >>> 32);
buf[off++] = (byte) (values[i + 5] >>> 24);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 36);
buf[off++] = (byte) (values[i + 6] >>> 28);
buf[off++] = (byte) (values[i + 6] >>> 20);
buf[off++] = (byte) (values[i + 6] >>> 12);
buf[off++] = (byte) (values[i + 6] >>> 4);
buf[off] = (byte) (values[i + 6] << 4);
buf[off++] |= values[i + 7] >>> 40;
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits45(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 37);
buf[off++] = (byte) (values[i + 0] >>> 29);
buf[off++] = (byte) (values[i + 0] >>> 21);
buf[off++] = (byte) (values[i + 0] >>> 13);
buf[off++] = (byte) (values[i + 0] >>> 5);
buf[off] = (byte) (values[i + 0] << 3);
buf[off++] |= values[i + 1] >>> 42;
buf[off++] = (byte) (values[i + 1] >>> 34);
buf[off++] = (byte) (values[i + 1] >>> 26);
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 39;
buf[off++] = (byte) (values[i + 2] >>> 31);
buf[off++] = (byte) (values[i + 2] >>> 23);
buf[off++] = (byte) (values[i + 2] >>> 15);
buf[off++] = (byte) (values[i + 2] >>> 7);
buf[off] = (byte) (values[i + 2] << 1);
buf[off++] |= values[i + 3] >>> 44;
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 41;
buf[off++] = (byte) (values[i + 4] >>> 33);
buf[off++] = (byte) (values[i + 4] >>> 25);
buf[off++] = (byte) (values[i + 4] >>> 17);
buf[off++] = (byte) (values[i + 4] >>> 9);
buf[off++] = (byte) (values[i + 4] >>> 1);
buf[off] = (byte) (values[i + 4] << 7);
buf[off++] |= values[i + 5] >>> 38;
buf[off++] = (byte) (values[i + 5] >>> 30);
buf[off++] = (byte) (values[i + 5] >>> 22);
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 43;
buf[off++] = (byte) (values[i + 6] >>> 35);
buf[off++] = (byte) (values[i + 6] >>> 27);
buf[off++] = (byte) (values[i + 6] >>> 19);
buf[off++] = (byte) (values[i + 6] >>> 11);
buf[off++] = (byte) (values[i + 6] >>> 3);
buf[off] = (byte) (values[i + 6] << 5);
buf[off++] |= values[i + 7] >>> 40;
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits46(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 38);
buf[off++] = (byte) (values[i + 0] >>> 30);
buf[off++] = (byte) (values[i + 0] >>> 22);
buf[off++] = (byte) (values[i + 0] >>> 14);
buf[off++] = (byte) (values[i + 0] >>> 6);
buf[off] = (byte) (values[i + 0] << 2);
buf[off++] |= values[i + 1] >>> 44;
buf[off++] = (byte) (values[i + 1] >>> 36);
buf[off++] = (byte) (values[i + 1] >>> 28);
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 42;
buf[off++] = (byte) (values[i + 2] >>> 34);
buf[off++] = (byte) (values[i + 2] >>> 26);
buf[off++] = (byte) (values[i + 2] >>> 18);
buf[off++] = (byte) (values[i + 2] >>> 10);
buf[off++] = (byte) (values[i + 2] >>> 2);
buf[off] = (byte) (values[i + 2] << 6);
buf[off++] |= values[i + 3] >>> 40;
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 38);
buf[off++] = (byte) (values[i + 4] >>> 30);
buf[off++] = (byte) (values[i + 4] >>> 22);
buf[off++] = (byte) (values[i + 4] >>> 14);
buf[off++] = (byte) (values[i + 4] >>> 6);
buf[off] = (byte) (values[i + 4] << 2);
buf[off++] |= values[i + 5] >>> 44;
buf[off++] = (byte) (values[i + 5] >>> 36);
buf[off++] = (byte) (values[i + 5] >>> 28);
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 42;
buf[off++] = (byte) (values[i + 6] >>> 34);
buf[off++] = (byte) (values[i + 6] >>> 26);
buf[off++] = (byte) (values[i + 6] >>> 18);
buf[off++] = (byte) (values[i + 6] >>> 10);
buf[off++] = (byte) (values[i + 6] >>> 2);
buf[off] = (byte) (values[i + 6] << 6);
buf[off++] |= values[i + 7] >>> 40;
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits47(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 39);
buf[off++] = (byte) (values[i + 0] >>> 31);
buf[off++] = (byte) (values[i + 0] >>> 23);
buf[off++] = (byte) (values[i + 0] >>> 15);
buf[off++] = (byte) (values[i + 0] >>> 7);
buf[off] = (byte) (values[i + 0] << 1);
buf[off++] |= values[i + 1] >>> 46;
buf[off++] = (byte) (values[i + 1] >>> 38);
buf[off++] = (byte) (values[i + 1] >>> 30);
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 45;
buf[off++] = (byte) (values[i + 2] >>> 37);
buf[off++] = (byte) (values[i + 2] >>> 29);
buf[off++] = (byte) (values[i + 2] >>> 21);
buf[off++] = (byte) (values[i + 2] >>> 13);
buf[off++] = (byte) (values[i + 2] >>> 5);
buf[off] = (byte) (values[i + 2] << 3);
buf[off++] |= values[i + 3] >>> 44;
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 43;
buf[off++] = (byte) (values[i + 4] >>> 35);
buf[off++] = (byte) (values[i + 4] >>> 27);
buf[off++] = (byte) (values[i + 4] >>> 19);
buf[off++] = (byte) (values[i + 4] >>> 11);
buf[off++] = (byte) (values[i + 4] >>> 3);
buf[off] = (byte) (values[i + 4] << 5);
buf[off++] |= values[i + 5] >>> 42;
buf[off++] = (byte) (values[i + 5] >>> 34);
buf[off++] = (byte) (values[i + 5] >>> 26);
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 41;
buf[off++] = (byte) (values[i + 6] >>> 33);
buf[off++] = (byte) (values[i + 6] >>> 25);
buf[off++] = (byte) (values[i + 6] >>> 17);
buf[off++] = (byte) (values[i + 6] >>> 9);
buf[off++] = (byte) (values[i + 6] >>> 1);
buf[off] = (byte) (values[i + 6] << 7);
buf[off++] |= values[i + 7] >>> 40;
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits48(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 40);
buf[off++] = (byte) (values[i + 0] >>> 32);
buf[off++] = (byte) (values[i + 0] >>> 24);
buf[off++] = (byte) (values[i + 0] >>> 16);
buf[off++] = (byte) (values[i + 0] >>> 8);
buf[off++] = (byte) (values[i + 0]);
buf[off++] = (byte) (values[i + 1] >>> 40);
buf[off++] = (byte) (values[i + 1] >>> 32);
buf[off++] = (byte) (values[i + 1] >>> 24);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 40);
buf[off++] = (byte) (values[i + 2] >>> 32);
buf[off++] = (byte) (values[i + 2] >>> 24);
buf[off++] = (byte) (values[i + 2] >>> 16);
buf[off++] = (byte) (values[i + 2] >>> 8);
buf[off++] = (byte) (values[i + 2]);
buf[off++] = (byte) (values[i + 3] >>> 40);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 40);
buf[off++] = (byte) (values[i + 4] >>> 32);
buf[off++] = (byte) (values[i + 4] >>> 24);
buf[off++] = (byte) (values[i + 4] >>> 16);
buf[off++] = (byte) (values[i + 4] >>> 8);
buf[off++] = (byte) (values[i + 4]);
buf[off++] = (byte) (values[i + 5] >>> 40);
buf[off++] = (byte) (values[i + 5] >>> 32);
buf[off++] = (byte) (values[i + 5] >>> 24);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 40);
buf[off++] = (byte) (values[i + 6] >>> 32);
buf[off++] = (byte) (values[i + 6] >>> 24);
buf[off++] = (byte) (values[i + 6] >>> 16);
buf[off++] = (byte) (values[i + 6] >>> 8);
buf[off++] = (byte) (values[i + 6]);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits49(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 41);
buf[off++] = (byte) (values[i + 0] >>> 33);
buf[off++] = (byte) (values[i + 0] >>> 25);
buf[off++] = (byte) (values[i + 0] >>> 17);
buf[off++] = (byte) (values[i + 0] >>> 9);
buf[off++] = (byte) (values[i + 0] >>> 1);
buf[off] = (byte) (values[i + 0] << 7);
buf[off++] |= values[i + 1] >>> 42;
buf[off++] = (byte) (values[i + 1] >>> 34);
buf[off++] = (byte) (values[i + 1] >>> 26);
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 43;
buf[off++] = (byte) (values[i + 2] >>> 35);
buf[off++] = (byte) (values[i + 2] >>> 27);
buf[off++] = (byte) (values[i + 2] >>> 19);
buf[off++] = (byte) (values[i + 2] >>> 11);
buf[off++] = (byte) (values[i + 2] >>> 3);
buf[off] = (byte) (values[i + 2] << 5);
buf[off++] |= values[i + 3] >>> 44;
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 45;
buf[off++] = (byte) (values[i + 4] >>> 37);
buf[off++] = (byte) (values[i + 4] >>> 29);
buf[off++] = (byte) (values[i + 4] >>> 21);
buf[off++] = (byte) (values[i + 4] >>> 13);
buf[off++] = (byte) (values[i + 4] >>> 5);
buf[off] = (byte) (values[i + 4] << 3);
buf[off++] |= values[i + 5] >>> 46;
buf[off++] = (byte) (values[i + 5] >>> 38);
buf[off++] = (byte) (values[i + 5] >>> 30);
buf[off++] = (byte) (values[i + 5] >>> 22);
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 47;
buf[off++] = (byte) (values[i + 6] >>> 39);
buf[off++] = (byte) (values[i + 6] >>> 31);
buf[off++] = (byte) (values[i + 6] >>> 23);
buf[off++] = (byte) (values[i + 6] >>> 15);
buf[off++] = (byte) (values[i + 6] >>> 7);
buf[off] = (byte) (values[i + 6] << 1);
buf[off++] |= values[i + 7] >>> 48;
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits50(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 42);
buf[off++] = (byte) (values[i + 0] >>> 34);
buf[off++] = (byte) (values[i + 0] >>> 26);
buf[off++] = (byte) (values[i + 0] >>> 18);
buf[off++] = (byte) (values[i + 0] >>> 10);
buf[off++] = (byte) (values[i + 0] >>> 2);
buf[off] = (byte) (values[i + 0] << 6);
buf[off++] |= values[i + 1] >>> 44;
buf[off++] = (byte) (values[i + 1] >>> 36);
buf[off++] = (byte) (values[i + 1] >>> 28);
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 46;
buf[off++] = (byte) (values[i + 2] >>> 38);
buf[off++] = (byte) (values[i + 2] >>> 30);
buf[off++] = (byte) (values[i + 2] >>> 22);
buf[off++] = (byte) (values[i + 2] >>> 14);
buf[off++] = (byte) (values[i + 2] >>> 6);
buf[off] = (byte) (values[i + 2] << 2);
buf[off++] |= values[i + 3] >>> 48;
buf[off++] = (byte) (values[i + 3] >>> 40);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 42);
buf[off++] = (byte) (values[i + 4] >>> 34);
buf[off++] = (byte) (values[i + 4] >>> 26);
buf[off++] = (byte) (values[i + 4] >>> 18);
buf[off++] = (byte) (values[i + 4] >>> 10);
buf[off++] = (byte) (values[i + 4] >>> 2);
buf[off] = (byte) (values[i + 4] << 6);
buf[off++] |= values[i + 5] >>> 44;
buf[off++] = (byte) (values[i + 5] >>> 36);
buf[off++] = (byte) (values[i + 5] >>> 28);
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 46;
buf[off++] = (byte) (values[i + 6] >>> 38);
buf[off++] = (byte) (values[i + 6] >>> 30);
buf[off++] = (byte) (values[i + 6] >>> 22);
buf[off++] = (byte) (values[i + 6] >>> 14);
buf[off++] = (byte) (values[i + 6] >>> 6);
buf[off] = (byte) (values[i + 6] << 2);
buf[off++] |= values[i + 7] >>> 48;
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits51(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 43);
buf[off++] = (byte) (values[i + 0] >>> 35);
buf[off++] = (byte) (values[i + 0] >>> 27);
buf[off++] = (byte) (values[i + 0] >>> 19);
buf[off++] = (byte) (values[i + 0] >>> 11);
buf[off++] = (byte) (values[i + 0] >>> 3);
buf[off] = (byte) (values[i + 0] << 5);
buf[off++] |= values[i + 1] >>> 46;
buf[off++] = (byte) (values[i + 1] >>> 38);
buf[off++] = (byte) (values[i + 1] >>> 30);
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 49;
buf[off++] = (byte) (values[i + 2] >>> 41);
buf[off++] = (byte) (values[i + 2] >>> 33);
buf[off++] = (byte) (values[i + 2] >>> 25);
buf[off++] = (byte) (values[i + 2] >>> 17);
buf[off++] = (byte) (values[i + 2] >>> 9);
buf[off++] = (byte) (values[i + 2] >>> 1);
buf[off] = (byte) (values[i + 2] << 7);
buf[off++] |= values[i + 3] >>> 44;
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 47;
buf[off++] = (byte) (values[i + 4] >>> 39);
buf[off++] = (byte) (values[i + 4] >>> 31);
buf[off++] = (byte) (values[i + 4] >>> 23);
buf[off++] = (byte) (values[i + 4] >>> 15);
buf[off++] = (byte) (values[i + 4] >>> 7);
buf[off] = (byte) (values[i + 4] << 1);
buf[off++] |= values[i + 5] >>> 50;
buf[off++] = (byte) (values[i + 5] >>> 42);
buf[off++] = (byte) (values[i + 5] >>> 34);
buf[off++] = (byte) (values[i + 5] >>> 26);
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 45;
buf[off++] = (byte) (values[i + 6] >>> 37);
buf[off++] = (byte) (values[i + 6] >>> 29);
buf[off++] = (byte) (values[i + 6] >>> 21);
buf[off++] = (byte) (values[i + 6] >>> 13);
buf[off++] = (byte) (values[i + 6] >>> 5);
buf[off] = (byte) (values[i + 6] << 3);
buf[off++] |= values[i + 7] >>> 48;
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits52(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 44);
buf[off++] = (byte) (values[i + 0] >>> 36);
buf[off++] = (byte) (values[i + 0] >>> 28);
buf[off++] = (byte) (values[i + 0] >>> 20);
buf[off++] = (byte) (values[i + 0] >>> 12);
buf[off++] = (byte) (values[i + 0] >>> 4);
buf[off] = (byte) (values[i + 0] << 4);
buf[off++] |= values[i + 1] >>> 48;
buf[off++] = (byte) (values[i + 1] >>> 40);
buf[off++] = (byte) (values[i + 1] >>> 32);
buf[off++] = (byte) (values[i + 1] >>> 24);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 44);
buf[off++] = (byte) (values[i + 2] >>> 36);
buf[off++] = (byte) (values[i + 2] >>> 28);
buf[off++] = (byte) (values[i + 2] >>> 20);
buf[off++] = (byte) (values[i + 2] >>> 12);
buf[off++] = (byte) (values[i + 2] >>> 4);
buf[off] = (byte) (values[i + 2] << 4);
buf[off++] |= values[i + 3] >>> 48;
buf[off++] = (byte) (values[i + 3] >>> 40);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 44);
buf[off++] = (byte) (values[i + 4] >>> 36);
buf[off++] = (byte) (values[i + 4] >>> 28);
buf[off++] = (byte) (values[i + 4] >>> 20);
buf[off++] = (byte) (values[i + 4] >>> 12);
buf[off++] = (byte) (values[i + 4] >>> 4);
buf[off] = (byte) (values[i + 4] << 4);
buf[off++] |= values[i + 5] >>> 48;
buf[off++] = (byte) (values[i + 5] >>> 40);
buf[off++] = (byte) (values[i + 5] >>> 32);
buf[off++] = (byte) (values[i + 5] >>> 24);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 44);
buf[off++] = (byte) (values[i + 6] >>> 36);
buf[off++] = (byte) (values[i + 6] >>> 28);
buf[off++] = (byte) (values[i + 6] >>> 20);
buf[off++] = (byte) (values[i + 6] >>> 12);
buf[off++] = (byte) (values[i + 6] >>> 4);
buf[off] = (byte) (values[i + 6] << 4);
buf[off++] |= values[i + 7] >>> 48;
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits53(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 45);
buf[off++] = (byte) (values[i + 0] >>> 37);
buf[off++] = (byte) (values[i + 0] >>> 29);
buf[off++] = (byte) (values[i + 0] >>> 21);
buf[off++] = (byte) (values[i + 0] >>> 13);
buf[off++] = (byte) (values[i + 0] >>> 5);
buf[off] = (byte) (values[i + 0] << 3);
buf[off++] |= values[i + 1] >>> 50;
buf[off++] = (byte) (values[i + 1] >>> 42);
buf[off++] = (byte) (values[i + 1] >>> 34);
buf[off++] = (byte) (values[i + 1] >>> 26);
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 47;
buf[off++] = (byte) (values[i + 2] >>> 39);
buf[off++] = (byte) (values[i + 2] >>> 31);
buf[off++] = (byte) (values[i + 2] >>> 23);
buf[off++] = (byte) (values[i + 2] >>> 15);
buf[off++] = (byte) (values[i + 2] >>> 7);
buf[off] = (byte) (values[i + 2] << 1);
buf[off++] |= values[i + 3] >>> 52;
buf[off++] = (byte) (values[i + 3] >>> 44);
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 49;
buf[off++] = (byte) (values[i + 4] >>> 41);
buf[off++] = (byte) (values[i + 4] >>> 33);
buf[off++] = (byte) (values[i + 4] >>> 25);
buf[off++] = (byte) (values[i + 4] >>> 17);
buf[off++] = (byte) (values[i + 4] >>> 9);
buf[off++] = (byte) (values[i + 4] >>> 1);
buf[off] = (byte) (values[i + 4] << 7);
buf[off++] |= values[i + 5] >>> 46;
buf[off++] = (byte) (values[i + 5] >>> 38);
buf[off++] = (byte) (values[i + 5] >>> 30);
buf[off++] = (byte) (values[i + 5] >>> 22);
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 51;
buf[off++] = (byte) (values[i + 6] >>> 43);
buf[off++] = (byte) (values[i + 6] >>> 35);
buf[off++] = (byte) (values[i + 6] >>> 27);
buf[off++] = (byte) (values[i + 6] >>> 19);
buf[off++] = (byte) (values[i + 6] >>> 11);
buf[off++] = (byte) (values[i + 6] >>> 3);
buf[off] = (byte) (values[i + 6] << 5);
buf[off++] |= values[i + 7] >>> 48;
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits54(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 46);
buf[off++] = (byte) (values[i + 0] >>> 38);
buf[off++] = (byte) (values[i + 0] >>> 30);
buf[off++] = (byte) (values[i + 0] >>> 22);
buf[off++] = (byte) (values[i + 0] >>> 14);
buf[off++] = (byte) (values[i + 0] >>> 6);
buf[off] = (byte) (values[i + 0] << 2);
buf[off++] |= values[i + 1] >>> 52;
buf[off++] = (byte) (values[i + 1] >>> 44);
buf[off++] = (byte) (values[i + 1] >>> 36);
buf[off++] = (byte) (values[i + 1] >>> 28);
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 50;
buf[off++] = (byte) (values[i + 2] >>> 42);
buf[off++] = (byte) (values[i + 2] >>> 34);
buf[off++] = (byte) (values[i + 2] >>> 26);
buf[off++] = (byte) (values[i + 2] >>> 18);
buf[off++] = (byte) (values[i + 2] >>> 10);
buf[off++] = (byte) (values[i + 2] >>> 2);
buf[off] = (byte) (values[i + 2] << 6);
buf[off++] |= values[i + 3] >>> 48;
buf[off++] = (byte) (values[i + 3] >>> 40);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 46);
buf[off++] = (byte) (values[i + 4] >>> 38);
buf[off++] = (byte) (values[i + 4] >>> 30);
buf[off++] = (byte) (values[i + 4] >>> 22);
buf[off++] = (byte) (values[i + 4] >>> 14);
buf[off++] = (byte) (values[i + 4] >>> 6);
buf[off] = (byte) (values[i + 4] << 2);
buf[off++] |= values[i + 5] >>> 52;
buf[off++] = (byte) (values[i + 5] >>> 44);
buf[off++] = (byte) (values[i + 5] >>> 36);
buf[off++] = (byte) (values[i + 5] >>> 28);
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 50;
buf[off++] = (byte) (values[i + 6] >>> 42);
buf[off++] = (byte) (values[i + 6] >>> 34);
buf[off++] = (byte) (values[i + 6] >>> 26);
buf[off++] = (byte) (values[i + 6] >>> 18);
buf[off++] = (byte) (values[i + 6] >>> 10);
buf[off++] = (byte) (values[i + 6] >>> 2);
buf[off] = (byte) (values[i + 6] << 6);
buf[off++] |= values[i + 7] >>> 48;
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits55(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 47);
buf[off++] = (byte) (values[i + 0] >>> 39);
buf[off++] = (byte) (values[i + 0] >>> 31);
buf[off++] = (byte) (values[i + 0] >>> 23);
buf[off++] = (byte) (values[i + 0] >>> 15);
buf[off++] = (byte) (values[i + 0] >>> 7);
buf[off] = (byte) (values[i + 0] << 1);
buf[off++] |= values[i + 1] >>> 54;
buf[off++] = (byte) (values[i + 1] >>> 46);
buf[off++] = (byte) (values[i + 1] >>> 38);
buf[off++] = (byte) (values[i + 1] >>> 30);
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 53;
buf[off++] = (byte) (values[i + 2] >>> 45);
buf[off++] = (byte) (values[i + 2] >>> 37);
buf[off++] = (byte) (values[i + 2] >>> 29);
buf[off++] = (byte) (values[i + 2] >>> 21);
buf[off++] = (byte) (values[i + 2] >>> 13);
buf[off++] = (byte) (values[i + 2] >>> 5);
buf[off] = (byte) (values[i + 2] << 3);
buf[off++] |= values[i + 3] >>> 52;
buf[off++] = (byte) (values[i + 3] >>> 44);
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 51;
buf[off++] = (byte) (values[i + 4] >>> 43);
buf[off++] = (byte) (values[i + 4] >>> 35);
buf[off++] = (byte) (values[i + 4] >>> 27);
buf[off++] = (byte) (values[i + 4] >>> 19);
buf[off++] = (byte) (values[i + 4] >>> 11);
buf[off++] = (byte) (values[i + 4] >>> 3);
buf[off] = (byte) (values[i + 4] << 5);
buf[off++] |= values[i + 5] >>> 50;
buf[off++] = (byte) (values[i + 5] >>> 42);
buf[off++] = (byte) (values[i + 5] >>> 34);
buf[off++] = (byte) (values[i + 5] >>> 26);
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 49;
buf[off++] = (byte) (values[i + 6] >>> 41);
buf[off++] = (byte) (values[i + 6] >>> 33);
buf[off++] = (byte) (values[i + 6] >>> 25);
buf[off++] = (byte) (values[i + 6] >>> 17);
buf[off++] = (byte) (values[i + 6] >>> 9);
buf[off++] = (byte) (values[i + 6] >>> 1);
buf[off] = (byte) (values[i + 6] << 7);
buf[off++] |= values[i + 7] >>> 48;
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits56(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 48);
buf[off++] = (byte) (values[i + 0] >>> 40);
buf[off++] = (byte) (values[i + 0] >>> 32);
buf[off++] = (byte) (values[i + 0] >>> 24);
buf[off++] = (byte) (values[i + 0] >>> 16);
buf[off++] = (byte) (values[i + 0] >>> 8);
buf[off++] = (byte) (values[i + 0]);
buf[off++] = (byte) (values[i + 1] >>> 48);
buf[off++] = (byte) (values[i + 1] >>> 40);
buf[off++] = (byte) (values[i + 1] >>> 32);
buf[off++] = (byte) (values[i + 1] >>> 24);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 48);
buf[off++] = (byte) (values[i + 2] >>> 40);
buf[off++] = (byte) (values[i + 2] >>> 32);
buf[off++] = (byte) (values[i + 2] >>> 24);
buf[off++] = (byte) (values[i + 2] >>> 16);
buf[off++] = (byte) (values[i + 2] >>> 8);
buf[off++] = (byte) (values[i + 2]);
buf[off++] = (byte) (values[i + 3] >>> 48);
buf[off++] = (byte) (values[i + 3] >>> 40);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 48);
buf[off++] = (byte) (values[i + 4] >>> 40);
buf[off++] = (byte) (values[i + 4] >>> 32);
buf[off++] = (byte) (values[i + 4] >>> 24);
buf[off++] = (byte) (values[i + 4] >>> 16);
buf[off++] = (byte) (values[i + 4] >>> 8);
buf[off++] = (byte) (values[i + 4]);
buf[off++] = (byte) (values[i + 5] >>> 48);
buf[off++] = (byte) (values[i + 5] >>> 40);
buf[off++] = (byte) (values[i + 5] >>> 32);
buf[off++] = (byte) (values[i + 5] >>> 24);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 48);
buf[off++] = (byte) (values[i + 6] >>> 40);
buf[off++] = (byte) (values[i + 6] >>> 32);
buf[off++] = (byte) (values[i + 6] >>> 24);
buf[off++] = (byte) (values[i + 6] >>> 16);
buf[off++] = (byte) (values[i + 6] >>> 8);
buf[off++] = (byte) (values[i + 6]);
buf[off++] = (byte) (values[i + 7] >>> 48);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits57(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 49);
buf[off++] = (byte) (values[i + 0] >>> 41);
buf[off++] = (byte) (values[i + 0] >>> 33);
buf[off++] = (byte) (values[i + 0] >>> 25);
buf[off++] = (byte) (values[i + 0] >>> 17);
buf[off++] = (byte) (values[i + 0] >>> 9);
buf[off++] = (byte) (values[i + 0] >>> 1);
buf[off] = (byte) (values[i + 0] << 7);
buf[off++] |= values[i + 1] >>> 50;
buf[off++] = (byte) (values[i + 1] >>> 42);
buf[off++] = (byte) (values[i + 1] >>> 34);
buf[off++] = (byte) (values[i + 1] >>> 26);
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 51;
buf[off++] = (byte) (values[i + 2] >>> 43);
buf[off++] = (byte) (values[i + 2] >>> 35);
buf[off++] = (byte) (values[i + 2] >>> 27);
buf[off++] = (byte) (values[i + 2] >>> 19);
buf[off++] = (byte) (values[i + 2] >>> 11);
buf[off++] = (byte) (values[i + 2] >>> 3);
buf[off] = (byte) (values[i + 2] << 5);
buf[off++] |= values[i + 3] >>> 52;
buf[off++] = (byte) (values[i + 3] >>> 44);
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 53;
buf[off++] = (byte) (values[i + 4] >>> 45);
buf[off++] = (byte) (values[i + 4] >>> 37);
buf[off++] = (byte) (values[i + 4] >>> 29);
buf[off++] = (byte) (values[i + 4] >>> 21);
buf[off++] = (byte) (values[i + 4] >>> 13);
buf[off++] = (byte) (values[i + 4] >>> 5);
buf[off] = (byte) (values[i + 4] << 3);
buf[off++] |= values[i + 5] >>> 54;
buf[off++] = (byte) (values[i + 5] >>> 46);
buf[off++] = (byte) (values[i + 5] >>> 38);
buf[off++] = (byte) (values[i + 5] >>> 30);
buf[off++] = (byte) (values[i + 5] >>> 22);
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 55;
buf[off++] = (byte) (values[i + 6] >>> 47);
buf[off++] = (byte) (values[i + 6] >>> 39);
buf[off++] = (byte) (values[i + 6] >>> 31);
buf[off++] = (byte) (values[i + 6] >>> 23);
buf[off++] = (byte) (values[i + 6] >>> 15);
buf[off++] = (byte) (values[i + 6] >>> 7);
buf[off] = (byte) (values[i + 6] << 1);
buf[off++] |= values[i + 7] >>> 56;
buf[off++] = (byte) (values[i + 7] >>> 48);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits58(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 50);
buf[off++] = (byte) (values[i + 0] >>> 42);
buf[off++] = (byte) (values[i + 0] >>> 34);
buf[off++] = (byte) (values[i + 0] >>> 26);
buf[off++] = (byte) (values[i + 0] >>> 18);
buf[off++] = (byte) (values[i + 0] >>> 10);
buf[off++] = (byte) (values[i + 0] >>> 2);
buf[off] = (byte) (values[i + 0] << 6);
buf[off++] |= values[i + 1] >>> 52;
buf[off++] = (byte) (values[i + 1] >>> 44);
buf[off++] = (byte) (values[i + 1] >>> 36);
buf[off++] = (byte) (values[i + 1] >>> 28);
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 54;
buf[off++] = (byte) (values[i + 2] >>> 46);
buf[off++] = (byte) (values[i + 2] >>> 38);
buf[off++] = (byte) (values[i + 2] >>> 30);
buf[off++] = (byte) (values[i + 2] >>> 22);
buf[off++] = (byte) (values[i + 2] >>> 14);
buf[off++] = (byte) (values[i + 2] >>> 6);
buf[off] = (byte) (values[i + 2] << 2);
buf[off++] |= values[i + 3] >>> 56;
buf[off++] = (byte) (values[i + 3] >>> 48);
buf[off++] = (byte) (values[i + 3] >>> 40);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 50);
buf[off++] = (byte) (values[i + 4] >>> 42);
buf[off++] = (byte) (values[i + 4] >>> 34);
buf[off++] = (byte) (values[i + 4] >>> 26);
buf[off++] = (byte) (values[i + 4] >>> 18);
buf[off++] = (byte) (values[i + 4] >>> 10);
buf[off++] = (byte) (values[i + 4] >>> 2);
buf[off] = (byte) (values[i + 4] << 6);
buf[off++] |= values[i + 5] >>> 52;
buf[off++] = (byte) (values[i + 5] >>> 44);
buf[off++] = (byte) (values[i + 5] >>> 36);
buf[off++] = (byte) (values[i + 5] >>> 28);
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 54;
buf[off++] = (byte) (values[i + 6] >>> 46);
buf[off++] = (byte) (values[i + 6] >>> 38);
buf[off++] = (byte) (values[i + 6] >>> 30);
buf[off++] = (byte) (values[i + 6] >>> 22);
buf[off++] = (byte) (values[i + 6] >>> 14);
buf[off++] = (byte) (values[i + 6] >>> 6);
buf[off] = (byte) (values[i + 6] << 2);
buf[off++] |= values[i + 7] >>> 56;
buf[off++] = (byte) (values[i + 7] >>> 48);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits59(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 51);
buf[off++] = (byte) (values[i + 0] >>> 43);
buf[off++] = (byte) (values[i + 0] >>> 35);
buf[off++] = (byte) (values[i + 0] >>> 27);
buf[off++] = (byte) (values[i + 0] >>> 19);
buf[off++] = (byte) (values[i + 0] >>> 11);
buf[off++] = (byte) (values[i + 0] >>> 3);
buf[off] = (byte) (values[i + 0] << 5);
buf[off++] |= values[i + 1] >>> 54;
buf[off++] = (byte) (values[i + 1] >>> 46);
buf[off++] = (byte) (values[i + 1] >>> 38);
buf[off++] = (byte) (values[i + 1] >>> 30);
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 57;
buf[off++] = (byte) (values[i + 2] >>> 49);
buf[off++] = (byte) (values[i + 2] >>> 41);
buf[off++] = (byte) (values[i + 2] >>> 33);
buf[off++] = (byte) (values[i + 2] >>> 25);
buf[off++] = (byte) (values[i + 2] >>> 17);
buf[off++] = (byte) (values[i + 2] >>> 9);
buf[off++] = (byte) (values[i + 2] >>> 1);
buf[off] = (byte) (values[i + 2] << 7);
buf[off++] |= values[i + 3] >>> 52;
buf[off++] = (byte) (values[i + 3] >>> 44);
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 55;
buf[off++] = (byte) (values[i + 4] >>> 47);
buf[off++] = (byte) (values[i + 4] >>> 39);
buf[off++] = (byte) (values[i + 4] >>> 31);
buf[off++] = (byte) (values[i + 4] >>> 23);
buf[off++] = (byte) (values[i + 4] >>> 15);
buf[off++] = (byte) (values[i + 4] >>> 7);
buf[off] = (byte) (values[i + 4] << 1);
buf[off++] |= values[i + 5] >>> 58;
buf[off++] = (byte) (values[i + 5] >>> 50);
buf[off++] = (byte) (values[i + 5] >>> 42);
buf[off++] = (byte) (values[i + 5] >>> 34);
buf[off++] = (byte) (values[i + 5] >>> 26);
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 53;
buf[off++] = (byte) (values[i + 6] >>> 45);
buf[off++] = (byte) (values[i + 6] >>> 37);
buf[off++] = (byte) (values[i + 6] >>> 29);
buf[off++] = (byte) (values[i + 6] >>> 21);
buf[off++] = (byte) (values[i + 6] >>> 13);
buf[off++] = (byte) (values[i + 6] >>> 5);
buf[off] = (byte) (values[i + 6] << 3);
buf[off++] |= values[i + 7] >>> 56;
buf[off++] = (byte) (values[i + 7] >>> 48);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits60(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 52);
buf[off++] = (byte) (values[i + 0] >>> 44);
buf[off++] = (byte) (values[i + 0] >>> 36);
buf[off++] = (byte) (values[i + 0] >>> 28);
buf[off++] = (byte) (values[i + 0] >>> 20);
buf[off++] = (byte) (values[i + 0] >>> 12);
buf[off++] = (byte) (values[i + 0] >>> 4);
buf[off] = (byte) (values[i + 0] << 4);
buf[off++] |= values[i + 1] >>> 56;
buf[off++] = (byte) (values[i + 1] >>> 48);
buf[off++] = (byte) (values[i + 1] >>> 40);
buf[off++] = (byte) (values[i + 1] >>> 32);
buf[off++] = (byte) (values[i + 1] >>> 24);
buf[off++] = (byte) (values[i + 1] >>> 16);
buf[off++] = (byte) (values[i + 1] >>> 8);
buf[off++] = (byte) (values[i + 1]);
buf[off++] = (byte) (values[i + 2] >>> 52);
buf[off++] = (byte) (values[i + 2] >>> 44);
buf[off++] = (byte) (values[i + 2] >>> 36);
buf[off++] = (byte) (values[i + 2] >>> 28);
buf[off++] = (byte) (values[i + 2] >>> 20);
buf[off++] = (byte) (values[i + 2] >>> 12);
buf[off++] = (byte) (values[i + 2] >>> 4);
buf[off] = (byte) (values[i + 2] << 4);
buf[off++] |= values[i + 3] >>> 56;
buf[off++] = (byte) (values[i + 3] >>> 48);
buf[off++] = (byte) (values[i + 3] >>> 40);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 52);
buf[off++] = (byte) (values[i + 4] >>> 44);
buf[off++] = (byte) (values[i + 4] >>> 36);
buf[off++] = (byte) (values[i + 4] >>> 28);
buf[off++] = (byte) (values[i + 4] >>> 20);
buf[off++] = (byte) (values[i + 4] >>> 12);
buf[off++] = (byte) (values[i + 4] >>> 4);
buf[off] = (byte) (values[i + 4] << 4);
buf[off++] |= values[i + 5] >>> 56;
buf[off++] = (byte) (values[i + 5] >>> 48);
buf[off++] = (byte) (values[i + 5] >>> 40);
buf[off++] = (byte) (values[i + 5] >>> 32);
buf[off++] = (byte) (values[i + 5] >>> 24);
buf[off++] = (byte) (values[i + 5] >>> 16);
buf[off++] = (byte) (values[i + 5] >>> 8);
buf[off++] = (byte) (values[i + 5]);
buf[off++] = (byte) (values[i + 6] >>> 52);
buf[off++] = (byte) (values[i + 6] >>> 44);
buf[off++] = (byte) (values[i + 6] >>> 36);
buf[off++] = (byte) (values[i + 6] >>> 28);
buf[off++] = (byte) (values[i + 6] >>> 20);
buf[off++] = (byte) (values[i + 6] >>> 12);
buf[off++] = (byte) (values[i + 6] >>> 4);
buf[off] = (byte) (values[i + 6] << 4);
buf[off++] |= values[i + 7] >>> 56;
buf[off++] = (byte) (values[i + 7] >>> 48);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits61(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 53);
buf[off++] = (byte) (values[i + 0] >>> 45);
buf[off++] = (byte) (values[i + 0] >>> 37);
buf[off++] = (byte) (values[i + 0] >>> 29);
buf[off++] = (byte) (values[i + 0] >>> 21);
buf[off++] = (byte) (values[i + 0] >>> 13);
buf[off++] = (byte) (values[i + 0] >>> 5);
buf[off] = (byte) (values[i + 0] << 3);
buf[off++] |= values[i + 1] >>> 58;
buf[off++] = (byte) (values[i + 1] >>> 50);
buf[off++] = (byte) (values[i + 1] >>> 42);
buf[off++] = (byte) (values[i + 1] >>> 34);
buf[off++] = (byte) (values[i + 1] >>> 26);
buf[off++] = (byte) (values[i + 1] >>> 18);
buf[off++] = (byte) (values[i + 1] >>> 10);
buf[off++] = (byte) (values[i + 1] >>> 2);
buf[off] = (byte) (values[i + 1] << 6);
buf[off++] |= values[i + 2] >>> 55;
buf[off++] = (byte) (values[i + 2] >>> 47);
buf[off++] = (byte) (values[i + 2] >>> 39);
buf[off++] = (byte) (values[i + 2] >>> 31);
buf[off++] = (byte) (values[i + 2] >>> 23);
buf[off++] = (byte) (values[i + 2] >>> 15);
buf[off++] = (byte) (values[i + 2] >>> 7);
buf[off] = (byte) (values[i + 2] << 1);
buf[off++] |= values[i + 3] >>> 60;
buf[off++] = (byte) (values[i + 3] >>> 52);
buf[off++] = (byte) (values[i + 3] >>> 44);
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 57;
buf[off++] = (byte) (values[i + 4] >>> 49);
buf[off++] = (byte) (values[i + 4] >>> 41);
buf[off++] = (byte) (values[i + 4] >>> 33);
buf[off++] = (byte) (values[i + 4] >>> 25);
buf[off++] = (byte) (values[i + 4] >>> 17);
buf[off++] = (byte) (values[i + 4] >>> 9);
buf[off++] = (byte) (values[i + 4] >>> 1);
buf[off] = (byte) (values[i + 4] << 7);
buf[off++] |= values[i + 5] >>> 54;
buf[off++] = (byte) (values[i + 5] >>> 46);
buf[off++] = (byte) (values[i + 5] >>> 38);
buf[off++] = (byte) (values[i + 5] >>> 30);
buf[off++] = (byte) (values[i + 5] >>> 22);
buf[off++] = (byte) (values[i + 5] >>> 14);
buf[off++] = (byte) (values[i + 5] >>> 6);
buf[off] = (byte) (values[i + 5] << 2);
buf[off++] |= values[i + 6] >>> 59;
buf[off++] = (byte) (values[i + 6] >>> 51);
buf[off++] = (byte) (values[i + 6] >>> 43);
buf[off++] = (byte) (values[i + 6] >>> 35);
buf[off++] = (byte) (values[i + 6] >>> 27);
buf[off++] = (byte) (values[i + 6] >>> 19);
buf[off++] = (byte) (values[i + 6] >>> 11);
buf[off++] = (byte) (values[i + 6] >>> 3);
buf[off] = (byte) (values[i + 6] << 5);
buf[off++] |= values[i + 7] >>> 56;
buf[off++] = (byte) (values[i + 7] >>> 48);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits62(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 54);
buf[off++] = (byte) (values[i + 0] >>> 46);
buf[off++] = (byte) (values[i + 0] >>> 38);
buf[off++] = (byte) (values[i + 0] >>> 30);
buf[off++] = (byte) (values[i + 0] >>> 22);
buf[off++] = (byte) (values[i + 0] >>> 14);
buf[off++] = (byte) (values[i + 0] >>> 6);
buf[off] = (byte) (values[i + 0] << 2);
buf[off++] |= values[i + 1] >>> 60;
buf[off++] = (byte) (values[i + 1] >>> 52);
buf[off++] = (byte) (values[i + 1] >>> 44);
buf[off++] = (byte) (values[i + 1] >>> 36);
buf[off++] = (byte) (values[i + 1] >>> 28);
buf[off++] = (byte) (values[i + 1] >>> 20);
buf[off++] = (byte) (values[i + 1] >>> 12);
buf[off++] = (byte) (values[i + 1] >>> 4);
buf[off] = (byte) (values[i + 1] << 4);
buf[off++] |= values[i + 2] >>> 58;
buf[off++] = (byte) (values[i + 2] >>> 50);
buf[off++] = (byte) (values[i + 2] >>> 42);
buf[off++] = (byte) (values[i + 2] >>> 34);
buf[off++] = (byte) (values[i + 2] >>> 26);
buf[off++] = (byte) (values[i + 2] >>> 18);
buf[off++] = (byte) (values[i + 2] >>> 10);
buf[off++] = (byte) (values[i + 2] >>> 2);
buf[off] = (byte) (values[i + 2] << 6);
buf[off++] |= values[i + 3] >>> 56;
buf[off++] = (byte) (values[i + 3] >>> 48);
buf[off++] = (byte) (values[i + 3] >>> 40);
buf[off++] = (byte) (values[i + 3] >>> 32);
buf[off++] = (byte) (values[i + 3] >>> 24);
buf[off++] = (byte) (values[i + 3] >>> 16);
buf[off++] = (byte) (values[i + 3] >>> 8);
buf[off++] = (byte) (values[i + 3]);
buf[off++] = (byte) (values[i + 4] >>> 54);
buf[off++] = (byte) (values[i + 4] >>> 46);
buf[off++] = (byte) (values[i + 4] >>> 38);
buf[off++] = (byte) (values[i + 4] >>> 30);
buf[off++] = (byte) (values[i + 4] >>> 22);
buf[off++] = (byte) (values[i + 4] >>> 14);
buf[off++] = (byte) (values[i + 4] >>> 6);
buf[off] = (byte) (values[i + 4] << 2);
buf[off++] |= values[i + 5] >>> 60;
buf[off++] = (byte) (values[i + 5] >>> 52);
buf[off++] = (byte) (values[i + 5] >>> 44);
buf[off++] = (byte) (values[i + 5] >>> 36);
buf[off++] = (byte) (values[i + 5] >>> 28);
buf[off++] = (byte) (values[i + 5] >>> 20);
buf[off++] = (byte) (values[i + 5] >>> 12);
buf[off++] = (byte) (values[i + 5] >>> 4);
buf[off] = (byte) (values[i + 5] << 4);
buf[off++] |= values[i + 6] >>> 58;
buf[off++] = (byte) (values[i + 6] >>> 50);
buf[off++] = (byte) (values[i + 6] >>> 42);
buf[off++] = (byte) (values[i + 6] >>> 34);
buf[off++] = (byte) (values[i + 6] >>> 26);
buf[off++] = (byte) (values[i + 6] >>> 18);
buf[off++] = (byte) (values[i + 6] >>> 10);
buf[off++] = (byte) (values[i + 6] >>> 2);
buf[off] = (byte) (values[i + 6] << 6);
buf[off++] |= values[i + 7] >>> 56;
buf[off++] = (byte) (values[i + 7] >>> 48);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) (values[i + 7]);
}
static void packBits63(final long[] values, final int i, final byte[] buf, int off) {
buf[off++] = (byte) (values[i + 0] >>> 55);
buf[off++] = (byte) (values[i + 0] >>> 47);
buf[off++] = (byte) (values[i + 0] >>> 39);
buf[off++] = (byte) (values[i + 0] >>> 31);
buf[off++] = (byte) (values[i + 0] >>> 23);
buf[off++] = (byte) (values[i + 0] >>> 15);
buf[off++] = (byte) (values[i + 0] >>> 7);
buf[off] = (byte) (values[i + 0] << 1);
buf[off++] |= values[i + 1] >>> 62;
buf[off++] = (byte) (values[i + 1] >>> 54);
buf[off++] = (byte) (values[i + 1] >>> 46);
buf[off++] = (byte) (values[i + 1] >>> 38);
buf[off++] = (byte) (values[i + 1] >>> 30);
buf[off++] = (byte) (values[i + 1] >>> 22);
buf[off++] = (byte) (values[i + 1] >>> 14);
buf[off++] = (byte) (values[i + 1] >>> 6);
buf[off] = (byte) (values[i + 1] << 2);
buf[off++] |= values[i + 2] >>> 61;
buf[off++] = (byte) (values[i + 2] >>> 53);
buf[off++] = (byte) (values[i + 2] >>> 45);
buf[off++] = (byte) (values[i + 2] >>> 37);
buf[off++] = (byte) (values[i + 2] >>> 29);
buf[off++] = (byte) (values[i + 2] >>> 21);
buf[off++] = (byte) (values[i + 2] >>> 13);
buf[off++] = (byte) (values[i + 2] >>> 5);
buf[off] = (byte) (values[i + 2] << 3);
buf[off++] |= values[i + 3] >>> 60;
buf[off++] = (byte) (values[i + 3] >>> 52);
buf[off++] = (byte) (values[i + 3] >>> 44);
buf[off++] = (byte) (values[i + 3] >>> 36);
buf[off++] = (byte) (values[i + 3] >>> 28);
buf[off++] = (byte) (values[i + 3] >>> 20);
buf[off++] = (byte) (values[i + 3] >>> 12);
buf[off++] = (byte) (values[i + 3] >>> 4);
buf[off] = (byte) (values[i + 3] << 4);
buf[off++] |= values[i + 4] >>> 59;
buf[off++] = (byte) (values[i + 4] >>> 51);
buf[off++] = (byte) (values[i + 4] >>> 43);
buf[off++] = (byte) (values[i + 4] >>> 35);
buf[off++] = (byte) (values[i + 4] >>> 27);
buf[off++] = (byte) (values[i + 4] >>> 19);
buf[off++] = (byte) (values[i + 4] >>> 11);
buf[off++] = (byte) (values[i + 4] >>> 3);
buf[off] = (byte) (values[i + 4] << 5);
buf[off++] |= values[i + 5] >>> 58;
buf[off++] = (byte) (values[i + 5] >>> 50);
buf[off++] = (byte) (values[i + 5] >>> 42);
buf[off++] = (byte) (values[i + 5] >>> 34);
buf[off++] = (byte) (values[i + 5] >>> 26);
buf[off++] = (byte) (values[i + 5] >>> 18);
buf[off++] = (byte) (values[i + 5] >>> 10);
buf[off++] = (byte) (values[i + 5] >>> 2);
buf[off] = (byte) (values[i + 5] << 6);
buf[off++] |= values[i + 6] >>> 57;
buf[off++] = (byte) (values[i + 6] >>> 49);
buf[off++] = (byte) (values[i + 6] >>> 41);
buf[off++] = (byte) (values[i + 6] >>> 33);
buf[off++] = (byte) (values[i + 6] >>> 25);
buf[off++] = (byte) (values[i + 6] >>> 17);
buf[off++] = (byte) (values[i + 6] >>> 9);
buf[off++] = (byte) (values[i + 6] >>> 1);
buf[off] = (byte) (values[i + 6] << 7);
buf[off++] |= values[i + 7] >>> 56;
buf[off++] = (byte) (values[i + 7] >>> 48);
buf[off++] = (byte) (values[i + 7] >>> 40);
buf[off++] = (byte) (values[i + 7] >>> 32);
buf[off++] = (byte) (values[i + 7] >>> 24);
buf[off++] = (byte) (values[i + 7] >>> 16);
buf[off++] = (byte) (values[i + 7] >>> 8);
buf[off] = (byte) values[i + 7];
}
static void unpackBits1(final long[] values, final int i, final byte[] buf, final int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off]) >>> 7) & 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off]) >>> 6) & 1;
values[i + 2] = (Byte.toUnsignedLong(buf[off]) >>> 5) & 1;
values[i + 3] = (Byte.toUnsignedLong(buf[off]) >>> 4) & 1;
values[i + 4] = (Byte.toUnsignedLong(buf[off]) >>> 3) & 1;
values[i + 5] = (Byte.toUnsignedLong(buf[off]) >>> 2) & 1;
values[i + 6] = (Byte.toUnsignedLong(buf[off]) >>> 1) & 1;
values[i + 7] = Byte.toUnsignedLong(buf[off]) & 1;
}
static void unpackBits2(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off]) >>> 6) & 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off]) >>> 4) & 3;
values[i + 2] = (Byte.toUnsignedLong(buf[off]) >>> 2) & 3;
values[i + 3] = Byte.toUnsignedLong(buf[off++]) & 3;
values[i + 4] = (Byte.toUnsignedLong(buf[off]) >>> 6) & 3;
values[i + 5] = (Byte.toUnsignedLong(buf[off]) >>> 4) & 3;
values[i + 6] = (Byte.toUnsignedLong(buf[off]) >>> 2) & 3;
values[i + 7] = Byte.toUnsignedLong(buf[off]) & 3;
}
static void unpackBits3(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 1] = (Byte.toUnsignedLong(buf[off]) >>> 2) & 7;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 1;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 3] = (Byte.toUnsignedLong(buf[off]) >>> 4) & 7;
values[i + 4] = (Byte.toUnsignedLong(buf[off]) >>> 1) & 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 1) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off]) >>> 3) & 7;
values[i + 7] = Byte.toUnsignedLong(buf[off]) & 7;
}
static void unpackBits4(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 1] = Byte.toUnsignedLong(buf[off++]) & 0xf;
values[i + 2] = Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 3] = Byte.toUnsignedLong(buf[off++]) & 0xf;
values[i + 4] = Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 5] = Byte.toUnsignedLong(buf[off++]) & 0xf;
values[i + 6] = Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 7] = Byte.toUnsignedLong(buf[off]) & 0xf;
}
static void unpackBits5(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 7) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off]) >>> 1) & 0x1f;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 1) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 1;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off]) >>> 2) & 0x1f;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 3;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 7] = Byte.toUnsignedLong(buf[off]) & 0x1f;
}
static void unpackBits6(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 3) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 2;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 3] = Byte.toUnsignedLong(buf[off++]) & 0x3f;
values[i + 4] = Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 3) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 2;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 7] = Byte.toUnsignedLong(buf[off]) & 0x3f;
}
static void unpackBits7(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 1) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 5;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 7) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 3;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 1;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 7] = Byte.toUnsignedLong(buf[off]) & 0x7f;
}
static void unpackBits8(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]);
values[i + 1] = Byte.toUnsignedLong(buf[off++]);
values[i + 2] = Byte.toUnsignedLong(buf[off++]);
values[i + 3] = Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]);
values[i + 5] = Byte.toUnsignedLong(buf[off++]);
values[i + 6] = Byte.toUnsignedLong(buf[off++]);
values[i + 7] = Byte.toUnsignedLong(buf[off]);
}
static void unpackBits9(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 3;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 5;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 7) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 7;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 1) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits10(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 6;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 3) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 6;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 3) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits11(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 9;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 7;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 1) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 5;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 7) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits12(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits13(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 7) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 7;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 1) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 9;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 11;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits14(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 3) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 10;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 3) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 10;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits15(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 1) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 13;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 7) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 11;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 9;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits16(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]);
values[i + 1] = Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]);
values[i + 3] = Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]);
values[i + 5] = Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]);
values[i + 7] = Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits17(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 11;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 13;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 7) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 15;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 1) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits18(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 14;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 3) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 14;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 3) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits19(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 17;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 15;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 1) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 13;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 7) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits20(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits21(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 7) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 15;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 1) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 17;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 19;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits22(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 3) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 18;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 3) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 18;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits23(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 1) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 21;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 7) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 19;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 17;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits24(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]);
values[i + 1] = Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]);
values[i + 3] = Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]);
values[i + 5] = Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]);
values[i + 7] = Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits25(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 19;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 21;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 7) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 23;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 1) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits26(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 22;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 3) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 22;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 3) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits27(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 25;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 23;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 1) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 21;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 7) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits28(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits29(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 7) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 23;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 1) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 25;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 27;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits30(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 3) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 26;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 3) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 26;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits31(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 1) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 29;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 7) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 27;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 25;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits32(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]);
values[i + 1] = (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]);
values[i + 3] = (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]);
values[i + 5] = (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]);
values[i + 7] = (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits33(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 27;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 29;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 7) << 30;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 31;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 1) << 32;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits34(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 30;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 3) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 30;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 3) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]);
}
static void unpackBits35(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 2) << 33;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 31;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 1) << 34;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 29;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 7) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits36(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 32;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 32;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits37(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 7) << 34;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 31;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 23;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 1) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 33;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 30;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 35;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits38(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 3) << 36;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 34;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 3) << 36;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 34;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits39(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 1) << 38;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 37;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 7) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 35;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 34;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 33;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits40(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]);
values[i + 1] = (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]);
values[i + 3] = (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]);
values[i + 5] = (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]);
values[i + 7] = (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits41(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 34;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 35;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 37;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 7) << 38;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 39;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 1) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits42(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 36;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 38;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 3) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 36;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 38;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 3) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits43(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 38;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 41;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 39;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 1) << 42;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 37;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 7) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits44(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 40;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 40;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits45(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 7) << 42;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 39;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 23;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 1) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 41;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 38;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 43;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits46(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 3) << 44;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 42;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 3) << 44;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 42;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits47(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 1) << 46;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 45;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 7) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 43;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 42;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 41;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits48(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]);
values[i + 1] = (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]);
values[i + 3] = (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]);
values[i + 5] = (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]);
values[i + 7] = (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits49(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 41;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 42;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 43;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 45;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 7) << 46;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 47;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 1) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits50(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 44;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 46;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 3) << 48;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 44;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 46;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 3) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits51(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 43;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 46;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 49;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 41;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 47;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 1) << 50;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 45;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 7) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits52(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 48;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 48;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 48;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits53(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 45;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 7) << 50;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 47;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 23;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 1) << 52;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 49;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 41;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 46;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 51;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 43;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits54(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 3) << 52;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 50;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 48;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 3) << 52;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 50;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]);
}
static void unpackBits55(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 47;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 1) << 54;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 53;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 45;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 7) << 52;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 51;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 43;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 50;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 49;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 41;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits56(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]);
values[i + 1] = (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]);
values[i + 3] = (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]);
values[i + 5] = (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]);
values[i + 7] = (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits57(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 49;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 41;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 50;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 51;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 43;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 52;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 53;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 45;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 7) << 54;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 55;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 47;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 1) << 56;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits58(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 50;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 52;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 54;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 3) << 56;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 50;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 52;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 54;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 3) << 56;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]);
}
static void unpackBits59(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 51;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 43;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 54;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 57;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 49;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 41;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 52;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 55;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 47;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 1) << 58;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 50;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 53;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 45;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 7) << 56;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits60(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 52;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 56;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]);
values[i + 2] = (Byte.toUnsignedLong(buf[off++])) << 52;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 56;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 52;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 56;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]);
values[i + 6] = (Byte.toUnsignedLong(buf[off++])) << 52;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 56;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits61(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 53;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 45;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 7) << 58;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 50;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 55;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 47;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 1) << 60;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 52;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 57;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 49;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 41;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 54;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 3) << 59;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 51;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 43;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 56;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits62(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 54;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 3) << 60;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 52;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 58;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 50;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 56;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]);
values[i + 4] = (Byte.toUnsignedLong(buf[off++])) << 54;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 3) << 60;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 52;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 58;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 50;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 56;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
static void unpackBits63(final long[] values, final int i, final byte[] buf, int off) {
values[i + 0] = (Byte.toUnsignedLong(buf[off++])) << 55;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 47;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 39;
values[i + 0] |= (Byte.toUnsignedLong(buf[off++])) << 31;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 23;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 15;
values[i + 0] |= Byte.toUnsignedLong(buf[off++]) << 7;
values[i + 0] |= Byte.toUnsignedLong(buf[off]) >>> 1;
values[i + 1] = (Byte.toUnsignedLong(buf[off++]) & 1) << 62;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 54;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 46;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 38;
values[i + 1] |= (Byte.toUnsignedLong(buf[off++])) << 30;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 22;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 14;
values[i + 1] |= Byte.toUnsignedLong(buf[off++]) << 6;
values[i + 1] |= Byte.toUnsignedLong(buf[off]) >>> 2;
values[i + 2] = (Byte.toUnsignedLong(buf[off++]) & 3) << 61;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 53;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 45;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 37;
values[i + 2] |= (Byte.toUnsignedLong(buf[off++])) << 29;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 21;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 13;
values[i + 2] |= Byte.toUnsignedLong(buf[off++]) << 5;
values[i + 2] |= Byte.toUnsignedLong(buf[off]) >>> 3;
values[i + 3] = (Byte.toUnsignedLong(buf[off++]) & 7) << 60;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 52;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 44;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 36;
values[i + 3] |= (Byte.toUnsignedLong(buf[off++])) << 28;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 20;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 12;
values[i + 3] |= Byte.toUnsignedLong(buf[off++]) << 4;
values[i + 3] |= Byte.toUnsignedLong(buf[off]) >>> 4;
values[i + 4] = (Byte.toUnsignedLong(buf[off++]) & 0xf) << 59;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 51;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 43;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 35;
values[i + 4] |= (Byte.toUnsignedLong(buf[off++])) << 27;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 19;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 11;
values[i + 4] |= Byte.toUnsignedLong(buf[off++]) << 3;
values[i + 4] |= Byte.toUnsignedLong(buf[off]) >>> 5;
values[i + 5] = (Byte.toUnsignedLong(buf[off++]) & 0x1f) << 58;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 50;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 42;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 34;
values[i + 5] |= (Byte.toUnsignedLong(buf[off++])) << 26;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 18;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 10;
values[i + 5] |= Byte.toUnsignedLong(buf[off++]) << 2;
values[i + 5] |= Byte.toUnsignedLong(buf[off]) >>> 6;
values[i + 6] = (Byte.toUnsignedLong(buf[off++]) & 0x3f) << 57;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 49;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 41;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 33;
values[i + 6] |= (Byte.toUnsignedLong(buf[off++])) << 25;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 17;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 9;
values[i + 6] |= Byte.toUnsignedLong(buf[off++]) << 1;
values[i + 6] |= Byte.toUnsignedLong(buf[off]) >>> 7;
values[i + 7] = (Byte.toUnsignedLong(buf[off++]) & 0x7f) << 56;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 48;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 40;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 32;
values[i + 7] |= (Byte.toUnsignedLong(buf[off++])) << 24;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 16;
values[i + 7] |= Byte.toUnsignedLong(buf[off++]) << 8;
values[i + 7] |= Byte.toUnsignedLong(buf[off]);
}
}
| 2,761 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/HeapCompactSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.CompactOperations.checkIllegalCurCountAndEmpty;
import static org.apache.datasketches.theta.CompactOperations.componentsToCompact;
import static org.apache.datasketches.theta.CompactOperations.computeCompactPreLongs;
import static org.apache.datasketches.theta.CompactOperations.correctThetaOnCompact;
import static org.apache.datasketches.theta.CompactOperations.isSingleItem;
import static org.apache.datasketches.theta.CompactOperations.loadCompactMemory;
import static org.apache.datasketches.theta.PreambleUtil.COMPACT_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.ORDERED_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.READ_ONLY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.SINGLEITEM_FLAG_MASK;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
/**
* Parent class of the Heap Compact Sketches.
*
* @author Lee Rhodes
*/
class HeapCompactSketch extends CompactSketch {
private final long thetaLong_; //computed
private final int curCount_;
private final int preLongs_; //computed
private final short seedHash_;
private final boolean empty_;
private final boolean ordered_;
private final boolean singleItem_;
private final long[] cache_;
/**
* Constructs this sketch from correct, valid components.
* @param cache in compact form
* @param empty The correct <a href="{@docRoot}/resources/dictionary.html#empty">Empty</a>.
* @param seedHash The correct
* <a href="{@docRoot}/resources/dictionary.html#seedHash">Seed Hash</a>.
* @param curCount correct value
* @param thetaLong The correct
* <a href="{@docRoot}/resources/dictionary.html#thetaLong">thetaLong</a>.
*/
HeapCompactSketch(final long[] cache, final boolean empty, final short seedHash,
final int curCount, final long thetaLong, final boolean ordered) {
seedHash_ = seedHash;
curCount_ = curCount;
empty_ = empty;
ordered_ = ordered;
cache_ = cache;
//computed
thetaLong_ = correctThetaOnCompact(empty, curCount, thetaLong);
preLongs_ = computeCompactPreLongs(empty, curCount, thetaLong); //considers singleItem
singleItem_ = isSingleItem(empty, curCount, thetaLong);
checkIllegalCurCountAndEmpty(empty, curCount);
}
//Sketch
@Override
public CompactSketch compact(final boolean dstOrdered, final WritableMemory dstMem) {
if (dstMem == null && (dstOrdered == false || this.ordered_ == dstOrdered)) { return this; }
return componentsToCompact(getThetaLong(), getRetainedEntries(true), getSeedHash(), isEmpty(),
true, ordered_, dstOrdered, dstMem, getCache().clone());
}
@Override
public int getCurrentBytes() {
return (preLongs_ + curCount_) << 3;
}
@Override
public double getEstimate() {
return Sketch.estimate(thetaLong_, curCount_);
}
@Override
public int getRetainedEntries(final boolean valid) {
return curCount_;
}
@Override
public long getThetaLong() {
return thetaLong_;
}
@Override
public boolean hasMemory() {
return false;
}
@Override
public boolean isDirect() {
return false;
}
@Override
public boolean isEmpty() {
return empty_;
}
@Override
public boolean isOrdered() {
return ordered_;
}
@Override
public HashIterator iterator() {
return new HeapCompactHashIterator(cache_);
}
//restricted methods
@Override
long[] getCache() {
return cache_;
}
@Override
int getCompactPreambleLongs() {
return preLongs_;
}
@Override
int getCurrentPreambleLongs() { //already compact; ignored
return preLongs_;
}
@Override
Memory getMemory() {
return null;
}
@Override
short getSeedHash() {
return seedHash_;
}
//use of Memory is convenient. The byteArray and Memory are loaded simultaneously.
@Override
public byte[] toByteArray() {
final int bytes = getCurrentBytes();
final byte[] byteArray = new byte[bytes];
final WritableMemory dstMem = WritableMemory.writableWrap(byteArray);
final int emptyBit = isEmpty() ? EMPTY_FLAG_MASK : 0;
final int orderedBit = ordered_ ? ORDERED_FLAG_MASK : 0;
final int singleItemBit = singleItem_ ? SINGLEITEM_FLAG_MASK : 0;
final byte flags = (byte) (emptyBit | READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK
| orderedBit | singleItemBit);
final int preLongs = getCompactPreambleLongs();
loadCompactMemory(getCache(), getSeedHash(), getRetainedEntries(true), getThetaLong(),
dstMem, flags, preLongs);
return byteArray;
}
}
| 2,762 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/DirectQuickSelectSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Util.LONG_MAX_VALUE_AS_DOUBLE;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.FLAGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.P_FLOAT;
import static org.apache.datasketches.theta.PreambleUtil.RETAINED_ENTRIES_INT;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER;
import static org.apache.datasketches.theta.PreambleUtil.THETA_LONG;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractLgNomLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.getMemBytes;
import static org.apache.datasketches.theta.PreambleUtil.insertCurCount;
import static org.apache.datasketches.theta.PreambleUtil.insertFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.insertFlags;
import static org.apache.datasketches.theta.PreambleUtil.insertLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertLgNomLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertLgResizeFactor;
import static org.apache.datasketches.theta.PreambleUtil.insertP;
import static org.apache.datasketches.theta.PreambleUtil.insertPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertSeedHash;
import static org.apache.datasketches.theta.PreambleUtil.insertSerVer;
import static org.apache.datasketches.theta.PreambleUtil.insertThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.insertUnionThetaLong;
import static org.apache.datasketches.theta.Rebuilder.actLgResizeFactor;
import static org.apache.datasketches.theta.Rebuilder.moveAndResize;
import static org.apache.datasketches.theta.Rebuilder.quickSelectAndRebuild;
import static org.apache.datasketches.theta.Rebuilder.resize;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncremented;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncrementedRebuilt;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncrementedResized;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedDuplicate;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedOverTheta;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.HashOperations;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* The default Theta Sketch using the QuickSelect algorithm.
* This subclass implements methods, which affect the state (update, rebuild, reset)
*
* <p>This implementation uses data in a given Memory that is owned and managed by the caller.
* This Memory can be off-heap, which if managed properly will greatly reduce the need for
* the JVM to perform garbage collection.</p>
*
* @author Lee Rhodes
* @author Kevin Lang
*/
class DirectQuickSelectSketch extends DirectQuickSelectSketchR {
MemoryRequestServer memReqSvr_ = null; //never serialized
private DirectQuickSelectSketch(
final long seed,
final WritableMemory wmem) {
super(seed, wmem);
}
/**
* Construct a new sketch instance and initialize the given Memory as its backing store.
*
* @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 Currently internally fixed at 2. Unless dstMem is not configured with a valid
* MemoryRequest, in which case the rf is effectively 1, which is no resizing at all and the
* dstMem must be large enough for a full sketch.
* <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
* @param memReqSvr the given MemoryRequestServer
* @param dstMem the given Memory object destination. It cannot be null.
* It will be cleared prior to use.
* @param unionGadget true if this sketch is implementing the Union gadget function.
* Otherwise, it is behaving as a normal QuickSelectSketch.
*/
DirectQuickSelectSketch(
final int lgNomLongs,
final long seed,
final float p,
final ResizeFactor rf,
final MemoryRequestServer memReqSvr,
final WritableMemory dstMem,
final boolean unionGadget) {
super(seed, dstMem);
//Choose family, preambleLongs
final Family family;
final int preambleLongs;
if (unionGadget) {
preambleLongs = Family.UNION.getMinPreLongs();
family = Family.UNION;
}
else {
preambleLongs = Family.QUICKSELECT.getMinPreLongs();
family = Family.QUICKSELECT;
}
//Choose RF, minReqBytes, lgArrLongs.
final int lgRF = rf.lg();
final int lgArrLongs = (lgRF == 0) ? lgNomLongs + 1 : ThetaUtil.MIN_LG_ARR_LONGS;
final int minReqBytes = getMemBytes(lgArrLongs, preambleLongs);
//Make sure Memory is large enough
final long curMemCapBytes = dstMem.getCapacity();
if (curMemCapBytes < minReqBytes) {
throw new SketchesArgumentException(
"Memory capacity is too small: " + curMemCapBytes + " < " + minReqBytes);
}
//@formatter:off
//Build preamble
insertPreLongs(dstMem, preambleLongs); //byte 0
insertLgResizeFactor(dstMem, lgRF); //byte 0
insertSerVer(dstMem, SER_VER); //byte 1
insertFamilyID(dstMem, family.getID()); //byte 2
insertLgNomLongs(dstMem, lgNomLongs); //byte 3
insertLgArrLongs(dstMem, lgArrLongs); //byte 4
//flags: bigEndian = readOnly = compact = ordered = false; empty = true : 00100 = 4
insertFlags(dstMem, EMPTY_FLAG_MASK); //byte 5
insertSeedHash(dstMem, ThetaUtil.computeSeedHash(seed)); //bytes 6,7
insertCurCount(dstMem, 0); //bytes 8-11
insertP(dstMem, p); //bytes 12-15
final long thetaLong = (long)(p * LONG_MAX_VALUE_AS_DOUBLE);
insertThetaLong(dstMem, thetaLong); //bytes 16-23
if (unionGadget) {
insertUnionThetaLong(dstMem, thetaLong);
}
//@formatter:on
//clear hash table area
dstMem.clear(preambleLongs << 3, 8 << lgArrLongs);
hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
memReqSvr_ = memReqSvr;
}
/**
* Wrap a sketch around the given source Memory containing sketch data that originated from
* this sketch.
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* The given Memory object must be in hash table form and not read only.
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>
* @return instance of this sketch
*/
static DirectQuickSelectSketch writableWrap(final WritableMemory 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
UpdateSketch.checkUnionQuickSelectFamily(srcMem, preambleLongs, lgNomLongs);
checkMemIntegrity(srcMem, seed, preambleLongs, lgNomLongs, lgArrLongs);
if (isResizeFactorIncorrect(srcMem, lgNomLongs, lgArrLongs)) {
//If incorrect it sets it to X2 which always works.
insertLgResizeFactor(srcMem, ResizeFactor.X2.lg());
}
final DirectQuickSelectSketch dqss =
new DirectQuickSelectSketch(seed, srcMem);
dqss.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
return dqss;
}
/**
* Fast-wrap a sketch around the given source Memory containing sketch data that originated from
* this sketch. This does NO validity checking of the given Memory.
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* The given Memory object must be in hash table form and not read only.
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>
* @return instance of this sketch
*/
static DirectQuickSelectSketch fastWritableWrap(final WritableMemory srcMem, final long seed) {
final int lgNomLongs = extractLgNomLongs(srcMem); //byte 3
final int lgArrLongs = extractLgArrLongs(srcMem); //byte 4
final DirectQuickSelectSketch dqss =
new DirectQuickSelectSketch(seed, srcMem);
dqss.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
return dqss;
}
//Sketch
//UpdateSketch
@Override
public UpdateSketch rebuild() {
final int lgNomLongs = getLgNomLongs();
final int preambleLongs = wmem_.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
if (getRetainedEntries(true) > (1 << lgNomLongs)) {
quickSelectAndRebuild(wmem_, preambleLongs, lgNomLongs);
}
return this;
}
@Override
public void reset() {
//clear hash table
//hash table size and hashTableThreshold stays the same
//lgArrLongs stays the same
//thetaLongs resets to p
final int arrLongs = 1 << getLgArrLongs();
final int preambleLongs = wmem_.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int preBytes = preambleLongs << 3;
wmem_.clear(preBytes, arrLongs * 8L); //clear data array
//flags: bigEndian = readOnly = compact = ordered = false; empty = true.
wmem_.putByte(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK);
wmem_.putInt(RETAINED_ENTRIES_INT, 0);
final float p = wmem_.getFloat(P_FLOAT);
final long thetaLong = (long) (p * LONG_MAX_VALUE_AS_DOUBLE);
wmem_.putLong(THETA_LONG, thetaLong);
}
//restricted methods
@Override
UpdateReturnState hashUpdate(final long hash) {
HashOperations.checkHashCorruption(hash);
wmem_.putByte(FLAGS_BYTE, (byte) (wmem_.getByte(FLAGS_BYTE) & ~EMPTY_FLAG_MASK));
final long thetaLong = getThetaLong();
final int lgNomLongs = getLgNomLongs();
//The over-theta test
if (HashOperations.continueCondition(thetaLong, hash)) {
return RejectedOverTheta; //signal that hash was rejected due to theta or zero.
}
final int lgArrLongs = getLgArrLongs();
final int preambleLongs = wmem_.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
//The duplicate test
final int index =
HashOperations.hashSearchOrInsertMemory(wmem_, lgArrLongs, hash, preambleLongs << 3);
if (index >= 0) {
return RejectedDuplicate; //Duplicate, not inserted
}
//insertion occurred, increment curCount
final int curCount = getRetainedEntries(true) + 1;
wmem_.putInt(RETAINED_ENTRIES_INT, curCount); //update curCount
if (isOutOfSpace(curCount)) { //we need to do something, we are out of space
if (lgArrLongs > lgNomLongs) { //at full size, rebuild
//Assumes no dirty values, changes thetaLong, curCount_
assert (lgArrLongs == (lgNomLongs + 1))
: "lgArr: " + lgArrLongs + ", lgNom: " + lgNomLongs;
//rebuild, refresh curCount based on # values in the hashtable.
quickSelectAndRebuild(wmem_, preambleLongs, lgNomLongs);
return InsertedCountIncrementedRebuilt;
} //end of rebuild, exit
else { //Not at full size, resize. Should not get here if lgRF = 0 and memCap is too small.
final int lgRF = getLgRF();
final int actLgRF = actLgResizeFactor(wmem_.getCapacity(), lgArrLongs, preambleLongs, lgRF);
int tgtLgArrLongs = Math.min(lgArrLongs + actLgRF, lgNomLongs + 1);
if (actLgRF > 0) { //Expand in current Memory
//lgArrLongs will change; thetaLong, curCount will not
resize(wmem_, preambleLongs, lgArrLongs, tgtLgArrLongs);
hashTableThreshold_ = setHashTableThreshold(lgNomLongs, tgtLgArrLongs);
return InsertedCountIncrementedResized;
} //end of Expand in current memory, exit.
else {
//Request more memory, then resize. lgArrLongs will change; thetaLong, curCount will not
final int preBytes = preambleLongs << 3;
tgtLgArrLongs = Math.min(lgArrLongs + lgRF, lgNomLongs + 1);
final int tgtArrBytes = 8 << tgtLgArrLongs;
final int reqBytes = tgtArrBytes + preBytes;
memReqSvr_ = (memReqSvr_ == null) ? wmem_.getMemoryRequestServer() : memReqSvr_;
final WritableMemory newDstMem = memReqSvr_.request(wmem_,reqBytes);
moveAndResize(wmem_, preambleLongs, lgArrLongs, newDstMem, tgtLgArrLongs, thetaLong);
memReqSvr_.requestClose(wmem_, newDstMem);
wmem_ = newDstMem;
hashTableThreshold_ = setHashTableThreshold(lgNomLongs, tgtLgArrLongs);
return InsertedCountIncrementedResized;
} //end of Request more memory to resize
} //end of resize
} //end of isOutOfSpace
return InsertedCountIncremented;
}
}
| 2,763 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/JaccardSimilarity.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.apache.datasketches.common.Util.ceilingIntPowerOf2;
import static org.apache.datasketches.thetacommon.BoundsOnRatiosInThetaSketchedSets.getEstimateOfBoverA;
import static org.apache.datasketches.thetacommon.BoundsOnRatiosInThetaSketchedSets.getLowerBoundForBoverA;
import static org.apache.datasketches.thetacommon.BoundsOnRatiosInThetaSketchedSets.getUpperBoundForBoverA;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* Jaccard similarity of two Theta Sketches.
*
* @author Lee Rhodes
*/
public final class JaccardSimilarity {
private static final double[] ZEROS = {0.0, 0.0, 0.0}; // LB, Estimate, UB
private static final double[] ONES = {1.0, 1.0, 1.0};
/**
* Computes the Jaccard similarity index with upper and lower bounds. The Jaccard similarity index
* <i>J(A,B) = (A ^ B)/(A U B)</i> is used to measure how similar the two sketches are to each
* other. If J = 1.0, the sketches are considered equal. If J = 0, the two sketches are
* distinct from each other. A Jaccard of .95 means the overlap between the two
* populations is 95% of the union of the two populations.
*
* <p>Note: For very large pairs of sketches, where the configured nominal entries of the sketches
* are 2^25 or 2^26, this method may produce unpredictable results.
*
* @param sketchA given sketch A
* @param sketchB given sketch B
* @return a double array {LowerBound, Estimate, UpperBound} of the Jaccard index.
* The Upper and Lower bounds are for a confidence interval of 95.4% or +/- 2 standard deviations.
*/
public static double[] jaccard(final Sketch sketchA, final Sketch sketchB) {
//Corner case checks
if (sketchA == null || sketchB == null) { return ZEROS.clone(); }
if (sketchA == sketchB) { return ONES.clone(); }
if (sketchA.isEmpty() && sketchB.isEmpty()) { return ONES.clone(); }
if (sketchA.isEmpty() || sketchB.isEmpty()) { return ZEROS.clone(); }
final int countA = sketchA.getRetainedEntries(true);
final int countB = sketchB.getRetainedEntries(true);
//Create the Union
final int minK = 1 << ThetaUtil.MIN_LG_NOM_LONGS;
final int maxK = 1 << ThetaUtil.MAX_LG_NOM_LONGS;
final int newK = max(min(ceilingIntPowerOf2(countA + countB), maxK), minK);
final Union union =
SetOperation.builder().setNominalEntries(newK).buildUnion();
union.union(sketchA);
union.union(sketchB);
final Sketch unionAB = union.getResult(false, null);
final long thetaLongUAB = unionAB.getThetaLong();
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
final int countUAB = unionAB.getRetainedEntries(true);
//Check for identical data
if (countUAB == countA && countUAB == countB
&& thetaLongUAB == thetaLongA && thetaLongUAB == thetaLongB) {
return ONES.clone();
}
//Create the Intersection
final Intersection inter = SetOperation.builder().buildIntersection();
inter.intersect(sketchA);
inter.intersect(sketchB);
inter.intersect(unionAB); //ensures that intersection is a subset of the union
final Sketch interABU = inter.getResult(false, null);
final double lb = getLowerBoundForBoverA(unionAB, interABU);
final double est = getEstimateOfBoverA(unionAB, interABU);
final double ub = getUpperBoundForBoverA(unionAB, interABU);
return new double[] {lb, est, ub};
}
/**
* Returns true if the two given sketches have exactly the same hash values and the same
* theta values. Thus, they are equivalent.
* @param sketchA the given sketch A
* @param sketchB the given sketch B
* @return true if the two given sketches have exactly the same hash values and the same
* theta values.
*/
public static boolean exactlyEqual(final Sketch sketchA, final Sketch sketchB) {
//Corner case checks
if (sketchA == null || sketchB == null) { return false; }
if (sketchA == sketchB) { return true; }
if (sketchA.isEmpty() && sketchB.isEmpty()) { return true; }
if (sketchA.isEmpty() || sketchB.isEmpty()) { return false; }
final int countA = sketchA.getRetainedEntries(true);
final int countB = sketchB.getRetainedEntries(true);
//Create the Union
final Union union =
SetOperation.builder().setNominalEntries(ceilingIntPowerOf2(countA + countB)).buildUnion();
union.union(sketchA);
union.union(sketchB);
final Sketch unionAB = union.getResult();
final long thetaLongUAB = unionAB.getThetaLong();
final long thetaLongA = sketchA.getThetaLong();
final long thetaLongB = sketchB.getThetaLong();
final int countUAB = unionAB.getRetainedEntries(true);
//Check for identical counts and thetas
if (countUAB == countA && countUAB == countB
&& thetaLongUAB == thetaLongA && thetaLongUAB == thetaLongB) {
return true;
}
return false;
}
/**
* Tests similarity of a measured Sketch against an expected Sketch.
* Computes the lower bound of the Jaccard index <i>J<sub>LB</sub></i> of the measured and
* expected sketches.
* if <i>J<sub>LB</sub> ≥ threshold</i>, then the sketches are considered to be
* similar with a confidence of 97.7%.
*
* @param measured the sketch to be tested
* @param expected the reference sketch that is considered to be correct.
* @param threshold a real value between zero and one.
* @return if true, the similarity of the two sketches is greater than the given threshold
* with at least 97.7% confidence.
*/
public static boolean similarityTest(final Sketch measured, final Sketch expected,
final double threshold) {
//index 0: the lower bound
//index 1: the mean estimate
//index 2: the upper bound
final double jRatioLB = jaccard(measured, expected)[0]; //choosing the lower bound
return jRatioLB >= threshold;
}
/**
* Tests dissimilarity of a measured Sketch against an expected Sketch.
* Computes the upper bound of the Jaccard index <i>J<sub>UB</sub></i> of the measured and
* expected sketches.
* if <i>J<sub>UB</sub> ≤ threshold</i>, then the sketches are considered to be
* dissimilar with a confidence of 97.7%.
*
* @param measured the sketch to be tested
* @param expected the reference sketch that is considered to be correct.
* @param threshold a real value between zero and one.
* @return if true, the dissimilarity of the two sketches is greater than the given threshold
* with at least 97.7% confidence.
*/
public static boolean dissimilarityTest(final Sketch measured, final Sketch expected,
final double threshold) {
//index 0: the lower bound
//index 1: the mean estimate
//index 2: the upper bound
final double jRatioUB = jaccard(measured, expected)[2]; //choosing the upper bound
return jRatioUB <= threshold;
}
}
| 2,764 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/ConcurrentPropagationService.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import org.apache.datasketches.common.SuppressFBWarnings;
/**
* Pool of threads to serve <i>all</i> propagation tasks in the system.
*
* @author Eshcar Hillel
*/
final class ConcurrentPropagationService {
static int NUM_POOL_THREADS = 3; // Default: 3 threads
private static volatile ConcurrentPropagationService instance = null; // Singleton
private static ExecutorService[] propagationExecutorService = null;
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD", justification = "Fix later")
private ConcurrentPropagationService() {
propagationExecutorService = new ExecutorService[NUM_POOL_THREADS];
}
//Factory: Get the singleton
@SuppressFBWarnings(value = "SSD_DO_NOT_USE_INSTANCE_LOCK_ON_SHARED_STATIC_DATA", justification = "Fix later")
private static ConcurrentPropagationService getInstance() {
if (instance == null) {
synchronized (ConcurrentPropagationService.class) {
if (instance == null) {
instance = new ConcurrentPropagationService(); //SpotBugs: SSD_DO_NOT_USE_INSTANCE_LOCK_ON_SHARED_STATIC_DATA
}
}
}
return instance;
}
public static ExecutorService getExecutorService(final long id) {
return getInstance().initExecutorService((int) id % NUM_POOL_THREADS);
}
@SuppressWarnings("static-access")
public static ExecutorService resetExecutorService(final long id) {
return getInstance().propagationExecutorService[(int) id % NUM_POOL_THREADS] = null;
}
@SuppressWarnings("static-method")
private ExecutorService initExecutorService(final int i) {
if (propagationExecutorService[i] == null) {
propagationExecutorService[i] = Executors.newSingleThreadExecutor();
}
return propagationExecutorService[i];
}
}
| 2,765 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/AnotB.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.memory.WritableMemory;
/**
* Computes a set difference, A-AND-NOT-B, of two theta sketches.
* This class includes both stateful and stateless operations.
*
* <p>The stateful operation is as follows:</p>
* <pre><code>
* AnotB anotb = SetOperationBuilder.buildAnotB();
*
* anotb.setA(Sketch skA); //The first argument.
* anotb.notB(Sketch skB); //The second (subtraction) argument.
* anotb.notB(Sketch skC); // ...any number of additional subtractions...
* anotb.getResult(false); //Get an interim result.
* anotb.notB(Sketch skD); //Additional subtractions.
* anotb.getResult(true); //Final result and resets the AnotB operator.
* </code></pre>
*
* <p>The stateless operation is as follows:</p>
* <pre><code>
* AnotB anotb = SetOperationBuilder.buildAnotB();
*
* CompactSketch csk = anotb.aNotB(Sketch skA, Sketch skB);
* </code></pre>
*
* <p>Calling the <i>setA</i> operation a second time essentially clears the internal state and loads
* the new sketch.</p>
*
* <p>The stateless and stateful operations are independent of each other with the exception of
* sharing the same update hash seed loaded as the default seed or specified by the user as an
* argument to the builder.</p>
*
* @author Lee Rhodes
*/
public abstract class AnotB extends SetOperation {
@Override
public Family getFamily() {
return Family.A_NOT_B;
}
/**
* This is part of a multistep, stateful AnotB operation and sets the given Theta sketch as the
* first argument <i>A</i> of <i>A-AND-NOT-B</i>. This overwrites the internal state of this
* AnotB operator with the contents of the given sketch.
* This sets the stage for multiple following <i>notB</i> steps.
*
* <p>An input argument of null will throw an exception.</p>
*
* <p>Rationale: In mathematics a "null set" is a set with no members, which we call an empty set.
* That is distinctly different from the java <i>null</i>, which represents a nonexistent object.
* In most cases it is a programming error due to some object that was not properly initialized.
* With a null as the first argument, we cannot know what the user's intent is.
* Since it is very likely that a <i>null</i> is a programming error, we throw a an exception.</p>
*
* <p>An empty input argument will set the internal state to empty.</p>
*
* <p>Rationale: An empty set is a mathematically legal concept. Although it makes any subsequent,
* valid argument for B irrelevant, we must allow this and assume the user knows what they are
* doing.</p>
*
* <p>Performing {@link #getResult(boolean)} just after this step will return a compact form of
* the given argument.</p>
*
* @param skA The incoming sketch for the first argument, <i>A</i>.
*/
public abstract void setA(Sketch skA);
/**
* This is part of a multistep, stateful AnotB operation and sets the given Theta sketch as the
* second (or <i>n+1</i>th) argument <i>B</i> of <i>A-AND-NOT-B</i>.
* Performs an <i>AND NOT</i> operation with the existing internal state of this AnotB operator.
*
* <p>An input argument of null or empty is ignored.</p>
*
* <p>Rationale: A <i>null</i> for the second or following arguments is more tolerable because
* <i>A NOT null</i> is still <i>A</i> even if we don't know exactly what the null represents. It
* clearly does not have any content that overlaps with <i>A</i>. Also, because this can be part of
* a multistep operation with multiple <i>notB</i> steps. Other following steps can still produce
* a valid result.</p>
*
* <p>Use {@link #getResult(boolean)} to obtain the result.</p>
*
* @param skB The incoming Theta sketch for the second (or following) argument <i>B</i>.
*/
public abstract void notB(Sketch skB);
/**
* Gets the result of the multistep, stateful operation AnotB that have been executed with calls
* to {@link #setA(Sketch)} and ({@link #notB(Sketch)} or
* {@link #notB(org.apache.datasketches.theta.Sketch)}).
*
* @param reset If <i>true</i>, clears this operator to the empty state after this result is
* returned. Set this to <i>false</i> if you wish to obtain an intermediate result.
*
* @return the result of this operation as an ordered, on-heap {@link CompactSketch}.
*/
public abstract CompactSketch getResult(boolean reset);
/**
* Gets the result of the multistep, stateful operation AnotB that have been executed with calls
* to {@link #setA(Sketch)} and ({@link #notB(Sketch)} or
* {@link #notB(org.apache.datasketches.theta.Sketch)}).
*
* @param dstOrdered If <i>true</i>, the result will be an ordered {@link CompactSketch}.
* <a href="{@docRoot}/resources/dictionary.html#dstOrdered">See Destination Ordered</a>.
*
* @param dstMem if not <i>null</i> the given Memory will be the target location of the result.
* <a href="{@docRoot}/resources/dictionary.html#dstMem">See Destination Memory</a>.
*
* @param reset If <i>true</i>, clears this operator to the empty state after this result is
* returned. Set this to <i>false</i> if you wish to obtain an intermediate result.
*
* @return the result of this operation as a {@link CompactSketch} in the given dstMem.
*/
public abstract CompactSketch getResult(boolean dstOrdered, WritableMemory dstMem, boolean reset);
/**
* Perform A-and-not-B set operation on the two given sketches and return the result as an
* ordered CompactSketch on the heap.
*
* <p>This a stateless operation and has no impact on the internal state of this operator.
* Thus, this is not an accumulating update and does not interact with the {@link #setA(Sketch)},
* {@link #notB(Sketch)}, {@link #getResult(boolean)}, or
* {@link #getResult(boolean, WritableMemory, boolean)} methods.</p>
*
* <p>If either argument is null an exception is thrown.</p>
*
* <p>Rationale: In mathematics a "null set" is a set with no members, which we call an empty set.
* That is distinctly different from the java <i>null</i>, which represents a nonexistent object.
* In most cases <i>null</i> is a programming error due to a non-initialized object. </p>
*
* <p>With a null as the first argument we cannot know what the user's intent is and throw an
* exception. With a null as the second argument for this method we must return a result and
* there is no following possible viable arguments for the second argument so we thrown an
* exception.</p>
*
* @param skA The incoming sketch for the first argument. It must not be null.
* @param skB The incoming sketch for the second argument. It must not be null.
* @return an ordered CompactSketch on the heap
*/
public CompactSketch aNotB(final Sketch skA, final Sketch skB) {
return aNotB(skA, skB, true, null);
}
/**
* Perform A-and-not-B set operation on the two given sketches and return the result as a
* CompactSketch.
*
* <p>This a stateless operation and has no impact on the internal state of this operator.
* Thus, this is not an accumulating update and does not interact with the {@link #setA(Sketch)},
* {@link #notB(Sketch)}, {@link #getResult(boolean)}, or
* {@link #getResult(boolean, WritableMemory, boolean)} methods.</p>
*
* <p>If either argument is null an exception is thrown.</p>
*
* <p>Rationale: In mathematics a "null set" is a set with no members, which we call an empty set.
* That is distinctly different from the java <i>null</i>, which represents a nonexistent object.
* In most cases <i>null</i> is a programming error due to a non-initialized object. </p>
*
* <p>With a null as the first argument we cannot know what the user's intent is and throw an
* exception. With a null as the second argument for this method we must return a result and
* there is no following possible viable arguments for the second argument so we thrown an
* exception.</p>
*
* @param skA The incoming sketch for the first argument. It must not be null.
* @param skB The incoming sketch for the second argument. It must not be null.
* @param dstOrdered
* <a href="{@docRoot}/resources/dictionary.html#dstOrdered">See Destination Ordered</a>.
* @param dstMem
* <a href="{@docRoot}/resources/dictionary.html#dstMem">See Destination Memory</a>.
* @return the result as a CompactSketch.
*/
public abstract CompactSketch aNotB(Sketch skA, Sketch skB, boolean dstOrdered,
WritableMemory dstMem);
}
| 2,766 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/UpdateReturnState.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
/**
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*
* @author Lee Rhodes
*/
public enum UpdateReturnState {
/**
* The hash was accepted into the sketch and the retained count was incremented.
*/
InsertedCountIncremented, //all UpdateSketches
/**
* The hash was accepted into the sketch, the retained count was incremented.
* The current cache was out of room and resized larger based on the Resize Factor.
*/
InsertedCountIncrementedResized, //used by HeapQuickSelectSketch
/**
* The hash was accepted into the sketch, the retained count was incremented.
* The current cache was out of room and at maximum size, so the cache was rebuilt.
*/
InsertedCountIncrementedRebuilt, //used by HeapQuickSelectSketch
/**
* The hash was accepted into the sketch and the retained count was not incremented.
*/
InsertedCountNotIncremented, //used by enhancedHashInsert for Alpha
/**
* The hash was inserted into the local concurrent buffer,
* but has not yet been propagated to the concurrent shared sketch.
*/
ConcurrentBufferInserted, //used by ConcurrentHeapThetaBuffer
/**
* The hash has been propagated to the concurrent shared sketch.
* This does not reflect the action taken by the shared sketch.
*/
ConcurrentPropagated, //used by ConcurrentHeapThetaBuffer
/**
* The hash was rejected as a duplicate.
*/
RejectedDuplicate, //all UpdateSketches hashUpdate(), enhancedHashInsert
/**
* The hash was rejected because it was null or empty.
*/
RejectedNullOrEmpty, //UpdateSketch.update(arr[])
/**
* The hash was rejected because the value was negative, zero or
* greater than theta.
*/
RejectedOverTheta; //all UpdateSketches.hashUpdate()
}
| 2,767 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/Sketches.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.FAMILY_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.FLAGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.RETAINED_ENTRIES_INT;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.THETA_LONG;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* This class brings together the common sketch and set operation creation methods and
* the public static methods into one place.
*
* @author Lee Rhodes
*/
public final class Sketches {
private Sketches() {}
/**
* 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.
*/
public static double getEstimate(final Memory srcMem) {
checkIfValidThetaSketch(srcMem);
return Sketch.estimate(getThetaLong(srcMem), getRetainedEntries(srcMem));
}
/**
* Gets the approximate lower error bound from a valid memory image of a Sketch
* given the specified number of Standard Deviations.
* This will return getEstimate() if isEmpty() is true.
*
* @param numStdDev
* <a href="{@docRoot}/resources/dictionary.html#numStdDev">See Number of Standard Deviations</a>
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return the lower bound.
*/
public static double getLowerBound(final int numStdDev, final Memory srcMem) {
return Sketch.lowerBound(getRetainedEntries(srcMem), getThetaLong(srcMem), numStdDev, getEmpty(srcMem));
}
/**
* Ref: {@link SetOperation#getMaxAnotBResultBytes(int)}.
* Returns the maximum number of bytes for the returned CompactSketch, given the maximum
* value of nomEntries of the first sketch A of AnotB.
* @param maxNomEntries the given value
* @return the maximum number of bytes.
*/
public static int getMaxAnotBResultBytes(final int maxNomEntries) {
return SetOperation.getMaxAnotBResultBytes(maxNomEntries);
}
/**
* Ref: {@link Sketch#getMaxCompactSketchBytes(int)}
* @param numberOfEntries Ref: {@link Sketch#getMaxCompactSketchBytes(int)},
* {@code numberOfEntries}
* @return Ref: {@link Sketch#getMaxCompactSketchBytes(int)}
*/
public static int getMaxCompactSketchBytes(final int numberOfEntries) {
return Sketch.getMaxCompactSketchBytes(numberOfEntries);
}
/**
* Ref: {@link SetOperation#getMaxIntersectionBytes(int)}
* @param nomEntries Ref: {@link SetOperation#getMaxIntersectionBytes(int)}, {@code nomEntries}
* @return Ref: {@link SetOperation#getMaxIntersectionBytes(int)}
*/
public static int getMaxIntersectionBytes(final int nomEntries) {
return SetOperation.getMaxIntersectionBytes(nomEntries);
}
/**
* Ref: {@link SetOperation#getMaxUnionBytes(int)}
* @param nomEntries Ref: {@link SetOperation#getMaxUnionBytes(int)}, {@code nomEntries}
* @return Ref: {@link SetOperation#getMaxUnionBytes(int)}
*/
public static int getMaxUnionBytes(final int nomEntries) {
return SetOperation.getMaxUnionBytes(nomEntries);
}
/**
* Ref: {@link Sketch#getMaxUpdateSketchBytes(int)}
* @param nomEntries Ref: {@link Sketch#getMaxUpdateSketchBytes(int)}, {@code nomEntries}
* @return Ref: {@link Sketch#getMaxUpdateSketchBytes(int)}
*/
public static int getMaxUpdateSketchBytes(final int nomEntries) {
return Sketch.getMaxUpdateSketchBytes(nomEntries);
}
/**
* Ref: {@link Sketch#getSerializationVersion(Memory)}
* @param srcMem Ref: {@link Sketch#getSerializationVersion(Memory)}, {@code srcMem}
* @return Ref: {@link Sketch#getSerializationVersion(Memory)}
*/
public static int getSerializationVersion(final Memory srcMem) {
return Sketch.getSerializationVersion(srcMem);
}
/**
* Gets the approximate upper error bound from a valid memory image of a Sketch
* given the specified number of Standard Deviations.
* This will return getEstimate() if isEmpty() is true.
*
* @param numStdDev
* <a href="{@docRoot}/resources/dictionary.html#numStdDev">See Number of Standard Deviations</a>
* @param srcMem
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return the upper bound.
*/
public static double getUpperBound(final int numStdDev, final Memory srcMem) {
return Sketch.upperBound(getRetainedEntries(srcMem), getThetaLong(srcMem), numStdDev, getEmpty(srcMem));
}
//Heapify Operations
/**
* Ref: {@link CompactSketch#heapify(Memory) CompactSketch.heapify(Memory)}
* @param srcMem Ref: {@link CompactSketch#heapify(Memory) CompactSketch.heapify(Memory)}, {@code srcMem}
* @return {@link CompactSketch CompactSketch}
*/
public static CompactSketch heapifyCompactSketch(final Memory srcMem) {
return CompactSketch.heapify(srcMem);
}
/**
* Ref: {@link CompactSketch#heapify(Memory, long) CompactSketch.heapify(Memory, long)}
* @param srcMem Ref: {@link CompactSketch#heapify(Memory, long) CompactSketch.heapify(Memory, long)}, {@code srcMem}
* @param expectedSeed Ref: {@link CompactSketch#heapify(Memory, long) CompactSketch.heapify(Memory, long)},
* {@code expectedSeed}
* @return {@link CompactSketch CompactSketch}
*/
public static CompactSketch heapifyCompactSketch(final Memory srcMem, final long expectedSeed) {
return CompactSketch.heapify(srcMem, expectedSeed);
}
/**
* Ref: {@link CompactSketch#wrap(Memory) CompactSketch.wrap(Memory)}
* @param srcMem Ref: {@link CompactSketch#wrap(Memory) CompactSketch.wrap(Memory)}, {@code srcMem}
* @return {@link CompactSketch CompactSketch}
*/
public static CompactSketch wrapCompactSketch(final Memory srcMem) {
return CompactSketch.wrap(srcMem);
}
/**
* Ref: {@link CompactSketch#wrap(Memory, long) CompactSketch.wrap(Memory, long)}
* @param srcMem Ref: {@link CompactSketch#wrap(Memory, long) CompactSketch.wrap(Memory, long)}, {@code srcMem}
* @param expectedSeed Ref: {@link CompactSketch#wrap(Memory, long) CompactSketch.wrap(Memory, long)},
* {@code expectedSeed}
* @return {@link CompactSketch CompactSketch}
*/
public static CompactSketch wrapCompactSketch(final Memory srcMem, final long expectedSeed) {
return CompactSketch.wrap(srcMem, expectedSeed);
}
/**
* Ref: {@link SetOperation#heapify(Memory) SetOperation.heapify(Memory)}
* @param srcMem Ref: {@link SetOperation#heapify(Memory) SetOperation.heapify(Memory)}, {@code srcMem}
* @return {@link SetOperation SetOperation}
*/
public static SetOperation heapifySetOperation(final Memory srcMem) {
return SetOperation.heapify(srcMem);
}
/**
* Ref: {@link SetOperation#heapify(Memory, long) SetOperation.heapify(Memory, long)}
* @param srcMem Ref: {@link SetOperation#heapify(Memory, long) SetOperation.heapify(Memory, long)},
* {@code srcMem}
* @param expectedSeed the seed used to validate the given Memory image.
* Ref: {@link SetOperation#heapify(Memory, long) SetOperation.heapify(Memory, long)},
* {@code expectedSeed}
* @return {@link SetOperation SetOperation}
*/
public static SetOperation heapifySetOperation(final Memory srcMem, final long expectedSeed) {
return SetOperation.heapify(srcMem, expectedSeed);
}
/**
* Ref: {@link Sketch#heapify(Memory) Sketch.heapify(Memory)}
* @param srcMem Ref: {@link Sketch#heapify(Memory) Sketch.heapify(Memory)}, {@code srcMem}
* @return {@link Sketch Sketch}
*/
public static Sketch heapifySketch(final Memory srcMem) {
return Sketch.heapify(srcMem);
}
/**
* Ref: {@link Sketch#heapify(Memory, long) Sketch.heapify(Memory, long)}
* @param srcMem Ref: {@link Sketch#heapify(Memory, long) Sketch.heapify(Memory, long)}, {@code srcMem}
* @param expectedSeed the seed used to validate the given Memory image.
* Ref: {@link Sketch#heapify(Memory, long) Sketch.heapify(Memory, long)}, {@code expectedSeed}
* @return {@link Sketch Sketch}
*/
public static Sketch heapifySketch(final Memory srcMem, final long expectedSeed) {
return Sketch.heapify(srcMem, expectedSeed);
}
/**
* Ref: {@link UpdateSketch#heapify(Memory) UpdateSketch.heapify(Memory)}
* @param srcMem Ref: {@link UpdateSketch#heapify(Memory) UpdateSketch.heapify(Memory)}, {@code srcMem}
* @return {@link UpdateSketch UpdateSketch}
*/
public static UpdateSketch heapifyUpdateSketch(final Memory srcMem) {
return UpdateSketch.heapify(srcMem);
}
/**
* Ref: {@link UpdateSketch#heapify(Memory, long) UpdateSketch.heapify(Memory, long)}
* @param srcMem Ref: {@link UpdateSketch#heapify(Memory, long) UpdateSketch.heapify(Memory, long)},
* {@code srcMem}
* @param expectedSeed the seed used to validate the given Memory image.
* Ref: {@link UpdateSketch#heapify(Memory, long) UpdateSketch.heapify(Memory, long)},
* {@code expectedSeed}
* @return {@link UpdateSketch UpdateSketch}
*/
public static UpdateSketch heapifyUpdateSketch(final Memory srcMem, final long expectedSeed) {
return UpdateSketch.heapify(srcMem, expectedSeed);
}
//Builders
/**
* Ref: {@link SetOperationBuilder SetOperationBuilder}
* @return {@link SetOperationBuilder SetOperationBuilder}
*/
public static SetOperationBuilder setOperationBuilder() {
return new SetOperationBuilder();
}
/**
* Ref: {@link UpdateSketchBuilder UpdateSketchBuilder}
* @return {@link UpdateSketchBuilder UpdateSketchBuilder}
*/
public static UpdateSketchBuilder updateSketchBuilder() {
return new UpdateSketchBuilder();
}
//Wrap operations
/**
* Convenience method, calls {@link SetOperation#wrap(Memory)} and casts the result to a Intersection
* @param srcMem Ref: {@link SetOperation#wrap(Memory)}, {@code srcMem}
* @return a Intersection backed by the given Memory
*/
public static Intersection wrapIntersection(final Memory srcMem) {
return (Intersection) SetOperation.wrap(srcMem);
}
/**
* Convenience method, calls {@link SetOperation#wrap(Memory)} and casts the result to a Intersection
* @param srcMem Ref: {@link SetOperation#wrap(Memory)}, {@code srcMem}
* @return a Intersection backed by the given Memory
*/
public static Intersection wrapIntersection(final WritableMemory srcMem) {
return (Intersection) SetOperation.wrap(srcMem);
}
/**
* Ref: {@link SetOperation#wrap(Memory) SetOperation.wrap(Memory)}
* @param srcMem Ref: {@link SetOperation#wrap(Memory) SetOperation.wrap(Memory)}, {@code srcMem}
* @return {@link SetOperation SetOperation}
*/
public static SetOperation wrapSetOperation(final Memory srcMem) {
return wrapSetOperation(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Ref: {@link SetOperation#wrap(Memory, long) SetOperation.wrap(Memory, long)}
* @param srcMem Ref: {@link SetOperation#wrap(Memory, long) SetOperation.wrap(Memory, long)},
* {@code srcMem}
* @param expectedSeed the seed used to validate the given Memory image.
* Ref: {@link SetOperation#wrap(Memory, long) SetOperation.wrap(Memory, long)},
* {@code expectedSeed}
* @return {@link SetOperation SetOperation}
*/
public static SetOperation wrapSetOperation(final Memory srcMem, final long expectedSeed) {
return SetOperation.wrap(srcMem, expectedSeed);
}
/**
* Ref: {@link SetOperation#wrap(Memory) SetOperation.wrap(Memory)}
* @param srcMem Ref: {@link SetOperation#wrap(Memory) SetOperation.wrap(Memory)}, {@code srcMem}
* @return {@link SetOperation SetOperation}
*/
public static SetOperation wrapSetOperation(final WritableMemory srcMem) {
return wrapSetOperation(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Ref: {@link SetOperation#wrap(Memory, long) SetOperation.wrap(Memory, long)}
* @param srcMem Ref: {@link SetOperation#wrap(Memory, long) SetOperation.wrap(Memory, long)},
* {@code srcMem}
* @param expectedSeed the seed used to validate the given Memory image.
* Ref: {@link SetOperation#wrap(Memory, long) SetOperation.wrap(Memory, long)},
* {@code expectedSeed}
* @return {@link SetOperation SetOperation}
*/
public static SetOperation wrapSetOperation(final WritableMemory srcMem, final long expectedSeed) {
return SetOperation.wrap(srcMem, expectedSeed);
}
/**
* Ref: {@link Sketch#wrap(Memory) Sketch.wrap(Memory)}
* @param srcMem Ref: {@link Sketch#wrap(Memory) Sketch.wrap(Memory)}, {@code srcMem}
* @return {@link Sketch Sketch}
*/
public static Sketch wrapSketch(final Memory srcMem) {
return Sketch.wrap(srcMem);
}
/**
* Ref: {@link Sketch#wrap(Memory, long) Sketch.wrap(Memory, long)}
* @param srcMem Ref: {@link Sketch#wrap(Memory, long) Sketch.wrap(Memory, long)}, {@code srcMem}
* @param expectedSeed the expectedSeed used to validate the given Memory image.
* Ref: {@link Sketch#wrap(Memory, long) Sketch.wrap(Memory, long)}, {@code expectedSeed}
* @return {@link Sketch Sketch}
*/
public static Sketch wrapSketch(final Memory srcMem, final long expectedSeed) {
return Sketch.wrap(srcMem, expectedSeed);
}
/**
* Convenience method, calls {@link SetOperation#wrap(Memory)} and casts the result to a Union
* @param srcMem Ref: {@link SetOperation#wrap(Memory)}, {@code srcMem}
* @return a Union backed by the given Memory
*/
public static Union wrapUnion(final Memory srcMem) {
return (Union) SetOperation.wrap(srcMem);
}
/**
* Convenience method, calls {@link SetOperation#wrap(Memory)} and casts the result to a Union
* @param srcMem Ref: {@link SetOperation#wrap(Memory)}, {@code srcMem}
* @return a Union backed by the given Memory
*/
public static Union wrapUnion(final WritableMemory srcMem) {
return (Union) SetOperation.wrap(srcMem);
}
/**
* Ref: {@link UpdateSketch#wrap(Memory) UpdateSketch.wrap(Memory)}
* @param srcMem Ref: {@link UpdateSketch#wrap(Memory) UpdateSketch.wrap(Memory)}, {@code srcMem}
* @return {@link UpdateSketch UpdateSketch}
*/
public static UpdateSketch wrapUpdateSketch(final WritableMemory srcMem) {
return wrapUpdateSketch(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Ref: {@link UpdateSketch#wrap(Memory, long) UpdateSketch.wrap(Memory, long)}
* @param srcMem Ref: {@link UpdateSketch#wrap(Memory, long) UpdateSketch.wrap(Memory, long)}, {@code srcMem}
* @param expectedSeed the seed used to validate the given Memory image.
* Ref: {@link UpdateSketch#wrap(Memory, long) UpdateSketch.wrap(Memory, long)}, {@code expectedSeed}
* @return {@link UpdateSketch UpdateSketch}
*/
public static UpdateSketch wrapUpdateSketch(final WritableMemory srcMem, final long expectedSeed) {
return UpdateSketch.wrap(srcMem, expectedSeed);
}
//Restricted static methods
static void checkIfValidThetaSketch(final Memory srcMem) {
final int fam = srcMem.getByte(FAMILY_BYTE);
if (!Sketch.isValidSketchID(fam)) {
throw new SketchesArgumentException("Source Memory not a valid Sketch. Family: "
+ Family.idToFamily(fam).toString());
}
}
static boolean getEmpty(final Memory srcMem) {
final int serVer = srcMem.getByte(SER_VER_BYTE);
if (serVer == 1) {
return ((getThetaLong(srcMem) == Long.MAX_VALUE) && (getRetainedEntries(srcMem) == 0));
}
return (srcMem.getByte(FLAGS_BYTE) & EMPTY_FLAG_MASK) != 0; //for SerVer 2 & 3
}
static int getPreambleLongs(final Memory srcMem) {
return srcMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F; //for SerVer 1,2,3
}
static int getRetainedEntries(final Memory srcMem) {
final int serVer = srcMem.getByte(SER_VER_BYTE);
if (serVer == 1) {
final int entries = srcMem.getInt(RETAINED_ENTRIES_INT);
if ((getThetaLong(srcMem) == Long.MAX_VALUE) && (entries == 0)) {
return 0;
}
return entries;
}
//SerVer 2 or 3
final int preLongs = getPreambleLongs(srcMem);
final boolean empty = (srcMem.getByte(FLAGS_BYTE) & EMPTY_FLAG_MASK) != 0; //for SerVer 2 & 3
if (preLongs == 1) {
return empty ? 0 : 1;
}
//preLongs > 1
return srcMem.getInt(RETAINED_ENTRIES_INT); //for SerVer 1,2,3
}
static long getThetaLong(final Memory srcMem) {
final int preLongs = getPreambleLongs(srcMem);
return (preLongs < 3) ? Long.MAX_VALUE : srcMem.getLong(THETA_LONG); //for SerVer 1,2,3
}
}
| 2,768 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/HeapCompactHashIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
class HeapCompactHashIterator implements HashIterator {
private long[] cache;
private int index;
HeapCompactHashIterator(final long[] cache) {
this.cache = cache;
index = -1;
}
@Override
public long get() {
return cache[index];
}
@Override
public boolean next() {
return ++index < cache.length;
}
}
| 2,769 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/Sketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Family.idToFamily;
import static org.apache.datasketches.common.Util.LONG_MAX_VALUE_AS_DOUBLE;
import static org.apache.datasketches.common.Util.LS;
import static org.apache.datasketches.common.Util.ceilingIntPowerOf2;
import static org.apache.datasketches.common.Util.zeroPad;
import static org.apache.datasketches.theta.PreambleUtil.COMPACT_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.FAMILY_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.ORDERED_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER_BYTE;
import static org.apache.datasketches.thetacommon.HashOperations.count;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.BinomialBoundsN;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* The top-level class for all theta sketches. This class is never constructed directly.
* Use the UpdateSketch.builder() methods to create UpdateSketches.
*
* @author Lee Rhodes
*/
public abstract class Sketch {
static final int DEFAULT_LG_RESIZE_FACTOR = 3; //Unique to Heap
Sketch() {}
//public static factory constructor-type methods
/**
* Heapify takes the sketch image in Memory and instantiates an on-heap Sketch.
*
* <p>The resulting sketch will not retain any link to the source Memory.</p>
*
* <p>For Update Sketches this method checks if the
* <a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update Seed</a></p>
* was used to create the source Memory image.
*
* <p>For Compact Sketches this method assumes that the sketch image was created with the
* correct hash seed, so it is not checked.</p>
*
* @param srcMem an image of a Sketch.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>.
* @return a Sketch on the heap.
*/
public static Sketch heapify(final Memory srcMem) {
final byte familyID = srcMem.getByte(FAMILY_BYTE);
final Family family = idToFamily(familyID);
if (family == Family.COMPACT) {
return CompactSketch.heapify(srcMem);
}
return heapifyUpdateFromMemory(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Heapify takes the sketch image in Memory and instantiates an on-heap Sketch.
*
* <p>The resulting sketch will not retain any link to the source Memory.</p>
*
* <p>For Update and Compact Sketches this method checks if the given expectedSeed was used to
* create the source Memory image. However, SerialVersion 1 sketches cannot be checked.</p>
*
* @param srcMem an image of a Sketch that was created using the given expectedSeed.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>.
* @param expectedSeed the seed used to validate the given Memory image.
* <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 Sketch on the heap.
*/
public static Sketch heapify(final Memory srcMem, final long expectedSeed) {
final byte familyID = srcMem.getByte(FAMILY_BYTE);
final Family family = idToFamily(familyID);
if (family == Family.COMPACT) {
return CompactSketch.heapify(srcMem, expectedSeed);
}
return heapifyUpdateFromMemory(srcMem, expectedSeed);
}
/**
* Wrap takes the sketch image in the given Memory and refers to it directly.
* There is no data copying onto the java heap.
* The wrap operation enables fast read-only merging and access to all the public read-only API.
*
* <p>Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have
* been explicitly stored as direct sketches can be wrapped.
* Wrapping earlier serial version sketches will result in a on-heap CompactSketch
* where all data will be copied to the heap. These early versions were never designed to
* "wrap".</p>
*
* <p>Wrapping any subclass of this class that is empty or contains only a single item will
* result in on-heap equivalent forms of empty and single item sketch respectively.
* This is actually faster and consumes less overall memory.</p>
*
* <p>For Update Sketches this method checks if the
* <a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update Seed</a></p>
* was used to create the source Memory image.
*
* <p>For Compact Sketches this method assumes that the sketch image was created with the
* correct hash seed, so it is not checked.</p>
*
* @param srcMem an image of a Sketch.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>.
* @return a Sketch backed by the given Memory
*/
public static Sketch wrap(final Memory srcMem) {
final int preLongs = srcMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int serVer = srcMem.getByte(SER_VER_BYTE) & 0XFF;
final int familyID = srcMem.getByte(FAMILY_BYTE) & 0XFF;
final Family family = Family.idToFamily(familyID);
if (family == Family.QUICKSELECT) {
if (serVer == 3 && preLongs == 3) {
return DirectQuickSelectSketchR.readOnlyWrap(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
} else {
throw new SketchesArgumentException(
"Corrupted: " + family + " family image: must have SerVer = 3 and preLongs = 3");
}
}
if (family == Family.COMPACT) {
return CompactSketch.wrap(srcMem);
}
throw new SketchesArgumentException(
"Cannot wrap family: " + family + " as a Sketch");
}
/**
* Wrap takes the sketch image in the given Memory and refers to it directly.
* There is no data copying onto the java heap.
* The wrap operation enables fast read-only merging and access to all the public read-only API.
*
* <p>Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have
* been explicitly stored as direct sketches can be wrapped.
* Wrapping earlier serial version sketches will result in a on-heap CompactSketch
* where all data will be copied to the heap. These early versions were never designed to
* "wrap".</p>
*
* <p>Wrapping any subclass of this class that is empty or contains only a single item will
* result in on-heap equivalent forms of empty and single item sketch respectively.
* This is actually faster and consumes less overall memory.</p>
*
* <p>For Update and Compact Sketches this method checks if the given expectedSeed was used to
* create the source Memory image. However, SerialVersion 1 sketches cannot be checked.</p>
*
* @param srcMem an image of a Sketch.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a UpdateSketch backed by the given Memory except as above.
*/
public static Sketch wrap(final Memory srcMem, final long expectedSeed) {
final int preLongs = srcMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int serVer = srcMem.getByte(SER_VER_BYTE) & 0XFF;
final int familyID = srcMem.getByte(FAMILY_BYTE) & 0XFF;
final Family family = Family.idToFamily(familyID);
if (family == Family.QUICKSELECT) {
if (serVer == 3 && preLongs == 3) {
return DirectQuickSelectSketchR.readOnlyWrap(srcMem, expectedSeed);
} else {
throw new SketchesArgumentException(
"Corrupted: " + family + " family image: must have SerVer = 3 and preLongs = 3");
}
}
if (family == Family.COMPACT) {
return CompactSketch.wrap(srcMem, expectedSeed);
}
throw new SketchesArgumentException(
"Cannot wrap family: " + family + " as a Sketch");
}
//Sketch interface
/**
* Converts this sketch to a ordered CompactSketch.
*
* <p>If <i>this.isCompact() == true</i> this method returns <i>this</i>,
* otherwise, this method is equivalent to
* {@link #compact(boolean, WritableMemory) compact(true, null)}.
*
* <p>A CompactSketch is always immutable.</p>
*
* @return this sketch as an ordered CompactSketch.
*/
public CompactSketch compact() {
return (this.isCompact()) ? (CompactSketch)this : compact(true, null);
}
/**
* Convert this sketch to a <i>CompactSketch</i>.
*
* <p>If this sketch is a type of <i>UpdateSketch</i>, the compacting process converts the hash table
* of the <i>UpdateSketch</i> to a simple list of the valid hash values.
* Any hash values of zero or equal-to or greater than theta will be discarded.
* The number of valid values remaining in the <i>CompactSketch</i> depends on a number of factors,
* but may be larger or smaller than <i>Nominal Entries</i> (or <i>k</i>).
* It will never exceed 2<i>k</i>.
* If it is critical to always limit the size to no more than <i>k</i>,
* then <i>rebuild()</i> should be called on the <i>UpdateSketch</i> prior to calling this method.</p>
*
* <p>A <i>CompactSketch</i> is always immutable.</p>
*
* <p>A new <i>CompactSketch</i> object is created:</p>
* <ul><li>if <i>dstMem != null</i></li>
* <li>if <i>dstMem == null</i> and <i>this.hasMemory() == true</i></li>
* <li>if <i>dstMem == null</i> and <i>this</i> has more than 1 item and <i>this.isOrdered() == false</i>
* and <i>dstOrdered == true</i>.</li>
*</ul>
*
* <p>Otherwise, this operation returns <i>this</i>.</p>
*
* @param dstOrdered assumed true if this sketch is empty or has only one value
* <a href="{@docRoot}/resources/dictionary.html#dstOrdered">See Destination Ordered</a>
*
* @param dstMem
* <a href="{@docRoot}/resources/dictionary.html#dstMem">See Destination Memory</a>.
*
* @return this sketch as a <i>CompactSketch</i>.
*/
public abstract CompactSketch compact(final boolean dstOrdered, final WritableMemory dstMem);
/**
* Returns the number of storage bytes required for this Sketch if its current state were
* compacted. It this sketch is already in the compact form this is equivalent to
* calling {@link #getCurrentBytes()}.
* @return number of compact bytes
*/
public abstract int getCompactBytes();
/**
* Gets the number of hash values less than the given theta expressed as a long.
* @param thetaLong the given theta as a long between zero and <i>Long.MAX_VALUE</i>.
* @return the number of hash values less than the given thetaLong.
*/
public int getCountLessThanThetaLong(final long thetaLong) {
return count(getCache(), thetaLong);
}
/**
* Returns the number of storage bytes required for this sketch in its current state.
*
* @return the number of storage bytes required for this sketch
*/
public abstract int getCurrentBytes();
/**
* Gets the unique count estimate.
* @return the sketch's best estimate of the cardinality of the input stream.
*/
public abstract double getEstimate();
/**
* Returns the Family that this sketch belongs to
* @return the Family that this sketch belongs to
*/
public abstract Family getFamily();
/**
* Gets the approximate lower error bound given the specified number of Standard Deviations.
* This will return getEstimate() if isEmpty() is true.
*
* @param numStdDev
* <a href="{@docRoot}/resources/dictionary.html#numStdDev">See Number of Standard Deviations</a>
* @return the lower bound.
*/
public double getLowerBound(final int numStdDev) {
return isEstimationMode()
? lowerBound(getRetainedEntries(true), getThetaLong(), numStdDev, isEmpty())
: getRetainedEntries(true);
}
/**
* Returns the maximum number of storage bytes required for a CompactSketch with the given
* number of actual entries. Note that this assumes the worse case of the sketch in
* estimation mode, which requires storing theta and count.
* @param numberOfEntries the actual number of entries stored with the CompactSketch.
* @return the maximum number of storage bytes required for a CompactSketch with the given number
* of entries.
*/
public static int getMaxCompactSketchBytes(final int numberOfEntries) {
if (numberOfEntries == 0) { return 8; }
if (numberOfEntries == 1) { return 16; }
return (numberOfEntries << 3) + 24;
}
/**
* Returns the maximum number of storage bytes required for an UpdateSketch with the given
* number of nominal entries (power of 2).
* @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 the maximum number of storage bytes required for a UpdateSketch with the given
* nomEntries
*/
public static int getMaxUpdateSketchBytes(final int nomEntries) {
final int nomEnt = ceilingIntPowerOf2(nomEntries);
return (nomEnt << 4) + (Family.QUICKSELECT.getMaxPreLongs() << 3);
}
/**
* Returns the number of valid entries that have been retained by the sketch.
* @return the number of valid retained entries
*/
public int getRetainedEntries() {
return getRetainedEntries(true);
}
/**
* Returns the number of entries that have been retained by the sketch.
* @param valid if true, returns the number of valid entries, which are less than theta and used
* for estimation.
* Otherwise, return the number of all entries, valid or not, that are currently in the internal
* sketch cache.
* @return the number of retained entries
*/
public abstract int getRetainedEntries(boolean valid);
/**
* Returns the serialization version from the given Memory
* @param mem the sketch Memory
* @return the serialization version from the Memory
*/
public static int getSerializationVersion(final Memory mem) {
return mem.getByte(SER_VER_BYTE);
}
/**
* Gets the value of theta as a double with a value between zero and one
* @return the value of theta as a double
*/
public double getTheta() {
return getThetaLong() / LONG_MAX_VALUE_AS_DOUBLE;
}
/**
* Gets the value of theta as a long
* @return the value of theta as a long
*/
public abstract long getThetaLong();
/**
* Gets the approximate upper error bound given the specified number of Standard Deviations.
* This will return getEstimate() if isEmpty() is true.
*
* @param numStdDev
* <a href="{@docRoot}/resources/dictionary.html#numStdDev">See Number of Standard Deviations</a>
* @return the upper bound.
*/
public double getUpperBound(final int numStdDev) {
return isEstimationMode()
? upperBound(getRetainedEntries(true), getThetaLong(), numStdDev, isEmpty())
: getRetainedEntries(true);
}
/**
* Returns true if this sketch's data structure is backed by Memory or WritableMemory.
* @return true if this sketch's data structure is backed by Memory or WritableMemory.
*/
public abstract boolean hasMemory();
/**
* Returns true if this sketch is in compact form.
* @return true if this sketch is in compact form.
*/
public abstract boolean isCompact();
/**
* Returns true if the this sketch's internal data structure is backed by direct (off-heap)
* Memory.
* @return true if the this sketch's internal data structure is backed by direct (off-heap)
* Memory.
*/
public abstract boolean isDirect();
/**
* <a href="{@docRoot}/resources/dictionary.html#empty">See Empty</a>
* @return true if empty.
*/
public abstract boolean isEmpty();
/**
* Returns true if the sketch is Estimation Mode (as opposed to Exact Mode).
* This is true if theta < 1.0 AND isEmpty() is false.
* @return true if the sketch is in estimation mode.
*/
public boolean isEstimationMode() {
return estMode(getThetaLong(), isEmpty());
}
/**
* Returns true if internal cache is ordered
* @return true if internal cache is ordered
*/
public abstract boolean isOrdered();
/**
* Returns true if the backing resource of <i>this</i> is identical with the backing resource
* of <i>that</i>. The capacities must be the same. If <i>this</i> is a region,
* the region offset must also be the same.
* @param that A different non-null object
* @return true if the backing resource of <i>this</i> is the same as the backing resource
* of <i>that</i>.
*/
public boolean isSameResource(final Memory that) {
return false;
}
/**
* Returns a HashIterator that can be used to iterate over the retained hash values of the
* Theta sketch.
* @return a HashIterator that can be used to iterate over the retained hash values of the
* Theta sketch.
*/
public abstract HashIterator iterator();
/**
* Serialize this sketch to a byte array form.
* @return byte array of this sketch
*/
public abstract byte[] toByteArray();
/**
* Returns a human readable summary of the sketch. This method is equivalent to the parameterized
* call:<br>
* <i>Sketch.toString(sketch, true, false, 8, true);</i>
* @return summary
*/
@Override
public String toString() {
return toString(true, false, 8, true);
}
/**
* Gets a human readable listing of contents and summary of the given sketch.
* This can be a very long string. If this sketch is in a "dirty" state there
* may be values in the dataDetail view that are ≥ theta.
*
* @param sketchSummary If true the sketch summary will be output at the end.
* @param dataDetail If true, includes all valid hash values in the sketch.
* @param width The number of columns of hash values. Default is 8.
* @param hexMode If true, hashes will be output in hex.
* @return The result string, which can be very long.
*/
public String toString(final boolean sketchSummary, final boolean dataDetail, final int width,
final boolean hexMode) {
final StringBuilder sb = new StringBuilder();
final long[] cache = getCache();
int nomLongs = 0;
int arrLongs = cache.length;
float p = 0;
int rf = 0;
final boolean updateSketch = this instanceof UpdateSketch;
final long thetaLong = getThetaLong();
final int curCount = this.getRetainedEntries(true);
if (updateSketch) {
final UpdateSketch uis = (UpdateSketch)this;
nomLongs = 1 << uis.getLgNomLongs();
arrLongs = 1 << uis.getLgArrLongs();
p = uis.getP();
rf = uis.getResizeFactor().getValue();
}
if (dataDetail) {
final int w = width > 0 ? width : 8; // default is 8 wide
if (curCount > 0) {
sb.append("### SKETCH DATA DETAIL");
for (int i = 0, j = 0; i < arrLongs; i++ ) {
final long h;
h = cache[i];
if (h <= 0 || h >= thetaLong) {
continue;
}
if (j % w == 0) {
sb.append(LS).append(String.format(" %6d", j + 1));
}
if (hexMode) {
sb.append(" " + zeroPad(Long.toHexString(h), 16) + ",");
}
else {
sb.append(String.format(" %20d,", h));
}
j++ ;
}
sb.append(LS).append("### END DATA DETAIL").append(LS + LS);
}
}
if (sketchSummary) {
final double thetaDbl = thetaLong / LONG_MAX_VALUE_AS_DOUBLE;
final String thetaHex = zeroPad(Long.toHexString(thetaLong), 16);
final String thisSimpleName = this.getClass().getSimpleName();
final int seedHash = Short.toUnsignedInt(getSeedHash());
sb.append(LS);
sb.append("### ").append(thisSimpleName).append(" SUMMARY: ").append(LS);
if (updateSketch) {
sb.append(" Nominal Entries (k) : ").append(nomLongs).append(LS);
}
sb.append(" Estimate : ").append(getEstimate()).append(LS);
sb.append(" Upper Bound, 95% conf : ").append(getUpperBound(2)).append(LS);
sb.append(" Lower Bound, 95% conf : ").append(getLowerBound(2)).append(LS);
if (updateSketch) {
sb.append(" p : ").append(p).append(LS);
}
sb.append(" Theta (double) : ").append(thetaDbl).append(LS);
sb.append(" Theta (long) : ").append(thetaLong).append(LS);
sb.append(" Theta (long) hex : ").append(thetaHex).append(LS);
sb.append(" EstMode? : ").append(isEstimationMode()).append(LS);
sb.append(" Empty? : ").append(isEmpty()).append(LS);
sb.append(" Ordered? : ").append(isOrdered()).append(LS);
if (updateSketch) {
sb.append(" Resize Factor : ").append(rf).append(LS);
sb.append(" Array Size Entries : ").append(arrLongs).append(LS);
}
sb.append(" Retained Entries : ").append(curCount).append(LS);
sb.append(" Seed Hash : ").append(Integer.toHexString(seedHash))
.append(" | ").append(seedHash).append(LS);
sb.append("### END SKETCH SUMMARY").append(LS);
}
return sb.toString();
}
/**
* Returns a human readable string of the preamble of a byte array image of a Theta Sketch.
* @param byteArr the given byte array
* @return a human readable string of the preamble of a byte array image of a Theta Sketch.
*/
public static String toString(final byte[] byteArr) {
return PreambleUtil.preambleToString(byteArr);
}
/**
* Returns a human readable string of the preamble of a Memory image of a Theta Sketch.
* @param mem the given Memory object
* @return a human readable string of the preamble of a Memory image of a Theta Sketch.
*/
public static String toString(final Memory mem) {
return PreambleUtil.preambleToString(mem);
}
//Restricted methods
/**
* Gets the internal cache array. For on-heap sketches this will return a reference to the actual
* cache array. For Memory-based sketches this returns a copy.
* @return the internal cache array.
*/
abstract long[] getCache();
/**
* Gets preamble longs if stored in compact form. If this sketch is already in compact form,
* this is identical to the call {@link #getCurrentPreambleLongs()}.
* @return preamble longs if stored in compact form.
*/
abstract int getCompactPreambleLongs();
/**
* Gets the number of data longs if stored in current state.
* @return the number of data longs if stored in current state.
*/
abstract int getCurrentDataLongs();
/**
* Returns preamble longs if stored in current state.
* @return number of preamble longs if stored.
*/
abstract int getCurrentPreambleLongs();
/**
* Returns the Memory object if it exists, otherwise null.
* @return the Memory object if it exists, otherwise null.
*/
abstract Memory getMemory();
/**
* Gets the 16-bit seed hash
* @return the seed hash
*/
abstract short getSeedHash();
/**
* 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
*/
static final boolean isValidSketchID(final int id) {
return id == Family.ALPHA.getID()
|| id == Family.QUICKSELECT.getID()
|| id == Family.COMPACT.getID();
}
/**
* Checks Ordered and Compact flags for integrity between sketch and Memory
* @param sketch the given sketch
*/
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 double estimate(final long thetaLong, final int curCount) {
return curCount * (LONG_MAX_VALUE_AS_DOUBLE / thetaLong);
}
static final double lowerBound(final int curCount, final long thetaLong, final int numStdDev,
final boolean empty) {
final double theta = thetaLong / LONG_MAX_VALUE_AS_DOUBLE;
return BinomialBoundsN.getLowerBound(curCount, theta, numStdDev, empty);
}
static final double upperBound(final int curCount, final long thetaLong, final int numStdDev,
final boolean empty) {
final double theta = thetaLong / LONG_MAX_VALUE_AS_DOUBLE;
return BinomialBoundsN.getUpperBound(curCount, theta, numStdDev, empty);
}
private static final boolean estMode(final long thetaLong, final boolean empty) {
return thetaLong < Long.MAX_VALUE && !empty;
}
/**
* Instantiates a Heap Update Sketch from Memory. Only SerVer3. SerVer 1 & 2 already handled.
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return a Sketch
*/
private static final Sketch heapifyUpdateFromMemory(final Memory srcMem, final long expectedSeed) {
final long cap = srcMem.getCapacity();
if (cap < 8) {
throw new SketchesArgumentException(
"Corrupted: valid sketch must be at least 8 bytes.");
}
final byte familyID = srcMem.getByte(FAMILY_BYTE);
final Family family = idToFamily(familyID);
if (family == Family.ALPHA) {
final int flags = PreambleUtil.extractFlags(srcMem);
final boolean compactFlag = (flags & COMPACT_FLAG_MASK) != 0;
if (compactFlag) {
throw new SketchesArgumentException(
"Corrupted: ALPHA family image: cannot be compact");
}
return HeapAlphaSketch.heapifyInstance(srcMem, expectedSeed);
}
if (family == Family.QUICKSELECT) {
return HeapQuickSelectSketch.heapifyInstance(srcMem, expectedSeed);
}
throw new SketchesArgumentException(
"Sketch cannot heapify family: " + family + " as a Sketch");
}
}
| 2,770 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/SingleItemSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.datasketches.common.ByteArrayUtil.putLongLE;
import static org.apache.datasketches.hash.MurmurHash3.hash;
import static org.apache.datasketches.theta.PreambleUtil.SINGLEITEM_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractSeedHash;
import static org.apache.datasketches.theta.PreambleUtil.extractSerVer;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* A CompactSketch that holds only one item hash.
*
* @author Lee Rhodes
*/
final class SingleItemSketch extends CompactSketch {
private static final long DEFAULT_SEED_HASH = ThetaUtil.computeSeedHash(ThetaUtil.DEFAULT_UPDATE_SEED) & 0xFFFFL;
// For backward compatibility, a candidate pre0_ long must have:
// Flags (byte 5): Ordered, Compact, NOT Empty, Read Only, LittleEndian = 11010 = 0x1A.
// Flags mask will be 0x1F.
// SingleItem flag may not be set due to a historical bug, so we can't depend on it for now.
// However, if the above flags are correct, preLongs == 1, SerVer >= 3, FamilyID == 3,
// and the hash seed matches, it is virtually guaranteed that we have a SingleItem Sketch.
private static final long PRE0_LO6_SI = 0X00_00_3A_00_00_03_03_01L; //with SI flag
private long pre0_ = 0;
private long hash_ = 0;
//Internal Constructor. All checking & hashing has been done, assumes default seed
private SingleItemSketch(final long hash) {
pre0_ = (DEFAULT_SEED_HASH << 48) | PRE0_LO6_SI;
hash_ = hash;
}
//All checking & hashing has been done, given the relevant seed
SingleItemSketch(final long hash, final long seed) {
final long seedHash = ThetaUtil.computeSeedHash(seed) & 0xFFFFL;
pre0_ = (seedHash << 48) | PRE0_LO6_SI;
hash_ = hash;
}
//All checking & hashing has been done, given the relevant seedHash
SingleItemSketch(final long hash, final short seedHash) {
final long seedH = seedHash & 0xFFFFL;
pre0_ = (seedH << 48) | PRE0_LO6_SI;
hash_ = hash;
}
/**
* Creates a SingleItemSketch on the heap given a SingleItemSketch Memory image and a seedHash.
* Checks the seed hash of the given Memory against the given seedHash.
* @param srcMem the Memory to be heapified.
* @param expectedSeedHash the given seedHash to be checked against the srcMem seedHash
* @return a SingleItemSketch
*/ //does not override Sketch
static SingleItemSketch heapify(final Memory srcMem, final short expectedSeedHash) {
ThetaUtil.checkSeedHashes((short) extractSeedHash(srcMem), expectedSeedHash);
final boolean singleItem = otherCheckForSingleItem(srcMem);
if (singleItem) { return new SingleItemSketch(srcMem.getLong(8), expectedSeedHash); }
throw new SketchesArgumentException("Input Memory is not a SingleItemSketch.");
}
@Override
public CompactSketch compact(final boolean dstOrdered, final WritableMemory dstMem) {
if (dstMem == null) { return this; }
else {
dstMem.putLong(0, pre0_);
dstMem.putLong(8, hash_);
return new DirectCompactSketch(dstMem);
}
}
//Create methods using the default seed
/**
* Create this sketch with a long.
*
* @param datum The given long datum.
* @return a SingleItemSketch
*/
static SingleItemSketch create(final long datum) {
final long[] data = { datum };
return new SingleItemSketch(hash(data, ThetaUtil.DEFAULT_UPDATE_SEED)[0] >>> 1);
}
/**
* Create this sketch with the given double (or float) datum.
* The double will be converted to a long using Double.doubleToLongBits(datum),
* which normalizes all NaN values to a single NaN representation.
* Plus and minus zero will be normalized to plus zero.
* The special floating-point values NaN and +/- Infinity are treated as distinct.
*
* @param datum The given double datum.
* @return a SingleItemSketch
*/
static SingleItemSketch create(final double datum) {
final double d = (datum == 0.0) ? 0.0 : datum; // canonicalize -0.0, 0.0
final long[] data = { Double.doubleToLongBits(d) };// canonicalize all NaN forms
return new SingleItemSketch(hash(data, ThetaUtil.DEFAULT_UPDATE_SEED)[0] >>> 1);
}
/**
* Create this sketch with the given String.
* The string is converted to a byte array using UTF8 encoding.
* If the string is null or empty no create attempt is made and the method returns null.
*
* <p>Note: this will not produce the same 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.
* @return a SingleItemSketch or null
*/
static SingleItemSketch create(final String datum) {
if ((datum == null) || datum.isEmpty()) { return null; }
final byte[] data = datum.getBytes(UTF_8);
return new SingleItemSketch(hash(data, ThetaUtil.DEFAULT_UPDATE_SEED)[0] >>> 1);
}
/**
* Create this sketch with the given byte array.
* If the byte array is null or empty no create attempt is made and the method returns null.
*
* @param data The given byte array.
* @return a SingleItemSketch or null
*/
static SingleItemSketch create(final byte[] data) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, ThetaUtil.DEFAULT_UPDATE_SEED)[0] >>> 1);
}
/**
* Create this sketch with the given char array.
* If the char array 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(String)}
* method but will be a little faster as it avoids the complexity of the UTF8 encoding.</p>
*
* @param data The given char array.
* @return a SingleItemSketch or null
*/
static SingleItemSketch create(final char[] data) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, ThetaUtil.DEFAULT_UPDATE_SEED)[0] >>> 1);
}
/**
* Create this sketch with the given integer array.
* If the integer array is null or empty no create attempt is made and the method returns null.
*
* @param data The given int array.
* @return a SingleItemSketch or null
*/
static SingleItemSketch create(final int[] data) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, ThetaUtil.DEFAULT_UPDATE_SEED)[0] >>> 1);
}
/**
* Create this sketch with the given long array.
* If the long array is null or empty no create attempt is made and the method returns null.
*
* @param data The given long array.
* @return a SingleItemSketch or null
*/
static SingleItemSketch create(final long[] data) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, ThetaUtil.DEFAULT_UPDATE_SEED)[0] >>> 1);
}
//Updates with a user specified seed
/**
* 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
*/
static SingleItemSketch create(final long datum, final long seed) {
final long[] data = { datum };
return new SingleItemSketch(hash(data, seed)[0] >>> 1);
}
/**
* Create this sketch with the given double (or float) datum and a seed.
* The double will be converted to a long using Double.doubleToLongBits(datum),
* which normalizes all NaN values to a single NaN representation.
* Plus and minus zero will be normalized to plus zero.
* The special floating-point values NaN and +/- Infinity are treated as distinct.
*
* @param datum The given double datum.
* @param seed used to hash the given value.
* @return a SingleItemSketch
*/
static SingleItemSketch create(final double datum, final long seed) {
final double d = (datum == 0.0) ? 0.0 : datum; // canonicalize -0.0, 0.0
final long[] data = { Double.doubleToLongBits(d) };// canonicalize all NaN forms
return new SingleItemSketch(hash(data, seed)[0] >>> 1, seed);
}
/**
* 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
*/
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);
}
/**
* 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
*/
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);
}
/**
* Create this sketch with the given char array and a seed.
* If the char array 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(String)}
* method but will be a little faster as it avoids the complexity of the UTF8 encoding.</p>
*
* @param data The given char array.
* @param seed used to hash the given value.
* @return a SingleItemSketch or null
*/
static SingleItemSketch create(final char[] data, final long seed) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, seed)[0] >>> 1, seed);
}
/**
* Create this sketch with the given integer array and a seed.
* If the integer array is null or empty no create attempt is made and the method returns null.
*
* @param data The given int array.
* @param seed used to hash the given value.
* @return a SingleItemSketch or null
*/
static SingleItemSketch create(final int[] data, final long seed) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, seed)[0] >>> 1, seed);
}
/**
* Create this sketch with the given long array (as an item) and a seed.
* If the long array is null or empty no create attempt is made and the method returns null.
*
* @param data The given long array.
* @param seed used to hash the given value.
* @return a SingleItemSketch or null
*/
static SingleItemSketch create(final long[] data, final long seed) {
if ((data == null) || (data.length == 0)) { return null; }
return new SingleItemSketch(hash(data, seed)[0] >>> 1, seed);
}
//Sketch
@Override //much faster
public int getCountLessThanThetaLong(final long thetaLong) {
return (hash_ < thetaLong) ? 1 : 0;
}
@Override
public int getCurrentBytes() {
return 16;
}
@Override
public double getEstimate() {
return 1.0;
}
@Override
public HashIterator iterator() {
return new HeapCompactHashIterator(new long[] { hash_ });
}
@Override
public double getLowerBound(final int numStdDev) {
return 1.0;
}
@Override
public int getRetainedEntries(final boolean valid) {
return 1;
}
@Override
public long getThetaLong() {
return Long.MAX_VALUE;
}
@Override
public double getUpperBound(final int numStdDev) {
return 1.0;
}
@Override
public boolean hasMemory() {
return false;
}
@Override
public boolean isDirect() {
return false;
}
@Override
public boolean isEmpty() {
return false;
}
@Override
public boolean isOrdered() {
return true;
}
@Override
public byte[] toByteArray() {
final byte[] out = new byte[16];
putLongLE(out, 0, pre0_);
putLongLE(out, 8, hash_);
return out;
}
//restricted methods
@Override
long[] getCache() {
return new long[] { hash_ };
}
@Override
int getCompactPreambleLongs() {
return 1;
}
@Override
int getCurrentPreambleLongs() {
return 1;
}
@Override
Memory getMemory() {
return null;
}
@Override
short getSeedHash() {
return (short) (pre0_ >>> 48);
}
static final boolean otherCheckForSingleItem(final Memory mem) {
return otherCheckForSingleItem(extractPreLongs(mem), extractSerVer(mem),
extractFamilyID(mem), extractFlags(mem) );
}
static final boolean otherCheckForSingleItem(final int preLongs, final int serVer,
final int famId, final int flags) {
// Flags byte: SI=X, Ordered=T, Compact=T, Empty=F, ReadOnly=T, BigEndian=F = X11010 = 0x1A.
// Flags mask will be 0x1F.
// SingleItem flag may not be set due to a historical bug, so we can't depend on it for now.
// However, if the above flags are correct, preLongs == 1, SerVer >= 3, FamilyID == 3,
// and the hash seed matches (not done here), it is virtually guaranteed that we have a
// SingleItem Sketch.
final boolean numPreLongs = preLongs == 1;
final boolean numSerVer = serVer >= 3;
final boolean numFamId = famId == Family.COMPACT.getID();
final boolean numFlags = (flags & 0x1F) == 0x1A; //no SI, yet
final boolean singleFlag = (flags & SINGLEITEM_FLAG_MASK) > 0;
return (numPreLongs && numSerVer && numFamId && numFlags) || singleFlag;
}
}
| 2,771 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/HeapAlphaSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static java.lang.Math.sqrt;
import static org.apache.datasketches.common.Util.LONG_MAX_VALUE_AS_DOUBLE;
import static org.apache.datasketches.common.Util.checkBounds;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractLgNomLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractLgResizeFactor;
import static org.apache.datasketches.theta.PreambleUtil.extractP;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncremented;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountNotIncremented;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedDuplicate;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedOverTheta;
import static org.apache.datasketches.thetacommon.HashOperations.STRIDE_MASK;
import java.util.Objects;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.HashOperations;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* This sketch uses the
* <a href="{@docRoot}/resources/dictionary.html#thetaSketch">Theta Sketch Framework</a>
* and the
* <a href="{@docRoot}/resources/dictionary.html#alphaTCF">Alpha TCF</a> algorithm
* with a single cache.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
final class HeapAlphaSketch extends HeapUpdateSketch {
private static final int ALPHA_MIN_LG_NOM_LONGS = 9; //The smallest Log2 k allowed => 512.
private final double alpha_; // computed from lgNomLongs
private final long split1_; // computed from alpha and p
private int lgArrLongs_;
private int hashTableThreshold_; //never serialized
private int curCount_ = 0;
private long thetaLong_;
private boolean empty_ = true;
private long[] cache_;
private boolean dirty_ = false;
private HeapAlphaSketch(final int lgNomLongs, final long seed, final float p,
final ResizeFactor rf, final double alpha, final long split1) {
super(lgNomLongs, seed, p, rf);
alpha_ = alpha;
split1_ = split1;
}
/**
* 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
*/
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) * LONG_MAX_VALUE_AS_DOUBLE);
final HeapAlphaSketch has = new HeapAlphaSketch(lgNomLongs, seed, p, rf, alpha, split1);
final int lgArrLongs = ThetaUtil.startingSubMultiple(lgNomLongs + 1, rf.lg(), ThetaUtil.MIN_LG_ARR_LONGS);
has.lgArrLongs_ = lgArrLongs;
has.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
has.curCount_ = 0;
has.thetaLong_ = (long)(p * LONG_MAX_VALUE_AS_DOUBLE);
has.empty_ = true; //other flags: bigEndian = readOnly = compact = ordered = false;
has.cache_ = new long[1 << lgArrLongs];
return has;
}
/**
* 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>
* It must have a size of at least 24 bytes.
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return instance of this sketch
*/
static HeapAlphaSketch heapifyInstance(final Memory srcMem, final long expectedSeed) {
Objects.requireNonNull(srcMem, "Source Memory must not be null");
checkBounds(0, 24, srcMem.getCapacity());
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, expectedSeed, preambleLongs, lgNomLongs, lgArrLongs);
final float p = extractP(srcMem); //bytes 12-15
final int memlgRF = extractLgResizeFactor(srcMem); //byte 0
ResizeFactor memRF = ResizeFactor.getRF(memlgRF);
final double nomLongs = (1L << lgNomLongs);
final double alpha = nomLongs / (nomLongs + 1.0);
final long split1 = (long) (((p * (alpha + 1.0)) / 2.0) * LONG_MAX_VALUE_AS_DOUBLE);
if (isResizeFactorIncorrect(srcMem, lgNomLongs, lgArrLongs)) {
memRF = ResizeFactor.X2; //X2 always works.
}
final HeapAlphaSketch has = new HeapAlphaSketch(lgNomLongs, expectedSeed, p, memRF, alpha, split1);
has.lgArrLongs_ = lgArrLongs;
has.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
has.curCount_ = extractCurCount(srcMem);
has.thetaLong_ = extractThetaLong(srcMem);
has.empty_ = PreambleUtil.isEmptyFlag(srcMem);
has.cache_ = new long[1 << lgArrLongs];
srcMem.getLongArray(preambleLongs << 3, has.cache_, 0, 1 << lgArrLongs); //read in as hash table
return has;
}
//Sketch
@Override
public Family getFamily() {
return Family.ALPHA;
}
@Override
public HashIterator iterator() {
return new HeapHashIterator(cache_, thetaLong_);
}
@Override
public double getEstimate() {
return (thetaLong_ > split1_)
? Sketch.estimate(thetaLong_, curCount_)
: (1 << lgNomLongs_) * (LONG_MAX_VALUE_AS_DOUBLE / thetaLong_);
}
@Override
public double getLowerBound(final int numStdDev) {
if ((numStdDev < 1) || (numStdDev > 3)) {
throw new SketchesArgumentException("numStdDev can only be the values 1, 2 or 3.");
}
double lb;
if (isEstimationMode()) {
final int validCount = getRetainedEntries(true);
if (validCount > 0) {
final double est = getEstimate();
final double var = getVariance(1 << lgNomLongs_, getP(), alpha_, getTheta(), validCount);
lb = est - (numStdDev * sqrt(var));
lb = max(lb, 0.0);
}
else {
lb = 0.0;
}
}
else {
lb = curCount_;
}
return lb;
}
@Override
public int getRetainedEntries(final boolean valid) {
if (curCount_ > 0) {
if (valid && isDirty()) {
final int curCount = HashOperations.countPart(getCache(), getLgArrLongs(), getThetaLong());
return curCount;
}
}
return curCount_;
}
@Override
public long getThetaLong() {
return thetaLong_;
}
@Override
public double getUpperBound(final int numStdDev) {
if ((numStdDev < 1) || (numStdDev > 3)) {
throw new SketchesArgumentException("numStdDev can only be the values 1, 2 or 3.");
}
if (isEstimationMode()) {
final double var =
getVariance(1 << lgNomLongs_, getP(), alpha_, getTheta(), getRetainedEntries(true));
return getEstimate() + (numStdDev * sqrt(var));
}
return curCount_;
}
@Override
public boolean isEmpty() {
return empty_;
}
/*
* Alpha Sketch Preamble Layout ( same as Theta UpdateSketch )
* <pre>
* Long || Start Byte Adr:
* Adr:
* || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* 0 || Seed Hash | Flags | LgArr | LgNom | FamID | SerVer | lgRF | PreLongs=3 |
*
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||-----------------p-----------------|----------Retained Entries Count---------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||---------------------------------Theta---------------------------------------------|
* </pre>
*/
@Override
public byte[] toByteArray() {
return toByteArray(Family.ALPHA.getMinPreLongs(), (byte) Family.ALPHA.getID());
}
//UpdateSketch
@Override
public UpdateSketch rebuild() {
if (isDirty()) {
rebuildDirty();
}
return this;
}
@Override
public final void reset() {
final int lgArrLongs =
ThetaUtil.startingSubMultiple(lgNomLongs_ + 1, getResizeFactor().lg(), ThetaUtil.MIN_LG_ARR_LONGS);
if (lgArrLongs == lgArrLongs_) {
final int arrLongs = cache_.length;
assert (1 << lgArrLongs_) == arrLongs;
java.util.Arrays.fill(cache_, 0L);
}
else {
cache_ = new long[1 << lgArrLongs];
lgArrLongs_ = lgArrLongs;
}
hashTableThreshold_ = setHashTableThreshold(lgNomLongs_, lgArrLongs_);
empty_ = true;
curCount_ = 0;
thetaLong_ = (long)(getP() * LONG_MAX_VALUE_AS_DOUBLE);
dirty_ = false;
}
//restricted methods
@Override
int getCompactPreambleLongs() {
return CompactOperations.computeCompactPreLongs(empty_, curCount_, thetaLong_);
}
@Override
int getCurrentPreambleLongs() {
return Family.ALPHA.getMinPreLongs();
}
@Override
WritableMemory getMemory() {
return null;
}
@Override
long[] getCache() {
return cache_;
}
@Override
boolean isDirty() {
return dirty_;
}
@Override
boolean isOutOfSpace(final int numEntries) {
return numEntries > hashTableThreshold_;
}
@Override
int getLgArrLongs() {
return lgArrLongs_;
}
@Override
UpdateReturnState hashUpdate(final long hash) {
HashOperations.checkHashCorruption(hash);
empty_ = false;
//The over-theta test
if (HashOperations.continueCondition(thetaLong_, hash)) {
return RejectedOverTheta; //signal that hash was rejected due to theta.
}
//The duplicate/inserted tests
if (dirty_) { //may have dirty values, must be at tgt size
return enhancedHashInsert(cache_, hash);
}
//NOT dirty, the other duplicate or inserted test
if (HashOperations.hashSearchOrInsert(cache_, lgArrLongs_, hash) >= 0) {
return UpdateReturnState.RejectedDuplicate;
}
//insertion occurred, must increment
curCount_++;
final int r = (thetaLong_ > split1_) ? 0 : 1; //are we in sketch mode? (i.e., seen k+1 inserts?)
if (r == 0) { //not yet sketch mode (has not seen k+1 inserts), but could be sampling
if (curCount_ > (1 << lgNomLongs_)) { // > k
//Reached the k+1 insert. Must be at tgt size or larger.
//Transition to Sketch Mode. Happens only once.
//Decrement theta, make dirty, don't bother check size, already not-empty.
thetaLong_ = (long) (thetaLong_ * alpha_);
dirty_ = true; //now may have dirty values
}
else {
//inserts (not entries!) <= k. It may not be at tgt size.
//Check size, don't decrement theta. cnt already ++, empty_ already false;
if (isOutOfSpace(curCount_)) {
resizeClean(); //not dirty, not at tgt size.
}
}
}
else { //r > 0: sketch mode and not dirty (e.g., after a rebuild).
//dec theta, make dirty, cnt already ++, must be at tgt size or larger. check for rebuild
assert (lgArrLongs_ > lgNomLongs_) : "lgArr: " + lgArrLongs_ + ", lgNom: " + lgNomLongs_;
thetaLong_ = (long) (thetaLong_ * alpha_); //decrement theta
dirty_ = true; //now may have dirty values
if (isOutOfSpace(curCount_)) {
rebuildDirty(); // at tgt size and maybe dirty
}
}
return UpdateReturnState.InsertedCountIncremented;
}
/**
* Enhanced Knuth-style Open Addressing, Double Hash insert.
* The insertion process will overwrite an already existing, dirty (over-theta) value if one is
* found in the search.
* If an empty cell is found first, it will be inserted normally.
*
* @param hashTable the hash table to insert into
* @param hash must not be 0. If not a duplicate, it will be inserted into the hash array
* @return <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
final UpdateReturnState enhancedHashInsert(final long[] hashTable, final long hash) {
final int arrayMask = (1 << lgArrLongs_) - 1; // arrayLongs -1
// make odd and independent of curProbe:
final int stride = (2 * (int) ((hash >>> lgArrLongs_) & STRIDE_MASK)) + 1;
int curProbe = (int) (hash & arrayMask);
long curTableHash = hashTable[curProbe];
final int loopIndex = curProbe;
// This is the enhanced part
// Search for duplicate or zero, or opportunity to replace garbage.
while ((curTableHash != hash) && (curTableHash != 0)) {
// curHash is not a duplicate and not zero
if (curTableHash >= thetaLong_) { // curTableHash is garbage, do enhanced insert
final int rememberPos = curProbe; // remember its position.
// Now we must make sure there are no duplicates in this search path,
// so we keep searching
curProbe = (curProbe + stride) & arrayMask; // move forward
curTableHash = hashTable[curProbe];
while ((curTableHash != hash) && (curTableHash != 0)) {
curProbe = (curProbe + stride) & arrayMask;
curTableHash = hashTable[curProbe];
}
// curTableHash is a duplicate or zero
if (curTableHash == hash) {
return RejectedDuplicate; // duplicate, just return
}
assert (curTableHash == 0); // must be zero
// Now that we know there are no duplicates we can
// go back and insert at first garbage value position
hashTable[rememberPos] = hash;
thetaLong_ = (long) (thetaLong_ * alpha_); //decrement theta
dirty_ = true; //the decremented theta could have produced a new dirty value
return InsertedCountNotIncremented;
}
// curTableHash was not a duplicate, not zero, and NOT garbage,
// so we keep searching
assert (curTableHash < thetaLong_);
curProbe = (curProbe + stride) & arrayMask;
curTableHash = hashTable[curProbe];
// ensure no infinite loop
if (curProbe == loopIndex) {
throw new SketchesArgumentException("No empty slot in table!");
}
// end of Enhanced insert
} // end while and search
// curTableHash is a duplicate or zero and NOT garbage
if (curTableHash == hash) {
return RejectedDuplicate; // duplicate, just return
}
// must be zero, so insert and increment
assert (curTableHash == 0);
hashTable[curProbe] = hash;
thetaLong_ = (long) (thetaLong_ * alpha_); //decrement theta
dirty_ = true; //the decremented theta could have produced a new dirty value
if (++curCount_ > hashTableThreshold_) {
rebuildDirty(); //at tgt size and maybe dirty
}
return InsertedCountIncremented;
}
//At tgt size or greater
//Checks for rare lockup condition
// Used by hashUpdate(), rebuild()
private final void rebuildDirty() {
final int curCountBefore = curCount_;
forceRebuildDirtyCache(); //changes curCount_ only
if (curCountBefore == curCount_) {
//clean but unsuccessful at reducing count, must take drastic measures, very rare.
forceResizeCleanCache(1);
}
}
//curCount > hashTableThreshold
//Checks for rare lockup condition
// Used by hashUpdate()
private final void resizeClean() {
//must resize, but are we at tgt size?
final int lgTgtLongs = lgNomLongs_ + 1;
if (lgTgtLongs > lgArrLongs_) {
//not yet at tgt size
final ResizeFactor rf = getResizeFactor();
final int lgDeltaLongs = lgTgtLongs - lgArrLongs_; //must be > 0
final int lgResizeFactor = max(min(rf.lg(), lgDeltaLongs), 1); //rf_.lg() could be 0
forceResizeCleanCache(lgResizeFactor);
}
else {
//at tgt size or larger, no dirty values, must take drastic measures, very rare.
forceResizeCleanCache(1);
}
}
//Force resize. Changes lgArrLongs_ only. Theta doesn't change, count doesn't change.
// Used by rebuildDirty(), resizeClean()
private final void forceResizeCleanCache(final int lgResizeFactor) {
assert (!dirty_); // Should never be dirty before a resize.
lgArrLongs_ += lgResizeFactor; // new tgt size
final long[] tgtArr = new long[1 << lgArrLongs_];
final int newCount = HashOperations.hashArrayInsert(cache_, tgtArr, lgArrLongs_, thetaLong_);
assert (curCount_ == newCount);
curCount_ = newCount;
cache_ = tgtArr;
hashTableThreshold_ = setHashTableThreshold(lgNomLongs_, lgArrLongs_);
}
//Cache stays the same size. Must be dirty. Theta doesn't change, count will change.
// Used by rebuildDirtyAtTgtSize()
private final void forceRebuildDirtyCache() {
final long[] tgtArr = new long[1 << lgArrLongs_];
curCount_ = HashOperations.hashArrayInsert(cache_, tgtArr, lgArrLongs_, thetaLong_);
cache_ = tgtArr;
dirty_ = false;
//hashTableThreshold stays the same
}
// @formatter:off
/**
* Computes an estimate of the error variance based on Historic Inverse Probability (HIP)
* estimators. See Cohen: All-Distances Sketches, Revisited: HIP Estimators for Massive Graph
* Analysis, Nov 2014.
* <pre>
* Table of sketch states and how Upper and Lower Bounds are computed
*
* Theta P Count Empty EstMode Est UB LB Comments
* 1.0 1.0 0 T F 0 0 0 Empty Sketch-mode only sketch
* 1.0 1.0 N F F N N N Degenerate Sketch-mode only sketch
* <1.0 1.0 - F T est HIP HIP Normal Sketch-mode only sketch
* P <1.0 0 T F 0 0 0 Virgin sampling sketch
* P <1.0 N F T est HIP HIP Degenerate sampling sketch
* <P <1.0 N F T est HIP HIP Sampling sketch also in sketch-mode
* </pre>
* @param k alias for nominal entries.
* @param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>.
* @param alpha the value of alpha for this sketch
* @param theta <a href="{@docRoot}/resources/dictionary.html#theta">See <i>theta</i></a>.
* @param count the current valid count.
* @return the variance.
*/
// @formatter:on
private static final double getVariance(final double k, final double p, final double alpha,
final double theta, final int count) {
final double kPlus1 = k + 1.0;
final double y = 1.0 / p;
final double ySq = y * y;
final double ySqMinusY = ySq - y;
final int r = getR(theta, alpha, p);
final double result;
if (r == 0) {
result = count * ySqMinusY;
}
else if (r == 1) {
result = kPlus1 * ySqMinusY; //term1
}
else { //r > 1
final double b = 1.0 / alpha;
final double bSq = b * b;
final double x = p / theta;
final double xSq = x * x;
final double term1 = kPlus1 * ySqMinusY;
final double term2 = y / (1.0 - bSq);
final double term3 = (((y * bSq) - (y * xSq) - b - bSq) + x + (x * b));
result = term1 + (term2 * term3);
}
final double term4 = (1 - theta) / (theta * theta);
return result + term4;
}
/**
* 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.
*/
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;
}
/**
* Returns the cardinality limit given the current size of the hash table array.
*
* @param lgNomLongs <a href="{@docRoot}/resources/dictionary.html#lgNomLongs">See lgNomLongs</a>.
* @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @return the hash table threshold
*/
private static final int setHashTableThreshold(final int lgNomLongs, final int lgArrLongs) {
final double fraction = (lgArrLongs <= lgNomLongs) ? ThetaUtil.RESIZE_THRESHOLD : ThetaUtil.REBUILD_THRESHOLD;
return (int) Math.floor(fraction * (1 << lgArrLongs));
}
static void checkAlphaFamily(final Memory mem, final int preambleLongs, final int lgNomLongs) {
//Check Family
final int familyID = extractFamilyID(mem); //byte 2
final Family family = Family.idToFamily(familyID);
if (family.equals(Family.ALPHA)) {
if (preambleLongs != Family.ALPHA.getMinPreLongs()) {
throw new SketchesArgumentException(
"Possible corruption: Invalid PreambleLongs value for ALPHA: " + preambleLongs);
}
}
else {
throw new SketchesArgumentException(
"Possible corruption: Invalid Family: " + family.toString());
}
//Check lgNomLongs
if (lgNomLongs < ALPHA_MIN_LG_NOM_LONGS) {
throw new SketchesArgumentException(
"Possible corruption: This sketch requires a minimum nominal entries of "
+ (1 << ALPHA_MIN_LG_NOM_LONGS));
}
}
}
| 2,772 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/DirectQuickSelectSketchR.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.CompactOperations.checkIllegalCurCountAndEmpty;
import static org.apache.datasketches.theta.CompactOperations.computeCompactPreLongs;
import static org.apache.datasketches.theta.CompactOperations.correctThetaOnCompact;
import static org.apache.datasketches.theta.PreambleUtil.FAMILY_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.LG_ARR_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.LG_NOM_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.LG_RESIZE_FACTOR_BIT;
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.P_FLOAT;
import static org.apache.datasketches.theta.PreambleUtil.RETAINED_ENTRIES_INT;
import static org.apache.datasketches.theta.PreambleUtil.THETA_LONG;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractLgNomLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.insertThetaLong;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SketchesReadOnlyException;
import org.apache.datasketches.common.SuppressFBWarnings;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* The default Theta Sketch using the QuickSelect algorithm.
* This is the read-only implementation with non-functional methods, which affect the state.
*
* <p>This implementation uses data in a given Memory that is owned and managed by the caller.
* This Memory can be off-heap, which if managed properly will greatly reduce the need for
* the JVM to perform garbage collection.</p>
*
* @author Lee Rhodes
* @author Kevin Lang
*/
class DirectQuickSelectSketchR extends UpdateSketch {
static final double DQS_RESIZE_THRESHOLD = 15.0 / 16.0; //tuned for space
final long seed_; //provided, kept only on heap, never serialized.
int hashTableThreshold_; //computed, kept only on heap, never serialized.
WritableMemory wmem_; //A WritableMemory for child class, but no write methods here
//only called by DirectQuickSelectSketch and below
DirectQuickSelectSketchR(final long seed, final WritableMemory wmem) {
seed_ = seed;
wmem_ = wmem;
}
/**
* Wrap a sketch around the given source Memory containing sketch data that originated from
* this sketch.
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* The given Memory object must be in hash table form and not read only.
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>
* @return instance of this sketch
*/
static DirectQuickSelectSketchR readOnlyWrap(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
UpdateSketch.checkUnionQuickSelectFamily(srcMem, preambleLongs, lgNomLongs);
checkMemIntegrity(srcMem, seed, preambleLongs, lgNomLongs, lgArrLongs);
final DirectQuickSelectSketchR dqssr =
new DirectQuickSelectSketchR(seed, (WritableMemory) srcMem);
dqssr.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
return dqssr;
}
/**
* Fast-wrap a sketch around the given source Memory containing sketch data that originated from
* this sketch. This does NO validity checking of the given Memory.
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* The given Memory object must be in hash table form and not read only.
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>
* @return instance of this sketch
*/
static DirectQuickSelectSketchR fastReadOnlyWrap(final Memory srcMem, final long seed) {
final int lgNomLongs = srcMem.getByte(LG_NOM_LONGS_BYTE) & 0XFF;
final int lgArrLongs = srcMem.getByte(LG_ARR_LONGS_BYTE) & 0XFF;
final DirectQuickSelectSketchR dqss =
new DirectQuickSelectSketchR(seed, (WritableMemory) srcMem);
dqss.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
return dqss;
}
//Sketch
@Override
public int getCurrentBytes() {
//not compact
final byte lgArrLongs = wmem_.getByte(LG_ARR_LONGS_BYTE);
final int preLongs = wmem_.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int lengthBytes = (preLongs + (1 << lgArrLongs)) << 3;
return lengthBytes;
}
@Override
public double getEstimate() {
final int curCount = extractCurCount(wmem_);
final long thetaLong = extractThetaLong(wmem_);
return Sketch.estimate(thetaLong, curCount);
}
@Override
public Family getFamily() {
final int familyID = wmem_.getByte(FAMILY_BYTE) & 0XFF;
return Family.idToFamily(familyID);
}
@Override
public int getRetainedEntries(final boolean valid) { //always valid
return wmem_.getInt(RETAINED_ENTRIES_INT);
}
@Override
public long getThetaLong() {
return isEmpty() ? Long.MAX_VALUE : wmem_.getLong(THETA_LONG);
}
@Override
public boolean hasMemory() {
return true;
}
@Override
public boolean isDirect() {
return wmem_.isDirect();
}
@Override
public boolean isEmpty() {
return PreambleUtil.isEmptyFlag(wmem_);
}
@Override
public boolean isSameResource(final Memory that) {
return wmem_.isSameResource(that);
}
@Override
public HashIterator iterator() {
return new MemoryHashIterator(wmem_, 1 << getLgArrLongs(), getThetaLong());
}
@Override
public byte[] toByteArray() { //MY_FAMILY is stored in wmem_
checkIllegalCurCountAndEmpty(isEmpty(), extractCurCount(wmem_));
final int lengthBytes = getCurrentBytes();
final byte[] byteArray = new byte[lengthBytes];
final WritableMemory mem = WritableMemory.writableWrap(byteArray);
wmem_.copyTo(0, mem, 0, lengthBytes);
final long thetaLong =
correctThetaOnCompact(isEmpty(), extractCurCount(wmem_), extractThetaLong(wmem_));
insertThetaLong(wmem_, thetaLong);
return byteArray;
}
//UpdateSketch
@Override
public final int getLgNomLongs() {
return PreambleUtil.extractLgNomLongs(wmem_);
}
@Override
float getP() {
return wmem_.getFloat(P_FLOAT);
}
@Override
public ResizeFactor getResizeFactor() {
return ResizeFactor.getRF(getLgRF());
}
@Override
long getSeed() {
return seed_;
}
@Override
public UpdateSketch rebuild() {
throw new SketchesReadOnlyException();
}
@Override
public void reset() {
throw new SketchesReadOnlyException();
}
//restricted methods
@Override
long[] getCache() {
final long lgArrLongs = wmem_.getByte(LG_ARR_LONGS_BYTE) & 0XFF;
final int preambleLongs = wmem_.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final long[] cacheArr = new long[1 << lgArrLongs];
final WritableMemory mem = WritableMemory.writableWrap(cacheArr);
wmem_.copyTo(preambleLongs << 3, mem, 0, 8 << lgArrLongs);
return cacheArr;
}
@Override
int getCompactPreambleLongs() {
return computeCompactPreLongs(isEmpty(), getRetainedEntries(true), getThetaLong());
}
@Override
int getCurrentPreambleLongs() {
return PreambleUtil.extractPreLongs(wmem_);
}
@Override
WritableMemory getMemory() {
return wmem_;
}
@Override
short getSeedHash() {
return (short) PreambleUtil.extractSeedHash(wmem_);
}
@Override
boolean isDirty() {
return false; //Always false for QuickSelectSketch
}
@Override
boolean isOutOfSpace(final int numEntries) {
return numEntries > hashTableThreshold_;
}
@Override
int getLgArrLongs() {
return wmem_.getByte(LG_ARR_LONGS_BYTE) & 0XFF;
}
int getLgRF() { //only Direct needs this
return (wmem_.getByte(PREAMBLE_LONGS_BYTE) >>> LG_RESIZE_FACTOR_BIT) & 0X3;
}
@Override
UpdateReturnState hashUpdate(final long hash) {
throw new SketchesReadOnlyException();
}
/**
* Returns the cardinality limit given the current size of the hash table array.
*
* @param lgNomLongs <a href="{@docRoot}/resources/dictionary.html#lgNomLongs">See lgNomLongs</a>.
* @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @return the hash table threshold
*/
@SuppressFBWarnings(value = "DB_DUPLICATE_BRANCHES", justification = "False Positive, see the code comments")
static final int setHashTableThreshold(final int lgNomLongs, final int lgArrLongs) {
//SpotBugs may complain (DB_DUPLICATE_BRANCHES) if DQS_RESIZE_THRESHOLD == REBUILD_THRESHOLD,
//but this allows us to tune these constants for different sketches.
final double fraction = (lgArrLongs <= lgNomLongs) ? DQS_RESIZE_THRESHOLD : ThetaUtil.REBUILD_THRESHOLD;
return (int) Math.floor(fraction * (1 << lgArrLongs));
}
}
| 2,773 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/UpdateSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static java.nio.charset.StandardCharsets.UTF_8;
import static org.apache.datasketches.common.Util.LONG_MAX_VALUE_AS_DOUBLE;
import static org.apache.datasketches.common.Util.checkBounds;
import static org.apache.datasketches.hash.MurmurHash3.hash;
import static org.apache.datasketches.theta.CompactOperations.componentsToCompact;
import static org.apache.datasketches.theta.PreambleUtil.BIG_ENDIAN_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.COMPACT_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.FAMILY_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.ORDERED_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.READ_ONLY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.checkMemorySeedHash;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractLgResizeFactor;
import static org.apache.datasketches.theta.PreambleUtil.extractP;
import static org.apache.datasketches.theta.PreambleUtil.extractSerVer;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.getMemBytes;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedNullOrEmpty;
import java.util.Objects;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* The parent class for the Update Sketch families, such as QuickSelect and Alpha.
* The primary task of an Update Sketch is to consider datums presented via the update() methods
* for inclusion in its internal cache. This is the sketch building process.
*
* @author Lee Rhodes
*/
public abstract class UpdateSketch extends Sketch {
UpdateSketch() {}
/**
* Wrap takes the sketch image in Memory and refers to it directly. There is no data copying onto
* the java heap. Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have
* been explicitly stored as direct objects can be wrapped. This method assumes the
* {@link org.apache.datasketches.thetacommon.ThetaUtil#DEFAULT_UPDATE_SEED}.
* <a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update Seed</a>.
* @param srcMem an image of a Sketch where the image seed hash matches the default seed hash.
* It must have a size of at least 24 bytes.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a Sketch backed by the given Memory
*/
public static UpdateSketch wrap(final WritableMemory srcMem) {
return wrap(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Wrap takes the sketch image in Memory and refers to it directly. There is no data copying onto
* the java heap. Only "Direct" Serialization Version 3 (i.e, OpenSource) sketches that have
* been explicitly stored as direct objects can be wrapped.
* An attempt to "wrap" earlier version sketches will result in a "heapified", normal
* Java Heap version of the sketch where all data will be copied to the heap.
* @param srcMem an image of a Sketch where the image seed hash matches the given seed hash.
* It must have a size of at least 24 bytes.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param expectedSeed the seed used to validate the given Memory image.
* <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 UpdateSketch backed by the given Memory
*/
public static UpdateSketch wrap(final WritableMemory srcMem, final long expectedSeed) {
Objects.requireNonNull(srcMem, "Source Memory must not be null");
checkBounds(0, 24, srcMem.getCapacity()); //need min 24 bytes
final int preLongs = srcMem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
final int serVer = srcMem.getByte(SER_VER_BYTE) & 0XFF;
final int familyID = srcMem.getByte(FAMILY_BYTE) & 0XFF;
final Family family = Family.idToFamily(familyID);
if (family != Family.QUICKSELECT) {
throw new SketchesArgumentException(
"A " + family + " sketch cannot be wrapped as an UpdateSketch.");
}
if ((serVer == 3) && (preLongs == 3)) {
return DirectQuickSelectSketch.writableWrap(srcMem, expectedSeed);
} else {
throw new SketchesArgumentException(
"Corrupted: An UpdateSketch image must have SerVer = 3 and preLongs = 3");
}
}
/**
* Instantiates an on-heap UpdateSketch from Memory. This method assumes the
* {@link org.apache.datasketches.thetacommon.ThetaUtil#DEFAULT_UPDATE_SEED}.
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* It must have a size of at least 24 bytes.
* @return an UpdateSketch
*/
public static UpdateSketch heapify(final Memory srcMem) {
return heapify(srcMem, ThetaUtil.DEFAULT_UPDATE_SEED);
}
/**
* Instantiates an on-heap UpdateSketch from Memory.
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* It must have a size of at least 24 bytes.
* @param expectedSeed the seed used to validate the given Memory image.
* <a href="{@docRoot}/resources/dictionary.html#seed">See Update Hash Seed</a>.
* @return an UpdateSketch
*/
public static UpdateSketch heapify(final Memory srcMem, final long expectedSeed) {
Objects.requireNonNull(srcMem, "Source Memory must not be null");
checkBounds(0, 24, srcMem.getCapacity()); //need min 24 bytes
final Family family = Family.idToFamily(srcMem.getByte(FAMILY_BYTE));
if (family.equals(Family.ALPHA)) {
return HeapAlphaSketch.heapifyInstance(srcMem, expectedSeed);
}
return HeapQuickSelectSketch.heapifyInstance(srcMem, expectedSeed);
}
//Sketch interface
@Override
public CompactSketch compact(final boolean dstOrdered, final WritableMemory dstMem) {
return componentsToCompact(getThetaLong(), getRetainedEntries(true), getSeedHash(), isEmpty(),
false, false, dstOrdered, dstMem, getCache());
}
@Override
public int getCompactBytes() {
final int preLongs = getCompactPreambleLongs();
final int dataLongs = getRetainedEntries(true);
return (preLongs + dataLongs) << 3;
}
@Override
int getCurrentDataLongs() {
return 1 << getLgArrLongs();
}
@Override
public boolean isCompact() {
return false;
}
@Override
public boolean isOrdered() {
return false;
}
//UpdateSketch interface
/**
* Returns a new builder
* @return a new builder
*/
public static final UpdateSketchBuilder builder() {
return new UpdateSketchBuilder();
}
/**
* Returns the configured ResizeFactor
* @return the configured ResizeFactor
*/
public abstract ResizeFactor getResizeFactor();
/**
* Gets the configured sampling probability, <i>p</i>.
* <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>
* @return the sampling probability, <i>p</i>
*/
abstract float getP();
/**
* Gets the configured seed
* @return the configured seed
*/
abstract long getSeed();
/**
* Resets this sketch back to a virgin empty state.
*/
public abstract void reset();
/**
* Rebuilds the hash table to remove dirty values or to reduce the size
* to nominal entries.
* @return this sketch
*/
public abstract UpdateSketch rebuild();
/**
* Present this sketch with a long.
*
* @param datum The given long datum.
* @return
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
public UpdateReturnState update(final long datum) {
final long[] data = { datum };
return hashUpdate(hash(data, getSeed())[0] >>> 1);
}
/**
* Present this sketch with the given double (or float) datum.
* The double will be converted to a long using Double.doubleToLongBits(datum),
* which normalizes all NaN values to a single NaN representation.
* Plus and minus zero will be normalized to plus zero.
* The special floating-point values NaN and +/- Infinity are treated as distinct.
*
* @param datum The given double datum.
* @return
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
public UpdateReturnState update(final double datum) {
final double d = (datum == 0.0) ? 0.0 : datum; // canonicalize -0.0, 0.0
final long[] data = { Double.doubleToLongBits(d) };// canonicalize all NaN & +/- infinity forms
return hashUpdate(hash(data, getSeed())[0] >>> 1);
}
/**
* Present this sketch with the given String.
* The string is converted to a byte array using UTF8 encoding.
* If the string is null or empty no update attempt is made and the method returns.
*
* <p>Note: this will not produce the same output hash values as the {@link #update(char[])}
* method and will generally be a little slower depending on the complexity of the UTF8 encoding.
* </p>
*
* @param datum The given String.
* @return
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
public UpdateReturnState update(final String datum) {
if ((datum == null) || datum.isEmpty()) {
return RejectedNullOrEmpty;
}
final byte[] data = datum.getBytes(UTF_8);
return hashUpdate(hash(data, getSeed())[0] >>> 1);
}
/**
* Present this sketch with the given byte array.
* If the byte array is null or empty no update attempt is made and the method returns.
*
* @param data The given byte array.
* @return
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
public UpdateReturnState update(final byte[] data) {
if ((data == null) || (data.length == 0)) {
return RejectedNullOrEmpty;
}
return hashUpdate(hash(data, getSeed())[0] >>> 1);
}
/**
* Present this sketch with the given char array.
* If the char array is null or empty no update attempt is made and the method returns.
*
* <p>Note: this will not produce the same output hash values as the {@link #update(String)}
* method but will be a little faster as it avoids the complexity of the UTF8 encoding.</p>
*
* @param data The given char array.
* @return
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
public UpdateReturnState update(final char[] data) {
if ((data == null) || (data.length == 0)) {
return RejectedNullOrEmpty;
}
return hashUpdate(hash(data, getSeed())[0] >>> 1);
}
/**
* Present this sketch with the given integer array.
* If the integer array is null or empty no update attempt is made and the method returns.
*
* @param data The given int array.
* @return
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
public UpdateReturnState update(final int[] data) {
if ((data == null) || (data.length == 0)) {
return RejectedNullOrEmpty;
}
return hashUpdate(hash(data, getSeed())[0] >>> 1);
}
/**
* Present this sketch with the given long array.
* If the long array is null or empty no update attempt is made and the method returns.
*
* @param data The given long array.
* @return
* <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
public UpdateReturnState update(final long[] data) {
if ((data == null) || (data.length == 0)) {
return RejectedNullOrEmpty;
}
return hashUpdate(hash(data, getSeed())[0] >>> 1);
}
//restricted methods
/**
* All potential updates converge here.
* <p>Don't ever call this unless you really know what you are doing!</p>
*
* @param hash the given input hash value. A hash of zero or Long.MAX_VALUE is ignored.
* A negative hash value will throw an exception.
* @return <a href="{@docRoot}/resources/dictionary.html#updateReturnState">See Update Return State</a>
*/
abstract UpdateReturnState hashUpdate(long hash);
/**
* Gets the Log base 2 of the current size of the internal cache
* @return the Log base 2 of the current size of the internal cache
*/
abstract int getLgArrLongs();
/**
* Gets the Log base 2 of the configured nominal entries
* @return the Log base 2 of the configured nominal entries
*/
public abstract int getLgNomLongs();
/**
* Returns true if the internal cache contains "dirty" values that are greater than or equal
* to thetaLong.
* @return true if the internal cache is dirty.
*/
abstract boolean isDirty();
/**
* Returns true if numEntries (curCount) is greater than the hashTableThreshold.
* @param numEntries the given number of entries (or current count).
* @return true if numEntries (curCount) is greater than the hashTableThreshold.
*/
abstract boolean isOutOfSpace(int numEntries);
static void checkUnionQuickSelectFamily(final Memory mem, final int preambleLongs,
final int lgNomLongs) {
//Check Family
final int familyID = extractFamilyID(mem); //byte 2
final Family family = Family.idToFamily(familyID);
if (family.equals(Family.UNION)) {
if (preambleLongs != Family.UNION.getMinPreLongs()) {
throw new SketchesArgumentException(
"Possible corruption: Invalid PreambleLongs value for UNION: " + preambleLongs);
}
}
else if (family.equals(Family.QUICKSELECT)) {
if (preambleLongs != Family.QUICKSELECT.getMinPreLongs()) {
throw new SketchesArgumentException(
"Possible corruption: Invalid PreambleLongs value for QUICKSELECT: " + preambleLongs);
}
} else {
throw new SketchesArgumentException(
"Possible corruption: Invalid Family: " + family.toString());
}
//Check lgNomLongs
if (lgNomLongs < ThetaUtil.MIN_LG_NOM_LONGS) {
throw new SketchesArgumentException(
"Possible corruption: Current Memory lgNomLongs < min required size: "
+ lgNomLongs + " < " + ThetaUtil.MIN_LG_NOM_LONGS);
}
}
static void checkMemIntegrity(final Memory srcMem, final long expectedSeed, final int preambleLongs,
final int lgNomLongs, final int lgArrLongs) {
//Check SerVer
final int serVer = extractSerVer(srcMem); //byte 1
if (serVer != SER_VER) {
throw new SketchesArgumentException(
"Possible corruption: Invalid Serialization Version: " + serVer);
}
//Check flags
final int flags = extractFlags(srcMem); //byte 5
final int flagsMask =
ORDERED_FLAG_MASK | COMPACT_FLAG_MASK | READ_ONLY_FLAG_MASK | BIG_ENDIAN_FLAG_MASK;
if ((flags & flagsMask) > 0) {
throw new SketchesArgumentException(
"Possible corruption: Input srcMem cannot be: big-endian, compact, ordered, or read-only");
}
//Check seed hashes
final short seedHash = checkMemorySeedHash(srcMem, expectedSeed); //byte 6,7
ThetaUtil.checkSeedHashes(seedHash, ThetaUtil.computeSeedHash(expectedSeed));
//Check mem capacity, lgArrLongs
final long curCapBytes = srcMem.getCapacity();
final int minReqBytes = getMemBytes(lgArrLongs, preambleLongs);
if (curCapBytes < minReqBytes) {
throw new SketchesArgumentException(
"Possible corruption: Current Memory size < min required size: "
+ curCapBytes + " < " + minReqBytes);
}
//check Theta, p
final float p = extractP(srcMem); //bytes 12-15
final long thetaLong = extractThetaLong(srcMem); //bytes 16-23
final double theta = thetaLong / LONG_MAX_VALUE_AS_DOUBLE;
//if (lgArrLongs <= lgNomLongs) the sketch is still resizing, thus theta cannot be < p.
if ((lgArrLongs <= lgNomLongs) && (theta < p) ) {
throw new SketchesArgumentException(
"Possible corruption: Theta cannot be < p and lgArrLongs <= lgNomLongs. "
+ lgArrLongs + " <= " + lgNomLongs + ", Theta: " + theta + ", p: " + p);
}
}
/**
* This checks to see if the memory RF factor was set correctly as early versions may not
* have set it.
* @param srcMem the source memory
* @param lgNomLongs the current lgNomLongs
* @param lgArrLongs the current lgArrLongs
* @return true if the the memory RF factor is incorrect and the caller can either
* correct it or throw an error.
*/
static boolean isResizeFactorIncorrect(final Memory srcMem, final int lgNomLongs,
final int lgArrLongs) {
final int lgT = lgNomLongs + 1;
final int lgA = lgArrLongs;
final int lgR = extractLgResizeFactor(srcMem);
if (lgR == 0) { return lgA != lgT; }
return !(((lgT - lgA) % lgR) == 0);
}
}
| 2,774 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/DirectCompactSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.CompactOperations.checkIllegalCurCountAndEmpty;
import static org.apache.datasketches.theta.CompactOperations.memoryToCompact;
import static org.apache.datasketches.theta.PreambleUtil.ORDERED_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractSeedHash;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.SingleItemSketch.otherCheckForSingleItem;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* An off-heap (Direct), compact, read-only sketch. The internal hash array can be either ordered
* or unordered.
*
* <p>This sketch can only be associated with a Serialization Version 3 format binary image.</p>
*
* <p>This implementation uses data in a given Memory that is owned and managed by the caller.
* This Memory can be off-heap, which if managed properly will greatly reduce the need for
* the JVM to perform garbage collection.</p>
*
* @author Lee Rhodes
*/
class DirectCompactSketch extends CompactSketch {
final Memory mem_;
/**
* Construct this sketch with the given memory.
* @param mem Read-only Memory object with the order bit properly set.
*/
DirectCompactSketch(final Memory mem) {
mem_ = mem;
}
/**
* Wraps the given Memory, which must be a SerVer 3, ordered, CompactSketch image.
* Must check the validity of the Memory before calling. The order bit must be set properly.
* @param srcMem <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param seedHash The update seedHash.
* <a href="{@docRoot}/resources/dictionary.html#seedHash">See Seed Hash</a>.
* @return this sketch
*/
static DirectCompactSketch wrapInstance(final Memory srcMem, final short seedHash) {
ThetaUtil.checkSeedHashes((short) extractSeedHash(srcMem), seedHash);
return new DirectCompactSketch(srcMem);
}
//Sketch Overrides
@Override
public CompactSketch compact(final boolean dstOrdered, final WritableMemory dstMem) {
return memoryToCompact(mem_, dstOrdered, dstMem);
}
@Override
public int getCurrentBytes() {
if (otherCheckForSingleItem(mem_)) { return 16; }
final int preLongs = extractPreLongs(mem_);
final int curCount = (preLongs == 1) ? 0 : extractCurCount(mem_);
return (preLongs + curCount) << 3;
}
@Override
public double getEstimate() {
if (otherCheckForSingleItem(mem_)) { return 1; }
final int preLongs = extractPreLongs(mem_);
final int curCount = (preLongs == 1) ? 0 : extractCurCount(mem_);
final long thetaLong = (preLongs > 2) ? extractThetaLong(mem_) : Long.MAX_VALUE;
return Sketch.estimate(thetaLong, curCount);
}
@Override
public int getRetainedEntries(final boolean valid) { //compact is always valid
if (otherCheckForSingleItem(mem_)) { return 1; }
final int preLongs = extractPreLongs(mem_);
final int curCount = (preLongs == 1) ? 0 : extractCurCount(mem_);
return curCount;
}
@Override
public long getThetaLong() {
final int preLongs = extractPreLongs(mem_);
return (preLongs > 2) ? extractThetaLong(mem_) : Long.MAX_VALUE;
}
@Override
public boolean hasMemory() {
return true;
}
@Override
public boolean isDirect() {
return mem_.isDirect();
}
@Override
public boolean isEmpty() {
final boolean emptyFlag = PreambleUtil.isEmptyFlag(mem_);
final long thetaLong = getThetaLong();
final int curCount = getRetainedEntries(true);
return emptyFlag || ((curCount == 0) && (thetaLong == Long.MAX_VALUE));
}
@Override
public boolean isOrdered() {
return (extractFlags(mem_) & ORDERED_FLAG_MASK) > 0;
}
@Override
public boolean isSameResource(final Memory that) {
return mem_.isSameResource(that);
}
@Override
public HashIterator iterator() {
return new MemoryHashIterator(mem_, getRetainedEntries(true), getThetaLong());
}
@Override
public byte[] toByteArray() {
final int curCount = getRetainedEntries(true);
checkIllegalCurCountAndEmpty(isEmpty(), curCount);
final int preLongs = extractPreLongs(mem_);
final int outBytes = (curCount + preLongs) << 3;
final byte[] byteArrOut = new byte[outBytes];
mem_.getByteArray(0, byteArrOut, 0, outBytes);
return byteArrOut;
}
//restricted methods
@Override
long[] getCache() {
if (otherCheckForSingleItem(mem_)) { return new long[] { mem_.getLong(8) }; }
final int preLongs = extractPreLongs(mem_);
final int curCount = (preLongs == 1) ? 0 : extractCurCount(mem_);
if (curCount > 0) {
final long[] cache = new long[curCount];
mem_.getLongArray(preLongs << 3, cache, 0, curCount);
return cache;
}
return new long[0];
}
@Override
int getCompactPreambleLongs() {
return extractPreLongs(mem_);
}
@Override
int getCurrentPreambleLongs() {
return extractPreLongs(mem_);
}
@Override
Memory getMemory() {
return mem_;
}
@Override
short getSeedHash() {
return (short) extractSeedHash(mem_);
}
}
| 2,775 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/ConcurrentBackgroundThetaPropagation.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import java.util.concurrent.atomic.AtomicBoolean;
/**
* Background propagation thread. Propagates a given sketch or a hash value from local threads
* buffers into the shared sketch which stores the most up-to-date estimation of number of unique
* items. This propagation is done at the background by dedicated threads, which allows
* application threads to continue updating their local buffer.
*
* @author eshcar
*/
class ConcurrentBackgroundThetaPropagation implements Runnable {
// Shared sketch to absorb the data
private final ConcurrentSharedThetaSketch sharedThetaSketch;
// Propagation flag of local buffer that is being processed.
// It is the synchronization primitive to coordinate the work of the propagation with the
// local buffer. Updated when the propagation completes.
private final AtomicBoolean localPropagationInProgress;
// Sketch to be propagated to shared sketch. Can be null if only a single hash is propagated
private final Sketch sketchIn;
// Hash of the datum to be propagated to shared sketch. Can be ConcurrentSharedThetaSketch.NOT_SINGLE_HASH
// if the data is propagated through a sketch.
private final long singleHash;
// The propagation epoch. The data can be propagated only within the context of this epoch.
// The data should not be propagated if this epoch is not equal to the
// shared sketch epoch.
private final long epoch;
ConcurrentBackgroundThetaPropagation(final ConcurrentSharedThetaSketch sharedThetaSketch,
final AtomicBoolean localPropagationInProgress, final Sketch sketchIn, final long singleHash,
final long epoch) {
this.sharedThetaSketch = sharedThetaSketch;
this.localPropagationInProgress = localPropagationInProgress;
this.sketchIn = sketchIn;
this.singleHash = singleHash;
this.epoch = epoch;
}
/**
* Propagation protocol:
* 1) validate propagation is executed at the context of the right epoch, otherwise abort
* 2) handle propagation: either of a single hash or of a sketch
* 3) complete propagation: ping local buffer
*/
@Override
public void run() {
// 1) validate propagation is executed at the context of the right epoch, otherwise abort
if (!sharedThetaSketch.validateEpoch(epoch)) {
// invalid epoch - should not propagate
sharedThetaSketch.endPropagation(null, false);
return;
}
// 2) handle propagation: either of a single hash or of a sketch
if (singleHash != ConcurrentSharedThetaSketch.NOT_SINGLE_HASH) {
sharedThetaSketch.propagate(singleHash);
} else if (sketchIn != null) {
final long volTheta = sharedThetaSketch.getVolatileTheta();
assert volTheta <= sketchIn.getThetaLong() :
"volTheta = " + volTheta + ", bufTheta = " + sketchIn.getThetaLong();
// propagate values from input sketch one by one
final long[] cacheIn = sketchIn.getCache();
if (sketchIn.isOrdered()) { //Ordered compact, Use early stop
for (final long hashIn : cacheIn) {
if (hashIn >= volTheta) {
break; //early stop
}
sharedThetaSketch.propagate(hashIn);
}
} else { //not ordered, also may have zeros (gaps) in the array.
for (final long hashIn : cacheIn) {
if (hashIn > 0) {
sharedThetaSketch.propagate(hashIn);
}
}
}
}
// 3) complete propagation: ping local buffer
sharedThetaSketch.endPropagation(localPropagationInProgress, false);
}
}
| 2,776 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/HashIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
/**
* This is used to iterate over the retained hash values of the Theta sketch.
* @author Lee Rhodes
*/
public interface HashIterator {
/**
* Gets the hash value
* @return the hash value
*/
long get();
/**
* Returns true at the next hash value in sequence.
* If false, the iteration is done.
* @return true at the next hash value in sequence.
*/
boolean next();
}
| 2,777 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/ConcurrentDirectQuickSelectSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.PreambleUtil.THETA_LONG;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SuppressFBWarnings;
import org.apache.datasketches.memory.WritableMemory;
/**
* A concurrent shared sketch that is based on DirectQuickSelectSketch.
* It reflects all data processed by a single or multiple update threads, and can serve queries at
* any time.
* Background propagation threads are used to propagate data from thread local buffers into this
* sketch which stores the most up-to-date estimation of number of unique items.
*
* @author eshcar
* @author Lee Rhodes
*/
final class ConcurrentDirectQuickSelectSketch extends DirectQuickSelectSketch
implements ConcurrentSharedThetaSketch {
// The propagation thread
private ExecutorService executorService_;
// A flag to coordinate between several eager propagation threads
private final AtomicBoolean sharedPropagationInProgress_;
// Theta value of concurrent sketch
private volatile long volatileThetaLong_;
// A snapshot of the estimated number of unique entries
private volatile double volatileEstimate_;
// Num of retained entries in which the sketch toggles from sync (exact) mode to async
// propagation mode
private final long exactLimit_;
// An epoch defines an interval between two resets. A propagation invoked at epoch i cannot
// affect the sketch at epoch j > i.
private volatile long epoch_;
/**
* Construct a new sketch instance and initialize the given Memory as its backing store.
*
* @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 maxConcurrencyError the max error value including error induced by concurrency.
* @param dstMem the given Memory object destination. It cannot be null.
*/
ConcurrentDirectQuickSelectSketch(final int lgNomLongs, final long seed,
final double maxConcurrencyError, final WritableMemory dstMem) {
super(lgNomLongs, seed, 1.0F, //p
ResizeFactor.X1, //rf,
null, dstMem, false); //unionGadget
volatileThetaLong_ = Long.MAX_VALUE;
volatileEstimate_ = 0;
exactLimit_ = ConcurrentSharedThetaSketch.computeExactLimit(1L << getLgNomLongs(),
maxConcurrencyError);
sharedPropagationInProgress_ = new AtomicBoolean(false);
epoch_ = 0;
initBgPropagationService();
}
ConcurrentDirectQuickSelectSketch(final UpdateSketch sketch, final long seed,
final double maxConcurrencyError, final WritableMemory dstMem) {
super(sketch.getLgNomLongs(), seed, 1.0F, //p
ResizeFactor.X1, //rf,
null, //mem Req Svr
dstMem,
false); //unionGadget
exactLimit_ = ConcurrentSharedThetaSketch.computeExactLimit(1L << getLgNomLongs(),
maxConcurrencyError);
sharedPropagationInProgress_ = new AtomicBoolean(false);
epoch_ = 0;
initBgPropagationService();
for (final long hashIn : sketch.getCache()) {
propagate(hashIn);
}
wmem_.putLong(THETA_LONG, sketch.getThetaLong());
updateVolatileTheta();
updateEstimationSnapshot();
}
//Sketch overrides
@Override
public double getEstimate() {
return volatileEstimate_;
}
@Override
public boolean isEstimationMode() {
return (getRetainedEntries(false) > exactLimit_) || super.isEstimationMode();
}
@Override
public byte[] toByteArray() {
while (!sharedPropagationInProgress_.compareAndSet(false, true)) { } //busy wait till free
final byte[] res = super.toByteArray();
sharedPropagationInProgress_.set(false);
return res;
}
//UpdateSketch overrides
@Override
public UpdateSketch rebuild() {
super.rebuild();
updateEstimationSnapshot();
return this;
}
/**
* {@inheritDoc}
* Takes care of mutual exclusion with propagation thread.
*/
@Override
public void reset() {
advanceEpoch();
super.reset();
volatileThetaLong_ = Long.MAX_VALUE;
volatileEstimate_ = 0;
}
@Override
UpdateReturnState hashUpdate(final long hash) {
final String msg = "No update method should be called directly to a shared theta sketch."
+ " Updating the shared sketch is only permitted through propagation from local sketches.";
throw new UnsupportedOperationException(msg);
}
//ConcurrentSharedThetaSketch declarations
@Override
public long getExactLimit() {
return exactLimit_;
}
@Override
public boolean startEagerPropagation() {
while (!sharedPropagationInProgress_.compareAndSet(false, true)) { } //busy wait till free
return (!isEstimationMode());// no eager propagation is allowed in estimation mode
}
@Override
public void endPropagation(final AtomicBoolean localPropagationInProgress, final boolean isEager) {
//update volatile theta, uniques estimate and propagation flag
updateVolatileTheta();
updateEstimationSnapshot();
if (isEager) {
sharedPropagationInProgress_.set(false);
}
if (localPropagationInProgress != null) {
localPropagationInProgress.set(false); //clear local propagation flag
}
}
@Override
public long getVolatileTheta() {
return volatileThetaLong_;
}
@Override
public void awaitBgPropagationTermination() {
try {
executorService_.shutdown();
while (!executorService_.awaitTermination(1, TimeUnit.MILLISECONDS)) {
Thread.sleep(1);
}
} catch (final InterruptedException e) {
e.printStackTrace();
}
}
@Override
public final void initBgPropagationService() {
executorService_ = ConcurrentPropagationService.getExecutorService(Thread.currentThread().getId());
}
@Override
public boolean propagate(final AtomicBoolean localPropagationInProgress,
final Sketch sketchIn, final long singleHash) {
final long epoch = epoch_;
if ((singleHash != NOT_SINGLE_HASH) // namely, is a single hash and
&& (getRetainedEntries(false) < exactLimit_)) { // a small sketch then propagate myself (blocking)
if (!startEagerPropagation()) {
endPropagation(localPropagationInProgress, true);
return false;
}
if (!validateEpoch(epoch)) {
endPropagation(null, true); // do not change local flag
return true;
}
propagate(singleHash);
endPropagation(localPropagationInProgress, true);
return true;
}
// otherwise, be nonblocking, let background thread do the work
final ConcurrentBackgroundThetaPropagation job = new ConcurrentBackgroundThetaPropagation(
this, localPropagationInProgress, sketchIn, singleHash, epoch);
executorService_.execute(job);
return true;
}
@Override
public void propagate(final long singleHash) {
super.hashUpdate(singleHash);
}
@Override
public void updateEstimationSnapshot() {
volatileEstimate_ = super.getEstimate();
}
@Override
public void updateVolatileTheta() {
volatileThetaLong_ = getThetaLong();
}
@Override
public boolean validateEpoch(final long epoch) {
return epoch_ == epoch;
}
//Restricted
/**
* Advances the epoch while there is no background propagation
* This ensures a propagation invoked before the reset cannot affect the sketch after the reset
* is completed. Ignore VO_VOLATILE_INCREMENT findbugs warning, it is False Positive.
*/
@SuppressFBWarnings(value = "VO_VOLATILE_INCREMENT", justification = "Likely False Positive, Fix Later")
private void advanceEpoch() {
awaitBgPropagationTermination();
startEagerPropagation();
ConcurrentPropagationService.resetExecutorService(Thread.currentThread().getId());
//no inspection NonAtomicOperationOnVolatileField
// this increment of a volatile field is done within the scope of the propagation
// synchronization and hence is done by a single thread.
epoch_++;
endPropagation(null, true);
initBgPropagationService();
}
}
| 2,778 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/Intersection.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Util.floorPowerOf2;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractSerVer;
import java.util.Arrays;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* The API for intersection operations
*
* @author Lee Rhodes
*/
public abstract class Intersection extends SetOperation {
@Override
public Family getFamily() {
return Family.INTERSECTION;
}
/**
* Gets the result of this operation as an ordered CompactSketch on the Java heap.
* This does not disturb the underlying data structure of this intersection.
* The {@link #intersect(Sketch)} method must have been called at least once, otherwise an
* exception will be thrown. This is because a virgin Intersection object represents the
* Universal Set, which has an infinite number of values.
* @return the result of this operation as an ordered CompactSketch on the Java heap
*/
public CompactSketch getResult() {
return getResult(true, null);
}
/**
* Gets the result of this operation as a CompactSketch in the given dstMem.
* This does not disturb the underlying data structure of this intersection.
* The {@link #intersect(Sketch)} method must have been called at least once, otherwise an
* exception will be thrown. This is because a virgin Intersection object represents the
* Universal Set, which has an infinite number of values.
*
* <p>Note that presenting an intersection with an empty sketch sets the internal
* state of the intersection to empty = true, and current count = 0. This is consistent with
* the mathematical definition of the intersection of any set with the empty set is
* always empty.</p>
*
* <p>Presenting an intersection with a null argument will throw an exception.</p>
*
* @param dstOrdered
* <a href="{@docRoot}/resources/dictionary.html#dstOrdered">See Destination Ordered</a>
*
* @param dstMem
* <a href="{@docRoot}/resources/dictionary.html#dstMem">See Destination Memory</a>.
*
* @return the result of this operation as a CompactSketch stored in the given dstMem,
* which can be either on or off-heap..
*/
public abstract CompactSketch getResult(boolean dstOrdered, WritableMemory dstMem);
/**
* Returns true if there is a valid intersection result available
* @return true if there is a valid intersection result available
*/
public abstract boolean hasResult();
/**
* Resets this Intersection for stateful operations only.
* The seed remains intact, otherwise reverts to
* the Universal Set: theta = 1.0, no retained data and empty = false.
*/
public abstract void reset();
/**
* Serialize this intersection to a byte array form.
* @return byte array of this intersection
*/
public abstract byte[] toByteArray();
/**
* Intersect the given sketch with the internal state.
* This method can be repeatedly called.
* If the given sketch is null the internal state becomes the empty sketch.
* Theta will become the minimum of thetas seen so far.
* @param sketchIn the given sketch
*/
public abstract void intersect(Sketch sketchIn);
/**
* Perform intersect set operation on the two given sketch arguments and return the result as an
* ordered CompactSketch on the heap.
* @param a The first sketch argument
* @param b The second sketch argument
* @return an ordered CompactSketch on the heap
*/
public CompactSketch intersect(final Sketch a, final Sketch b) {
return intersect(a, b, true, null);
}
/**
* Perform intersect set operation on the two given sketches and return the result as a
* CompactSketch.
* @param a The first sketch argument
* @param b The second sketch argument
* @param dstOrdered
* <a href="{@docRoot}/resources/dictionary.html#dstOrdered">See Destination Ordered</a>.
* @param dstMem
* <a href="{@docRoot}/resources/dictionary.html#dstMem">See Destination Memory</a>.
* @return the result as a CompactSketch.
*/
public abstract CompactSketch intersect(Sketch a, Sketch b, boolean dstOrdered,
WritableMemory dstMem);
// Restricted
/**
* Returns the maximum lgArrLongs given the capacity of the Memory.
* @param dstMem the given Memory
* @return the maximum lgArrLongs given the capacity of the Memory
*/
protected static int getMaxLgArrLongs(final Memory dstMem) {
final int preBytes = CONST_PREAMBLE_LONGS << 3;
final long cap = dstMem.getCapacity();
return Integer.numberOfTrailingZeros(floorPowerOf2((int)(cap - preBytes)) >>> 3);
}
protected static void checkMinSizeMemory(final Memory mem) {
final int minBytes = (CONST_PREAMBLE_LONGS << 3) + (8 << ThetaUtil.MIN_LG_ARR_LONGS);//280
final long cap = mem.getCapacity();
if (cap < minBytes) {
throw new SketchesArgumentException(
"Memory must be at least " + minBytes + " bytes. Actual capacity: " + cap);
}
}
/**
* 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
*/ //Only used in IntersectionImpl & Test
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;
}
protected static void memChecks(final Memory srcMem) {
//Get Preamble
//Note: Intersection does not use lgNomLongs (or k), per se.
//seedHash loaded and checked in private constructor
final int preLongs = extractPreLongs(srcMem);
final int serVer = extractSerVer(srcMem);
final int famID = extractFamilyID(srcMem);
final boolean empty = (extractFlags(srcMem) & EMPTY_FLAG_MASK) > 0;
final int curCount = extractCurCount(srcMem);
//Checks
if (preLongs != CONST_PREAMBLE_LONGS) {
throw new SketchesArgumentException(
"Memory PreambleLongs must equal " + CONST_PREAMBLE_LONGS + ": " + preLongs);
}
if (serVer != SER_VER) {
throw new SketchesArgumentException("Serialization Version must equal " + SER_VER);
}
Family.INTERSECTION.checkFamilyID(famID);
if (empty) {
if (curCount != 0) {
throw new SketchesArgumentException(
"srcMem empty state inconsistent with curCount: " + empty + "," + curCount);
}
//empty = true AND curCount_ = 0: OK
} //else empty = false, curCount could be anything
}
}
| 2,779 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/HeapQuickSelectSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.apache.datasketches.common.Util.LONG_MAX_VALUE_AS_DOUBLE;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractLgNomLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractLgResizeFactor;
import static org.apache.datasketches.theta.PreambleUtil.extractP;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncremented;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncrementedRebuilt;
import static org.apache.datasketches.theta.UpdateReturnState.InsertedCountIncrementedResized;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedDuplicate;
import static org.apache.datasketches.theta.UpdateReturnState.RejectedOverTheta;
import static org.apache.datasketches.thetacommon.QuickSelect.selectExcludingZeros;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.HashOperations;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* @author Lee Rhodes
* @author Kevin Lang
*/
class HeapQuickSelectSketch extends HeapUpdateSketch {
private final Family MY_FAMILY;
private final int preambleLongs_;
private int lgArrLongs_;
private int hashTableThreshold_; //never serialized
int curCount_;
long thetaLong_;
boolean empty_;
private long[] cache_;
private HeapQuickSelectSketch(final int lgNomLongs, final long seed, final float p,
final ResizeFactor rf, final int preambleLongs, final Family family) {
super(lgNomLongs, seed, p, rf);
preambleLongs_ = preambleLongs;
MY_FAMILY = family;
}
/**
* Construct a new sketch instance on the java heap.
*
* @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 unionGadget true if this sketch is implementing the Union gadget function.
* Otherwise, it is behaving as a normal QuickSelectSketch.
*/
HeapQuickSelectSketch(final int lgNomLongs, final long seed, final float p,
final ResizeFactor rf, final boolean unionGadget) {
super(lgNomLongs, seed, p, rf);
//Choose family, preambleLongs
if (unionGadget) {
preambleLongs_ = Family.UNION.getMinPreLongs();
MY_FAMILY = Family.UNION;
}
else {
preambleLongs_ = Family.QUICKSELECT.getMinPreLongs();
MY_FAMILY = Family.QUICKSELECT;
}
lgArrLongs_ = ThetaUtil.startingSubMultiple(lgNomLongs + 1, rf.lg(), ThetaUtil.MIN_LG_ARR_LONGS);
hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs_);
curCount_ = 0;
thetaLong_ = (long)(p * LONG_MAX_VALUE_AS_DOUBLE);
empty_ = true; //other flags: bigEndian = readOnly = compact = ordered = false;
cache_ = new long[1 << lgArrLongs_];
}
/**
* Heapify a sketch from a Memory UpdateSketch or Union 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
*/
static HeapQuickSelectSketch 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
checkUnionQuickSelectFamily(srcMem, preambleLongs, lgNomLongs);
checkMemIntegrity(srcMem, seed, preambleLongs, lgNomLongs, lgArrLongs);
final float p = extractP(srcMem); //bytes 12-15
final int memlgRF = extractLgResizeFactor(srcMem); //byte 0
ResizeFactor memRF = ResizeFactor.getRF(memlgRF);
final int familyID = extractFamilyID(srcMem);
final Family family = Family.idToFamily(familyID);
if (isResizeFactorIncorrect(srcMem, lgNomLongs, lgArrLongs)) {
memRF = ResizeFactor.X2; //X2 always works.
}
final HeapQuickSelectSketch hqss = new HeapQuickSelectSketch(lgNomLongs, seed, p, memRF,
preambleLongs, family);
hqss.lgArrLongs_ = lgArrLongs;
hqss.hashTableThreshold_ = setHashTableThreshold(lgNomLongs, lgArrLongs);
hqss.curCount_ = extractCurCount(srcMem);
hqss.thetaLong_ = extractThetaLong(srcMem);
hqss.empty_ = PreambleUtil.isEmptyFlag(srcMem);
hqss.cache_ = new long[1 << lgArrLongs];
srcMem.getLongArray(preambleLongs << 3, hqss.cache_, 0, 1 << lgArrLongs); //read in as hash table
return hqss;
}
//Sketch
@Override
public double getEstimate() {
return Sketch.estimate(thetaLong_, curCount_);
}
@Override
public Family getFamily() {
return MY_FAMILY;
}
@Override
public int getRetainedEntries(final boolean valid) {
return curCount_;
}
@Override
public long getThetaLong() {
return empty_ ? Long.MAX_VALUE : thetaLong_;
}
@Override
public boolean isEmpty() {
return empty_;
}
@Override
public HashIterator iterator() {
return new HeapHashIterator(cache_, thetaLong_);
}
@Override
public byte[] toByteArray() {
return toByteArray(preambleLongs_, (byte) MY_FAMILY.getID());
}
//UpdateSketch
@Override
public UpdateSketch rebuild() {
if (getRetainedEntries(true) > (1 << getLgNomLongs())) {
quickSelectAndRebuild();
}
return this;
}
@Override
public void reset() {
final ResizeFactor rf = getResizeFactor();
final int lgArrLongsSM = ThetaUtil.startingSubMultiple(lgNomLongs_ + 1, rf.lg(), ThetaUtil.MIN_LG_ARR_LONGS);
if (lgArrLongsSM == lgArrLongs_) {
final int arrLongs = cache_.length;
assert (1 << lgArrLongs_) == arrLongs;
java.util.Arrays.fill(cache_, 0L);
}
else {
cache_ = new long[1 << lgArrLongsSM];
lgArrLongs_ = lgArrLongsSM;
}
hashTableThreshold_ = setHashTableThreshold(lgNomLongs_, lgArrLongs_);
empty_ = true;
curCount_ = 0;
thetaLong_ = (long)(getP() * LONG_MAX_VALUE_AS_DOUBLE);
}
//restricted methods
@Override
long[] getCache() {
return cache_;
}
@Override
int getCompactPreambleLongs() {
return CompactOperations.computeCompactPreLongs(empty_, curCount_, thetaLong_);
}
@Override
int getCurrentPreambleLongs() {
return preambleLongs_;
}
//only used by ConcurrentHeapThetaBuffer & Test
int getHashTableThreshold() {
return hashTableThreshold_;
}
@Override
int getLgArrLongs() {
return lgArrLongs_;
}
@Override
WritableMemory getMemory() {
return null;
}
@Override
UpdateReturnState hashUpdate(final long hash) {
HashOperations.checkHashCorruption(hash);
empty_ = false;
//The over-theta test
if (HashOperations.continueCondition(thetaLong_, hash)) {
return RejectedOverTheta; //signal that hash was rejected due to theta.
}
//The duplicate test
if (HashOperations.hashSearchOrInsert(cache_, lgArrLongs_, hash) >= 0) {
return RejectedDuplicate; //Duplicate, not inserted
}
//insertion occurred, must increment curCount
curCount_++;
if (isOutOfSpace(curCount_)) { //we need to do something, we are out of space
//must rebuild or resize
if (lgArrLongs_ <= lgNomLongs_) { //resize
resizeCache();
return InsertedCountIncrementedResized;
}
//Already at tgt size, must rebuild
assert (lgArrLongs_ == (lgNomLongs_ + 1)) : "lgArr: " + lgArrLongs_ + ", lgNom: " + lgNomLongs_;
quickSelectAndRebuild(); //Changes thetaLong_, curCount_, reassigns cache
return InsertedCountIncrementedRebuilt;
}
return InsertedCountIncremented;
}
@Override
boolean isDirty() {
return false;
}
@Override
boolean isOutOfSpace(final int numEntries) {
return numEntries > hashTableThreshold_;
}
//Must resize. Changes lgArrLongs_, cache_, hashTableThreshold;
// theta and count don't change.
// Used by hashUpdate()
private final void resizeCache() {
final ResizeFactor rf = getResizeFactor();
final int lgMaxArrLongs = lgNomLongs_ + 1;
final int lgDeltaLongs = lgMaxArrLongs - lgArrLongs_;
final int lgResizeFactor = max(min(rf.lg(), lgDeltaLongs), 1); //rf_.lg() could be 0
lgArrLongs_ += lgResizeFactor; // new arr size
final long[] tgtArr = new long[1 << lgArrLongs_];
final int newCount = HashOperations.hashArrayInsert(cache_, tgtArr, lgArrLongs_, thetaLong_);
assert newCount == curCount_; //Assumes no dirty values.
curCount_ = newCount;
cache_ = tgtArr;
hashTableThreshold_ = setHashTableThreshold(lgNomLongs_, lgArrLongs_);
}
//array stays the same size. Changes theta and thus count
private final void quickSelectAndRebuild() {
final int arrLongs = 1 << lgArrLongs_; // generally 2 * k,
final int pivot = (1 << lgNomLongs_) + 1; // pivot for QS = k + 1
thetaLong_ = selectExcludingZeros(cache_, curCount_, pivot); //messes up the cache_
// now we rebuild to clean up dirty data, update count, reconfigure as a hash table
final long[] tgtArr = new long[arrLongs];
curCount_ = HashOperations.hashArrayInsert(cache_, tgtArr, lgArrLongs_, thetaLong_);
cache_ = tgtArr;
//hashTableThreshold stays the same
}
/**
* Returns the cardinality limit given the current size of the hash table array.
*
* @param lgNomLongs <a href="{@docRoot}/resources/dictionary.html#lgNomLongs">See lgNomLongs</a>.
* @param lgArrLongs <a href="{@docRoot}/resources/dictionary.html#lgArrLongs">See lgArrLongs</a>.
* @return the hash table threshold
*/
static final int setHashTableThreshold(final int lgNomLongs, final int lgArrLongs) {
final double fraction = (lgArrLongs <= lgNomLongs) ? ThetaUtil.RESIZE_THRESHOLD : ThetaUtil.REBUILD_THRESHOLD;
return (int) Math.floor(fraction * (1 << lgArrLongs));
}
}
| 2,780 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/EmptyCompactSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
/**
* Singleton empty CompactSketch.
*
* @author Lee Rhodes
*/
final class EmptyCompactSketch extends CompactSketch {
//For backward compatibility, a candidate long must have Flags= compact, read-only,
// COMPACT-Family=3, SerVer=3, PreLongs=1, and be exactly 8 bytes long. The seedHash is ignored.
// NOTE: The empty and ordered flags may or may not be set
private static final long EMPTY_SKETCH_MASK = 0X00_00_EB_00_00_FF_FF_FFL;
private static final long EMPTY_SKETCH_TEST = 0X00_00_0A_00_00_03_03_01L;
//When returning a byte array the empty and ordered bits are also set
static final byte[] EMPTY_COMPACT_SKETCH_ARR = { 1, 3, 3, 0, 0, 0x1E, 0, 0 };
private static final EmptyCompactSketch EMPTY_COMPACT_SKETCH = new EmptyCompactSketch();
private EmptyCompactSketch() {}
static EmptyCompactSketch getInstance() {
return EMPTY_COMPACT_SKETCH;
}
//This should be a heapify
static EmptyCompactSketch getHeapInstance(final Memory srcMem) {
final long pre0 = srcMem.getLong(0);
if (testCandidatePre0(pre0)) {
return EMPTY_COMPACT_SKETCH;
}
final long maskedPre0 = pre0 & EMPTY_SKETCH_MASK;
throw new SketchesArgumentException("Input Memory does not match required Preamble. "
+ "Memory Pre0: " + Long.toHexString(maskedPre0)
+ ", required Pre0: " + Long.toHexString(EMPTY_SKETCH_TEST));
}
@Override
// This returns with ordered flag = true independent of dstOrdered.
// This is required for fast detection.
// The hashSeed is ignored and set == 0.
public CompactSketch compact(final boolean dstOrdered, final WritableMemory wmem) {
if (wmem == null) { return EmptyCompactSketch.getInstance(); }
wmem.putByteArray(0, EMPTY_COMPACT_SKETCH_ARR, 0, 8);
return new DirectCompactSketch(wmem);
}
//static
static boolean testCandidatePre0(final long candidate) {
return (candidate & EMPTY_SKETCH_MASK) == EMPTY_SKETCH_TEST;
}
@Override
public int getCurrentBytes() {
return 8;
}
@Override
public double getEstimate() { return 0; }
@Override
public int getRetainedEntries(final boolean valid) {
return 0;
}
@Override
public long getThetaLong() {
return Long.MAX_VALUE;
}
@Override
public boolean hasMemory() {
return false;
}
@Override
public boolean isDirect() {
return false;
}
@Override
public boolean isEmpty() {
return true;
}
@Override
public boolean isOrdered() {
return true;
}
@Override
public HashIterator iterator() {
return new HeapCompactHashIterator(new long[0]);
}
/**
* Returns 8 bytes representing a CompactSketch that the following flags set:
* ordered, compact, empty, readOnly. The SerVer is 3, the Family is COMPACT(3),
* and the PreLongs = 1. The seedHash is zero.
*/
@Override
public byte[] toByteArray() {
return EMPTY_COMPACT_SKETCH_ARR;
}
@Override
long[] getCache() {
return new long[0];
}
@Override
int getCompactPreambleLongs() {
return 1;
}
@Override
int getCurrentPreambleLongs() {
return 1;
}
@Override
Memory getMemory() {
return null;
}
@Override
short getSeedHash() {
return 0;
}
}
| 2,781 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/UpdateSketchBuilder.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Util.LS;
import static org.apache.datasketches.common.Util.TAB;
import static org.apache.datasketches.common.Util.ceilingIntPowerOf2;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesStateException;
import org.apache.datasketches.common.SuppressFBWarnings;
import org.apache.datasketches.memory.DefaultMemoryRequestServer;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* For building a new UpdateSketch.
*
* @author Lee Rhodes
*/
public class UpdateSketchBuilder {
private int bLgNomLongs;
private long bSeed;
private ResizeFactor bRF;
private Family bFam;
private float bP;
private MemoryRequestServer bMemReqSvr;
//Fields for concurrent theta sketch
private int bNumPoolThreads;
private int bLocalLgNomLongs;
private boolean bPropagateOrderedCompact;
private double bMaxConcurrencyError;
private int bMaxNumLocalThreads;
/**
* Constructor for building a new UpdateSketch. The default configuration is
* <ul>
* <li>Nominal Entries: {@value org.apache.datasketches.thetacommon.ThetaUtil#DEFAULT_NOMINAL_ENTRIES}</li>
* <li>Seed: {@value org.apache.datasketches.thetacommon.ThetaUtil#DEFAULT_UPDATE_SEED}</li>
* <li>Input Sampling Probability: 1.0</li>
* <li>Family: {@link org.apache.datasketches.common.Family#QUICKSELECT}</li>
* <li>Resize Factor: The default for sketches on the Java heap is {@link ResizeFactor#X8}.
* For direct sketches, which are targeted for native memory off the Java heap, this value will
* be fixed at either {@link ResizeFactor#X1} or {@link ResizeFactor#X2}.</li>
* <li>MemoryRequestServer (Direct only):
* {@link org.apache.datasketches.memory.DefaultMemoryRequestServer}.</li>
* </ul>
* Parameters unique to the concurrent sketches only:
* <ul>
* <li>Number of local Nominal Entries: 4</li>
* <li>Concurrent NumPoolThreads: 3</li>
* <li>Concurrent PropagateOrderedCompact: true</li>
* <li>Concurrent MaxConcurrencyError: 0</li>
* </ul>
*/
public UpdateSketchBuilder() {
bLgNomLongs = Integer.numberOfTrailingZeros(ThetaUtil.DEFAULT_NOMINAL_ENTRIES);
bSeed = ThetaUtil.DEFAULT_UPDATE_SEED;
bP = (float) 1.0;
bRF = ResizeFactor.X8;
bFam = Family.QUICKSELECT;
bMemReqSvr = new DefaultMemoryRequestServer();
// Default values for concurrent sketch
bNumPoolThreads = ConcurrentPropagationService.NUM_POOL_THREADS;
bLocalLgNomLongs = 4; //default is smallest legal QS sketch
bPropagateOrderedCompact = true;
bMaxConcurrencyError = 0;
bMaxNumLocalThreads = 1;
}
/**
* Sets the Nominal Entries for this sketch.
* This value is also used for building a shared concurrent sketch.
* The minimum value is 16 (2^4) and the maximum value is 67,108,864 (2^26).
* Be aware that sketches as large as this maximum value may not have 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 the given value is not.
* @return this UpdateSketchBuilder
*/
public UpdateSketchBuilder setNominalEntries(final int nomEntries) {
bLgNomLongs = ThetaUtil.checkNomLongs(nomEntries);
return this;
}
/**
* 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 characterized for performance.
*
* @param lgNomEntries the Log Nominal Entries. Also for the concurrent shared sketch
* @return this UpdateSketchBuilder
*/
public UpdateSketchBuilder setLogNominalEntries(final int lgNomEntries) {
bLgNomLongs = ThetaUtil.checkNomLongs(1 << lgNomEntries);
return this;
}
/**
* Returns Log-base 2 Nominal Entries
* @return Log-base 2 Nominal Entries
*/
public int getLgNominalEntries() {
return bLgNomLongs;
}
/**
* 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 UpdateSketchBuilder
*/
public UpdateSketchBuilder setLocalNominalEntries(final int nomEntries) {
bLocalLgNomLongs = Integer.numberOfTrailingZeros(ceilingIntPowerOf2(nomEntries));
if ((bLocalLgNomLongs > ThetaUtil.MAX_LG_NOM_LONGS) || (bLocalLgNomLongs < ThetaUtil.MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException(
"Nominal Entries must be >= 16 and <= 67108864: " + nomEntries);
}
return this;
}
/**
* 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 UpdateSketchBuilder
*/
public UpdateSketchBuilder setLocalLogNominalEntries(final int lgNomEntries) {
bLocalLgNomLongs = lgNomEntries;
if ((bLocalLgNomLongs > ThetaUtil.MAX_LG_NOM_LONGS) || (bLocalLgNomLongs < ThetaUtil.MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException(
"Log Nominal Entries must be >= 4 and <= 26: " + lgNomEntries);
}
return this;
}
/**
* Returns Log-base 2 Nominal Entries for the concurrent local sketch
* @return Log-base 2 Nominal Entries for the concurrent local sketch
*/
public int getLocalLgNominalEntries() {
return bLocalLgNomLongs;
}
/**
* Sets the long seed value that is required by the hashing function.
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return this UpdateSketchBuilder
*/
public UpdateSketchBuilder setSeed(final long seed) {
bSeed = seed;
return this;
}
/**
* Returns the seed
* @return the seed
*/
public long getSeed() {
return bSeed;
}
/**
* Sets the upfront uniform sampling probability, <i>p</i>
* @param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>
* @return this UpdateSketchBuilder
*/
public UpdateSketchBuilder setP(final float p) {
if ((p <= 0.0) || (p > 1.0)) {
throw new SketchesArgumentException("p must be > 0 and <= 1.0: " + p);
}
bP = p;
return this;
}
/**
* Returns the pre-sampling probability <i>p</i>
* @return the pre-sampling probability <i>p</i>
*/
public float getP() {
return bP;
}
/**
* Sets the cache Resize Factor.
* @param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
* @return this UpdateSketchBuilder
*/
public UpdateSketchBuilder setResizeFactor(final ResizeFactor rf) {
bRF = rf;
return this;
}
/**
* Returns the Resize Factor
* @return the Resize Factor
*/
public ResizeFactor getResizeFactor() {
return bRF;
}
/**
* Set the Family.
* @param family the family for this builder
* @return this UpdateSketchBuilder
*/
public UpdateSketchBuilder setFamily(final Family family) {
bFam = family;
return this;
}
/**
* Returns the Family
* @return the Family
*/
public Family getFamily() {
return bFam;
}
/**
* Set the MemoryRequestServer
* @param memReqSvr the given MemoryRequestServer
* @return this UpdateSketchBuilder
*/
public UpdateSketchBuilder setMemoryRequestServer(final MemoryRequestServer memReqSvr) {
bMemReqSvr = memReqSvr;
return this;
}
/**
* Returns the MemoryRequestServer
* @return the MemoryRequestServer
*/
public MemoryRequestServer getMemoryRequestServer() {
return bMemReqSvr;
}
/**
* Sets the number of pool threads used for background propagation in the concurrent sketches.
* @param numPoolThreads the given number of pool threads
*/
public void setNumPoolThreads(final int numPoolThreads) {
bNumPoolThreads = numPoolThreads;
}
/**
* Gets the number of background pool threads used for propagation in the concurrent sketches.
* @return the number of background pool threads
*/
public int getNumPoolThreads() {
return bNumPoolThreads;
}
/**
* Sets the Propagate Ordered Compact flag to the given value. Used with concurrent sketches.
*
* @param prop the given value
* @return this UpdateSketchBuilder
*/
public UpdateSketchBuilder setPropagateOrderedCompact(final boolean prop) {
bPropagateOrderedCompact = prop;
return this;
}
/**
* Gets the Propagate Ordered Compact flag used with concurrent sketches.
* @return the Propagate Ordered Compact flag
*/
public boolean getPropagateOrderedCompact() {
return bPropagateOrderedCompact;
}
/**
* Sets the Maximum Concurrency Error.
* @param maxConcurrencyError the given Maximum Concurrency Error.
*/
public void setMaxConcurrencyError(final double maxConcurrencyError) {
bMaxConcurrencyError = maxConcurrencyError;
}
/**
* Gets the Maximum Concurrency Error
* @return the Maximum Concurrency Error
*/
public double getMaxConcurrencyError() {
return bMaxConcurrencyError;
}
/**
* Sets the Maximum Number of Local Threads.
* This is used to set the size of the local concurrent buffers.
* @param maxNumLocalThreads the given Maximum Number of Local Threads
*/
public void setMaxNumLocalThreads(final int maxNumLocalThreads) {
bMaxNumLocalThreads = maxNumLocalThreads;
}
/**
* Gets the Maximum Number of Local Threads.
* @return the Maximum Number of Local Threads.
*/
public int getMaxNumLocalThreads() {
return bMaxNumLocalThreads;
}
// BUILD FUNCTIONS
/**
* Returns an UpdateSketch with the current configuration of this Builder.
* @return an UpdateSketch
*/
public UpdateSketch build() {
return build(null);
}
/**
* Returns an UpdateSketch with the current configuration of this Builder
* with the specified backing destination Memory store.
* Note: this cannot be used with the Alpha Family of sketches.
* @param dstMem The destination Memory.
* @return an UpdateSketch
*/
public UpdateSketch build(final WritableMemory dstMem) {
UpdateSketch sketch = null;
switch (bFam) {
case ALPHA: {
if (dstMem == null) {
sketch = HeapAlphaSketch.newHeapInstance(bLgNomLongs, bSeed, bP, bRF);
}
else {
throw new SketchesArgumentException("AlphaSketch cannot be made Direct to Memory.");
}
break;
}
case QUICKSELECT: {
if (dstMem == null) {
sketch = new HeapQuickSelectSketch(bLgNomLongs, bSeed, bP, bRF, false);
}
else {
sketch = new DirectQuickSelectSketch(
bLgNomLongs, bSeed, bP, bRF, bMemReqSvr, dstMem, false);
}
break;
}
default: {
throw new SketchesArgumentException(
"Given Family cannot be built as a Theta Sketch: " + bFam.toString());
}
}
return sketch;
}
/**
* Returns an on-heap concurrent shared UpdateSketch with the current configuration of the
* Builder.
*
* <p>The parameters unique to the shared concurrent sketch are:
* <ul>
* <li>Number of Pool Threads (default is 3)</li>
* <li>Maximum Concurrency Error</li>
* </ul>
*
* <p>Key parameters that are in common with other <i>Theta</i> sketches:
* <ul>
* <li>Nominal Entries or Log Nominal Entries (for the shared concurrent sketch)</li>
* </ul>
*
* @return an on-heap concurrent UpdateSketch with the current configuration of the Builder.
*/
public UpdateSketch buildShared() {
return buildShared(null);
}
/**
* Returns a direct (potentially off-heap) concurrent shared UpdateSketch with the current
* configuration of the Builder and the given destination WritableMemory. If the destination
* WritableMemory is null, this defaults to an on-heap concurrent shared UpdateSketch.
*
* <p>The parameters unique to the shared concurrent sketch are:
* <ul>
* <li>Number of Pool Threads (default is 3)</li>
* <li>Maximum Concurrency Error</li>
* </ul>
*
* <p>Key parameters that are in common with other <i>Theta</i> sketches:
* <ul>
* <li>Nominal Entries or Log Nominal Entries (for the shared concurrent sketch)</li>
* <li>Destination Writable Memory (if not null, returned sketch is Direct. Default is null.)</li>
* </ul>
*
* @param dstMem the given WritableMemory for Direct, otherwise <i>null</i>.
* @return a concurrent UpdateSketch with the current configuration of the Builder
* and the given destination WritableMemory.
*/
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD",
justification = "Harmless in Builder, fix later")
public UpdateSketch buildShared(final WritableMemory dstMem) {
ConcurrentPropagationService.NUM_POOL_THREADS = bNumPoolThreads;
if (dstMem == null) {
return new ConcurrentHeapQuickSelectSketch(bLgNomLongs, bSeed, bMaxConcurrencyError);
} else {
return new ConcurrentDirectQuickSelectSketch(bLgNomLongs, bSeed, bMaxConcurrencyError, dstMem);
}
}
/**
* Returns a direct (potentially off-heap) concurrent shared UpdateSketch with the current
* configuration of the Builder, the data from the given sketch, and the given destination
* WritableMemory. If the destination WritableMemory is null, this defaults to an on-heap
* concurrent shared UpdateSketch.
*
* <p>The parameters unique to the shared concurrent sketch are:
* <ul>
* <li>Number of Pool Threads (default is 3)</li>
* <li>Maximum Concurrency Error</li>
* </ul>
*
* <p>Key parameters that are in common with other <i>Theta</i> sketches:
* <ul>
* <li>Nominal Entries or Log Nominal Entries (for the shared concurrent sketch)</li>
* <li>Destination Writable Memory (if not null, returned sketch is Direct. Default is null.)</li>
* </ul>
*
* @param sketch a given UpdateSketch from which the data is used to initialize the returned
* shared sketch.
* @param dstMem the given WritableMemory for Direct, otherwise <i>null</i>.
* @return a concurrent UpdateSketch with the current configuration of the Builder
* and the given destination WritableMemory.
*/
@SuppressFBWarnings(value = "ST_WRITE_TO_STATIC_FROM_INSTANCE_METHOD",
justification = "Harmless in Builder, fix later")
public UpdateSketch buildSharedFromSketch(final UpdateSketch sketch, final WritableMemory dstMem) {
ConcurrentPropagationService.NUM_POOL_THREADS = bNumPoolThreads;
if (dstMem == null) {
return new ConcurrentHeapQuickSelectSketch(sketch, bSeed, bMaxConcurrencyError);
} else {
return new ConcurrentDirectQuickSelectSketch(sketch, bSeed, bMaxConcurrencyError, dstMem);
}
}
/**
* Returns a local, on-heap, 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.
*/
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);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("UpdateSketchBuilder configuration:").append(LS);
sb.append("LgK:").append(TAB).append(bLgNomLongs).append(LS);
sb.append("K:").append(TAB).append(1 << bLgNomLongs).append(LS);
sb.append("LgLocalK:").append(TAB).append(bLocalLgNomLongs).append(LS);
sb.append("LocalK:").append(TAB).append(1 << bLocalLgNomLongs).append(LS);
sb.append("Seed:").append(TAB).append(bSeed).append(LS);
sb.append("p:").append(TAB).append(bP).append(LS);
sb.append("ResizeFactor:").append(TAB).append(bRF).append(LS);
sb.append("Family:").append(TAB).append(bFam).append(LS);
final String mrsStr = bMemReqSvr.getClass().getSimpleName();
sb.append("MemoryRequestServer:").append(TAB).append(mrsStr).append(LS);
sb.append("Propagate Ordered Compact").append(TAB).append(bPropagateOrderedCompact).append(LS);
sb.append("NumPoolThreads").append(TAB).append(bNumPoolThreads).append(LS);
sb.append("MaxConcurrencyError").append(TAB).append(bMaxConcurrencyError).append(LS);
sb.append("MaxNumLocalThreads").append(TAB).append(bMaxNumLocalThreads).append(LS);
return sb.toString();
}
}
| 2,782 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/HeapHashIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
/**
* @author Lee Rhodes
*/
class HeapHashIterator implements HashIterator {
private long[] cache;
private long thetaLong;
private int index;
private long hash;
HeapHashIterator(final long[] cache, final long thetaLong) {
this.cache = cache;
this.thetaLong = thetaLong;
index = -1;
hash = 0;
}
@Override
public long get() {
return hash;
}
@Override
public boolean next() {
while (++index < cache.length) {
hash = cache[index];
if ((hash != 0) && (hash < thetaLong)) {
return true;
}
}
return false;
}
}
| 2,783 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/IntersectionImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static java.lang.Math.min;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.FAMILY_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.FLAGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.LG_ARR_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.LG_NOM_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.PREAMBLE_LONGS_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.P_FLOAT;
import static org.apache.datasketches.theta.PreambleUtil.RETAINED_ENTRIES_INT;
import static org.apache.datasketches.theta.PreambleUtil.SEED_HASH_SHORT;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER_BYTE;
import static org.apache.datasketches.theta.PreambleUtil.THETA_LONG;
import static org.apache.datasketches.theta.PreambleUtil.clearEmpty;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFlags;
import static org.apache.datasketches.theta.PreambleUtil.extractLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.insertCurCount;
import static org.apache.datasketches.theta.PreambleUtil.insertFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.insertLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertP;
import static org.apache.datasketches.theta.PreambleUtil.insertPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertSerVer;
import static org.apache.datasketches.theta.PreambleUtil.insertThetaLong;
import static org.apache.datasketches.theta.PreambleUtil.setEmpty;
import static org.apache.datasketches.thetacommon.HashOperations.continueCondition;
import static org.apache.datasketches.thetacommon.HashOperations.hashInsertOnly;
import static org.apache.datasketches.thetacommon.HashOperations.hashInsertOnlyMemory;
import static org.apache.datasketches.thetacommon.HashOperations.hashSearch;
import static org.apache.datasketches.thetacommon.HashOperations.minLgHashTableSize;
import java.util.Arrays;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesReadOnlyException;
import org.apache.datasketches.common.SketchesStateException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* Intersection operation for Theta Sketches.
*
* <p>This implementation uses data either on-heap or off-heap in a given Memory
* that is owned and managed by the caller.
* The off-heap Memory, which if managed properly, will greatly reduce the need for
* the JVM to perform garbage collection.</p>
*
* @author Lee Rhodes
* @author Kevin Lang
*/
class IntersectionImpl extends Intersection {
protected final short seedHash_;
protected final boolean readOnly_; //True if this sketch is to be treated as read only
protected final WritableMemory wmem_;
protected final int maxLgArrLongs_; //only used with WritableMemory, not serialized
//Note: Intersection does not use lgNomLongs or k, per se.
protected int lgArrLongs_; //current size of hash table
protected int curCount_; //curCount of HT, if < 0 means Universal Set (US) is true
protected long thetaLong_;
protected boolean empty_; //A virgin intersection represents the Universal Set, so empty is FALSE!
protected long[] hashTable_; //retained entries of the intersection, on-heap only.
/**
* Constructor: Sets the class finals and computes, sets and checks the seedHash.
* @param wmem Can be either a Source(e.g. wrap) or Destination (new Direct) WritableMemory.
* @param seed Used to validate incoming sketch arguments.
* @param dstMemFlag The given memory is a Destination (new Direct) WritableMemory.
* @param readOnly True if memory is to be treated as read only.
*/
protected IntersectionImpl(final WritableMemory wmem, final long seed, final boolean dstMemFlag,
final boolean readOnly) {
readOnly_ = readOnly;
if (wmem != null) {
wmem_ = wmem;
if (dstMemFlag) { //DstMem: compute & store seedHash, no seedhash checking
checkMinSizeMemory(wmem);
maxLgArrLongs_ = !readOnly ? getMaxLgArrLongs(wmem) : 0; //Only Off Heap
seedHash_ = ThetaUtil.computeSeedHash(seed);
wmem_.putShort(SEED_HASH_SHORT, seedHash_);
} else { //SrcMem:gets and stores the seedHash, checks mem_seedHash against the seed
seedHash_ = wmem_.getShort(SEED_HASH_SHORT);
ThetaUtil.checkSeedHashes(seedHash_, ThetaUtil.computeSeedHash(seed)); //check for seed hash conflict
maxLgArrLongs_ = 0;
}
} else { //compute & store seedHash
wmem_ = null;
maxLgArrLongs_ = 0;
seedHash_ = ThetaUtil.computeSeedHash(seed);
}
}
/**
* Factory: Construct a new Intersection target on the java heap.
* Called by SetOperationBuilder, test.
*
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Seed</a>
* @return a new IntersectionImpl on the Java heap
*/
static IntersectionImpl initNewHeapInstance(final long seed) {
final boolean dstMemFlag = false;
final boolean readOnly = false;
final IntersectionImpl impl = new IntersectionImpl(null, seed, dstMemFlag, readOnly);
impl.hardReset();
return impl;
}
/**
* Factory: Construct a new Intersection target direct to the given destination Memory.
* Called by SetOperationBuilder, test.
*
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See Seed</a>
* @param dstMem destination Memory
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @return a new IntersectionImpl that may be off-heap
*/
static IntersectionImpl initNewDirectInstance(final long seed, final WritableMemory dstMem) {
//Load Preamble
//Pre0
dstMem.clear(0, CONST_PREAMBLE_LONGS << 3);
insertPreLongs(dstMem, CONST_PREAMBLE_LONGS); //RF not used = 0
insertSerVer(dstMem, SER_VER);
insertFamilyID(dstMem, Family.INTERSECTION.getID());
//lgNomLongs not used by Intersection
//lgArrLongs set by hardReset
//flags are already 0: bigEndian = readOnly = compact = ordered = empty = false;
//seedHash loaded and checked in IntersectionImpl constructor
//Pre1
//CurCount set by hardReset
insertP(dstMem, (float) 1.0); //not used by intersection
//Pre2
//thetaLong set by hardReset
//Initialize
final boolean dstMemFlag = true;
final boolean readOnly = false;
final IntersectionImpl impl = new IntersectionImpl(dstMem, seed, dstMemFlag, readOnly);
impl.hardReset();
return impl;
}
/**
* Factory: Heapify an intersection target from a Memory image containing 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 a IntersectionImpl instance on the Java heap
*/
static IntersectionImpl heapifyInstance(final Memory srcMem, final long seed) {
final boolean dstMemFlag = false;
final boolean readOnly = false;
final IntersectionImpl impl = new IntersectionImpl(null, seed, dstMemFlag, readOnly);
memChecks(srcMem);
//Initialize
impl.lgArrLongs_ = extractLgArrLongs(srcMem);
impl.curCount_ = extractCurCount(srcMem);
impl.thetaLong_ = extractThetaLong(srcMem);
impl.empty_ = (extractFlags(srcMem) & EMPTY_FLAG_MASK) > 0;
if (!impl.empty_) {
if (impl.curCount_ > 0) {
impl.hashTable_ = new long[1 << impl.lgArrLongs_];
srcMem.getLongArray(CONST_PREAMBLE_LONGS << 3, impl.hashTable_, 0, 1 << impl.lgArrLongs_);
}
}
return impl;
}
/**
* Factory: Wrap an Intersection target around the given source WritableMemory containing
* intersection data.
* @param srcMem The source WritableMemory image.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @param readOnly True if memory is to be treated as read only
* @return a IntersectionImpl that wraps a source WritableMemory that contains an Intersection image
*/
static IntersectionImpl wrapInstance(
final WritableMemory srcMem,
final long seed,
final boolean readOnly) {
final boolean dstMemFlag = false;
final IntersectionImpl impl = new IntersectionImpl(srcMem, seed, dstMemFlag, readOnly);
memChecks(srcMem);
impl.lgArrLongs_ = extractLgArrLongs(srcMem);
impl.curCount_ = extractCurCount(srcMem);
impl.thetaLong_ = extractThetaLong(srcMem);
impl.empty_ = (extractFlags(srcMem) & EMPTY_FLAG_MASK) > 0;
return impl;
}
@Override
public CompactSketch intersect(final Sketch a, final Sketch b, final boolean dstOrdered,
final WritableMemory dstMem) {
if (wmem_ != null && readOnly_) { throw new SketchesReadOnlyException(); }
hardReset();
intersect(a);
intersect(b);
final CompactSketch csk = getResult(dstOrdered, dstMem);
hardReset();
return csk;
}
@Override
public void intersect(final Sketch sketchIn) {
if (sketchIn == null) {
throw new SketchesArgumentException("Intersection argument must not be null.");
}
if (wmem_ != null && readOnly_) { throw new SketchesReadOnlyException(); }
if (empty_ || sketchIn.isEmpty()) { //empty rule
//Because of the def of null above and the Empty Rule (which is OR), empty_ must be true.
//Whatever the current internal state, we make our local empty.
resetToEmpty();
return;
}
ThetaUtil.checkSeedHashes(seedHash_, sketchIn.getSeedHash());
//Set minTheta
thetaLong_ = min(thetaLong_, sketchIn.getThetaLong()); //Theta rule
empty_ = false;
if (wmem_ != null) {
insertThetaLong(wmem_, thetaLong_);
clearEmpty(wmem_); //false
}
// The truth table for the following state machine. MinTheta is set above.
// Incoming sketch is not null and not empty, but could have 0 count and Theta < 1.0
// Case curCount sketchInEntries | Actions
// 1 <0 0 | First intersect, set curCount = 0; HT = null; minTh; exit
// 2 0 0 | set curCount = 0; HT = null; minTh; exit
// 3 >0 0 | set curCount = 0; HT = null; minTh; exit
// 4 | Not used
// 5 <0 >0 | First intersect, clone SketchIn; exit
// 6 0 >0 | set curCount = 0; HT = null; minTh; exit
// 7 >0 >0 | Perform full intersect
final int sketchInEntries = sketchIn.getRetainedEntries(true);
//states 1,2,3,6
if (curCount_ == 0 || sketchInEntries == 0) {
curCount_ = 0;
if (wmem_ != null) { insertCurCount(wmem_, 0); }
hashTable_ = null; //No need for a HT. Don't bother clearing mem if valid
} //end of states 1,2,3,6
// state 5
else if (curCount_ < 0 && sketchInEntries > 0) {
curCount_ = sketchIn.getRetainedEntries(true);
final int requiredLgArrLongs = minLgHashTableSize(curCount_, ThetaUtil.REBUILD_THRESHOLD);
final int priorLgArrLongs = lgArrLongs_; //prior only used in error message
lgArrLongs_ = requiredLgArrLongs;
if (wmem_ != null) { //Off heap, check if current dstMem is large enough
insertCurCount(wmem_, curCount_);
insertLgArrLongs(wmem_, lgArrLongs_);
if (requiredLgArrLongs <= maxLgArrLongs_) {
wmem_.clear(CONST_PREAMBLE_LONGS << 3, 8 << lgArrLongs_); //clear only what required
}
else { //not enough space in dstMem
final int requiredBytes = (8 << requiredLgArrLongs) + 24;
final int givenBytes = (8 << priorLgArrLongs) + 24;
throw new SketchesArgumentException(
"Insufficient internal Memory space: " + requiredBytes + " > " + givenBytes);
}
}
else { //On the heap, allocate a HT
hashTable_ = new long[1 << lgArrLongs_];
}
moveDataToTgt(sketchIn.getCache(), curCount_);
} //end of state 5
//state 7
else if (curCount_ > 0 && sketchInEntries > 0) {
//Sets resulting hashTable, curCount and adjusts lgArrLongs
performIntersect(sketchIn);
} //end of state 7
else {
assert false : "Should not happen";
}
}
@Override
public CompactSketch getResult(final boolean dstOrdered, final WritableMemory dstMem) {
if (curCount_ < 0) {
throw new SketchesStateException(
"Calling getResult() with no intervening intersections would represent the infinite set, "
+ "which is not a legal result.");
}
long[] compactCache;
final boolean srcOrdered, srcCompact;
if (curCount_ == 0) {
compactCache = new long[0];
srcCompact = true;
srcOrdered = false; //hashTable, even tho empty
return CompactOperations.componentsToCompact(
thetaLong_, curCount_, seedHash_, empty_, srcCompact, srcOrdered, dstOrdered,
dstMem, compactCache);
}
//else curCount > 0
final long[] hashTable;
if (wmem_ != null) {
final int htLen = 1 << lgArrLongs_;
hashTable = new long[htLen];
wmem_.getLongArray(CONST_PREAMBLE_LONGS << 3, hashTable, 0, htLen);
} else {
hashTable = hashTable_;
}
compactCache = compactCachePart(hashTable, lgArrLongs_, curCount_, thetaLong_, dstOrdered);
srcCompact = true;
srcOrdered = dstOrdered;
return CompactOperations.componentsToCompact(
thetaLong_, curCount_, seedHash_, empty_, srcCompact, srcOrdered, dstOrdered,
dstMem, compactCache);
}
@Override
public boolean hasResult() {
return wmem_ != null ? wmem_.getInt(RETAINED_ENTRIES_INT) >= 0 : curCount_ >= 0;
}
@Override
public boolean isSameResource(final Memory that) {
return wmem_ != null ? wmem_.isSameResource(that) : false;
}
@Override
public void reset() {
hardReset();
}
@Override
public byte[] toByteArray() {
final int preBytes = CONST_PREAMBLE_LONGS << 3;
final int dataBytes = curCount_ > 0 ? 8 << lgArrLongs_ : 0;
final byte[] byteArrOut = new byte[preBytes + dataBytes];
if (wmem_ != null) {
wmem_.getByteArray(0, byteArrOut, 0, preBytes + dataBytes);
}
else {
final WritableMemory memOut = WritableMemory.writableWrap(byteArrOut);
//preamble
memOut.putByte(PREAMBLE_LONGS_BYTE, (byte) CONST_PREAMBLE_LONGS); //RF not used = 0
memOut.putByte(SER_VER_BYTE, (byte) SER_VER);
memOut.putByte(FAMILY_BYTE, (byte) Family.INTERSECTION.getID());
memOut.putByte(LG_NOM_LONGS_BYTE, (byte) 0); //not used
memOut.putByte(LG_ARR_LONGS_BYTE, (byte) lgArrLongs_);
if (empty_) { memOut.setBits(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK); }
else { memOut.clearBits(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK); }
memOut.putShort(SEED_HASH_SHORT, seedHash_);
memOut.putInt(RETAINED_ENTRIES_INT, curCount_);
memOut.putFloat(P_FLOAT, (float) 1.0);
memOut.putLong(THETA_LONG, thetaLong_);
//data
if (curCount_ > 0) {
memOut.putLongArray(preBytes, hashTable_, 0, 1 << lgArrLongs_);
}
}
return byteArrOut;
}
//restricted
/**
* Gets the number of retained entries from this operation. If negative, it is interpreted
* as the infinite <i>Universal Set</i>.
*/
@Override
int getRetainedEntries() {
return curCount_;
}
@Override
boolean isEmpty() {
return empty_;
}
@Override
long[] getCache() {
if (wmem_ == null) {
return hashTable_ != null ? hashTable_ : new long[0];
}
//Direct
final int arrLongs = 1 << lgArrLongs_;
final long[] outArr = new long[arrLongs];
wmem_.getLongArray(CONST_PREAMBLE_LONGS << 3, outArr, 0, arrLongs);
return outArr;
}
@Override
short getSeedHash() {
return seedHash_;
}
@Override
long getThetaLong() {
return thetaLong_;
}
private void performIntersect(final Sketch sketchIn) {
// curCount and input data are nonzero, match against HT
assert curCount_ > 0 && !empty_;
final long[] cacheIn = sketchIn.getCache();
final int arrLongsIn = cacheIn.length;
final long[] hashTable;
if (wmem_ != null) {
final int htLen = 1 << lgArrLongs_;
hashTable = new long[htLen];
wmem_.getLongArray(CONST_PREAMBLE_LONGS << 3, hashTable, 0, htLen);
} else {
hashTable = hashTable_;
}
//allocate space for matching
final long[] matchSet = new long[ min(curCount_, sketchIn.getRetainedEntries(true)) ];
int matchSetCount = 0;
if (sketchIn.isOrdered()) {
//ordered compact, which enables early stop
for (int i = 0; i < arrLongsIn; i++ ) {
final long hashIn = cacheIn[i];
//if (hashIn <= 0L) continue; //<= 0 should not happen
if (hashIn >= thetaLong_) {
break; //early stop assumes that hashes in input sketch are ordered!
}
final int foundIdx = hashSearch(hashTable, lgArrLongs_, hashIn);
if (foundIdx == -1) { continue; }
matchSet[matchSetCount++] = hashIn;
}
}
else {
//either unordered compact or hash table
for (int i = 0; i < arrLongsIn; i++ ) {
final long hashIn = cacheIn[i];
if (hashIn <= 0L || hashIn >= thetaLong_) { continue; }
final int foundIdx = hashSearch(hashTable, lgArrLongs_, hashIn);
if (foundIdx == -1) { continue; }
matchSet[matchSetCount++] = hashIn;
}
}
//reduce effective array size to minimum
curCount_ = matchSetCount;
lgArrLongs_ = minLgHashTableSize(matchSetCount, ThetaUtil.REBUILD_THRESHOLD);
if (wmem_ != null) {
insertCurCount(wmem_, matchSetCount);
insertLgArrLongs(wmem_, lgArrLongs_);
wmem_.clear(CONST_PREAMBLE_LONGS << 3, 8 << lgArrLongs_); //clear for rebuild
} else {
Arrays.fill(hashTable_, 0, 1 << lgArrLongs_, 0L); //clear for rebuild
}
if (curCount_ > 0) {
moveDataToTgt(matchSet, matchSetCount); //move matchSet to target
} else {
if (thetaLong_ == Long.MAX_VALUE) {
empty_ = true;
}
}
}
private void moveDataToTgt(final long[] arr, final int count) {
final int arrLongsIn = arr.length;
int tmpCnt = 0;
if (wmem_ != null) { //Off Heap puts directly into mem
final int preBytes = CONST_PREAMBLE_LONGS << 3;
final int lgArrLongs = lgArrLongs_;
final long thetaLong = thetaLong_;
for (int i = 0; i < arrLongsIn; i++ ) {
final long hashIn = arr[i];
if (continueCondition(thetaLong, hashIn)) { continue; }
hashInsertOnlyMemory(wmem_, lgArrLongs, hashIn, preBytes);
tmpCnt++;
}
} else { //On Heap. Assumes HT exists and is large enough
for (int i = 0; i < arrLongsIn; i++ ) {
final long hashIn = arr[i];
if (continueCondition(thetaLong_, hashIn)) { continue; }
hashInsertOnly(hashTable_, lgArrLongs_, hashIn);
tmpCnt++;
}
}
assert tmpCnt == count : "Intersection Count Check: got: " + tmpCnt + ", expected: " + count;
}
private void hardReset() {
resetCommon();
if (wmem_ != null) {
insertCurCount(wmem_, -1); //Universal Set
clearEmpty(wmem_); //false
}
curCount_ = -1; //Universal Set
empty_ = false;
}
private void resetToEmpty() {
resetCommon();
if (wmem_ != null) {
insertCurCount(wmem_, 0);
setEmpty(wmem_); //true
}
curCount_ = 0;
empty_ = true;
}
private void resetCommon() {
if (wmem_ != null) {
if (readOnly_) { throw new SketchesReadOnlyException(); }
wmem_.clear(CONST_PREAMBLE_LONGS << 3, 8 << ThetaUtil.MIN_LG_ARR_LONGS);
insertLgArrLongs(wmem_, ThetaUtil.MIN_LG_ARR_LONGS);
insertThetaLong(wmem_, Long.MAX_VALUE);
}
lgArrLongs_ = ThetaUtil.MIN_LG_ARR_LONGS;
thetaLong_ = Long.MAX_VALUE;
hashTable_ = null;
}
}
| 2,784 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/MemoryHashIterator.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import org.apache.datasketches.memory.Memory;
/**
* @author Lee Rhodes
*/
class MemoryHashIterator implements HashIterator {
private Memory mem;
private int arrLongs;
private long thetaLong;
private long offsetBytes;
private int index;
private long hash;
MemoryHashIterator(final Memory mem, final int arrLongs, final long thetaLong) {
this.mem = mem;
this.arrLongs = arrLongs;
this.thetaLong = thetaLong;
offsetBytes = PreambleUtil.extractPreLongs(mem) << 3;
index = -1;
hash = 0;
}
@Override
public long get() {
return hash;
}
@Override
public boolean next() {
while (++index < arrLongs) {
hash = mem.getLong(offsetBytes + (index << 3));
if ((hash != 0) && (hash < thetaLong)) {
return true;
}
}
return false;
}
}
| 2,785 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/SetOperationBuilder.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Util.LS;
import static org.apache.datasketches.common.Util.TAB;
import static org.apache.datasketches.common.Util.ceilingIntPowerOf2;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.DefaultMemoryRequestServer;
import org.apache.datasketches.memory.MemoryRequestServer;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* For building a new SetOperation.
*
* @author Lee Rhodes
*/
public class SetOperationBuilder {
private int bLgNomLongs;
private long bSeed;
private ResizeFactor bRF;
private float bP;
private MemoryRequestServer bMemReqSvr;
/**
* Constructor for building a new SetOperation. The default configuration is
* <ul>
* <li>Max Nominal Entries (max K):
* {@value org.apache.datasketches.thetacommon.ThetaUtil#DEFAULT_NOMINAL_ENTRIES}</li>
* <li>Seed: {@value org.apache.datasketches.thetacommon.ThetaUtil#DEFAULT_UPDATE_SEED}</li>
* <li>{@link ResizeFactor#X8}</li>
* <li>Input Sampling Probability: 1.0</li>
* <li>Memory: null</li>
* </ul>
*/
public SetOperationBuilder() {
bLgNomLongs = Integer.numberOfTrailingZeros(ThetaUtil.DEFAULT_NOMINAL_ENTRIES);
bSeed = ThetaUtil.DEFAULT_UPDATE_SEED;
bP = (float) 1.0;
bRF = ResizeFactor.X8;
bMemReqSvr = new DefaultMemoryRequestServer();
}
/**
* Sets the Maximum Nominal Entries (max K) for this set operation. The effective value of K of the result of a
* Set Operation can be less than max K, but never greater.
* The minimum value is 16 and the maximum value is 67,108,864, which is 2^26.
* @param nomEntries <a href="{@docRoot}/resources/dictionary.html#nomEntries">Nominal Entres</a>
* This will become the ceiling power of 2 if it is not a power of 2.
* @return this SetOperationBuilder
*/
public SetOperationBuilder setNominalEntries(final int nomEntries) {
bLgNomLongs = Integer.numberOfTrailingZeros(ceilingIntPowerOf2(nomEntries));
if ((bLgNomLongs > ThetaUtil.MAX_LG_NOM_LONGS) || (bLgNomLongs < ThetaUtil.MIN_LG_NOM_LONGS)) {
throw new SketchesArgumentException("Nominal Entries must be >= 16 and <= 67108864: "
+ nomEntries);
}
return this;
}
/**
* Alternative method of setting the Nominal Entries for this set operation from the log_base2 value.
* The minimum value is 4 and the maximum value is 26.
* Be aware that set operations as large as this maximum value may not have been
* thoroughly characterized for performance.
*
* @param lgNomEntries the log_base2 Nominal Entries.
* @return this SetOperationBuilder
*/
public SetOperationBuilder setLogNominalEntries(final int lgNomEntries) {
bLgNomLongs = ThetaUtil.checkNomLongs(1 << lgNomEntries);
return this;
}
/**
* Returns Log-base 2 Nominal Entries
* @return Log-base 2 Nominal Entries
*/
public int getLgNominalEntries() {
return bLgNomLongs;
}
/**
* Sets the long seed value that is require by the hashing function.
* @param seed <a href="{@docRoot}/resources/dictionary.html#seed">See seed</a>
* @return this SetOperationBuilder
*/
public SetOperationBuilder setSeed(final long seed) {
bSeed = seed;
return this;
}
/**
* Returns the seed
* @return the seed
*/
public long getSeed() {
return bSeed;
}
/**
* Sets the upfront uniform sampling probability, <i>p</i>. Although this functionality is
* implemented for Unions only, it rarely makes sense to use it. The proper use of upfront
* sampling is when building the sketches.
* @param p <a href="{@docRoot}/resources/dictionary.html#p">See Sampling Probability, <i>p</i></a>
* @return this SetOperationBuilder
*/
public SetOperationBuilder setP(final float p) {
if ((p <= 0.0) || (p > 1.0)) {
throw new SketchesArgumentException("p must be > 0 and <= 1.0: " + p);
}
bP = p;
return this;
}
/**
* Returns the pre-sampling probability <i>p</i>
* @return the pre-sampling probability <i>p</i>
*/
public float getP() {
return bP;
}
/**
* Sets the cache Resize Factor
* @param rf <a href="{@docRoot}/resources/dictionary.html#resizeFactor">See Resize Factor</a>
* @return this SetOperationBuilder
*/
public SetOperationBuilder setResizeFactor(final ResizeFactor rf) {
bRF = rf;
return this;
}
/**
* Returns the Resize Factor
* @return the Resize Factor
*/
public ResizeFactor getResizeFactor() {
return bRF;
}
/**
* Set the MemoryRequestServer
* @param memReqSvr the given MemoryRequestServer
* @return this SetOperationBuilder
*/
public SetOperationBuilder setMemoryRequestServer(final MemoryRequestServer memReqSvr) {
bMemReqSvr = memReqSvr;
return this;
}
/**
* Returns the MemoryRequestServer
* @return the MemoryRequestServer
*/
public MemoryRequestServer getMemoryRequestServer() {
return bMemReqSvr;
}
/**
* Returns a SetOperation with the current configuration of this Builder and the given Family.
* @param family the chosen SetOperation family
* @return a SetOperation
*/
public SetOperation build(final Family family) {
return build(family, null);
}
/**
* Returns a SetOperation with the current configuration of this Builder, the given Family
* and the given destination memory. Note that the destination memory cannot be used with AnotB.
* @param family the chosen SetOperation family
* @param dstMem The destination Memory.
* @return a SetOperation
*/
public SetOperation build(final Family family, final WritableMemory dstMem) {
SetOperation setOp = null;
switch (family) {
case UNION: {
if (dstMem == null) {
setOp = UnionImpl.initNewHeapInstance(bLgNomLongs, bSeed, bP, bRF);
}
else {
setOp = UnionImpl.initNewDirectInstance(bLgNomLongs, bSeed, bP, bRF, bMemReqSvr, dstMem);
}
break;
}
case INTERSECTION: {
if (dstMem == null) {
setOp = IntersectionImpl.initNewHeapInstance(bSeed);
}
else {
setOp = IntersectionImpl.initNewDirectInstance(bSeed, dstMem);
}
break;
}
case A_NOT_B: {
if (dstMem == null) {
setOp = new AnotBimpl(bSeed);
}
else {
throw new SketchesArgumentException(
"AnotB can not be persisted.");
}
break;
}
default:
throw new SketchesArgumentException(
"Given Family cannot be built as a SetOperation: " + family.toString());
}
return setOp;
}
/**
* Convenience method, returns a configured SetOperation Union with
* <a href="{@docRoot}/resources/dictionary.html#defaultNomEntries">Default Nominal Entries</a>
* @return a Union object
*/
public Union buildUnion() {
return (Union) build(Family.UNION);
}
/**
* Convenience method, returns a configured SetOperation Union with
* <a href="{@docRoot}/resources/dictionary.html#defaultNomEntries">Default Nominal Entries</a>
* and the given destination memory.
* @param dstMem The destination Memory.
* @return a Union object
*/
public Union buildUnion(final WritableMemory dstMem) {
return (Union) build(Family.UNION, dstMem);
}
/**
* Convenience method, returns a configured SetOperation Intersection with
* <a href="{@docRoot}/resources/dictionary.html#defaultNomEntries">Default Nominal Entries</a>
* @return an Intersection object
*/
public Intersection buildIntersection() {
return (Intersection) build(Family.INTERSECTION);
}
/**
* Convenience method, returns a configured SetOperation Intersection with
* <a href="{@docRoot}/resources/dictionary.html#defaultNomEntries">Default Nominal Entries</a>
* and the given destination memory.
* @param dstMem The destination Memory.
* @return an Intersection object
*/
public Intersection buildIntersection(final WritableMemory dstMem) {
return (Intersection) build(Family.INTERSECTION, dstMem);
}
/**
* Convenience method, returns a configured SetOperation ANotB with
* <a href="{@docRoot}/resources/dictionary.html#defaultUpdateSeed">Default Update Seed</a>
* @return an ANotB object
*/
public AnotB buildANotB() {
return (AnotB) build(Family.A_NOT_B);
}
@Override
public String toString() {
final StringBuilder sb = new StringBuilder();
sb.append("SetOperationBuilder configuration:").append(LS);
sb.append("LgK:").append(TAB).append(bLgNomLongs).append(LS);
sb.append("K:").append(TAB).append(1 << bLgNomLongs).append(LS);
sb.append("Seed:").append(TAB).append(bSeed).append(LS);
sb.append("p:").append(TAB).append(bP).append(LS);
sb.append("ResizeFactor:").append(TAB).append(bRF).append(LS);
final String mrsStr = bMemReqSvr.getClass().getSimpleName();
sb.append("MemoryRequestServer:").append(TAB).append(mrsStr).append(LS);
return sb.toString();
}
}
| 2,786 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/PreambleUtil.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.common.Util.LS;
import static org.apache.datasketches.common.Util.zeroPad;
import java.nio.ByteOrder;
import org.apache.datasketches.common.Family;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.Util;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
//@formatter:off
/**
* This class defines the preamble data structure and provides basic utilities for some of the key
* fields.
* <p>The intent of the design of this class was to isolate the detailed knowledge of the bit and
* byte layout of the serialized form of the sketches derived from the Sketch class into one place.
* This allows the possibility of the introduction of different serialization
* schemes with minimal impact on the rest of the library.</p>
*
* <p>
* MAP: Low significance bytes of this <i>long</i> data structure are on the right. However, the
* multi-byte integers (<i>int</i> and <i>long</i>) are stored in native byte order. The
* <i>byte</i> values are treated as unsigned.</p>
*
* <p>An empty CompactSketch only requires 8 bytes.
* Flags: notSI, Ordered*, Compact, Empty*, ReadOnly, LE.
* (*) Earlier versions did not set these.</p>
*
* <pre>
* Long || Start Byte Adr:
* Adr:
* || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* 0 || Seed Hash | Flags | | | FamID | SerVer | PreLongs = 1 |
* </pre>
*
* <p>A SingleItemSketch (extends CompactSketch) requires an 8 byte preamble plus a single
* hash item of 8 bytes. Flags: SingleItem*, Ordered, Compact, notEmpty, ReadOnly, LE.
* (*) Earlier versions did not set these.</p>
*
* <pre>
* Long || Start Byte Adr:
* Adr:
* || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* 0 || Seed Hash | Flags | | | FamID | SerVer | PreLongs = 1 |
*
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||---------------------------Single long hash----------------------------------------|
* </pre>
*
* <p>An exact (non-estimating) CompactSketch requires 16 bytes of preamble plus a compact array of
* longs.</p>
*
* <pre>
* Long || Start Byte Adr:
* Adr:
* || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* 0 || Seed Hash | Flags | | | FamID | SerVer | PreLongs = 2 |
*
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||-----------------p-----------------|----------Retained Entries Count---------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||----------------------Start of Compact Long Array----------------------------------|
* </pre>
*
* <p>An estimating CompactSketch requires 24 bytes of preamble plus a compact array of longs.</p>
*
* <pre>
* Long || Start Byte Adr:
* Adr:
* || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* 0 || Seed Hash | Flags | | | FamID | SerVer | PreLongs = 3 |
*
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||-----------------p-----------------|----------Retained Entries Count---------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||------------------------------THETA_LONG-------------------------------------------|
*
* || 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 |
* 3 ||----------------------Start of Compact Long Array----------------------------------|
* </pre>
*
* <p>The UpdateSketch and AlphaSketch require 24 bytes of preamble followed by a non-compact
* array of longs representing a hash table.</p>
*
* <p>The following table applies to both the Theta UpdateSketch and the Alpha Sketch</p>
* <pre>
* Long || Start Byte Adr:
* Adr:
* || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* 0 || Seed Hash | Flags | LgArr | lgNom | FamID | SerVer | RF, PreLongs = 3 |
*
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||-----------------p-----------------|----------Retained Entries Count---------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||------------------------------THETA_LONG-------------------------------------------|
*
* || 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 |
* 3 ||----------------------Start of Hash Table of longs---------------------------------|
* </pre>
*
* <p> Union objects require 32 bytes of preamble plus a non-compact array of longs representing a
* hash table.</p>
*
* <pre>
* Long || Start Byte Adr:
* Adr:
* || 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
* 0 || Seed Hash | Flags | LgArr | lgNom | FamID | SerVer | RF, PreLongs = 4 |
*
* || 15 | 14 | 13 | 12 | 11 | 10 | 9 | 8 |
* 1 ||-----------------p-----------------|----------Retained Entries Count---------------|
*
* || 23 | 22 | 21 | 20 | 19 | 18 | 17 | 16 |
* 2 ||------------------------------THETA_LONG-------------------------------------------|
*
* || 31 | 30 | 29 | 28 | 27 | 26 | 25 | 24 |
* 3 ||---------------------------UNION THETA LONG----------------------------------------|
*
* || 39 | 38 | 37 | 36 | 35 | 34 | 33 | 32 |
* 4 ||----------------------Start of Hash Table of longs---------------------------------|
*
* </pre>
*
* @author Lee Rhodes
*/
final class PreambleUtil {
private PreambleUtil() {}
// ###### DO NOT MESS WITH THIS FROM HERE ...
// Preamble byte Addresses
static final int PREAMBLE_LONGS_BYTE = 0; //lower 6 bits in byte.
static final int LG_RESIZE_FACTOR_BIT = 6; //upper 2 bits in byte. Not used by compact, direct
static final int SER_VER_BYTE = 1;
static final int FAMILY_BYTE = 2; //SerVer1,2 was SKETCH_TYPE_BYTE
static final int LG_NOM_LONGS_BYTE = 3; //not used by compact
static final int LG_ARR_LONGS_BYTE = 4; //not used by compact
static final int FLAGS_BYTE = 5;
static final int SEED_HASH_SHORT = 6; //byte 6,7
static final int RETAINED_ENTRIES_INT = 8; //8 byte aligned
static final int P_FLOAT = 12; //4 byte aligned, not used by compact
static final int THETA_LONG = 16; //8-byte aligned
static final int UNION_THETA_LONG = 24; //8-byte aligned, only used by Union
// flag bit masks
static final int BIG_ENDIAN_FLAG_MASK = 1; //SerVer 1, 2, 3
static final int READ_ONLY_FLAG_MASK = 2; //Set but not read. Reserved. SerVer 1, 2, 3
static final int EMPTY_FLAG_MASK = 4; //SerVer 2, 3
static final int COMPACT_FLAG_MASK = 8; //SerVer 2 was NO_REBUILD_FLAG_MASK, 3
static final int ORDERED_FLAG_MASK = 16;//SerVer 2 was UNORDERED_FLAG_MASK, 3
static final int SINGLEITEM_FLAG_MASK = 32;//SerVer 3
//The last 2 bits of the flags byte are reserved and assumed to be zero, for now.
//Backward compatibility: SerVer1 preamble always 3 longs, SerVer2 preamble: 1, 2, 3 longs
// SKETCH_TYPE_BYTE 2 //SerVer1, SerVer2
// V1, V2 types: Alpha = 1, QuickSelect = 2, SetSketch = 3; V3 only: Buffered QS = 4
static final int LG_RESIZE_RATIO_BYTE_V1 = 5; //used by SerVer 1
static final int FLAGS_BYTE_V1 = 6; //used by SerVer 1
//Other constants
static final int SER_VER = 3;
// serial version 4 compressed ordered sketch, not empty, not single item
static final int ENTRY_BITS_BYTE_V4 = 3; // number of bits packed in deltas between hashes
static final int NUM_ENTRIES_BYTES_BYTE_V4 = 4; // number of bytes used for the number of entries
static final int THETA_LONG_V4 = 8; //8-byte aligned
static final boolean NATIVE_ORDER_IS_BIG_ENDIAN =
(ByteOrder.nativeOrder() == ByteOrder.BIG_ENDIAN);
/**
* Computes the number of bytes required for a non-full sized sketch in hash-table form.
* This can be used to compute current storage size for heap sketches, or current off-heap memory
* required for off-heap (direct) sketches. This does not apply for compact sketches.
* @param lgArrLongs log2(current hash-table size)
* @param preambleLongs current preamble size
* @return the size in bytes
*/
static final int getMemBytes(final int lgArrLongs, final int preambleLongs) {
return (8 << lgArrLongs) + (preambleLongs << 3);
}
// STRINGS
/**
* Returns a human readable string summary of the preamble state of the given byte array.
* Used primarily in testing.
*
* @param byteArr the given byte array.
* @return the summary preamble string.
*/
static String preambleToString(final byte[] byteArr) {
final Memory mem = Memory.wrap(byteArr);
return preambleToString(mem);
}
/**
* Returns a human readable string summary of the preamble state of the given Memory.
* Note: other than making sure that the given Memory size is large
* enough for just the preamble, this does not do much value checking of the contents of the
* preamble as this is primarily a tool for debugging the preamble visually.
*
* @param mem the given Memory.
* @return the summary preamble string.
*/
static String preambleToString(final Memory mem) {
final int preLongs = getAndCheckPreLongs(mem);
final int rfId = extractLgResizeFactor(mem);
final ResizeFactor rf = ResizeFactor.getRF(rfId);
final int serVer = extractSerVer(mem);
final int familyId = extractFamilyID(mem);
final Family family = Family.idToFamily(familyId);
final int lgNomLongs = extractLgNomLongs(mem);
final int lgArrLongs = extractLgArrLongs(mem);
//Flags
final int flags = extractFlags(mem);
final String flagsStr = (flags) + ", 0x" + (Integer.toHexString(flags)) + ", "
+ zeroPad(Integer.toBinaryString(flags), 8);
final String nativeOrder = ByteOrder.nativeOrder().toString();
final boolean bigEndian = (flags & BIG_ENDIAN_FLAG_MASK) > 0;
final boolean readOnly = (flags & READ_ONLY_FLAG_MASK) > 0;
final boolean empty = (flags & EMPTY_FLAG_MASK) > 0;
final boolean compact = (flags & COMPACT_FLAG_MASK) > 0;
final boolean ordered = (flags & ORDERED_FLAG_MASK) > 0;
final boolean singleItem = (flags & SINGLEITEM_FLAG_MASK) > 0; //!empty && (preLongs == 1);
final int seedHash = extractSeedHash(mem);
//assumes preLongs == 1; empty or singleItem
int curCount = singleItem ? 1 : 0;
float p = (float) 1.0; //preLongs 1 or 2
long thetaLong = Long.MAX_VALUE; //preLongs 1 or 2
long thetaULong = thetaLong; //preLongs 1, 2 or 3
if (preLongs == 2) { //exact (non-estimating) CompactSketch
curCount = extractCurCount(mem);
p = extractP(mem);
}
else if (preLongs == 3) { //Update Sketch
curCount = extractCurCount(mem);
p = extractP(mem);
thetaLong = extractThetaLong(mem);
thetaULong = thetaLong;
}
else if (preLongs == 4) { //Union
curCount = extractCurCount(mem);
p = extractP(mem);
thetaLong = extractThetaLong(mem);
thetaULong = extractUnionThetaLong(mem);
}
//else the same as an empty sketch or singleItem
final double thetaDbl = thetaLong / Util.LONG_MAX_VALUE_AS_DOUBLE;
final String thetaHex = zeroPad(Long.toHexString(thetaLong), 16);
final double thetaUDbl = thetaULong / Util.LONG_MAX_VALUE_AS_DOUBLE;
final String thetaUHex = zeroPad(Long.toHexString(thetaULong), 16);
final StringBuilder sb = new StringBuilder();
sb.append(LS);
sb.append("### SKETCH PREAMBLE SUMMARY:").append(LS);
sb.append("Native Byte Order : ").append(nativeOrder).append(LS);
sb.append("Byte 0: Preamble Longs : ").append(preLongs).append(LS);
sb.append("Byte 0: ResizeFactor : ").append(rfId + ", " + rf.toString()).append(LS);
sb.append("Byte 1: Serialization Version: ").append(serVer).append(LS);
sb.append("Byte 2: Family : ").append(familyId + ", " + family.toString()).append(LS);
sb.append("Byte 3: LgNomLongs : ").append(lgNomLongs).append(LS);
sb.append("Byte 4: LgArrLongs : ").append(lgArrLongs).append(LS);
sb.append("Byte 5: Flags Field : ").append(flagsStr).append(LS);
sb.append(" Bit Flag Name : State:").append(LS);
sb.append(" 0 BIG_ENDIAN_STORAGE : ").append(bigEndian).append(LS);
sb.append(" 1 READ_ONLY : ").append(readOnly).append(LS);
sb.append(" 2 EMPTY : ").append(empty).append(LS);
sb.append(" 3 COMPACT : ").append(compact).append(LS);
sb.append(" 4 ORDERED : ").append(ordered).append(LS);
sb.append(" 5 SINGLE_ITEM : ").append(singleItem).append(LS);
sb.append("Bytes 6-7 : Seed Hash Hex : ").append(Integer.toHexString(seedHash)).append(LS);
if (preLongs == 1) {
sb.append(" --ABSENT FIELDS, ASSUMED:").append(LS);
sb.append("Bytes 8-11 : CurrentCount : ").append(curCount).append(LS);
sb.append("Bytes 12-15: P : ").append(p).append(LS);
sb.append("Bytes 16-23: Theta (double) : ").append(thetaDbl).append(LS);
sb.append(" Theta (long) : ").append(thetaLong).append(LS);
sb.append(" Theta (long,hex) : ").append(thetaHex).append(LS);
}
else if (preLongs == 2) {
sb.append("Bytes 8-11 : CurrentCount : ").append(curCount).append(LS);
sb.append("Bytes 12-15: P : ").append(p).append(LS);
sb.append(" --ABSENT, ASSUMED:").append(LS);
sb.append("Bytes 16-23: Theta (double) : ").append(thetaDbl).append(LS);
sb.append(" Theta (long) : ").append(thetaLong).append(LS);
sb.append(" Theta (long,hex) : ").append(thetaHex).append(LS);
}
else if (preLongs == 3) {
sb.append("Bytes 8-11 : CurrentCount : ").append(curCount).append(LS);
sb.append("Bytes 12-15: P : ").append(p).append(LS);
sb.append("Bytes 16-23: Theta (double) : ").append(thetaDbl).append(LS);
sb.append(" Theta (long) : ").append(thetaLong).append(LS);
sb.append(" Theta (long,hex) : ").append(thetaHex).append(LS);
}
else { //preLongs == 4
sb.append("Bytes 8-11 : CurrentCount : ").append(curCount).append(LS);
sb.append("Bytes 12-15: P : ").append(p).append(LS);
sb.append("Bytes 16-23: Theta (double) : ").append(thetaDbl).append(LS);
sb.append(" Theta (long) : ").append(thetaLong).append(LS);
sb.append(" Theta (long,hex) : ").append(thetaHex).append(LS);
sb.append("Bytes 25-31: ThetaU (double) : ").append(thetaUDbl).append(LS);
sb.append(" ThetaU (long) : ").append(thetaULong).append(LS);
sb.append(" ThetaU (long,hex): ").append(thetaUHex).append(LS);
}
sb.append( "Preamble Bytes : ").append(preLongs * 8).append(LS);
sb.append( "Data Bytes : ").append(curCount * 8).append(LS);
sb.append( "TOTAL Sketch Bytes : ").append((preLongs + curCount) * 8).append(LS);
sb.append( "TOTAL Capacity Bytes : ").append(mem.getCapacity()).append(LS);
sb.append("### END SKETCH PREAMBLE SUMMARY").append(LS);
return sb.toString();
}
//@formatter:on
static int extractPreLongs(final Memory mem) {
return mem.getByte(PREAMBLE_LONGS_BYTE) & 0X3F;
}
static int extractLgResizeFactor(final Memory mem) {
return (mem.getByte(PREAMBLE_LONGS_BYTE) >>> LG_RESIZE_FACTOR_BIT) & 0X3;
}
static int extractLgResizeRatioV1(final Memory mem) {
return mem.getByte(LG_RESIZE_RATIO_BYTE_V1) & 0X3;
}
static int extractSerVer(final Memory mem) {
return mem.getByte(SER_VER_BYTE) & 0XFF;
}
static int extractFamilyID(final Memory mem) {
return mem.getByte(FAMILY_BYTE) & 0XFF;
}
static int extractLgNomLongs(final Memory mem) {
return mem.getByte(LG_NOM_LONGS_BYTE) & 0XFF;
}
static int extractLgArrLongs(final Memory mem) {
return mem.getByte(LG_ARR_LONGS_BYTE) & 0XFF;
}
static int extractFlags(final Memory mem) {
return mem.getByte(FLAGS_BYTE) & 0XFF;
}
static int extractFlagsV1(final Memory mem) {
return mem.getByte(FLAGS_BYTE_V1) & 0XFF;
}
static int extractSeedHash(final Memory mem) {
return mem.getShort(SEED_HASH_SHORT) & 0XFFFF;
}
static int extractCurCount(final Memory mem) {
return mem.getInt(RETAINED_ENTRIES_INT);
}
static float extractP(final Memory mem) {
return mem.getFloat(P_FLOAT);
}
static long extractThetaLong(final Memory mem) {
return mem.getLong(THETA_LONG);
}
static long extractUnionThetaLong(final Memory mem) {
return mem.getLong(UNION_THETA_LONG);
}
static int extractEntryBitsV4(final Memory mem) {
return mem.getByte(ENTRY_BITS_BYTE_V4) & 0XFF;
}
static int extractNumEntriesBytesV4(final Memory mem) {
return mem.getByte(NUM_ENTRIES_BYTES_BYTE_V4) & 0XFF;
}
static long extractThetaLongV4(final Memory mem) {
return mem.getLong(THETA_LONG_V4);
}
/**
* Sets PreLongs in the low 6 bits and sets LgRF in the upper 2 bits = 0.
* @param wmem the target WritableMemory
* @param preLongs the given number of preamble longs
*/
static void insertPreLongs(final WritableMemory wmem, final int preLongs) {
wmem.putByte(PREAMBLE_LONGS_BYTE, (byte) (preLongs & 0X3F));
}
/**
* Sets the top 2 lgRF bits and does not affect the lower 6 bits (PreLongs).
* To work properly, this should be called after insertPreLongs().
* @param wmem the target WritableMemory
* @param rf the given lgRF bits
*/
static void insertLgResizeFactor(final WritableMemory wmem, final int rf) {
final int curByte = wmem.getByte(PREAMBLE_LONGS_BYTE) & 0xFF;
final int shift = LG_RESIZE_FACTOR_BIT; // shift in bits
final int mask = 3;
final byte newByte = (byte) (((rf & mask) << shift) | (~(mask << shift) & curByte));
wmem.putByte(PREAMBLE_LONGS_BYTE, newByte);
}
static void insertSerVer(final WritableMemory wmem, final int serVer) {
wmem.putByte(SER_VER_BYTE, (byte) serVer);
}
static void insertFamilyID(final WritableMemory wmem, final int famId) {
wmem.putByte(FAMILY_BYTE, (byte) famId);
}
static void insertLgNomLongs(final WritableMemory wmem, final int lgNomLongs) {
wmem.putByte(LG_NOM_LONGS_BYTE, (byte) lgNomLongs);
}
static void insertLgArrLongs(final WritableMemory wmem, final int lgArrLongs) {
wmem.putByte(LG_ARR_LONGS_BYTE, (byte) lgArrLongs);
}
static void insertFlags(final WritableMemory wmem, final int flags) {
wmem.putByte(FLAGS_BYTE, (byte) flags);
}
static void insertSeedHash(final WritableMemory wmem, final int seedHash) {
wmem.putShort(SEED_HASH_SHORT, (short) seedHash);
}
static void insertCurCount(final WritableMemory wmem, final int curCount) {
wmem.putInt(RETAINED_ENTRIES_INT, curCount);
}
static void insertP(final WritableMemory wmem, final float p) {
wmem.putFloat(P_FLOAT, p);
}
static void insertThetaLong(final WritableMemory wmem, final long thetaLong) {
wmem.putLong(THETA_LONG, thetaLong);
}
static void insertUnionThetaLong(final WritableMemory wmem, final long unionThetaLong) {
wmem.putLong(UNION_THETA_LONG, unionThetaLong);
}
static void setEmpty(final WritableMemory wmem) {
int flags = wmem.getByte(FLAGS_BYTE) & 0XFF;
flags |= EMPTY_FLAG_MASK;
wmem.putByte(FLAGS_BYTE, (byte) flags);
}
static void clearEmpty(final WritableMemory wmem) {
int flags = wmem.getByte(FLAGS_BYTE) & 0XFF;
flags &= ~EMPTY_FLAG_MASK;
wmem.putByte(FLAGS_BYTE, (byte) flags);
}
static boolean isEmptyFlag(final Memory mem) {
return ((extractFlags(mem) & EMPTY_FLAG_MASK) > 0);
}
/**
* Checks Memory for capacity to hold the preamble and returns the extracted preLongs.
* @param mem the given Memory
* @return the extracted prelongs value.
*/
static int getAndCheckPreLongs(final Memory mem) {
final long cap = mem.getCapacity();
if (cap < 8) {
throwNotBigEnough(cap, 8);
}
final int preLongs = extractPreLongs(mem);
final int required = Math.max(preLongs << 3, 8);
if (cap < required) {
throwNotBigEnough(cap, required);
}
return preLongs;
}
static final short checkMemorySeedHash(final Memory mem, final long seed) {
final short seedHashMem = (short) extractSeedHash(mem);
ThetaUtil.checkSeedHashes(seedHashMem, ThetaUtil.computeSeedHash(seed)); //throws if bad seedHash
return seedHashMem;
}
private static void throwNotBigEnough(final long cap, final int required) {
throw new SketchesArgumentException(
"Possible Corruption: Size of byte array or Memory not large enough: Size: " + cap
+ ", Required: " + required);
}
}
| 2,787 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/package-info.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
/**
* The theta package contains the basic sketch classes that are members of the
* <a href="{@docRoot}/resources/dictionary.html#thetaSketch">Theta Sketch Framework</a>.
*
* <p>There is a separate Tuple package for many of the sketches that are derived from the
* same algorithms defined in the Theta Sketch Framework paper.</p>
*/
package org.apache.datasketches.theta;
| 2,788 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/ForwardCompatibility.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.PreambleUtil.extractCurCount;
import static org.apache.datasketches.theta.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.extractThetaLong;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
/**
* Used to convert older serialization versions 1 and 2 to version 3. The Serialization
* Version is the version of the sketch binary image format and should not be confused with the
* version number of the Open Source DataSketches Library.
*
* @author Lee Rhodes
*/
final class ForwardCompatibility {
/**
* Convert a serialization version (SerVer) 1 sketch (~Feb 2014) to a SerVer 3 sketch.
* Note: SerVer 1 sketches always have (metadata) preamble-longs of 3 and are always stored
* in a compact ordered form, but with 3 different sketch types. All SerVer 1 sketches will
* be converted to a SerVer 3 sketches. There is no concept of p-sampling, no empty bit.
*
* @param srcMem the image of a SerVer 1 sketch
*
* @param seedHash <a href="{@docRoot}/resources/dictionary.html#seedHash">See Seed Hash</a>.
* The seedHash that matches the seedHash of the original seed used to construct the sketch.
* Note: SerVer 1 sketches do not have the concept of the SeedHash, so the seedHash provided here
* MUST be derived from the actual seed that was used when the SerVer 1 sketches were built.
* @return a SerVer 3 {@link CompactSketch}.
*/
static final CompactSketch heapify1to3(final Memory srcMem, final short seedHash) {
final int memCap = (int) srcMem.getCapacity();
final int preLongs = extractPreLongs(srcMem); //always 3 for serVer 1
if (preLongs != 3) {
throw new SketchesArgumentException("PreLongs must be 3 for SerVer 1: " + preLongs);
}
final int familyId = extractFamilyID(srcMem); //1,2,3
if ((familyId < 1) || (familyId > 3)) {
throw new SketchesArgumentException("Family ID (Sketch Type) must be 1 to 3: " + familyId);
}
final int curCount = extractCurCount(srcMem);
final long thetaLong = extractThetaLong(srcMem);
final boolean empty = (curCount == 0) && (thetaLong == Long.MAX_VALUE);
if (empty || (memCap <= 24)) { //return empty
return EmptyCompactSketch.getInstance();
}
final int reqCap = (curCount + preLongs) << 3;
validateInputSize(reqCap, memCap);
if ((thetaLong == Long.MAX_VALUE) && (curCount == 1)) {
final long hash = srcMem.getLong(preLongs << 3);
return new SingleItemSketch(hash, seedHash);
}
//theta < 1.0 and/or curCount > 1
final long[] compactOrderedCache = new long[curCount];
srcMem.getLongArray(preLongs << 3, compactOrderedCache, 0, curCount);
return new HeapCompactSketch(compactOrderedCache, false, seedHash, curCount, thetaLong, true);
}
/**
* Convert a serialization version (SerVer) 2 sketch to a SerVer 3 HeapCompactOrderedSketch.
* Note: SerVer 2 sketches can have metadata-longs of 1,2 or 3 and are always stored
* in a compact ordered form (not as a hash table), but with 4 different sketch types.
* @param srcMem the image of a SerVer 2 sketch
* @param seedHash <a href="{@docRoot}/resources/dictionary.html#seedHash">See Seed Hash</a>.
* The seed used for building the sketch image in srcMem
* @return a SerVer 3 HeapCompactOrderedSketch
*/
static final CompactSketch heapify2to3(final Memory srcMem, final short seedHash) {
final int memCap = (int) srcMem.getCapacity();
final int preLongs = extractPreLongs(srcMem); //1,2 or 3
final int familyId = extractFamilyID(srcMem); //1,2,3,4
if ((familyId < 1) || (familyId > 4)) {
throw new SketchesArgumentException("Family (Sketch Type) must be 1 to 4: " + familyId);
}
int reqBytesIn = 8;
int curCount = 0;
long thetaLong = Long.MAX_VALUE;
if (preLongs == 1) {
reqBytesIn = 8;
validateInputSize(reqBytesIn, memCap);
return EmptyCompactSketch.getInstance();
}
if (preLongs == 2) { //includes pre0 + count, no theta (== 1.0)
reqBytesIn = preLongs << 3;
validateInputSize(reqBytesIn, memCap);
curCount = extractCurCount(srcMem);
if (curCount == 0) {
return EmptyCompactSketch.getInstance();
}
if (curCount == 1) {
reqBytesIn = (preLongs + 1) << 3;
validateInputSize(reqBytesIn, memCap);
final long hash = srcMem.getLong(preLongs << 3);
return new SingleItemSketch(hash, seedHash);
}
//curCount > 1
reqBytesIn = (curCount + preLongs) << 3;
validateInputSize(reqBytesIn, memCap);
final long[] compactOrderedCache = new long[curCount];
srcMem.getLongArray(preLongs << 3, compactOrderedCache, 0, curCount);
return new HeapCompactSketch(compactOrderedCache, false, seedHash, curCount, thetaLong,true);
}
if (preLongs == 3) { //pre0 + count + theta
reqBytesIn = (preLongs) << 3; //
validateInputSize(reqBytesIn, memCap);
curCount = extractCurCount(srcMem);
thetaLong = extractThetaLong(srcMem);
if ((curCount == 0) && (thetaLong == Long.MAX_VALUE)) {
return EmptyCompactSketch.getInstance();
}
if ((curCount == 1) && (thetaLong == Long.MAX_VALUE)) {
reqBytesIn = (preLongs + 1) << 3;
validateInputSize(reqBytesIn, memCap);
final long hash = srcMem.getLong(preLongs << 3);
return new SingleItemSketch(hash, seedHash);
}
//curCount > 1 and/or theta < 1.0
reqBytesIn = (curCount + preLongs) << 3;
validateInputSize(reqBytesIn, memCap);
final long[] compactOrderedCache = new long[curCount];
srcMem.getLongArray(preLongs << 3, compactOrderedCache, 0, curCount);
return new HeapCompactSketch(compactOrderedCache, false, seedHash, curCount, thetaLong, true);
}
throw new SketchesArgumentException("PreLongs must be 1,2, or 3: " + preLongs);
}
private static final void validateInputSize(final int reqBytesIn, final int memCap) {
if (reqBytesIn > memCap) {
throw new SketchesArgumentException(
"Input Memory or byte[] size is too small: Required Bytes: " + reqBytesIn
+ ", bytesIn: " + memCap);
}
}
}
| 2,789 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/ConcurrentHeapQuickSelectSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.common.SuppressFBWarnings;
/**
* A concurrent shared sketch that is based on HeapQuickSelectSketch.
* It reflects all data processed by a single or multiple update threads, and can serve queries at
* any time.
* Background propagation threads are used to propagate data from thread local buffers into this
* sketch which stores the most up-to-date estimation of number of unique items.
*
* @author eshcar
* @author Lee Rhodes
*/
final class ConcurrentHeapQuickSelectSketch extends HeapQuickSelectSketch
implements ConcurrentSharedThetaSketch {
// The propagation thread
private volatile ExecutorService executorService_;
//A flag to coordinate between several eager propagation threads
private final AtomicBoolean sharedPropagationInProgress_;
// Theta value of concurrent sketch
private volatile long volatileThetaLong_;
// A snapshot of the estimated number of unique entries
private volatile double volatileEstimate_;
// Num of retained entries in which the sketch toggles from sync (exact) mode to async
// propagation mode
private final long exactLimit_;
// An epoch defines an interval between two resets. A propagation invoked at epoch i cannot
// affect the sketch at epoch j > i.
private volatile long epoch_;
/**
* Construct a new sketch instance on the java heap.
*
* @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 maxConcurrencyError the max error value including error induced by concurrency
*
*/
ConcurrentHeapQuickSelectSketch(final int lgNomLongs, final long seed,
final double maxConcurrencyError) {
super(lgNomLongs, seed, 1.0F, //p
ResizeFactor.X1, //rf,
false); //unionGadget
volatileThetaLong_ = Long.MAX_VALUE;
volatileEstimate_ = 0;
exactLimit_ = ConcurrentSharedThetaSketch.computeExactLimit(1L << getLgNomLongs(),
maxConcurrencyError);
sharedPropagationInProgress_ = new AtomicBoolean(false);
epoch_ = 0;
initBgPropagationService();
}
ConcurrentHeapQuickSelectSketch(final UpdateSketch sketch, final long seed,
final double maxConcurrencyError) {
super(sketch.getLgNomLongs(), seed, 1.0F, //p
ResizeFactor.X1, //rf,
false); //unionGadget
exactLimit_ = ConcurrentSharedThetaSketch.computeExactLimit(1L << getLgNomLongs(),
maxConcurrencyError);
sharedPropagationInProgress_ = new AtomicBoolean(false);
epoch_ = 0;
initBgPropagationService();
for (final long hashIn : sketch.getCache()) {
propagate(hashIn);
}
thetaLong_ = sketch.getThetaLong();
updateVolatileTheta();
updateEstimationSnapshot();
}
//Sketch overrides
@Override
public double getEstimate() {
return volatileEstimate_;
}
@Override
public boolean isEstimationMode() {
return (getRetainedEntries(false) > exactLimit_) || super.isEstimationMode();
}
@Override
public byte[] toByteArray() {
while (!sharedPropagationInProgress_.compareAndSet(false, true)) { } //busy wait till free
final byte[] res = super.toByteArray();
sharedPropagationInProgress_.set(false);
return res;
}
//UpdateSketch overrides
@Override
public UpdateSketch rebuild() {
super.rebuild();
updateEstimationSnapshot();
return this;
}
/**
* {@inheritDoc}
* Takes care of mutual exclusion with propagation thread.
*/
@Override
public void reset() {
advanceEpoch();
super.reset();
volatileThetaLong_ = Long.MAX_VALUE;
volatileEstimate_ = 0;
}
@Override
UpdateReturnState hashUpdate(final long hash) {
final String msg = "No update method should be called directly to a shared theta sketch."
+ " Updating the shared sketch is only permitted through propagation from local sketches.";
throw new UnsupportedOperationException(msg);
}
//ConcurrentSharedThetaSketch declarations
@Override
public long getExactLimit() {
return exactLimit_;
}
@Override
public boolean startEagerPropagation() {
while (!sharedPropagationInProgress_.compareAndSet(false, true)) { } //busy wait till free
return (!isEstimationMode());// no eager propagation is allowed in estimation mode
}
@Override
public void endPropagation(final AtomicBoolean localPropagationInProgress, final boolean isEager) {
//update volatile theta, uniques estimate and propagation flag
updateVolatileTheta();
updateEstimationSnapshot();
if (isEager) {
sharedPropagationInProgress_.set(false);
}
if (localPropagationInProgress != null) {
localPropagationInProgress.set(false); //clear local propagation flag
}
}
@Override
public long getVolatileTheta() {
return volatileThetaLong_;
}
@Override
public void awaitBgPropagationTermination() {
try {
executorService_.shutdown();
while (!executorService_.awaitTermination(1, TimeUnit.MILLISECONDS)) {
Thread.sleep(1);
}
} catch (final InterruptedException e) {
e.printStackTrace();
}
}
@Override
public void initBgPropagationService() {
executorService_ = ConcurrentPropagationService.getExecutorService(Thread.currentThread().getId());
}
@Override
public boolean propagate(final AtomicBoolean localPropagationInProgress,
final Sketch sketchIn, final long singleHash) {
final long epoch = epoch_;
if ((singleHash != NOT_SINGLE_HASH) //namely, is a single hash and
&& (getRetainedEntries(false) < exactLimit_)) { //a small sketch then propagate myself (blocking)
if (!startEagerPropagation()) {
endPropagation(localPropagationInProgress, true);
return false;
}
if (!validateEpoch(epoch)) {
endPropagation(null, true); // do not change local flag
return true;
}
propagate(singleHash);
endPropagation(localPropagationInProgress, true);
return true;
}
// otherwise, be nonblocking, let background thread do the work
final ConcurrentBackgroundThetaPropagation job = new ConcurrentBackgroundThetaPropagation(
this, localPropagationInProgress, sketchIn, singleHash, epoch);
executorService_.execute(job);
return true;
}
@Override
public void propagate(final long singleHash) {
super.hashUpdate(singleHash);
}
@Override
public void updateEstimationSnapshot() {
volatileEstimate_ = super.getEstimate();
}
@Override
public void updateVolatileTheta() {
volatileThetaLong_ = getThetaLong();
}
@Override
public boolean validateEpoch(final long epoch) {
return epoch_ == epoch;
}
//Restricted
/**
* Advances the epoch while there is no background propagation
* This ensures a propagation invoked before the reset cannot affect the sketch after the reset
* is completed.
*/
@SuppressFBWarnings(value = "VO_VOLATILE_INCREMENT", justification = "Likely False Positive, Fix Later")
private void advanceEpoch() {
awaitBgPropagationTermination();
startEagerPropagation();
ConcurrentPropagationService.resetExecutorService(Thread.currentThread().getId());
//no inspection NonAtomicOperationOnVolatileField
// this increment of a volatile field is done within the scope of the propagation
// synchronization and hence is done by a single thread
// Ignore a FindBugs warning
epoch_++;
endPropagation(null, true);
initBgPropagationService();
}
}
| 2,790 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/theta/HeapUpdateSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.theta;
import static org.apache.datasketches.theta.CompactOperations.checkIllegalCurCountAndEmpty;
import static org.apache.datasketches.theta.CompactOperations.correctThetaOnCompact;
import static org.apache.datasketches.theta.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.theta.PreambleUtil.SER_VER;
import static org.apache.datasketches.theta.PreambleUtil.insertCurCount;
import static org.apache.datasketches.theta.PreambleUtil.insertFamilyID;
import static org.apache.datasketches.theta.PreambleUtil.insertFlags;
import static org.apache.datasketches.theta.PreambleUtil.insertLgArrLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertLgNomLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertLgResizeFactor;
import static org.apache.datasketches.theta.PreambleUtil.insertP;
import static org.apache.datasketches.theta.PreambleUtil.insertPreLongs;
import static org.apache.datasketches.theta.PreambleUtil.insertSeedHash;
import static org.apache.datasketches.theta.PreambleUtil.insertSerVer;
import static org.apache.datasketches.theta.PreambleUtil.insertThetaLong;
import org.apache.datasketches.common.ResizeFactor;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.thetacommon.ThetaUtil;
/**
* The parent class for Heap Updatable Theta Sketches.
*
* @author Lee Rhodes
*/
abstract class HeapUpdateSketch extends UpdateSketch {
final int lgNomLongs_;
private final long seed_;
private final float p_;
private final ResizeFactor rf_;
HeapUpdateSketch(final int lgNomLongs, final long seed, final float p, final ResizeFactor rf) {
lgNomLongs_ = Math.max(lgNomLongs, ThetaUtil.MIN_LG_NOM_LONGS);
seed_ = seed;
p_ = p;
rf_ = rf;
}
//Sketch
@Override
public int getCurrentBytes() {
final int preLongs = getCurrentPreambleLongs();
final int dataLongs = getCurrentDataLongs();
return (preLongs + dataLongs) << 3;
}
@Override
public boolean isDirect() {
return false;
}
@Override
public boolean hasMemory() {
return false;
}
//UpdateSketch
@Override
public final int getLgNomLongs() {
return lgNomLongs_;
}
@Override
float getP() {
return p_;
}
@Override
public ResizeFactor getResizeFactor() {
return rf_;
}
@Override
long getSeed() {
return seed_;
}
//restricted methods
@Override
short getSeedHash() {
return ThetaUtil.computeSeedHash(getSeed());
}
//Used by HeapAlphaSketch and HeapQuickSelectSketch / Theta UpdateSketch
byte[] toByteArray(final int preLongs, final byte familyID) {
if (isDirty()) { rebuild(); }
checkIllegalCurCountAndEmpty(isEmpty(), getRetainedEntries(true));
final int preBytes = (preLongs << 3) & 0X3F; //24 bytes
final int dataBytes = getCurrentDataLongs() << 3;
final byte[] byteArrOut = new byte[preBytes + dataBytes];
final WritableMemory memOut = WritableMemory.writableWrap(byteArrOut);
//preamble first 8 bytes. Note: only compact can be reduced to 8 bytes.
final int lgRf = getResizeFactor().lg() & 0x3;
insertPreLongs(memOut, preLongs); //byte 0 low 6 bits
insertLgResizeFactor(memOut, lgRf); //byte 0 high 2 bits
insertSerVer(memOut, SER_VER); //byte 1
insertFamilyID(memOut, familyID); //byte 2
insertLgNomLongs(memOut, getLgNomLongs()); //byte 3
insertLgArrLongs(memOut, getLgArrLongs()); //byte 4
insertSeedHash(memOut, getSeedHash()); //bytes 6 & 7
insertCurCount(memOut, this.getRetainedEntries(true));
insertP(memOut, getP());
final long thetaLong =
correctThetaOnCompact(isEmpty(), getRetainedEntries(true), getThetaLong());
insertThetaLong(memOut, thetaLong);
//Flags: BigEnd=0, ReadOnly=0, Empty=X, compact=0, ordered=0
final byte flags = isEmpty() ? (byte) EMPTY_FLAG_MASK : 0;
insertFlags(memOut, flags);
//Data
final int arrLongs = 1 << getLgArrLongs();
final long[] cache = getCache();
memOut.putLongArray(preBytes, cache, 0, arrLongs); //load byteArrOut
return byteArrOut;
}
}
| 2,791 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantiles/DoublesMergeImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantiles;
import static org.apache.datasketches.common.Util.checkIfIntPowerOf2;
import static org.apache.datasketches.quantiles.PreambleUtil.EMPTY_FLAG_MASK;
import static org.apache.datasketches.quantiles.PreambleUtil.FLAGS_BYTE;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.WritableMemory;
/**
* Down-sampling and merge algorithms for doubles quantiles.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
final class DoublesMergeImpl {
private DoublesMergeImpl() {}
/**
* Merges the source sketch into the target sketch that can have a smaller K parameter.
* However, it is required that the ratio of the two K parameters be a power of 2.
* I.e., source.getK() = target.getK() * 2^(nonnegative integer).
* The source is not modified.
*
* <p>Note: It is easy to prove that the following simplified code which launches multiple waves of
* carry propagation does exactly the same amount of merging work (including the work of
* allocating fresh buffers) as the more complicated and seemingly more efficient approach that
* tracks a single carry propagation wave through both sketches.
*
* <p>This simplified code probably does do slightly more "outer loop" work, but I am pretty
* sure that even that is within a constant factor of the more complicated code, plus the
* total amount of "outer loop" work is at least a factor of K smaller than the total amount of
* merging work, which is identical in the two approaches.
*
* <p>Note: a two-way merge that doesn't modify either of its two inputs could be implemented
* by making a deep copy of the larger sketch and then merging the smaller one into it.
* However, it was decided not to do this.
*
* @param src The source sketch
* @param tgt The target sketch
*/
static void mergeInto(final DoublesSketch src, final UpdateDoublesSketch tgt) {
final int srcK = src.getK();
final int tgtK = tgt.getK();
final long srcN = src.getN();
final long tgtN = tgt.getN();
if (srcK != tgtK) {
downSamplingMergeInto(src, tgt);
return;
}
//The remainder of this code is for the case where the k's are equal
final DoublesSketchAccessor srcSketchBuf = DoublesSketchAccessor.wrap(src);
final long nFinal = tgtN + srcN;
for (int i = 0; i < srcSketchBuf.numItems(); i++) { // update only the base buffer
tgt.update(srcSketchBuf.get(i));
}
final int spaceNeeded = DoublesUpdateImpl.getRequiredItemCapacity(tgtK, nFinal);
final int tgtCombBufItemCap = tgt.getCombinedBufferItemCapacity();
if (spaceNeeded > tgtCombBufItemCap) { //copies base buffer plus current levels
tgt.growCombinedBuffer(tgtCombBufItemCap, spaceNeeded);
}
final DoublesArrayAccessor scratch2KAcc = DoublesArrayAccessor.initialize(2 * tgtK);
long srcBitPattern = src.getBitPattern();
assert srcBitPattern == (srcN / (2L * srcK));
final DoublesSketchAccessor tgtSketchBuf = DoublesSketchAccessor.wrap(tgt, true);
long newTgtBitPattern = tgt.getBitPattern();
for (int srcLvl = 0; srcBitPattern != 0L; srcLvl++, srcBitPattern >>>= 1) {
if ((srcBitPattern & 1L) > 0L) {
newTgtBitPattern = DoublesUpdateImpl.inPlacePropagateCarry(
srcLvl,
srcSketchBuf.setLevel(srcLvl),
scratch2KAcc,
false,
tgtK,
tgtSketchBuf,
newTgtBitPattern
);
}
}
if (tgt.hasMemory() && (nFinal > 0)) {
final WritableMemory mem = tgt.getMemory();
mem.clearBits(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK);
}
tgt.putN(nFinal);
tgt.putBitPattern(newTgtBitPattern); // no-op if direct
assert (tgt.getN() / (2L * tgtK)) == tgt.getBitPattern(); // internal consistency check
double srcMax = src.getMaxItem();
srcMax = Double.isNaN(srcMax) ? Double.NEGATIVE_INFINITY : srcMax;
double srcMin = src.getMinItem();
srcMin = Double.isNaN(srcMin) ? Double.POSITIVE_INFINITY : srcMin;
double tgtMax = tgt.getMaxItem();
tgtMax = Double.isNaN(tgtMax) ? Double.NEGATIVE_INFINITY : tgtMax;
double tgtMin = tgt.getMinItem();
tgtMin = Double.isNaN(tgtMin) ? Double.POSITIVE_INFINITY : tgtMin;
tgt.putMaxItem(Math.max(srcMax, tgtMax));
tgt.putMinItem(Math.min(srcMin, tgtMin));
}
/**
* Merges the source sketch into the target sketch that can have a smaller K.
* However, it is required that the ratio of the two K's be a power of 2.
* I.e., source.getK() = target.getK() * 2^(nonnegative integer).
* The source is not modified.
*
* @param src The source sketch
* @param tgt The target sketch
*/
//also used by DoublesSketch, DoublesUnionImpl and HeapDoublesSketchTest
static void downSamplingMergeInto(final DoublesSketch src, final UpdateDoublesSketch tgt) {
final int sourceK = src.getK();
final int targetK = tgt.getK();
final long tgtN = tgt.getN();
if ((sourceK % targetK) != 0) {
throw new SketchesArgumentException(
"source.getK() must equal target.getK() * 2^(nonnegative integer).");
}
final int downFactor = sourceK / targetK;
checkIfIntPowerOf2(downFactor, "source.getK()/target.getK() ratio");
final int lgDownFactor = Integer.numberOfTrailingZeros(downFactor);
if (src.isEmpty()) { return; }
final DoublesSketchAccessor srcSketchBuf = DoublesSketchAccessor.wrap(src);
final long nFinal = tgtN + src.getN();
for (int i = 0; i < srcSketchBuf.numItems(); i++) { // update only the base buffer
tgt.update(srcSketchBuf.get(i));
}
final int spaceNeeded = DoublesUpdateImpl.getRequiredItemCapacity(targetK, nFinal);
final int curCombBufCap = tgt.getCombinedBufferItemCapacity();
if (spaceNeeded > curCombBufCap) { //copies base buffer plus current levels
tgt.growCombinedBuffer(curCombBufCap, spaceNeeded);
}
//working scratch buffers
final DoublesArrayAccessor scratch2KAcc = DoublesArrayAccessor.initialize(2 * targetK);
final DoublesArrayAccessor downScratchKAcc = DoublesArrayAccessor.initialize(targetK);
final DoublesSketchAccessor tgtSketchBuf = DoublesSketchAccessor.wrap(tgt, true);
long srcBitPattern = src.getBitPattern();
long newTgtBitPattern = tgt.getBitPattern();
for (int srcLvl = 0; srcBitPattern != 0L; srcLvl++, srcBitPattern >>>= 1) {
if ((srcBitPattern & 1L) > 0L) {
justZipWithStride(
srcSketchBuf.setLevel(srcLvl),
downScratchKAcc,
targetK,
downFactor
);
newTgtBitPattern = DoublesUpdateImpl.inPlacePropagateCarry(
srcLvl + lgDownFactor, //starting level
downScratchKAcc, //optSrcKBuf,
scratch2KAcc, //size2KBuf,
false, //do mergeInto version
targetK,
tgtSketchBuf,
newTgtBitPattern
);
tgt.putBitPattern(newTgtBitPattern); //off-heap is a no-op
}
}
if (tgt.hasMemory() && (nFinal > 0)) {
final WritableMemory mem = tgt.getMemory();
mem.clearBits(FLAGS_BYTE, (byte) EMPTY_FLAG_MASK);
}
tgt.putN(nFinal);
assert (tgt.getN() / (2L * targetK)) == newTgtBitPattern; // internal consistency check
double srcMax = src.getMaxItem();
srcMax = Double.isNaN(srcMax) ? Double.NEGATIVE_INFINITY : srcMax;
double srcMin = src.getMinItem();
srcMin = Double.isNaN(srcMin) ? Double.POSITIVE_INFINITY : srcMin;
double tgtMax = tgt.getMaxItem();
tgtMax = Double.isNaN(tgtMax) ? Double.NEGATIVE_INFINITY : tgtMax;
double tgtMin = tgt.getMinItem();
tgtMin = Double.isNaN(tgtMin) ? Double.POSITIVE_INFINITY : tgtMin;
if (srcMax > tgtMax) { tgt.putMaxItem(srcMax); }
if (srcMin < tgtMin) { tgt.putMinItem(srcMin); }
}
private static void justZipWithStride(
final DoublesBufferAccessor bufA, // input
final DoublesBufferAccessor bufC, // output
final int kC, // number of items that should be in the output
final int stride) {
final int randomOffset = DoublesSketch.rand.nextInt(stride);
for (int a = randomOffset, c = 0; c < kC; a += stride, c++ ) {
bufC.set(c, bufA.get(a));
}
}
}
| 2,792 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantiles/ItemsSketch.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantiles;
import static java.lang.Math.max;
import static java.lang.Math.min;
import static org.apache.datasketches.quantiles.ClassicUtil.MIN_K;
import static org.apache.datasketches.quantiles.ClassicUtil.checkFamilyID;
import static org.apache.datasketches.quantiles.ClassicUtil.checkK;
import static org.apache.datasketches.quantiles.ClassicUtil.checkPreLongsFlagsCap;
import static org.apache.datasketches.quantiles.ClassicUtil.computeBaseBufferItems;
import static org.apache.datasketches.quantiles.ClassicUtil.computeBitPattern;
import static org.apache.datasketches.quantiles.ClassicUtil.computeCombinedBufferItemCapacity;
import static org.apache.datasketches.quantiles.ClassicUtil.computeRetainedItems;
import static org.apache.datasketches.quantiles.PreambleUtil.COMPACT_FLAG_MASK;
import static org.apache.datasketches.quantiles.PreambleUtil.extractFamilyID;
import static org.apache.datasketches.quantiles.PreambleUtil.extractFlags;
import static org.apache.datasketches.quantiles.PreambleUtil.extractK;
import static org.apache.datasketches.quantiles.PreambleUtil.extractN;
import static org.apache.datasketches.quantiles.PreambleUtil.extractPreLongs;
import static org.apache.datasketches.quantiles.PreambleUtil.extractSerVer;
import static org.apache.datasketches.quantilescommon.QuantileSearchCriteria.INCLUSIVE;
import static org.apache.datasketches.quantilescommon.QuantilesUtil.equallyWeightedRanks;
import java.lang.reflect.Array;
import java.util.Arrays;
import java.util.Comparator;
import java.util.Objects;
import java.util.Random;
import org.apache.datasketches.common.ArrayOfItemsSerDe;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
import org.apache.datasketches.quantilescommon.GenericSortedView;
import org.apache.datasketches.quantilescommon.QuantileSearchCriteria;
import org.apache.datasketches.quantilescommon.QuantilesAPI;
import org.apache.datasketches.quantilescommon.QuantilesGenericAPI;
import org.apache.datasketches.quantilescommon.QuantilesGenericSketchIterator;
/**
* This is an implementation of the Low Discrepancy Mergeable Quantiles Sketch, using generic items,
* described in section 3.2 of the journal version of the paper "Mergeable Summaries"
* by Agarwal, Cormode, Huang, Phillips, Wei, and Yi:
*
* <p>Reference: <a href="http://dblp.org/rec/html/journals/tods/AgarwalCHPWY13"></a></p>
*
* <p>A <i>k</i> of 128 produces a normalized, rank error of about 1.7%.
* For example, the median returned from getQuantile(0.5) will be between the actual quantiles
* from the hypothetically sorted array of input quantiles at normalized ranks of 0.483 and 0.517, with
* a confidence of about 99%.</p>
*
* <p>The size of an ItemsSketch is very dependent on the size of the generic Items input into the sketch,
* so there is no comparable size table as there is for the DoublesSketch.</p>
*
* @see QuantilesAPI
*
* @param <T> The sketch data type
*/
public final class ItemsSketch<T> implements QuantilesGenericAPI<T> {
final Class<T> clazz;
private final Comparator<? super T> comparator_;
final int k_;
long n_;
/**
* The largest item ever seen in the stream.
*/
T maxItem_;
/**
* The smallest item ever seen in the stream.
*/
T minItem_;
/**
* In the initial on-heap version, equals combinedBuffer_.length.
* May differ in later versions that grow space more aggressively.
* Also, in the off-heap version, combinedBuffer_ won't even be a java array,
* so it won't know its own length.
*/
int combinedBufferItemCapacity_;
/**
* Number of items currently in base buffer.
*
* <p>Count = N % (2 * K)</p>
*/
int baseBufferCount_;
/**
* Active levels expressed as a bit pattern.
*
* <p>Pattern = N / (2 * K)</p>
*/
long bitPattern_;
/**
* This single array contains the base buffer plus all levels some of which may not be used.
* A level is of size K and is either full and sorted, or not used. A "not used" buffer may have
* garbage. Whether a level buffer used or not is indicated by the bitPattern_.
* The base buffer has length 2*K but might not be full and isn't necessarily sorted.
* The base buffer precedes the level buffers.
*
* <p>The levels arrays require quite a bit of explanation, which we defer until later.</p>
*/
Object[] combinedBuffer_;
ItemsSketchSortedView<T> classicQisSV = null;
/**
* Setting the seed makes the results of the sketch deterministic if the input items are
* received in exactly the same order. This is only useful when performing test comparisons,
* otherwise is not recommended.
*/
public static final Random rand = new Random();
private ItemsSketch(
final int k,
final Class<T> clazz,
final Comparator<? super T> comparator) {
Objects.requireNonNull(clazz, "Class<T> must not be null.");
Objects.requireNonNull(comparator, "Comparator must not be null.");
checkK(k);
k_ = k;
this.clazz = clazz;
comparator_ = comparator;
}
/**
* Obtains a new instance of an ItemsSketch using the DEFAULT_K.
* @param <T> The sketch data type
* @param clazz the given class of T
* @param comparator to compare items
* @return an ItemSketch<T>.
*/
public static <T> ItemsSketch<T> getInstance(
final Class<T> clazz,
final Comparator<? super T> comparator) {
return getInstance(clazz, PreambleUtil.DEFAULT_K, comparator);
}
/**
* Obtains a new instance of an ItemsSketch.
* @param clazz the given class of T
* @param k Parameter that controls space usage of sketch and accuracy of estimates.
* Must be greater than 2 and less than 65536 and a power of 2.
* @param comparator to compare items
* @param <T> The sketch data type
* @return an ItemSketch<T>.
*/
public static <T> ItemsSketch<T> getInstance(
final Class<T> clazz,
final int k,
final Comparator<? super T> comparator) {
final ItemsSketch<T> qs = new ItemsSketch<>(k, clazz, comparator);
final int bufAlloc = 2 * Math.min(MIN_K, k); //the min is important
qs.n_ = 0;
qs.combinedBufferItemCapacity_ = bufAlloc;
qs.combinedBuffer_ = new Object[bufAlloc];
qs.baseBufferCount_ = 0;
qs.bitPattern_ = 0;
qs.minItem_ = null;
qs.maxItem_ = null;
return qs;
}
/**
* Heapifies the given srcMem, which must be a Memory image of a ItemsSketch
* @param clazz the given class of T
* @param srcMem a Memory image of a sketch.
* <a href="{@docRoot}/resources/dictionary.html#mem">See Memory</a>
* @param comparator to compare items
* @param serDe an instance of ArrayOfItemsSerDe
* @param <T> The sketch data type
* @return a ItemSketch<T> on the Java heap.
*/
public static <T> ItemsSketch<T> getInstance(
final Class<T> clazz,
final Memory srcMem,
final Comparator<? super T> comparator,
final ArrayOfItemsSerDe<T> serDe) {
final long memCapBytes = srcMem.getCapacity();
if (memCapBytes < 8) {
throw new SketchesArgumentException("Memory too small: " + memCapBytes);
}
final int preambleLongs = extractPreLongs(srcMem);
final int serVer = extractSerVer(srcMem);
final int familyID = extractFamilyID(srcMem);
final int flags = extractFlags(srcMem);
final int k = extractK(srcMem);
ItemsUtil.checkItemsSerVer(serVer);
if (serVer == 3 && (flags & COMPACT_FLAG_MASK) == 0) {
throw new SketchesArgumentException("Non-compact Memory images are not supported.");
}
final boolean empty = checkPreLongsFlagsCap(preambleLongs, flags, memCapBytes);
checkFamilyID(familyID);
final ItemsSketch<T> sk = getInstance(clazz, k, comparator); //checks k
if (empty) { return sk; }
//Not empty, must have valid preamble + min, max
final long n = extractN(srcMem);
//can't check memory capacity here, not enough information
final int extra = 2; //for min, max
final int numMemItems = computeRetainedItems(k, n) + extra;
//set class members
sk.n_ = n;
sk.combinedBufferItemCapacity_ = computeCombinedBufferItemCapacity(k, n);
sk.baseBufferCount_ = computeBaseBufferItems(k, n);
sk.bitPattern_ = computeBitPattern(k, n);
sk.combinedBuffer_ = new Object[sk.combinedBufferItemCapacity_];
final int srcMemItemsOffsetBytes = preambleLongs * Long.BYTES;
final Memory mReg = srcMem.region(srcMemItemsOffsetBytes,
srcMem.getCapacity() - srcMemItemsOffsetBytes);
final T[] itemsArray = serDe.deserializeFromMemory(mReg, 0, numMemItems);
sk.itemsArrayToCombinedBuffer(itemsArray);
return sk;
}
/**
* Returns a copy of the given sketch
* @param <T> The sketch data type
* @param sketch the given sketch
* @return a copy of the given sketch
*/
static <T> ItemsSketch<T> copy(final ItemsSketch<T> sketch) {
final ItemsSketch<T> qsCopy = ItemsSketch.getInstance(sketch.clazz, sketch.k_, sketch.comparator_);
qsCopy.n_ = sketch.n_;
qsCopy.minItem_ = sketch.isEmpty() ? null : sketch.getMinItem();
qsCopy.maxItem_ = sketch.isEmpty() ? null : sketch.getMaxItem();
qsCopy.combinedBufferItemCapacity_ = sketch.getCombinedBufferAllocatedCount();
qsCopy.baseBufferCount_ = sketch.getBaseBufferCount();
qsCopy.bitPattern_ = sketch.getBitPattern();
final Object[] combBuf = sketch.getCombinedBuffer();
qsCopy.combinedBuffer_ = Arrays.copyOf(combBuf, combBuf.length);
return qsCopy;
}
@Override
public double[] getCDF(final T[] splitPoints) {
return getCDF(splitPoints, INCLUSIVE);
}
@Override
public double[] getCDF(final T[] splitPoints, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
refreshSortedView();
return classicQisSV.getCDF(splitPoints, searchCrit);
}
/**
* @return the sketch item type
*/
public Class<T> getSketchType() { return clazz; }
@Override
public T getMaxItem() {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
return maxItem_;
}
@Override
public T getMinItem() {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
return minItem_;
}
@Override
public GenericPartitionBoundaries<T> getPartitionBoundaries(final int numEquallyWeighted,
final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
final double[] ranks = equallyWeightedRanks(numEquallyWeighted);
final T[] boundaries = getQuantiles(ranks, searchCrit);
boundaries[0] = getMinItem();
boundaries[boundaries.length - 1] = getMaxItem();
final GenericPartitionBoundaries<T> gpb = new GenericPartitionBoundaries<>();
gpb.N = this.getN();
gpb.ranks = ranks;
gpb.boundaries = boundaries;
return gpb;
}
@Override
public double[] getPMF(final T[] splitPoints) {
return getPMF(splitPoints, INCLUSIVE);
}
@Override
public double[] getPMF(final T[] splitPoints, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
refreshSortedView();
return classicQisSV.getPMF(splitPoints, searchCrit);
}
@Override
public T getQuantile(final double rank) {
return getQuantile(rank, INCLUSIVE);
}
@Override
public T getQuantile(final double rank, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
refreshSortedView();
return classicQisSV.getQuantile(rank, searchCrit);
}
@Override
public T getQuantileLowerBound(final double rank) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
return getQuantile(max(0, rank - getNormalizedRankError(k_, false)));
}
@Override
public T getQuantileUpperBound(final double rank) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
return getQuantile(min(1.0, rank + getNormalizedRankError(k_, false)));
}
@Override
public T[] getQuantiles(final double[] ranks) {
return getQuantiles(ranks, INCLUSIVE);
}
@Override
@SuppressWarnings("unchecked")
public T[] getQuantiles(final double[] ranks, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
refreshSortedView();
final int len = ranks.length;
final T[] quantiles = (T[]) Array.newInstance(minItem_.getClass(), len);
for (int i = 0; i < len; i++) {
quantiles[i] = classicQisSV.getQuantile(ranks[i], searchCrit);
}
return quantiles;
}
@Override
public double getRank(final T quantile) {
return getRank(quantile, INCLUSIVE);
}
@Override
public double getRank(final T quantile, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
refreshSortedView();
return classicQisSV.getRank(quantile, searchCrit);
}
@Override
public double getRankLowerBound(final double rank) {
return max(0.0, rank - getNormalizedRankError(k_, false));
}
@Override
public double getRankUpperBound(final double rank) {
return min(1.0, rank + getNormalizedRankError(k_, false));
}
@Override
public double[] getRanks(final T[] quantiles) {
return getRanks(quantiles, INCLUSIVE);
}
@Override
public double[] getRanks(final T[] quantiles, final QuantileSearchCriteria searchCrit) {
if (isEmpty()) { throw new IllegalArgumentException(QuantilesAPI.EMPTY_MSG); }
refreshSortedView();
final int len = quantiles.length;
final double[] ranks = new double[len];
for (int i = 0; i < len; i++) {
ranks[i] = classicQisSV.getRank(quantiles[i], searchCrit);
}
return ranks;
}
@Override
public QuantilesGenericSketchIterator<T> iterator() {
return new ItemsSketchIterator<>(this, bitPattern_);
}
@Override
public int getK() {
return k_;
}
@Override
public long getN() {
return n_;
}
/**
* Gets the approximate rank error of this sketch normalized as a fraction between zero and one.
* @param pmf if true, returns the "double-sided" normalized rank error for the getPMF() function.
* Otherwise, it is the "single-sided" normalized rank error for all the other queries.
* @return if pmf is true, returns the normalized rank error for the getPMF() function.
* Otherwise, it is the "single-sided" normalized rank error for all the other queries.
*/
public double getNormalizedRankError(final boolean pmf) {
return getNormalizedRankError(k_, pmf);
}
/**
* Gets the normalized rank error given k and pmf.
* Static method version of the {@link #getNormalizedRankError(boolean)}.
* @param k the configuration parameter
* @param pmf if true, returns the "double-sided" normalized rank error for the getPMF() function.
* Otherwise, it is the "single-sided" normalized rank error for all the other queries.
* @return if pmf is true, the normalized rank error for the getPMF() function.
* Otherwise, it is the "single-sided" normalized rank error for all the other queries.
*/
public static double getNormalizedRankError(final int k, final boolean pmf) {
return ClassicUtil.getNormalizedRankError(k, pmf);
}
/**
* Gets the approximate <em>k</em> to use given epsilon, the normalized rank error.
* @param epsilon the normalized rank error between zero and one.
* @param pmf if true, this function returns <em>k</em> assuming the input epsilon
* is the desired "double-sided" epsilon for the getPMF() function. Otherwise, this function
* returns <em>k</em> assuming the input epsilon is the desired "single-sided"
* epsilon for all the other queries.
* @return <i>k</i> given epsilon.
*/
public static int getKFromEpsilon(final double epsilon, final boolean pmf) {
return ClassicUtil.getKFromEpsilon(epsilon, pmf);
}
@Override
public boolean hasMemory() {
return false;
}
@Override
public boolean isEmpty() {
return getN() == 0;
}
@Override
public boolean isDirect() {
return false;
}
@Override
public boolean isEstimationMode() {
return getN() >= 2L * k_;
}
@Override
public boolean isReadOnly() {
return false;
}
@Override
public void reset() {
n_ = 0;
combinedBufferItemCapacity_ = 2 * Math.min(MIN_K, k_); //the min is important
combinedBuffer_ = new Object[combinedBufferItemCapacity_];
baseBufferCount_ = 0;
bitPattern_ = 0;
minItem_ = null;
maxItem_ = null;
classicQisSV = null;
}
/**
* Serialize this sketch to a byte array form.
* @param serDe an instance of ArrayOfItemsSerDe
* @return byte array of this sketch
*/
public byte[] toByteArray(final ArrayOfItemsSerDe<T> serDe) {
return toByteArray(false, serDe);
}
/**
* Serialize this sketch to a byte array form.
* @param ordered if true the base buffer will be ordered (default == false).
* @param serDe an instance of ArrayOfItemsSerDe
* @return this sketch in a byte array form.
*/
public byte[] toByteArray(final boolean ordered, final ArrayOfItemsSerDe<T> serDe) {
return ItemsByteArrayImpl.toByteArray(this, ordered, serDe);
}
@Override
public String toString() {
return toString(true, false);
}
/**
* Returns summary information about this sketch. Used for debugging.
* @param sketchSummary if true includes sketch summary
* @param dataDetail if true includes data detail
* @return summary information about the sketch.
*/
public String toString(final boolean sketchSummary, final boolean dataDetail) {
return ItemsUtil.toString(sketchSummary, dataDetail, this);
}
/**
* Returns a human readable string of the preamble of a byte array image of an ItemsSketch.
* @param byteArr the given byte array
* @return a human readable string of the preamble of a byte array image of an ItemsSketch.
*/
public static String toString(final byte[] byteArr) {
return PreambleUtil.toString(byteArr, false);
}
/**
* Returns a human readable string of the preamble of a Memory image of an ItemsSketch.
* @param mem the given Memory
* @return a human readable string of the preamble of a Memory image of an ItemsSketch.
*/
public static String toString(final Memory mem) {
return PreambleUtil.toString(mem, false);
}
/**
* From an existing sketch, this creates a new sketch that can have a smaller K.
* The original sketch is not modified.
*
* @param newK the new K that must be smaller than current K.
* It is required that this.getK() = newK * 2^(nonnegative integer).
* @return the new sketch.
*/
public ItemsSketch<T> downSample(final int newK) {
final ItemsSketch<T> newSketch = ItemsSketch.getInstance(clazz, newK, comparator_);
ItemsMergeImpl.downSamplingMergeInto(this, newSketch);
return newSketch;
}
@Override
public int getNumRetained() {
return computeRetainedItems(getK(), getN());
}
/**
* Puts the current sketch into the given Memory if there is sufficient space.
* Otherwise, throws an error.
*
* @param dstMem the given memory.
* @param serDe an instance of ArrayOfItemsSerDe
*/
public void putMemory(final WritableMemory dstMem, final ArrayOfItemsSerDe<T> serDe) {
final byte[] byteArr = toByteArray(serDe);
final long memCap = dstMem.getCapacity();
if (memCap < byteArr.length) {
throw new SketchesArgumentException(
"Destination Memory not large enough: " + memCap + " < " + byteArr.length);
}
dstMem.putByteArray(0, byteArr, 0, byteArr.length);
}
@Override
public GenericSortedView<T> getSortedView() {
if (isEmpty()) { throw new SketchesArgumentException(EMPTY_MSG); }
return refreshSortedView();
}
@Override
public void update(final T item) {
// this method only uses the base buffer part of the combined buffer
if (item == null) { return; }
if (maxItem_ == null || comparator_.compare(item, maxItem_) > 0) { maxItem_ = item; }
if (minItem_ == null || comparator_.compare(item, minItem_) < 0) { minItem_ = item; }
if (baseBufferCount_ + 1 > combinedBufferItemCapacity_) {
ItemsSketch.growBaseBuffer(this);
}
combinedBuffer_[baseBufferCount_++] = item;
n_++;
if (baseBufferCount_ == 2 * k_) {
ItemsUtil.processFullBaseBuffer(this);
}
classicQisSV = null;
}
// Restricted
private final ItemsSketchSortedView<T> refreshSortedView() {
final ItemsSketchSortedView<T> sv = (classicQisSV == null)
? classicQisSV = new ItemsSketchSortedView<>(this)
: classicQisSV;
return sv;
}
/**
* Returns the base buffer count
* @return the base buffer count
*/
int getBaseBufferCount() {
return baseBufferCount_;
}
/**
* Returns the allocated count for the combined base buffer
* @return the allocated count for the combined base buffer
*/
int getCombinedBufferAllocatedCount() {
return combinedBufferItemCapacity_;
}
/**
* Returns the bit pattern for valid log levels
* @return the bit pattern for valid log levels
*/
long getBitPattern() {
return bitPattern_;
}
/**
* Returns the combined buffer reference
* @return the combined buffer reference
*/
Object[] getCombinedBuffer() {
return combinedBuffer_;
}
Comparator<? super T> getComparator() {
return comparator_;
}
/**
* Loads the Combined Buffer, min and max from the given items array.
* The Combined Buffer is always in non-compact form and must be pre-allocated.
* @param itemsArray the given items array
*/
private void itemsArrayToCombinedBuffer(final T[] itemsArray) {
final int extra = 2; // space for min and max items
//Load min, max
minItem_ = itemsArray[0];
maxItem_ = itemsArray[1];
//Load base buffer
System.arraycopy(itemsArray, extra, combinedBuffer_, 0, baseBufferCount_);
//Load levels
long bits = bitPattern_;
if (bits > 0) {
int index = extra + baseBufferCount_;
for (int level = 0; bits != 0L; level++, bits >>>= 1) {
if ((bits & 1L) > 0L) {
System.arraycopy(itemsArray, index, combinedBuffer_, (2 + level) * k_, k_);
index += k_;
}
}
}
}
private static <T> void growBaseBuffer(final ItemsSketch<T> sketch) {
final Object[] baseBuffer = sketch.getCombinedBuffer();
final int oldSize = sketch.getCombinedBufferAllocatedCount();
final int k = sketch.getK();
assert oldSize < 2 * k;
final int newSize = Math.max(Math.min(2 * k, 2 * oldSize), 1);
sketch.combinedBufferItemCapacity_ = newSize;
sketch.combinedBuffer_ = Arrays.copyOf(baseBuffer, newSize);
}
}
| 2,793 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantiles/DoublesUnionImplR.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantiles;
import static org.apache.datasketches.common.Util.LS;
import org.apache.datasketches.common.SketchesArgumentException;
import org.apache.datasketches.common.SketchesReadOnlyException;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
/**
* Union operation for on-heap.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
class DoublesUnionImplR extends DoublesUnion {
int maxK_;
UpdateDoublesSketch gadget_ = null;
DoublesUnionImplR(final int maxK) {
maxK_ = maxK;
}
/**
* Returns a read-only Union object that wraps off-heap data structure of the given memory
* image of a non-compact DoublesSketch. The data structures of the Union remain off-heap.
*
* @param mem A memory image of a non-compact DoublesSketch to be used as the data
* structure for the union and will be modified.
* @return a Union object
*/
static DoublesUnionImplR wrapInstance(final Memory mem) {
final DirectUpdateDoublesSketchR sketch = DirectUpdateDoublesSketchR.wrapInstance(mem);
final int k = sketch.getK();
final DoublesUnionImplR union = new DoublesUnionImplR(k);
union.maxK_ = k;
union.gadget_ = sketch;
return union;
}
@Override
public void union(final DoublesSketch sketchIn) {
throw new SketchesReadOnlyException("Call to update() on read-only Union");
}
@Override
public void union(final Memory mem) {
throw new SketchesReadOnlyException("Call to update() on read-only Union");
}
@Override
public void update(final double dataItem) {
throw new SketchesReadOnlyException("Call to update() on read-only Union");
}
@Override
public byte[] toByteArray() {
if (gadget_ == null) {
return DoublesSketch.builder().setK(maxK_).build().toByteArray();
}
return gadget_.toByteArray();
}
@Override
public UpdateDoublesSketch getResult() {
if (gadget_ == null) {
return HeapUpdateDoublesSketch.newInstance(maxK_);
}
return DoublesUtil.copyToHeap(gadget_); //can't have any externally owned handles.
}
@Override
public UpdateDoublesSketch getResult(final WritableMemory dstMem) {
final long memCapBytes = dstMem.getCapacity();
if (gadget_ == null) {
if (memCapBytes < DoublesSketch.getUpdatableStorageBytes(0, 0)) {
throw new SketchesArgumentException("Insufficient capacity for result: " + memCapBytes);
}
return DirectUpdateDoublesSketch.newInstance(maxK_, dstMem);
}
gadget_.putMemory(dstMem, false);
return DirectUpdateDoublesSketch.wrapInstance(dstMem);
}
@Override
public UpdateDoublesSketch getResultAndReset() {
throw new SketchesReadOnlyException("Call to getResultAndReset() on read-only Union");
}
@Override
public void reset() {
throw new SketchesReadOnlyException("Call to reset() on read-only Union");
}
@Override
public boolean hasMemory() {
return (gadget_ != null) && gadget_.hasMemory();
}
@Override
public boolean isDirect() {
return (gadget_ != null) && gadget_.isDirect();
}
@Override
public boolean isEmpty() {
return (gadget_ == null) || gadget_.isEmpty();
}
@Override
public int getMaxK() {
return maxK_;
}
@Override
public int getEffectiveK() {
return (gadget_ != null) ? gadget_.getK() : maxK_;
}
@Override
public String toString() {
return toString(true, false);
}
@Override
public String toString(final boolean sketchSummary, final boolean dataDetail) {
final StringBuilder sb = new StringBuilder();
final String thisSimpleName = this.getClass().getSimpleName();
final int maxK = getMaxK();
final String kStr = String.format("%,d", maxK);
sb.append(ClassicUtil.LS).append("### Quantiles ").append(thisSimpleName).append(LS);
sb.append(" maxK : ").append(kStr);
if (gadget_ == null) {
sb.append(HeapUpdateDoublesSketch.newInstance(maxK_).toString());
return sb.toString();
}
sb.append(gadget_.toString(sketchSummary, dataDetail));
return sb.toString();
}
@Override
public boolean isSameResource(final Memory that) {
return (gadget_ == null) ? false : gadget_.isSameResource(that);
}
}
| 2,794 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantiles/DoublesArrayAccessor.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantiles;
import java.util.Arrays;
/**
* @author Jon Malkin
*/
final class DoublesArrayAccessor extends DoublesBufferAccessor {
private int numItems_;
private double[] buffer_;
private DoublesArrayAccessor(final double[] buffer) {
numItems_ = buffer.length;
buffer_ = buffer;
}
static DoublesArrayAccessor wrap(final double[] buffer) {
return new DoublesArrayAccessor(buffer);
}
static DoublesArrayAccessor initialize(final int numItems) {
return new DoublesArrayAccessor(new double[numItems]);
}
@Override
double get(final int index) {
assert index >= 0 && index < numItems_;
return buffer_[index];
}
@Override
double set(final int index, final double quantile) {
assert index >= 0 && index < numItems_;
final double retVal = buffer_[index];
buffer_[index] = quantile;
return retVal;
}
@Override
int numItems() {
return numItems_;
}
@Override
double[] getArray(final int fromIdx, final int numItems) {
return Arrays.copyOfRange(buffer_, fromIdx, fromIdx + numItems);
}
@Override
void putArray(final double[] srcArray, final int srcIndex,
final int dstIndex, final int numItems) {
System.arraycopy(srcArray, srcIndex, buffer_, dstIndex, numItems);
}
}
| 2,795 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantiles/DoublesSketchAccessor.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantiles;
import static org.apache.datasketches.quantiles.PreambleUtil.COMBINED_BUFFER;
import org.apache.datasketches.common.Family;
/**
* This allows access to package-private levels and data in whatever quantiles sketch you give
* it: on-heap, off-heap; compact and non-compact
* @author Jon Malkin
*/
abstract class DoublesSketchAccessor extends DoublesBufferAccessor {
static final int BB_LVL_IDX = -1;
final DoublesSketch ds_;
final boolean forceSize_;
long n_;
int currLvl_;
int numItems_;
int offset_;
DoublesSketchAccessor(final DoublesSketch ds, final boolean forceSize, final int level) {
ds_ = ds;
forceSize_ = forceSize;
setLevel(level);
}
static DoublesSketchAccessor wrap(final DoublesSketch ds) {
return wrap(ds, false);
}
static DoublesSketchAccessor wrap(final DoublesSketch ds, final boolean forceSize) {
if (ds.hasMemory()) {
return new DirectDoublesSketchAccessor(ds, forceSize, BB_LVL_IDX);
}
return new HeapDoublesSketchAccessor(ds, forceSize, BB_LVL_IDX);
}
abstract DoublesSketchAccessor copyAndSetLevel(final int level);
DoublesSketchAccessor setLevel(final int lvl) {
currLvl_ = lvl;
if (lvl == BB_LVL_IDX) {
numItems_ = (forceSize_ ? ds_.getK() * 2 : ds_.getBaseBufferCount());
offset_ = (ds_.hasMemory() ? COMBINED_BUFFER : 0);
} else {
assert lvl >= 0;
if (((ds_.getBitPattern() & (1L << lvl)) > 0) || forceSize_) {
numItems_ = ds_.getK();
} else {
numItems_ = 0;
}
// determine offset in two parts
// 1. index into combined buffer (compact vs update)
// 2. adjust if byte offset (direct) instead of array index (heap)
final int levelStart;
if (ds_.isCompact()) {
levelStart = ds_.getBaseBufferCount() + (countValidLevelsBelow(lvl) * ds_.getK());
} else {
levelStart = (2 + currLvl_) * ds_.getK();
}
if (ds_.hasMemory()) {
final int preLongsAndExtra = Family.QUANTILES.getMaxPreLongs() + 2; // +2 for min, max vals
offset_ = (preLongsAndExtra + levelStart) << 3;
} else {
offset_ = levelStart;
}
}
n_ = ds_.getN();
return this;
}
// getters/queries
@Override
int numItems() {
return numItems_;
}
@Override
abstract double get(final int index);
@Override
abstract double[] getArray(final int fromIdx, final int numItems);
// setters/modifying methods
@Override
abstract double set(final int index, final double quantile);
@Override
abstract void putArray(final double[] srcArray, final int srcIndex,
final int dstIndex, final int numItems);
abstract void sort();
/**
* Counts number of full levels in the sketch below tgtLvl. Useful for computing the level
* offset in a compact sketch.
* @param tgtLvl Target level in the sketch
* @return Number of full levels in the sketch below tgtLvl
*/
private int countValidLevelsBelow(final int tgtLvl) {
int count = 0;
long bitPattern = ds_.getBitPattern();
for (int i = 0; (i < tgtLvl) && (bitPattern > 0); ++i, bitPattern >>>= 1) {
if ((bitPattern & 1L) > 0L) {
++count;
}
}
return count;
// shorter implementation, testing suggests a tiny bit slower
//final long mask = (1 << tgtLvl) - 1;
//return Long.bitCount(ds_.getBitPattern() & mask);
}
}
| 2,796 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantiles/DoublesUnionImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantiles;
import static org.apache.datasketches.quantiles.DoublesUtil.copyToHeap;
import java.util.Objects;
import org.apache.datasketches.memory.Memory;
import org.apache.datasketches.memory.WritableMemory;
/**
* Union operation for on-heap.
*
* @author Lee Rhodes
* @author Kevin Lang
*/
final class DoublesUnionImpl extends DoublesUnionImplR {
private DoublesUnionImpl(final int maxK) {
super(maxK);
}
/**
* Returns a empty Heap DoublesUnion object.
* @param maxK determines the accuracy and size of the union and is a maximum.
* 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 <i>k</i>.
* @return a new DoublesUnionImpl on the Java heap
*/
static DoublesUnionImpl heapInstance(final int maxK) {
return new DoublesUnionImpl(maxK);
}
/**
* 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.
* 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 <i>k</i>.
* @param dstMem the Memory to be used by the sketch
* @return a DoublesUnion object
*/
static DoublesUnionImpl directInstance(final int maxK, final WritableMemory dstMem) {
Objects.requireNonNull(dstMem);
final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.newInstance(maxK, dstMem);
final DoublesUnionImpl union = new DoublesUnionImpl(maxK);
union.maxK_ = maxK;
union.gadget_ = sketch;
return union;
}
/**
* 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
*/
static DoublesUnionImpl heapifyInstance(final DoublesSketch sketch) {
Objects.requireNonNull(sketch);
final int k = sketch.getK();
final DoublesUnionImpl union = new DoublesUnionImpl(k);
union.maxK_ = k;
union.gadget_ = copyToHeap(sketch);
return union;
}
/**
* Returns a Heap DoublesUnion object that has been initialized with the data from the given
* Memory image of a DoublesSketch. The srcMem object will not be modified and a reference to
* it is not retained. The <i>maxK</i> of the resulting union will be that obtained from
* the sketch Memory image.
*
* @param srcMem a Memory image of a quantiles DoublesSketch
* @return a DoublesUnion object
*/
static DoublesUnionImpl heapifyInstance(final Memory srcMem) {
Objects.requireNonNull(srcMem);
final HeapUpdateDoublesSketch sketch = HeapUpdateDoublesSketch.heapifyInstance(srcMem);
final DoublesUnionImpl union = new DoublesUnionImpl(sketch.getK());
union.gadget_ = sketch;
return union;
}
/**
* 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
*/
static DoublesUnionImpl wrapInstance(final WritableMemory mem) {
Objects.requireNonNull(mem);
final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch.wrapInstance(mem);
final DoublesUnionImpl union = new DoublesUnionImpl(sketch.getK());
union.gadget_ = sketch;
return union;
}
@Override
public void union(final DoublesSketch sketchIn) {
Objects.requireNonNull(sketchIn);
gadget_ = updateLogic(maxK_, gadget_, sketchIn);
gadget_.classicQdsSV = null;
}
@Override
public void union(final Memory mem) {
Objects.requireNonNull(mem);
gadget_ = updateLogic(maxK_, gadget_, DoublesSketch.wrap(mem));
gadget_.classicQdsSV = null;
}
@Override
public void update(final double quantile) {
if (gadget_ == null) {
gadget_ = HeapUpdateDoublesSketch.newInstance(maxK_);
}
gadget_.update(quantile);
gadget_.classicQdsSV = null;
}
@Override
public UpdateDoublesSketch getResultAndReset() {
if (gadget_ == null) { return null; } //Intentionally return null here for speed.
final UpdateDoublesSketch ds = gadget_;
gadget_ = null;
return ds;
}
@Override
public void reset() {
gadget_ = null;
}
//@formatter:off
static UpdateDoublesSketch updateLogic(final int myMaxK, final UpdateDoublesSketch myQS,
final DoublesSketch other) {
int sw1 = ((myQS == null) ? 0 : myQS.isEmpty() ? 4 : 8);
sw1 |= ((other == null) ? 0 : other.isEmpty() ? 1 : 2);
int outCase = 0; //0=null, 1=NOOP, 2=copy, 3=merge
switch (sw1) {
case 0: outCase = 0; break; //myQS = null, other = null ; return null
case 1: outCase = 4; break; //myQS = null, other = empty; create empty-heap(myMaxK)
case 2: outCase = 2; break; //myQS = null, other = valid; stream or downsample to myMaxK
case 4: outCase = 1; break; //myQS = empty, other = null ; no-op
case 5: outCase = 1; break; //myQS = empty, other = empty; no-op
case 6: outCase = 3; break; //myQS = empty, other = valid; merge
case 8: outCase = 1; break; //myQS = valid, other = null ; no-op
case 9: outCase = 1; break; //myQS = valid, other = empty: no-op
case 10: outCase = 3; break; //myQS = valid, other = valid; merge
default: break; //This cannot happen
}
UpdateDoublesSketch ret = null;
switch (outCase) {
case 0: break; //return null
case 1: ret = myQS; break; //no-op
case 2: { //myQS = null, other = valid; stream or downsample to myMaxK
assert other != null;
if (!other.isEstimationMode()) { //other is exact, stream items in
ret = HeapUpdateDoublesSketch.newInstance(myMaxK);
// exact mode, only need copy base buffer
final DoublesSketchAccessor otherAccessor = DoublesSketchAccessor.wrap(other);
for (int i = 0; i < otherAccessor.numItems(); ++i) {
ret.update(otherAccessor.get(i));
}
}
else { //myQS = null, other is est mode
ret = (myMaxK < other.getK())
? other.downSampleInternal(other, myMaxK, null) //null mem
: DoublesUtil.copyToHeap(other); //copy required because caller has handle
}
break;
}
case 3: { //myQS = empty/valid, other = valid; merge
assert other != null;
assert myQS != null;
if (!other.isEstimationMode()) { //other is exact, stream items in
ret = myQS;
// exact mode, only need copy base buffer
final DoublesSketchAccessor otherAccessor = DoublesSketchAccessor.wrap(other);
for (int i = 0; i < otherAccessor.numItems(); ++i) {
ret.update(otherAccessor.get(i));
}
}
else { //myQS = empty/valid, other = valid and in est mode
if (myQS.getK() <= other.getK()) { //I am smaller or equal, thus the target
DoublesMergeImpl.mergeInto(other, myQS);
ret = myQS;
}
else { //Bigger: myQS.getK() > other.getK(), must effectively downsize me or swap
if (myQS.isEmpty()) {
if (myQS.hasMemory()) {
final WritableMemory mem = myQS.getMemory(); //myQS is empty, ok to reconfigure
other.putMemory(mem, false); // not compact, but BB ordered
ret = DirectUpdateDoublesSketch.wrapInstance(mem);
} else { //myQS is empty and on heap
ret = DoublesUtil.copyToHeap(other);
}
}
else { //Not Empty: myQS has data, downsample to tmp
final UpdateDoublesSketch tmp = DoublesSketch.builder().setK(other.getK()).build();
DoublesMergeImpl.downSamplingMergeInto(myQS, tmp); //myData -> tmp
ret = (myQS.hasMemory())
? DoublesSketch.builder().setK(other.getK()).build(myQS.getMemory())
: DoublesSketch.builder().setK(other.getK()).build();
DoublesMergeImpl.mergeInto(tmp, ret);
DoublesMergeImpl.mergeInto(other, ret);
}
}
}
break;
}
case 4: { //myQS = null, other = empty; create empty-heap(myMaxK)
ret = HeapUpdateDoublesSketch.newInstance(myMaxK);
break;
}
default: break; //This cannot happen
}
return ret;
}
//@formatter:on
}
| 2,797 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantiles/ItemsMergeImpl.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantiles;
import static java.lang.System.arraycopy;
import static org.apache.datasketches.common.Util.checkIfIntPowerOf2;
import java.util.Arrays;
import java.util.Comparator;
import org.apache.datasketches.common.SketchesArgumentException;
/**
* Down-sampling and merge algorithms
*
* @author Lee Rhodes
* @author Alexander Saydakov
* @author Kevin Lang
*/
final class ItemsMergeImpl {
private ItemsMergeImpl() {}
/**
* Merges the source sketch into the target sketch that can have a smaller K parameter.
* However, it is required that the ratio of the two K parameters be a power of 2.
* I.e., source.getK() = target.getK() * 2^(nonnegative integer).
* The source is not modified.
*
* <p>Note: It is easy to prove that the following simplified code which launches multiple waves of
* carry propagation does exactly the same amount of merging work (including the work of
* allocating fresh buffers) as the more complicated and seemingly more efficient approach that
* tracks a single carry propagation wave through both sketches.
*
* <p>This simplified code probably does do slightly more "outer loop" work, but I am pretty
* sure that even that is within a constant factor of the more complicated code, plus the
* total amount of "outer loop" work is at least a factor of K smaller than the total amount of
* merging work, which is identical in the two approaches.
*
* <p>Note: a two-way merge that doesn't modify either of its two inputs could be implemented
* by making a deep copy of the larger sketch and then merging the smaller one into it.
* However, it was decided not to do this.
*
* @param <T> the data type
* @param src The source sketch
* @param tgt The target sketch
*/
@SuppressWarnings("unchecked")
static <T> void mergeInto(final ItemsSketch<T> src, final ItemsSketch<T> tgt) {
final int srcK = src.getK();
final int tgtK = tgt.getK();
final long srcN = src.getN();
final long tgtN = tgt.getN();
if (srcK != tgtK) {
downSamplingMergeInto(src, tgt);
return;
}
//The remainder of this code is for the case where the k's are equal
final Object[] srcCombBuf = src.getCombinedBuffer();
final long nFinal = tgtN + srcN;
for (int i = 0; i < src.getBaseBufferCount(); i++) { //update only the base buffer
tgt.update((T) srcCombBuf[i]);
}
ItemsUpdateImpl.maybeGrowLevels(tgt, nFinal);
final Object[] scratchBuf = new Object[2 * tgtK];
long srcBitPattern = src.getBitPattern();
assert srcBitPattern == (srcN / (2L * srcK));
for (int srcLvl = 0; srcBitPattern != 0L; srcLvl++, srcBitPattern >>>= 1) {
if ((srcBitPattern & 1L) > 0L) { //only one level above base buffer
ItemsUpdateImpl.inPlacePropagateCarry(
srcLvl,
(T[]) srcCombBuf, (2 + srcLvl) * tgtK,
(T[]) scratchBuf, 0,
false,
tgt);
// won't update tgt.n_ until the very end
}
}
tgt.n_ = nFinal;
assert (tgt.getN() / (2L * tgtK)) == tgt.getBitPattern(); // internal consistency check
final T srcMax = src.isEmpty() ? null : src.getMaxItem();
final T srcMin = src.isEmpty() ? null : src.getMinItem();
final T tgtMax = tgt.isEmpty() ? null : tgt.getMaxItem();
final T tgtMin = tgt.isEmpty() ? null : tgt.getMinItem();
if ((srcMax != null) && (tgtMax != null)) {
tgt.maxItem_ = (src.getComparator().compare(srcMax, tgtMax) > 0) ? srcMax : tgtMax;
} //only one could be null
else if (tgtMax == null) { //if srcMax were null we would leave tgt alone
tgt.maxItem_ = srcMax;
}
if ((srcMin != null) && (tgtMin != null)) {
tgt.minItem_ = (src.getComparator().compare(srcMin, tgtMin) > 0) ? tgtMin : srcMin;
} //only one could be null
else if (tgtMin == null) { //if srcMin were null we would leave tgt alone
tgt.minItem_ = srcMin;
}
}
/**
* Merges the source sketch into the target sketch that can have a smaller parameter K.
* However, it is required that the ratio of the two K parameters be a power of 2.
* I.e., source.getK() = target.getK() * 2^(nonnegative integer).
* The source is not modified.
* @param <T> the data type
* @param src The source sketch
* @param tgt The target sketch
*/
@SuppressWarnings("unchecked") //also used by ItemsSketch and ItemsUnion
static <T> void downSamplingMergeInto(final ItemsSketch<T> src, final ItemsSketch<T> tgt) {
final int sourceK = src.getK();
final int targetK = tgt.getK();
if ((sourceK % targetK) != 0) {
throw new SketchesArgumentException(
"source.getK() must equal target.getK() * 2^(nonnegative integer).");
}
final int downFactor = sourceK / targetK;
checkIfIntPowerOf2(downFactor, "source.getK()/target.getK() ratio");
final int lgDownFactor = Integer.numberOfTrailingZeros(downFactor);
final Object[] sourceLevels = src.getCombinedBuffer(); // aliasing is a bit dangerous
final Object[] sourceBaseBuffer = src.getCombinedBuffer(); // aliasing is a bit dangerous
final long nFinal = tgt.getN() + src.getN();
for (int i = 0; i < src.getBaseBufferCount(); i++) {
tgt.update((T) sourceBaseBuffer[i]);
}
ItemsUpdateImpl.maybeGrowLevels(tgt, nFinal);
final Object[] scratchBuf = new Object[2 * targetK];
final Object[] downBuf = new Object[targetK];
long srcBitPattern = src.getBitPattern();
for (int srcLvl = 0; srcBitPattern != 0L; srcLvl++, srcBitPattern >>>= 1) {
if ((srcBitPattern & 1L) > 0L) {
ItemsMergeImpl.justZipWithStride(
sourceLevels, (2 + srcLvl) * sourceK,
downBuf, 0,
targetK,
downFactor
);
ItemsUpdateImpl.inPlacePropagateCarry(
srcLvl + lgDownFactor,
(T[]) downBuf, 0,
(T[]) scratchBuf, 0,
false, tgt
);
// won't update target.n_ until the very end
}
}
tgt.n_ = nFinal;
assert (tgt.getN() / (2L * targetK)) == tgt.getBitPattern(); // internal consistency check
final T srcMax = src.isEmpty() ? null : src.getMaxItem();
final T srcMin = src.isEmpty() ? null : src.getMinItem();
final T tgtMax = tgt.isEmpty() ? null : tgt.getMaxItem();
final T tgtMin = tgt.isEmpty() ? null : tgt.getMinItem();
if ((srcMax != null) && (tgtMax != null)) {
tgt.maxItem_ = (src.getComparator().compare(srcMax, tgtMax) > 0) ? srcMax : tgtMax;
} //only one could be null
else if (tgtMax == null) { //if srcMax were null we would leave tgt alone
tgt.maxItem_ = srcMax;
}
if ((srcMin != null) && (tgtMin != null)) {
tgt.minItem_ = (src.getComparator().compare(srcMin, tgtMin) > 0) ? tgtMin : srcMin;
} //only one could be null
else if (tgtMin == null) { //if srcMin were null we would leave tgt alone
tgt.minItem_ = srcMin;
}
}
private static <T> void justZipWithStride(
final T[] bufSrc, final int startSrc, // input
final T[] bufC, final int startC, // output
final int kC, // number of items that should be in the output
final int stride) {
final int randomOffset = ItemsSketch.rand.nextInt(stride);
final int limC = startC + kC;
for (int a = startSrc + randomOffset, c = startC; c < limC; a += stride, c++ ) {
bufC[c] = bufSrc[a];
}
}
/**
* blockyTandemMergeSort() is an implementation of top-down merge sort specialized
* for the case where the input contains successive equal-length blocks
* that have already been sorted, so that only the top part of the
* merge tree remains to be executed. Also, two arrays are sorted in tandem,
* as discussed above.
* @param <T> the data type
* @param quantiles array of quantiles
* @param cumWts array of cum weights
* @param arrLen length of quantiles array and cumWts array
* @param blkSize size of internal sorted blocks
* @param comparator the comparator for data type T
*/
//also used by ItemsSketchSortedView
static <T> void blockyTandemMergeSort(final T[] quantiles, final long[] cumWts, final int arrLen,
final int blkSize, final Comparator<? super T> comparator) {
assert blkSize >= 1;
if (arrLen <= blkSize) { return; }
int numblks = arrLen / blkSize;
if ((numblks * blkSize) < arrLen) { numblks += 1; }
assert ((numblks * blkSize) >= arrLen);
// duplicate the input is preparation for the "ping-pong" copy reduction strategy.
final T[] keyTmp = Arrays.copyOf(quantiles, arrLen);
final long[] valTmp = Arrays.copyOf(cumWts, arrLen);
blockyTandemMergeSortRecursion(keyTmp, valTmp,
quantiles, cumWts,
0, numblks,
blkSize, arrLen, comparator);
}
/**
* blockyTandemMergeSortRecursion() is called by blockyTandemMergeSort().
* In addition to performing the algorithm's top down recursion,
* it manages the buffer swapping that eliminates most copying.
* It also maps the input's pre-sorted blocks into the subarrays
* that are processed by tandemMerge().
* @param <T> the data type
* @param qSrc source array of quantiles
* @param cwSrc source weights array
* @param qDst destination quantiles array
* @param cwDest destination weights array
* @param grpStart group start, refers to pre-sorted blocks such as block 0, block 1, etc.
* @param grpLen group length, refers to pre-sorted blocks such as block 0, block 1, etc.
* @param blkSize block size
* @param arrLim array limit
* @param comparator to compare keys
*/
private static <T> void blockyTandemMergeSortRecursion(final T[] qSrc, final long[] cwSrc,
final T[] qDst, final long[] cwDest, final int grpStart, final int grpLen, // block indices
final int blkSize, final int arrLim, final Comparator<? super T> comparator) {
// Important note: grpStart and grpLen do NOT refer to positions in the underlying array.
// Instead, they refer to the pre-sorted blocks, such as block 0, block 1, etc.
assert (grpLen > 0);
if (grpLen == 1) { return; }
final int grpLen1 = grpLen / 2;
final int grpLen2 = grpLen - grpLen1;
assert (grpLen1 >= 1);
assert (grpLen2 >= grpLen1);
final int grpStart1 = grpStart;
final int grpStart2 = grpStart + grpLen1;
//swap roles of src and dst
blockyTandemMergeSortRecursion(qDst, cwDest,
qSrc, cwSrc,
grpStart1, grpLen1, blkSize, arrLim, comparator);
//swap roles of src and dst
blockyTandemMergeSortRecursion(qDst, cwDest,
qSrc, cwSrc,
grpStart2, grpLen2, blkSize, arrLim, comparator);
// here we convert indices of blocks into positions in the underlying array.
final int arrStart1 = grpStart1 * blkSize;
final int arrStart2 = grpStart2 * blkSize;
final int arrLen1 = grpLen1 * blkSize;
int arrLen2 = grpLen2 * blkSize;
// special case for the final block which might be shorter than blkSize.
if ((arrStart2 + arrLen2) > arrLim) {
arrLen2 = arrLim - arrStart2;
}
tandemMerge(qSrc, cwSrc,
arrStart1, arrLen1,
arrStart2, arrLen2,
qDst, cwDest,
arrStart1, comparator); // which will be arrStart3
}
/**
* Performs two merges in tandem. One of them provides the sort keys
* while the other one passively undergoes the same data motion.
* @param <T> the data type
* @param qSrc quantiles source
* @param cwSrc cum wts source
* @param arrStart1 Array 1 start offset
* @param arrLen1 Array 1 length
* @param arrStart2 Array 2 start offset
* @param arrLen2 Array 2 length
* @param qDst quantiles destination
* @param cwDst cum wts destination
* @param arrStart3 Array 3 start offset
* @param comparator to compare keys
*/
private static <T> void tandemMerge(final T[] qSrc, final long[] cwSrc,
final int arrStart1, final int arrLen1,
final int arrStart2, final int arrLen2,
final T[] qDst, final long[] cwDst,
final int arrStart3, final Comparator<? super T> comparator) {
final int arrStop1 = arrStart1 + arrLen1;
final int arrStop2 = arrStart2 + arrLen2;
int i1 = arrStart1;
int i2 = arrStart2;
int i3 = arrStart3;
while ((i1 < arrStop1) && (i2 < arrStop2)) {
if (comparator.compare(qSrc[i2], qSrc[i1]) < 0) {
qDst[i3] = qSrc[i2];
cwDst[i3] = cwSrc[i2];
i3++; i2++;
} else {
qDst[i3] = qSrc[i1];
cwDst[i3] = cwSrc[i1];
i3++; i1++;
}
}
if (i1 < arrStop1) {
arraycopy(qSrc, i1, qDst, i3, arrStop1 - i1);
arraycopy(cwSrc, i1, cwDst, i3, arrStop1 - i1);
} else {
assert i2 < arrStop2;
arraycopy(qSrc, i2, qDst, i3, arrStop2 - i2);
arraycopy(cwSrc, i2, cwDst, i3, arrStop2 - i2);
}
}
}
| 2,798 |
0 | Create_ds/datasketches-java/src/main/java/org/apache/datasketches | Create_ds/datasketches-java/src/main/java/org/apache/datasketches/quantiles/KolmogorovSmirnov.java | /*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
package org.apache.datasketches.quantiles;
/**
* Kolmogorov-Smirnov Test
* See <a href="https://en.wikipedia.org/wiki/Kolmogorov-Smirnov_test">Kolmogorov–Smirnov Test</a>
*/
final class KolmogorovSmirnov {
//TODO This KS test will have to be redesigned to accommodate REQ sketches.
/**
* Computes the raw delta area between two quantile sketches for the
* <i>kolmogorovSmirnovTest(DoublesSketch, DoublesSketch, double)</i>
* method.
* @param sketch1 Input DoubleSketch 1
* @param sketch2 Input DoubleSketch 2
* @return the raw delta area between two quantile sketches
*/
public static double computeKSDelta(final DoublesSketch sketch1, final DoublesSketch sketch2) {
final DoublesSketchSortedView p = new DoublesSketchSortedView(sketch1);
final DoublesSketchSortedView q = new DoublesSketchSortedView(sketch2);
final double[] pSamplesArr = p.getQuantiles();
final double[] qSamplesArr = q.getQuantiles();
final long[] pCumWtsArr = p.getCumulativeWeights();
final long[] qCumWtsArr = q.getCumulativeWeights();
final int pSamplesArrLen = pSamplesArr.length;
final int qSamplesArrLen = qSamplesArr.length;
final double n1 = sketch1.getN();
final double n2 = sketch2.getN();
double deltaHeight = 0;
int i = 0;
int j = 0;
while ((i < pSamplesArrLen - 1) && (j < qSamplesArrLen - 1)) {
deltaHeight = Math.max(deltaHeight, Math.abs(pCumWtsArr[i] / n1 - qCumWtsArr[j] / n2));
if (pSamplesArr[i] < qSamplesArr[j]) {
i++;
} else if (qSamplesArr[j] < pSamplesArr[i]) {
j++;
} else {
i++;
j++;
}
}
deltaHeight = Math.max(deltaHeight, Math.abs(pCumWtsArr[i] / n1 - qCumWtsArr[j] / n2));
return deltaHeight;
}
/**
* Computes the adjusted delta height threshold for the
* <i>kolmogorovSmirnovTest(DoublesSketch, DoublesSketch, double)</i>
* method.
* This adjusts the computed threshold by the error epsilons of the two given sketches.
* @param sketch1 Input DoubleSketch 1
* @param sketch2 Input DoubleSketch 2
* @param tgtPvalue Target p-value. Typically .001 to .1, e.g., .05.
* @return the adjusted threshold to be compared with the raw delta area.
*/
public static double computeKSThreshold(final DoublesSketch sketch1,
final DoublesSketch sketch2,
final double tgtPvalue) {
final double r1 = sketch1.getNumRetained();
final double r2 = sketch2.getNumRetained();
final double alpha = tgtPvalue;
final double alphaFactor = Math.sqrt(-0.5 * Math.log(0.5 * alpha));
final double deltaAreaThreshold = alphaFactor * Math.sqrt((r1 + r2) / (r1 * r2));
final double eps1 = sketch1.getNormalizedRankError(false);
final double eps2 = sketch2.getNormalizedRankError(false);
return deltaAreaThreshold + eps1 + eps2;
}
/**
* Performs the Kolmogorov-Smirnov Test between two quantiles sketches.
* Note: if the given sketches have insufficient data or if the sketch sizes are too small,
* this will return false.
* @param sketch1 Input DoubleSketch 1
* @param sketch2 Input DoubleSketch 2
* @param tgtPvalue Target p-value. Typically .001 to .1, e.g., .05.
* @return Boolean indicating whether we can reject the null hypothesis (that the sketches
* reflect the same underlying distribution) using the provided tgtPValue.
*/
public static boolean kolmogorovSmirnovTest(final DoublesSketch sketch1,
final DoublesSketch sketch2, final double tgtPvalue) {
final double delta = computeKSDelta(sketch1, sketch2);
final double thresh = computeKSThreshold(sketch1, sketch2, tgtPvalue);
return delta > thresh;
}
}
| 2,799 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.