idx int64 0 165k | question stringlengths 73 4.15k | target stringlengths 5 918 | len_question int64 21 890 | len_target int64 3 255 |
|---|---|---|---|---|
31,800 | public static ArrayOfDoublesUnion wrap ( final Memory mem , final long seed ) { return wrapUnionImpl ( ( WritableMemory ) mem , seed , false ) ; } | Wrap the given Memory and seed as an ArrayOfDoublesUnion | 36 | 14 |
31,801 | public void update ( final ArrayOfDoublesSketch sketchIn ) { if ( sketchIn == null ) { return ; } Util . checkSeedHashes ( seedHash_ , sketchIn . getSeedHash ( ) ) ; if ( sketch_ . getNumValues ( ) != sketchIn . getNumValues ( ) ) { throw new SketchesArgumentException ( "Incompatible sketches: number of values mismatch " + sketch_ . getNumValues ( ) + " and " + sketchIn . getNumValues ( ) ) ; } if ( sketchIn . isEmpty ( ) ) { return ; } if ( sketchIn . getThetaLong ( ) < theta_ ) { theta_ = sketchIn . getThetaLong ( ) ; } final ArrayOfDoublesSketchIterator it = sketchIn . iterator ( ) ; while ( it . next ( ) ) { sketch_ . merge ( it . getKey ( ) , it . getValues ( ) ) ; } } | Updates the union by adding a set of entries from a given sketch | 211 | 14 |
31,802 | public ArrayOfDoublesCompactSketch getResult ( final WritableMemory dstMem ) { if ( sketch_ . getRetainedEntries ( ) > sketch_ . getNominalEntries ( ) ) { theta_ = Math . min ( theta_ , sketch_ . getNewTheta ( ) ) ; } if ( dstMem == null ) { return new HeapArrayOfDoublesCompactSketch ( sketch_ , theta_ ) ; } return new DirectArrayOfDoublesCompactSketch ( sketch_ , theta_ , dstMem ) ; } | Returns the resulting union in the form of a compact sketch | 127 | 11 |
31,803 | static final void extractCommonHll ( final Memory srcMem , final HllArray hllArray ) { hllArray . putOutOfOrderFlag ( extractOooFlag ( srcMem ) ) ; hllArray . putCurMin ( extractCurMin ( srcMem ) ) ; hllArray . putHipAccum ( extractHipAccum ( srcMem ) ) ; hllArray . putKxQ0 ( extractKxQ0 ( srcMem ) ) ; hllArray . putKxQ1 ( extractKxQ1 ( srcMem ) ) ; hllArray . putNumAtCurMin ( extractNumAtCurMin ( srcMem ) ) ; //load Hll array srcMem . getByteArray ( HLL_BYTE_ARR_START , hllArray . hllByteArr , 0 , hllArray . hllByteArr . length ) ; } | used by heapify by all Heap HLL | 192 | 10 |
31,804 | static byte [ ] compactMemoryToByteArray ( final Memory srcMem , final int preLongs , final int curCount ) { final int outBytes = ( curCount + preLongs ) << 3 ; final byte [ ] byteArrOut = new byte [ outBytes ] ; srcMem . getByteArray ( 0 , byteArrOut , 0 , outBytes ) ; //copies the whole thing return byteArrOut ; } | Serializes a Memory based compact sketch to a byte array | 92 | 11 |
31,805 | 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 ) ; } | 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 . | 419 | 67 |
31,806 | 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 } | 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 . | 380 | 69 |
31,807 | 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 ; } | 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 ; | 124 | 34 |
31,808 | public UpdateSketchBuilder setLogNominalEntries ( final int lgNomEntries ) { bLgNomLongs = lgNomEntries ; if ( ( bLgNomLongs > MAX_LG_NOM_LONGS ) || ( bLgNomLongs < MIN_LG_NOM_LONGS ) ) { throw new SketchesArgumentException ( "Log Nominal Entries must be >= 4 and <= 26: " + lgNomEntries ) ; } return this ; } | Alternative method of setting the Nominal Entries for this sketch from the log_base2 value . This value is also used for building a shared concurrent sketch . The minimum value is 4 and the maximum value is 26 . Be aware that sketches as large as this maximum value may not have been thoroughly tested or characterized for performance . | 122 | 65 |
31,809 | public UpdateSketchBuilder setLocalNominalEntries ( final int nomEntries ) { bLocalLgNomLongs = Integer . numberOfTrailingZeros ( ceilingPowerOf2 ( nomEntries ) ) ; if ( ( bLocalLgNomLongs > MAX_LG_NOM_LONGS ) || ( bLocalLgNomLongs < MIN_LG_NOM_LONGS ) ) { throw new SketchesArgumentException ( "Nominal Entries must be >= 16 and <= 67108864: " + nomEntries ) ; } return this ; } | 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 . | 135 | 53 |
31,810 | public UpdateSketchBuilder setLocalLogNominalEntries ( final int lgNomEntries ) { bLocalLgNomLongs = lgNomEntries ; if ( ( bLocalLgNomLongs > MAX_LG_NOM_LONGS ) || ( bLocalLgNomLongs < MIN_LG_NOM_LONGS ) ) { throw new SketchesArgumentException ( "Log Nominal Entries must be >= 4 and <= 26: " + lgNomEntries ) ; } return this ; } | 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 . | 126 | 54 |
31,811 | 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 ) ; } | Returns a local concurrent UpdateSketch to be used as a per - thread local buffer along with the given concurrent shared UpdateSketch and the current configuration of this Builder | 115 | 35 |
31,812 | 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 a copy of this sketch | 133 | 6 |
31,813 | public static int getMaxSerializedBytes ( final int lgK ) { checkLgK ( lgK ) ; if ( lgK <= 19 ) { return empiricalMaxBytes [ lgK - 4 ] + 40 ; } final int k = 1 << lgK ; return ( int ) ( 0.6 * k ) + 40 ; // 0.6 = 4.8 / 8.0 } | 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 . | 87 | 34 |
31,814 | public static CpcSketch heapify ( final Memory mem , final long seed ) { final CompressedState state = CompressedState . importFromMemory ( mem ) ; return uncompress ( state , seed ) ; } | Return the given Memory as a CpcSketch on the Java heap . | 46 | 16 |
31,815 | public static CpcSketch heapify ( final byte [ ] byteArray , final long seed ) { final Memory mem = Memory . wrap ( byteArray ) ; return heapify ( mem , seed ) ; } | Return the given byte array as a CpcSketch on the Java heap . | 44 | 17 |
31,816 | public final void reset ( ) { numCoupons = 0 ; mergeFlag = false ; fiCol = 0 ; windowOffset = 0 ; slidingWindow = null ; pairTable = null ; kxp = 1 << lgK ; hipEstAccum = 0 ; } | Resets this sketch to empty but retains the original LgK and Seed . | 56 | 16 |
31,817 | 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 ( ) ; } | Return this sketch as a compressed byte array . | 83 | 9 |
31,818 | public void update ( final long datum ) { final long [ ] data = { datum } ; final long [ ] arr = hash ( data , seed ) ; hashUpdate ( arr [ 0 ] , arr [ 1 ] ) ; } | Present the given long as a potential unique item . | 49 | 10 |
31,819 | 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 integer array as a potential unique item . If the integer array is null or empty no update attempt is made and the method returns . | 59 | 29 |
31,820 | 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 ) ; } | Returns the Format of the serialized form of this sketch . | 139 | 12 |
31,821 | 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 ; } | In terms of flavor this promotes SPARSE to HYBRID . | 337 | 14 |
31,822 | static void refreshKXP ( final CpcSketch sketch , final long [ ] bitMatrix ) { final int k = ( 1 << sketch . lgK ) ; // for improved numerical accuracy, we separately sum the bytes of the U64's final double [ ] byteSums = new double [ 8 ] ; for ( int j = 0 ; j < 8 ; j ++ ) { byteSums [ j ] = 0.0 ; } for ( int i = 0 ; i < k ; i ++ ) { long row = bitMatrix [ i ] ; for ( int j = 0 ; j < 8 ; j ++ ) { final int byteIdx = ( int ) ( row & 0XFF L ) ; 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 ; } | Also used in test | 254 | 4 |
31,823 | 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 = ( 0XFF L << 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 ) & 0XFF L ) ; 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 } } | This moves the sliding window | 520 | 5 |
31,824 | 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" } | Call this whenever a new coupon has been collected . | 88 | 10 |
31,825 | 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) } } } | The flavor is HYBRID PINNED or SLIDING . | 533 | 14 |
31,826 | static CpcSketch uncompress ( final CompressedState source , final long seed ) { checkSeedHashes ( computeSeedHash ( seed ) , source . seedHash ) ; final CpcSketch sketch = new CpcSketch ( source . lgK , seed ) ; sketch . numCoupons = source . numCoupons ; sketch . windowOffset = source . getWindowOffset ( ) ; sketch . fiCol = source . fiCol ; sketch . mergeFlag = source . mergeFlag ; sketch . kxp = source . kxp ; sketch . hipEstAccum = source . hipEstAccum ; sketch . slidingWindow = null ; sketch . pairTable = null ; CpcCompression . uncompress ( source , sketch ) ; return sketch ; } | also used in test | 166 | 4 |
31,827 | 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 here and for testing | 292 | 5 |
31,828 | 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 ) ; } } | Used by union and in testing | 113 | 6 |
31,829 | static long [ ] getBitMatrix ( final CpcUnion union ) { checkUnionState ( union ) ; return ( union . bitMatrix != null ) ? union . bitMatrix : CpcUtil . bitMatrixOfSketch ( union . accumulator ) ; } | used for testing only | 56 | 4 |
31,830 | public UpdatableSketchBuilder < U , S > setSamplingProbability ( final float samplingProbability ) { if ( ( samplingProbability < 0 ) || ( samplingProbability > 1f ) ) { throw new SketchesArgumentException ( "sampling probability must be between 0 and 1" ) ; } samplingProbability_ = samplingProbability ; return this ; } | This is to set sampling probability . Default probability is 1 . | 88 | 12 |
31,831 | public UpdatableSketch < U , S > build ( ) { return new UpdatableSketch <> ( nomEntries_ , resizeFactor_ . lg ( ) , samplingProbability_ , summaryFactory_ ) ; } | Returns an UpdatableSketch with the current configuration of this Builder . | 53 | 16 |
31,832 | private void srcMemoryToCombinedBuffer ( final Memory srcMem , final int serVer , final boolean srcIsCompact , final int combBufCap ) { final int preLongs = 2 ; final int extra = ( serVer == 1 ) ? 3 : 2 ; // space for min and max values, buf alloc (SerVer 1) final int preBytes = ( preLongs + extra ) << 3 ; final int k = getK ( ) ; combinedBuffer_ = new double [ combBufCap ] ; if ( srcIsCompact ) { // just load the array, sort base buffer if serVer 2 srcMem . getDoubleArray ( preBytes , combinedBuffer_ , 0 , combBufCap ) ; if ( serVer == 2 ) { Arrays . sort ( combinedBuffer_ , 0 , baseBufferCount_ ) ; } } else { // non-compact source // load base buffer and ensure it's sorted srcMem . getDoubleArray ( preBytes , combinedBuffer_ , 0 , baseBufferCount_ ) ; Arrays . sort ( combinedBuffer_ , 0 , baseBufferCount_ ) ; // iterate through levels int srcOffset = preBytes + ( ( 2 * k ) << 3 ) ; int dstOffset = baseBufferCount_ ; long bitPattern = bitPattern_ ; for ( ; bitPattern != 0 ; srcOffset += ( k << 3 ) , bitPattern >>>= 1 ) { if ( ( bitPattern & 1L ) > 0L ) { srcMem . getDoubleArray ( srcOffset , combinedBuffer_ , dstOffset , k ) ; dstOffset += k ; } } } } | Loads the Combined Buffer from the given source Memory . The resulting Combined Buffer is allocated in this method and is always in compact form . | 341 | 27 |
31,833 | public static double getLowerBoundForBoverA ( final long a , final long b , final double f ) { checkInputs ( a , b , f ) ; if ( a == 0 ) { return 0.0 ; } if ( f == 1.0 ) { return ( double ) b / a ; } return approximateLowerBoundOnP ( a , b , NUM_STD_DEVS * hackyAdjuster ( f ) ) ; } | Return the approximate lower bound based on a 95% confidence interval | 94 | 12 |
31,834 | public static double getUpperBoundForBoverA ( final long a , final long b , final double f ) { checkInputs ( a , b , f ) ; if ( a == 0 ) { return 1.0 ; } if ( f == 1.0 ) { return ( double ) b / a ; } return approximateUpperBoundOnP ( a , b , NUM_STD_DEVS * hackyAdjuster ( f ) ) ; } | Return the approximate upper bound based on a 95% confidence interval | 96 | 12 |
31,835 | private static double hackyAdjuster ( final double f ) { final double tmp = Math . sqrt ( 1.0 - f ) ; return ( f <= 0.5 ) ? tmp : tmp + ( 0.01 * ( f - 0.5 ) ) ; } | This hackyAdjuster is tightly coupled with the width of the confidence interval normally specified with number of standard deviations . To simplify this interface the number of standard deviations has been fixed to 2 . 0 which corresponds to a confidence interval of 95% . | 57 | 49 |
31,836 | static final int coupon16 ( final byte [ ] identifier ) { final long [ ] hash = MurmurHash3 . hash ( identifier , SEED ) ; final int hllIdx = ( int ) ( ( ( hash [ 0 ] >>> 1 ) % 1024 ) & TEN_BIT_MASK ) ; //hash[0] for 10-bit address final int lz = Long . numberOfLeadingZeros ( hash [ 1 ] ) ; final int value = ( lz > 62 ? 62 : lz ) + 1 ; return ( value << 10 ) | hllIdx ; } | Returns the HLL array index and value as a 16 - bit coupon given the identifier to be hashed and k . | 126 | 24 |
31,837 | public static < S extends Summary > Sketch < S > heapifySketch ( final Memory mem , final SummaryDeserializer < S > deserializer ) { final SerializerDeserializer . SketchType sketchType = SerializerDeserializer . getSketchType ( mem ) ; if ( sketchType == SerializerDeserializer . SketchType . QuickSelectSketch ) { return new QuickSelectSketch < S > ( mem , deserializer , null ) ; } return new CompactSketch < S > ( mem , deserializer ) ; } | Instantiate Sketch from a given Memory | 121 | 7 |
31,838 | public static < U , S extends UpdatableSummary < U > > UpdatableSketch < U , S > heapifyUpdatableSketch ( final Memory mem , final SummaryDeserializer < S > deserializer , final SummaryFactory < S > summaryFactory ) { return new UpdatableSketch < U , S > ( mem , deserializer , summaryFactory ) ; } | Instantiate UpdatableSketch from a given Memory | 86 | 12 |
31,839 | public void update ( final long [ ] data ) { if ( ( data == null ) || ( data . length == 0 ) ) { return ; } couponUpdate ( coupon ( hash ( data , DEFAULT_UPDATE_SEED ) ) ) ; } | 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 . | 52 | 29 |
31,840 | public static long hash ( final long in , final long seed ) { long hash = seed + P5 ; hash += 8 ; long k1 = in ; k1 *= P2 ; k1 = Long . rotateLeft ( k1 , 31 ) ; k1 *= P1 ; hash ^= k1 ; hash = ( Long . rotateLeft ( hash , 27 ) * P1 ) + P4 ; return finalize ( hash ) ; } | Returns a 64 - bit hash . | 94 | 7 |
31,841 | @ SuppressWarnings ( "null" ) @ Override public byte [ ] toByteArray ( ) { int summariesBytesLength = 0 ; byte [ ] [ ] summariesBytes = null ; final int count = getRetainedEntries ( ) ; if ( count > 0 ) { summariesBytes = new byte [ count ] [ ] ; for ( int i = 0 ; i < count ; i ++ ) { summariesBytes [ i ] = summaries_ [ i ] . toByteArray ( ) ; summariesBytesLength += summariesBytes [ i ] . length ; } } int sizeBytes = Byte . BYTES // preamble longs + Byte . BYTES // serial version + Byte . BYTES // family id + Byte . BYTES // sketch type + Byte . BYTES ; // flags final boolean isThetaIncluded = theta_ < Long . MAX_VALUE ; if ( isThetaIncluded ) { sizeBytes += Long . BYTES ; // theta } if ( count > 0 ) { sizeBytes += + Integer . BYTES // count + ( Long . BYTES * count ) + summariesBytesLength ; } final byte [ ] bytes = new byte [ sizeBytes ] ; int offset = 0 ; bytes [ offset ++ ] = PREAMBLE_LONGS ; bytes [ offset ++ ] = serialVersionUID ; bytes [ offset ++ ] = ( byte ) Family . TUPLE . getID ( ) ; bytes [ offset ++ ] = ( byte ) SerializerDeserializer . SketchType . CompactSketch . ordinal ( ) ; final boolean isBigEndian = ByteOrder . nativeOrder ( ) . equals ( ByteOrder . BIG_ENDIAN ) ; bytes [ offset ++ ] = ( byte ) ( ( isBigEndian ? 1 << Flags . IS_BIG_ENDIAN . ordinal ( ) : 0 ) | ( isEmpty_ ? 1 << Flags . IS_EMPTY . ordinal ( ) : 0 ) | ( count > 0 ? 1 << Flags . HAS_ENTRIES . ordinal ( ) : 0 ) | ( isThetaIncluded ? 1 << Flags . IS_THETA_INCLUDED . ordinal ( ) : 0 ) ) ; if ( isThetaIncluded ) { ByteArrayUtil . putLongLE ( bytes , offset , theta_ ) ; offset += Long . BYTES ; } if ( count > 0 ) { ByteArrayUtil . putIntLE ( bytes , offset , getRetainedEntries ( ) ) ; offset += Integer . BYTES ; for ( int i = 0 ; i < count ; i ++ ) { ByteArrayUtil . putLongLE ( bytes , offset , keys_ [ i ] ) ; offset += Long . BYTES ; } for ( int i = 0 ; i < count ; i ++ ) { System . arraycopy ( summariesBytes [ i ] , 0 , bytes , offset , summariesBytes [ i ] . length ) ; offset += summariesBytes [ i ] . length ; } } return bytes ; } | 0 || | Flags | SkType | FamID | SerVer | Preamble_Longs | | 654 | 21 |
31,842 | static ArrayOfDoublesUnion heapifyUnion ( final Memory mem , final long seed ) { final SerializerDeserializer . SketchType type = SerializerDeserializer . getSketchType ( mem ) ; // compatibility with version 0.9.1 and lower if ( type == SerializerDeserializer . SketchType . ArrayOfDoublesQuickSelectSketch ) { final ArrayOfDoublesQuickSelectSketch sketch = new HeapArrayOfDoublesQuickSelectSketch ( mem , seed ) ; return new HeapArrayOfDoublesUnion ( sketch ) ; } final byte version = mem . getByte ( SERIAL_VERSION_BYTE ) ; if ( version != serialVersionUID ) { throw new SketchesArgumentException ( "Serial version mismatch. Expected: " + serialVersionUID + ", actual: " + version ) ; } SerializerDeserializer . validateFamily ( mem . getByte ( FAMILY_ID_BYTE ) , mem . getByte ( PREAMBLE_LONGS_BYTE ) ) ; SerializerDeserializer . validateType ( mem . getByte ( SKETCH_TYPE_BYTE ) , SerializerDeserializer . SketchType . ArrayOfDoublesUnion ) ; final long unionTheta = mem . getLong ( THETA_LONG ) ; final Memory sketchMem = mem . region ( PREAMBLE_SIZE_BYTES , mem . getCapacity ( ) - PREAMBLE_SIZE_BYTES ) ; final ArrayOfDoublesQuickSelectSketch sketch = new HeapArrayOfDoublesQuickSelectSketch ( sketchMem , seed ) ; final ArrayOfDoublesUnion union = new HeapArrayOfDoublesUnion ( sketch ) ; union . theta_ = unionTheta ; return union ; } | This is to create an instance given a serialized form and a custom seed | 385 | 15 |
31,843 | private static int asInteger ( final long [ ] data , final int n ) { int t ; int cnt = 0 ; long seed = 0 ; if ( n < 2 ) { throw new SketchesArgumentException ( "Given value of n must be > 1." ) ; } if ( n > ( 1 << 30 ) ) { while ( ++ cnt < 10000 ) { final long [ ] h = MurmurHash3 . hash ( data , seed ) ; t = ( int ) ( h [ 0 ] & INT_MASK ) ; if ( t < n ) { return t ; } t = ( int ) ( ( h [ 0 ] >>> 33 ) ) ; if ( t < n ) { return t ; } t = ( int ) ( h [ 1 ] & INT_MASK ) ; if ( t < n ) { return t ; } t = ( int ) ( ( h [ 1 ] >>> 33 ) ) ; if ( t < n ) { return t ; } seed += PRIME ; } // end while throw new SketchesStateException ( "Internal Error: Failed to find integer < n within 10000 iterations." ) ; } final long mask = ceilingPowerOf2 ( n ) - 1 ; while ( ++ cnt < 10000 ) { final long [ ] h = MurmurHash3 . hash ( data , seed ) ; t = ( int ) ( h [ 0 ] & mask ) ; if ( t < n ) { return t ; } t = ( int ) ( ( h [ 0 ] >>> 33 ) & mask ) ; if ( t < n ) { return t ; } t = ( int ) ( h [ 1 ] & mask ) ; if ( t < n ) { return t ; } t = ( int ) ( ( h [ 1 ] >>> 33 ) & mask ) ; if ( t < n ) { return t ; } seed += PRIME ; } // end while throw new SketchesStateException ( "Internal Error: Failed to find integer < n within 10000 iterations." ) ; } | Returns a deterministic uniform random integer with a minimum inclusive value of zero and a maximum exclusive value of n given the input data . | 431 | 26 |
31,844 | public static int modulo ( final long h0 , final long h1 , final int divisor ) { final long d = divisor ; final long modH0 = ( h0 < 0L ) ? addRule ( mulRule ( BIT62 , 2L , d ) , ( h0 & MAX_LONG ) , d ) : h0 % d ; final long modH1 = ( h1 < 0L ) ? addRule ( mulRule ( BIT62 , 2L , d ) , ( h1 & MAX_LONG ) , d ) : h1 % d ; final long modTop = mulRule ( mulRule ( BIT62 , 4L , d ) , modH1 , d ) ; return ( int ) addRule ( modTop , modH0 , d ) ; } | Returns the remainder from the modulo division of the 128 - bit output of the murmurHash3 by the divisor . | 170 | 26 |
31,845 | public List < Group > getResult ( final int [ ] priKeyIndices , final int limit , final int numStdDev , final char sep ) { final PostProcessor proc = new PostProcessor ( this , new Group ( ) , sep ) ; return proc . getGroupList ( priKeyIndices , numStdDev , limit ) ; } | Returns an ordered List of Groups of the most frequent distinct population of subset tuples represented by the count of entries of each group . | 75 | 26 |
31,846 | public double getLowerBound ( final int numStdDev , final int numSubsetEntries ) { if ( ! isEstimationMode ( ) ) { return numSubsetEntries ; } return BinomialBoundsN . getLowerBound ( numSubsetEntries , getTheta ( ) , numStdDev , isEmpty ( ) ) ; } | Gets the estimate of the lower bound of the true distinct population represented by the count of entries in a group . | 76 | 23 |
31,847 | public double getUpperBound ( final int numStdDev , final int numSubsetEntries ) { if ( ! isEstimationMode ( ) ) { return numSubsetEntries ; } return BinomialBoundsN . getUpperBound ( numSubsetEntries , getTheta ( ) , numStdDev , isEmpty ( ) ) ; } | Gets the estimate of the upper bound of the true distinct population represented by the count of entries in a group . | 78 | 23 |
31,848 | static int computeLgK ( final double threshold , final double rse ) { final double v = Math . ceil ( 1.0 / ( threshold * rse * rse ) ) ; final int lgK = ( int ) Math . ceil ( Math . log ( v ) / Math . log ( 2 ) ) ; if ( lgK > MAX_LG_NOM_LONGS ) { throw new SketchesArgumentException ( "Requested Sketch (LgK = " + lgK + " > 2^26), " + "either increase the threshold, the rse or both." ) ; } return lgK ; } | Computes LgK given the threshold and RSE . | 143 | 12 |
31,849 | T getQuantile ( final double fRank ) { checkFractionalRankBounds ( fRank ) ; if ( auxN_ <= 0 ) { return null ; } final long pos = QuantilesHelper . posOfPhi ( fRank , auxN_ ) ; return approximatelyAnswerPositionalQuery ( pos ) ; } | Get the estimated quantile given a fractional rank . | 68 | 11 |
31,850 | @ SuppressWarnings ( "unchecked" ) private T approximatelyAnswerPositionalQuery ( final long pos ) { assert 0 <= pos ; assert pos < auxN_ ; final int index = QuantilesHelper . chunkContainingPos ( auxCumWtsArr_ , pos ) ; return ( T ) this . auxSamplesArr_ [ index ] ; } | Assuming that there are n items in the true stream this asks what item would appear in position 0 &le ; pos < ; n of a hypothetical sorted version of that stream . | 79 | 36 |
31,851 | private final static < T > void populateFromItemsSketch ( final int k , final long n , final long bitPattern , final T [ ] combinedBuffer , final int baseBufferCount , final int numSamples , final T [ ] itemsArr , final long [ ] cumWtsArr , final Comparator < ? super T > comparator ) { long weight = 1 ; int nxt = 0 ; long bits = bitPattern ; assert bits == ( n / ( 2L * k ) ) ; // internal consistency check for ( int lvl = 0 ; bits != 0L ; lvl ++ , bits >>>= 1 ) { weight *= 2 ; if ( ( bits & 1L ) > 0L ) { final int offset = ( 2 + lvl ) * k ; for ( int i = 0 ; i < k ; i ++ ) { itemsArr [ nxt ] = combinedBuffer [ i + offset ] ; cumWtsArr [ nxt ] = weight ; nxt ++ ; } } } weight = 1 ; //NOT a mistake! We just copied the highest level; now we need to copy the base buffer final int startOfBaseBufferBlock = nxt ; // Copy BaseBuffer over, along with weight = 1 for ( int i = 0 ; i < baseBufferCount ; i ++ ) { itemsArr [ nxt ] = combinedBuffer [ i ] ; cumWtsArr [ nxt ] = weight ; nxt ++ ; } assert nxt == numSamples ; // Must sort the items that came from the base buffer. // Don't need to sort the corresponding weights because they are all the same. Arrays . sort ( itemsArr , startOfBaseBufferBlock , numSamples , comparator ) ; cumWtsArr [ numSamples ] = 0 ; } | Populate the arrays and registers from an ItemsSketch | 379 | 12 |
31,852 | static DirectCompactUnorderedSketch wrapInstance ( final Memory srcMem , final long seed ) { final short memSeedHash = srcMem . getShort ( SEED_HASH_SHORT ) ; final short computedSeedHash = computeSeedHash ( seed ) ; checkSeedHashes ( memSeedHash , computedSeedHash ) ; return new DirectCompactUnorderedSketch ( srcMem ) ; } | Wraps the given Memory which must be a SerVer 3 unordered Compact Sketch image . Must check the validity of the Memory before calling . | 93 | 28 |
31,853 | static DirectCompactUnorderedSketch compact ( final UpdateSketch sketch , final WritableMemory dstMem ) { final int curCount = sketch . getRetainedEntries ( true ) ; long thetaLong = sketch . getThetaLong ( ) ; boolean empty = sketch . isEmpty ( ) ; thetaLong = thetaOnCompact ( empty , curCount , thetaLong ) ; empty = emptyOnCompact ( curCount , thetaLong ) ; final int preLongs = computeCompactPreLongs ( thetaLong , empty , curCount ) ; final short seedHash = sketch . getSeedHash ( ) ; final long [ ] cache = sketch . getCache ( ) ; final int requiredFlags = READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK ; final byte flags = ( byte ) ( requiredFlags | ( empty ? EMPTY_FLAG_MASK : 0 ) ) ; final boolean ordered = false ; final long [ ] compactCache = CompactSketch . compactCache ( cache , curCount , thetaLong , ordered ) ; loadCompactMemory ( compactCache , seedHash , curCount , thetaLong , dstMem , flags , preLongs ) ; return new DirectCompactUnorderedSketch ( dstMem ) ; } | Constructs given an UpdateSketch . | 277 | 9 |
31,854 | static DirectCompactUnorderedSketch compact ( final long [ ] cache , final boolean empty , final short seedHash , final int curCount , final long thetaLong , final WritableMemory dstMem ) { final int preLongs = computeCompactPreLongs ( thetaLong , empty , curCount ) ; final int requiredFlags = READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK ; final byte flags = ( byte ) ( requiredFlags | ( empty ? EMPTY_FLAG_MASK : 0 ) ) ; loadCompactMemory ( cache , seedHash , curCount , thetaLong , dstMem , flags , preLongs ) ; return new DirectCompactUnorderedSketch ( dstMem ) ; } | Constructs this sketch from correct valid components . | 160 | 9 |
31,855 | public long [ ] getSamples ( ) { if ( itemsSeen_ == 0 ) { return null ; } final int numSamples = ( int ) Math . min ( reservoirSize_ , itemsSeen_ ) ; return java . util . Arrays . copyOf ( data_ , numSamples ) ; } | Returns a copy of the items in the reservoir . The returned array length may be smaller than the reservoir capacity . | 67 | 22 |
31,856 | public static DeserializeResult < DoubleSummary > fromMemory ( final Memory mem ) { return new DeserializeResult <> ( new DoubleSummary ( mem . getDouble ( VALUE_DOUBLE ) , Mode . values ( ) [ mem . getByte ( MODE_BYTE ) ] ) , SERIALIZED_SIZE_BYTES ) ; } | Creates an instance of the DoubleSummary given a serialized representation | 77 | 13 |
31,857 | public void update ( final long datum ) { if ( gadget_ == null ) { gadget_ = ReservoirLongsSketch . newInstance ( maxK_ ) ; } gadget_ . update ( datum ) ; } | Present this union with a long . | 48 | 7 |
31,858 | static String preambleToString ( final byte [ ] byteArr ) { final Memory mem = Memory . wrap ( byteArr ) ; return preambleToString ( mem ) ; } | Returns a human readable string summary of the preamble state of the given byte array . Used primarily in testing . | 41 | 23 |
31,859 | private final static void populateFromDoublesSketch ( final int k , final long n , final long bitPattern , final DoublesSketchAccessor sketchAccessor , final double [ ] itemsArr , final long [ ] cumWtsArr ) { long weight = 1 ; int nxt = 0 ; long bits = bitPattern ; assert bits == ( n / ( 2L * k ) ) ; // internal consistency check for ( int lvl = 0 ; bits != 0L ; lvl ++ , bits >>>= 1 ) { weight *= 2 ; if ( ( bits & 1L ) > 0L ) { sketchAccessor . setLevel ( lvl ) ; for ( int i = 0 ; i < sketchAccessor . numItems ( ) ; i ++ ) { itemsArr [ nxt ] = sketchAccessor . get ( i ) ; cumWtsArr [ nxt ] = weight ; nxt ++ ; } } } weight = 1 ; //NOT a mistake! We just copied the highest level; now we need to copy the base buffer final int startOfBaseBufferBlock = nxt ; // Copy BaseBuffer over, along with weight = 1 sketchAccessor . setLevel ( BB_LVL_IDX ) ; for ( int i = 0 ; i < sketchAccessor . numItems ( ) ; i ++ ) { itemsArr [ nxt ] = sketchAccessor . get ( i ) ; cumWtsArr [ nxt ] = weight ; nxt ++ ; } assert nxt == itemsArr . length ; // Must sort the items that came from the base buffer. // Don't need to sort the corresponding weights because they are all the same. final int numSamples = nxt ; Arrays . sort ( itemsArr , startOfBaseBufferBlock , numSamples ) ; cumWtsArr [ numSamples ] = 0 ; } | Populate the arrays and registers from a DoublesSketch | 397 | 13 |
31,860 | static void blockyTandemMergeSort ( final double [ ] keyArr , final long [ ] valArr , final int arrLen , final int blkSize ) { assert blkSize >= 1 ; if ( arrLen <= blkSize ) { return ; } int numblks = arrLen / blkSize ; if ( ( numblks * blkSize ) < arrLen ) { numblks += 1 ; } assert ( ( numblks * blkSize ) >= arrLen ) ; // duplicate the input is preparation for the "ping-pong" copy reduction strategy. final double [ ] keyTmp = Arrays . copyOf ( keyArr , arrLen ) ; final long [ ] valTmp = Arrays . copyOf ( valArr , arrLen ) ; blockyTandemMergeSortRecursion ( keyTmp , valTmp , keyArr , valArr , 0 , numblks , blkSize , arrLen ) ; } | used by DoublesAuxiliary and UtilTest | 212 | 11 |
31,861 | private static void tandemMerge ( final double [ ] keySrc , final long [ ] valSrc , final int arrStart1 , final int arrLen1 , final int arrStart2 , final int arrLen2 , final double [ ] keyDst , final long [ ] valDst , final int arrStart3 ) { final int arrStop1 = arrStart1 + arrLen1 ; final int arrStop2 = arrStart2 + arrLen2 ; int i1 = arrStart1 ; int i2 = arrStart2 ; int i3 = arrStart3 ; while ( ( i1 < arrStop1 ) && ( i2 < arrStop2 ) ) { if ( keySrc [ i2 ] < keySrc [ i1 ] ) { keyDst [ i3 ] = keySrc [ i2 ] ; valDst [ i3 ] = valSrc [ i2 ] ; i2 ++ ; } else { keyDst [ i3 ] = keySrc [ i1 ] ; valDst [ i3 ] = valSrc [ i1 ] ; i1 ++ ; } i3 ++ ; } if ( i1 < arrStop1 ) { arraycopy ( keySrc , i1 , keyDst , i3 , arrStop1 - i1 ) ; arraycopy ( valSrc , i1 , valDst , i3 , arrStop1 - i1 ) ; } else { assert i2 < arrStop2 ; arraycopy ( keySrc , i2 , keyDst , i3 , arrStop2 - i2 ) ; arraycopy ( valSrc , i2 , valDst , i3 , arrStop2 - i2 ) ; } } | Performs two merges in tandem . One of them provides the sort keys while the other one passively undergoes the same data motion . | 366 | 27 |
31,862 | public static long [ ] hash ( final long [ ] in , final long seed ) { if ( ( in == null ) || ( in . length == 0 ) ) { return emptyOrNull ( seed , new long [ 2 ] ) ; } return hash ( Memory . wrap ( in ) , 0L , in . length << 3 , seed , new long [ 2 ] ) ; } | Returns a 128 - bit hash of the input . Provided for compatibility with older version of MurmurHash3 but empty or null input now returns a hash . | 79 | 31 |
31,863 | public static long [ ] hash ( final String in , final long seed , final long [ ] hashOut ) { if ( ( in == null ) || ( in . length ( ) == 0 ) ) { return emptyOrNull ( seed , hashOut ) ; } final byte [ ] byteArr = in . getBytes ( UTF_8 ) ; return hash ( Memory . wrap ( byteArr ) , 0L , byteArr . length , seed , hashOut ) ; } | Returns a 128 - bit hash of the input . | 100 | 10 |
31,864 | private static long mixK1 ( long k1 ) { k1 *= C1 ; k1 = Long . rotateLeft ( k1 , 31 ) ; k1 *= C2 ; return k1 ; } | Self mix of k1 | 45 | 5 |
31,865 | private static long mixK2 ( long k2 ) { k2 *= C2 ; k2 = Long . rotateLeft ( k2 , 33 ) ; k2 *= C1 ; return k2 ; } | Self mix of k2 | 45 | 5 |
31,866 | @ SuppressWarnings ( "unchecked" ) private static < T > T [ ] combinedBufferToItemsArray ( final ItemsSketch < T > sketch , final boolean ordered ) { final int extra = 2 ; // extra space for min and max values final int outArrCap = sketch . getRetainedItems ( ) ; final T minValue = sketch . getMinValue ( ) ; final T [ ] outArr = ( T [ ] ) Array . newInstance ( minValue . getClass ( ) , outArrCap + extra ) ; //Load min, max outArr [ 0 ] = minValue ; outArr [ 1 ] = sketch . getMaxValue ( ) ; final int baseBufferCount = sketch . getBaseBufferCount ( ) ; final Object [ ] combinedBuffer = sketch . getCombinedBuffer ( ) ; //Load base buffer System . arraycopy ( combinedBuffer , 0 , outArr , extra , baseBufferCount ) ; //Load levels long bitPattern = sketch . getBitPattern ( ) ; if ( bitPattern > 0 ) { final int k = sketch . getK ( ) ; int index = extra + baseBufferCount ; for ( int level = 0 ; bitPattern != 0L ; level ++ , bitPattern >>>= 1 ) { if ( ( bitPattern & 1L ) > 0L ) { System . arraycopy ( combinedBuffer , ( 2 + level ) * k , outArr , index , k ) ; index += k ; } } } if ( ordered ) { Arrays . sort ( outArr , extra , baseBufferCount + extra , sketch . getComparator ( ) ) ; } return outArr ; } | Returns an array of items in compact form including min and max extracted from the Combined Buffer . | 354 | 18 |
31,867 | public static boolean exactlyEqual ( final Sketch sketchA , final Sketch sketchB ) { //Corner case checks if ( ( sketchA == null ) || ( sketchB == null ) ) { return false ; } if ( sketchA == sketchB ) { return true ; } if ( sketchA . isEmpty ( ) && sketchB . isEmpty ( ) ) { return true ; } if ( sketchA . isEmpty ( ) || sketchB . isEmpty ( ) ) { return false ; } final int countA = sketchA . getRetainedEntries ( ) ; final int countB = sketchB . getRetainedEntries ( ) ; //Create the Union final Union union = SetOperation . builder ( ) . setNominalEntries ( ceilingPowerOf2 ( countA + countB ) ) . buildUnion ( ) ; union . update ( sketchA ) ; union . update ( sketchB ) ; final Sketch unionAB = union . getResult ( ) ; final long thetaLongUAB = unionAB . getThetaLong ( ) ; final long thetaLongA = sketchA . getThetaLong ( ) ; final long thetaLongB = sketchB . getThetaLong ( ) ; final int countUAB = unionAB . getRetainedEntries ( ) ; //Check for identical counts and thetas if ( ( countUAB == countA ) && ( countUAB == countB ) && ( thetaLongUAB == thetaLongA ) && ( thetaLongUAB == thetaLongB ) ) { return true ; } return false ; } | Returns true if the two given sketches have exactly the same hash values and the same theta values . Thus they are equivalent . | 336 | 25 |
31,868 | public void update ( final Sketch < S > sketchIn ) { if ( sketchIn == null || sketchIn . isEmpty ( ) ) { return ; } if ( sketchIn . theta_ < theta_ ) { theta_ = sketchIn . theta_ ; } final SketchIterator < S > it = sketchIn . iterator ( ) ; while ( it . next ( ) ) { sketch_ . merge ( it . getKey ( ) , it . getSummary ( ) , summarySetOps_ ) ; } } | Updates the internal set by adding entries from the given sketch | 109 | 12 |
31,869 | public List < Group > getGroupList ( final int [ ] priKeyIndices , final int numStdDev , final int limit ) { //allows subsequent queries with different priKeyIndices without rebuilding the map if ( ! mapValid ) { populateMap ( priKeyIndices ) ; } return populateList ( numStdDev , limit ) ; } | Return the most frequent Groups associated with Primary Keys based on the size of the groups . | 74 | 17 |
31,870 | private void populateMap ( final int [ ] priKeyIndices ) { final SketchIterator < ArrayOfStringsSummary > it = sketch . iterator ( ) ; Arrays . fill ( hashArr , 0L ) ; Arrays . fill ( priKeyArr , null ) ; Arrays . fill ( counterArr , 0 ) ; groupCount = 0 ; final int lgMapArrSize = Integer . numberOfTrailingZeros ( mapArrSize ) ; while ( it . next ( ) ) { final String [ ] arr = it . getSummary ( ) . getValue ( ) ; final String priKey = getPrimaryKey ( arr , priKeyIndices , sep ) ; final long hash = stringHash ( priKey ) ; final int index = hashSearchOrInsert ( hashArr , lgMapArrSize , hash ) ; if ( index < 0 ) { //was empty, hash inserted final int idx = - ( index + 1 ) ; //actual index counterArr [ idx ] = 1 ; groupCount ++ ; priKeyArr [ idx ] = priKey ; } else { //found, duplicate counterArr [ index ] ++ ; //increment } } mapValid = true ; } | Scan each entry in the sketch . Count the number of duplicate occurrences of each primary key in a hash map . | 260 | 22 |
31,871 | private List < Group > populateList ( final int numStdDev , final int limit ) { final List < Group > list = new ArrayList <> ( ) ; for ( int i = 0 ; i < mapArrSize ; i ++ ) { if ( hashArr [ i ] != 0 ) { final String priKey = priKeyArr [ i ] ; final int count = counterArr [ i ] ; final double est = sketch . getEstimate ( count ) ; final double ub = sketch . getUpperBound ( numStdDev , count ) ; final double lb = sketch . getLowerBound ( numStdDev , count ) ; final double thresh = ( double ) count / sketch . getRetainedEntries ( ) ; final double rse = ( sketch . getUpperBound ( 1 , count ) / est ) - 1.0 ; final Group gp = group . copy ( ) ; gp . init ( priKey , count , est , ub , lb , thresh , rse ) ; list . add ( gp ) ; } } list . sort ( null ) ; //Comparable implemented in Group final int totLen = list . size ( ) ; final List < Group > returnList ; if ( ( limit > 0 ) && ( limit < totLen ) ) { returnList = list . subList ( 0 , limit ) ; } else { returnList = list ; } return returnList ; } | Create the list of groups along with the error statistics | 300 | 10 |
31,872 | private static String getPrimaryKey ( final String [ ] tuple , final int [ ] priKeyIndices , final char sep ) { assert priKeyIndices . length < tuple . length ; final StringBuilder sb = new StringBuilder ( ) ; final int keys = priKeyIndices . length ; for ( int i = 0 ; i < keys ; i ++ ) { final int idx = priKeyIndices [ i ] ; sb . append ( tuple [ idx ] ) ; if ( ( i + 1 ) < keys ) { sb . append ( sep ) ; } } return sb . toString ( ) ; } | also used by test | 133 | 4 |
31,873 | static final byte [ ] toHllByteArray ( final AbstractHllArray impl , final boolean compact ) { int auxBytes = 0 ; if ( impl . tgtHllType == TgtHllType . HLL_4 ) { final AuxHashMap auxHashMap = impl . getAuxHashMap ( ) ; if ( auxHashMap != null ) { auxBytes = ( compact ) ? auxHashMap . getCompactSizeBytes ( ) : auxHashMap . getUpdatableSizeBytes ( ) ; } else { auxBytes = ( compact ) ? 0 : 4 << LG_AUX_ARR_INTS [ impl . lgConfigK ] ; } } final int totBytes = HLL_BYTE_ARR_START + impl . getHllByteArrBytes ( ) + auxBytes ; final byte [ ] byteArr = new byte [ totBytes ] ; final WritableMemory wmem = WritableMemory . wrap ( byteArr ) ; insertHll ( impl , wmem , compact ) ; return byteArr ; } | To byte array used by the heap HLL types . | 226 | 11 |
31,874 | static int getAndCheckPreLongs ( final Memory mem ) { final long cap = mem . getCapacity ( ) ; if ( cap < 8 ) { throwNotBigEnough ( cap , 8 ) ; } final int preLongs = mem . getByte ( 0 ) & 0x3F ; final int required = Math . max ( preLongs << 3 , 8 ) ; if ( cap < required ) { throwNotBigEnough ( cap , required ) ; } return preLongs ; } | Checks Memory for capacity to hold the preamble and returns the extracted preLongs . | 104 | 19 |
31,875 | public void update ( final ArrayOfDoublesSketch sketchIn , final ArrayOfDoublesCombiner combiner ) { final boolean isFirstCall = isFirstCall_ ; isFirstCall_ = false ; if ( sketchIn == null ) { isEmpty_ = true ; sketch_ = null ; return ; } Util . checkSeedHashes ( seedHash_ , sketchIn . getSeedHash ( ) ) ; theta_ = min ( theta_ , sketchIn . getThetaLong ( ) ) ; isEmpty_ |= sketchIn . isEmpty ( ) ; if ( isEmpty_ || sketchIn . getRetainedEntries ( ) == 0 ) { sketch_ = null ; return ; } if ( isFirstCall ) { sketch_ = createSketch ( sketchIn . getRetainedEntries ( ) , numValues_ , seed_ ) ; final ArrayOfDoublesSketchIterator it = sketchIn . iterator ( ) ; while ( it . next ( ) ) { sketch_ . insert ( it . getKey ( ) , it . getValues ( ) ) ; } } else { //not the first call final int matchSize = min ( sketch_ . getRetainedEntries ( ) , sketchIn . getRetainedEntries ( ) ) ; final long [ ] matchKeys = new long [ matchSize ] ; final double [ ] [ ] matchValues = new double [ matchSize ] [ ] ; int matchCount = 0 ; final ArrayOfDoublesSketchIterator it = sketchIn . iterator ( ) ; while ( it . next ( ) ) { final double [ ] values = sketch_ . find ( it . getKey ( ) ) ; if ( values != null ) { matchKeys [ matchCount ] = it . getKey ( ) ; matchValues [ matchCount ] = combiner . combine ( values , it . getValues ( ) ) ; matchCount ++ ; } } sketch_ = null ; if ( matchCount > 0 ) { sketch_ = createSketch ( matchCount , numValues_ , seed_ ) ; for ( int i = 0 ; i < matchCount ; i ++ ) { sketch_ . insert ( matchKeys [ i ] , matchValues [ i ] ) ; } } if ( sketch_ != null ) { sketch_ . setThetaLong ( theta_ ) ; sketch_ . setNotEmpty ( ) ; } } } | Updates the internal set by intersecting it with the given sketch . | 506 | 14 |
31,876 | public ArrayOfDoublesCompactSketch getResult ( final WritableMemory dstMem ) { if ( isFirstCall_ ) { throw new SketchesStateException ( "getResult() with no intervening intersections is not a legal result." ) ; } if ( sketch_ == null ) { return new HeapArrayOfDoublesCompactSketch ( null , null , Long . MAX_VALUE , true , numValues_ , seedHash_ ) ; } return sketch_ . compact ( dstMem ) ; } | Gets the internal set as an off - heap compact sketch using the given memory . | 109 | 17 |
31,877 | public void reset ( ) { isEmpty_ = false ; theta_ = Long . MAX_VALUE ; sketch_ = null ; isFirstCall_ = true ; } | Resets the internal set to the initial state which represents the Universal Set | 35 | 14 |
31,878 | public static ArrayOfDoublesSketch heapify ( final Memory mem , final long seed ) { final SerializerDeserializer . SketchType sketchType = SerializerDeserializer . getSketchType ( mem ) ; if ( sketchType == SerializerDeserializer . SketchType . ArrayOfDoublesQuickSelectSketch ) { return new HeapArrayOfDoublesQuickSelectSketch ( mem , seed ) ; } return new HeapArrayOfDoublesCompactSketch ( mem , seed ) ; } | Heapify the given Memory and seed as a ArrayOfDoublesSketch | 113 | 17 |
31,879 | public static ArrayOfDoublesSketch wrap ( final Memory mem , final long seed ) { final SerializerDeserializer . SketchType sketchType = SerializerDeserializer . getSketchType ( mem ) ; if ( sketchType == SerializerDeserializer . SketchType . ArrayOfDoublesQuickSelectSketch ) { return new DirectArrayOfDoublesQuickSelectSketchR ( mem , seed ) ; } return new DirectArrayOfDoublesCompactSketch ( mem , seed ) ; } | Wrap the given Memory and seed as a ArrayOfDoublesSketch | 111 | 16 |
31,880 | public CompactSketch aNotB ( final Sketch a , final Sketch b ) { return aNotB ( a , b , true , null ) ; } | Perform A - and - not - B set operation on the two given sketches and return the result as an ordered CompactSketch on the heap . | 33 | 31 |
31,881 | public static final HllSketch heapify ( final Memory srcMem ) { final CurMode curMode = checkPreamble ( srcMem ) ; final HllSketch heapSketch ; if ( curMode == CurMode . HLL ) { final TgtHllType tgtHllType = extractTgtHllType ( srcMem ) ; if ( tgtHllType == TgtHllType . HLL_4 ) { heapSketch = new HllSketch ( Hll4Array . heapify ( srcMem ) ) ; } else if ( tgtHllType == TgtHllType . HLL_6 ) { heapSketch = new HllSketch ( Hll6Array . heapify ( srcMem ) ) ; } else { //Hll_8 heapSketch = new HllSketch ( Hll8Array . heapify ( srcMem ) ) ; } } else if ( curMode == CurMode . LIST ) { heapSketch = new HllSketch ( CouponList . heapifyList ( srcMem ) ) ; } else { heapSketch = new HllSketch ( CouponHashSet . heapifySet ( srcMem ) ) ; } return heapSketch ; } | Heapify the given Memory which must be a valid HllSketch image and may have data . | 279 | 22 |
31,882 | public static final HllSketch writableWrap ( final WritableMemory wmem ) { final boolean compact = extractCompactFlag ( wmem ) ; if ( compact ) { throw new SketchesArgumentException ( "Cannot perform a writableWrap of a writable sketch image that is in compact form." ) ; } final int lgConfigK = extractLgK ( wmem ) ; final TgtHllType tgtHllType = extractTgtHllType ( wmem ) ; final long minBytes = getMaxUpdatableSerializationBytes ( lgConfigK , tgtHllType ) ; final long capBytes = wmem . getCapacity ( ) ; HllUtil . checkMemSize ( minBytes , capBytes ) ; final CurMode curMode = checkPreamble ( wmem ) ; final HllSketch directSketch ; if ( curMode == CurMode . HLL ) { if ( tgtHllType == TgtHllType . HLL_4 ) { directSketch = new HllSketch ( new DirectHll4Array ( lgConfigK , wmem ) ) ; } else if ( tgtHllType == TgtHllType . HLL_6 ) { directSketch = new HllSketch ( new DirectHll6Array ( lgConfigK , wmem ) ) ; } else { //Hll_8 directSketch = new HllSketch ( new DirectHll8Array ( lgConfigK , wmem ) ) ; } } else if ( curMode == CurMode . LIST ) { directSketch = new HllSketch ( new DirectCouponList ( lgConfigK , tgtHllType , curMode , wmem ) ) ; } else { directSketch = new HllSketch ( new DirectCouponHashSet ( lgConfigK , tgtHllType , wmem ) ) ; } return directSketch ; } | Wraps the given WritableMemory which must be a image of a valid updatable sketch and may have data . What remains on the java heap is a thin wrapper object that reads and writes to the given WritableMemory which depending on how the user configures the WritableMemory may actually reside on the Java heap or off - heap . | 441 | 68 |
31,883 | public static final int getMaxUpdatableSerializationBytes ( final int lgConfigK , final TgtHllType tgtHllType ) { final int arrBytes ; if ( tgtHllType == TgtHllType . HLL_4 ) { final int auxBytes = 4 << LG_AUX_ARR_INTS [ lgConfigK ] ; arrBytes = AbstractHllArray . hll4ArrBytes ( lgConfigK ) + auxBytes ; } else if ( tgtHllType == TgtHllType . HLL_6 ) { arrBytes = AbstractHllArray . hll6ArrBytes ( lgConfigK ) ; } else { //HLL_8 arrBytes = AbstractHllArray . hll8ArrBytes ( lgConfigK ) ; } return HLL_BYTE_ARR_START + arrBytes ; } | Returns the maximum size in bytes that this sketch can grow to given lgConfigK . However for the HLL_4 sketch type this value can be exceeded in extremely rare cases . If exceeded it will be larger by only a few percent . | 194 | 49 |
31,884 | private static byte [ ] convertToByteArray ( final DoublesSketch sketch , final int flags , final boolean ordered , final boolean compact ) { final int preLongs = 2 ; final int extra = 2 ; // extra space for min and max values final int prePlusExtraBytes = ( preLongs + extra ) << 3 ; final int k = sketch . getK ( ) ; final long n = sketch . getN ( ) ; // If not-compact, have accessor always report full levels. Then use level size to determine // whether to copy data out. final DoublesSketchAccessor dsa = DoublesSketchAccessor . wrap ( sketch , ! compact ) ; final int outBytes = ( compact ? sketch . getCompactStorageBytes ( ) : sketch . getUpdatableStorageBytes ( ) ) ; final byte [ ] outByteArr = new byte [ outBytes ] ; final WritableMemory memOut = WritableMemory . wrap ( outByteArr ) ; //insert preamble-0, N, min, max insertPre0 ( memOut , preLongs , flags , k ) ; if ( sketch . isEmpty ( ) ) { return outByteArr ; } insertN ( memOut , n ) ; insertMinDouble ( memOut , sketch . getMinValue ( ) ) ; insertMaxDouble ( memOut , sketch . getMaxValue ( ) ) ; long memOffsetBytes = prePlusExtraBytes ; // might need to sort base buffer but don't want to change input sketch final int bbCnt = Util . computeBaseBufferItems ( k , n ) ; if ( bbCnt > 0 ) { //Base buffer items only final double [ ] bbItemsArr = dsa . getArray ( 0 , bbCnt ) ; if ( ordered ) { Arrays . sort ( bbItemsArr ) ; } memOut . putDoubleArray ( memOffsetBytes , bbItemsArr , 0 , bbCnt ) ; } // If n < 2k, totalLevels == 0 so ok to overshoot the offset update memOffsetBytes += ( compact ? bbCnt : 2 * k ) << 3 ; // If serializing from a compact sketch to a non-compact form, we may end up copying data for a // higher level one or more times into an unused level. A bit wasteful, but not incorrect. final int totalLevels = Util . computeTotalLevels ( sketch . getBitPattern ( ) ) ; for ( int lvl = 0 ; lvl < totalLevels ; ++ lvl ) { dsa . setLevel ( lvl ) ; if ( dsa . numItems ( ) > 0 ) { assert dsa . numItems ( ) == k ; memOut . putDoubleArray ( memOffsetBytes , dsa . getArray ( 0 , k ) , 0 , k ) ; memOffsetBytes += ( k << 3 ) ; } } return outByteArr ; } | Returns a byte array including preamble min max and data extracted from the sketch . | 629 | 17 |
31,885 | public void update ( final T item , final long count ) { if ( ( item == null ) || ( count == 0 ) ) { return ; } if ( count < 0 ) { throw new SketchesArgumentException ( "Count may not be negative" ) ; } this . streamWeight += count ; hashMap . adjustOrPutValue ( item , count ) ; if ( getNumActiveItems ( ) > curMapCap ) { //over the threshold, we need to do something if ( hashMap . getLgLength ( ) < lgMaxMapSize ) { //below tgt size, we can grow hashMap . resize ( 2 * hashMap . getLength ( ) ) ; curMapCap = hashMap . getCapacity ( ) ; } else { //At tgt size, must purge offset += hashMap . purge ( sampleSize ) ; if ( getNumActiveItems ( ) > getMaximumMapCapacity ( ) ) { throw new SketchesStateException ( "Purge did not reduce active items." ) ; } } } } | Update this sketch with a item and a positive frequency count . | 221 | 12 |
31,886 | void adjustOrPutValue ( final T key , final long adjustAmount ) { final int arrayMask = keys . length - 1 ; int probe = ( int ) hash ( key . hashCode ( ) ) & arrayMask ; int drift = 1 ; while ( states [ probe ] != 0 && ! keys [ probe ] . equals ( key ) ) { probe = ( probe + 1 ) & arrayMask ; drift ++ ; //only used for theoretical analysis assert ( drift < DRIFT_LIMIT ) : "drift: " + drift + " >= DRIFT_LIMIT" ; } if ( states [ probe ] == 0 ) { // adding the key to the table the value assert ( numActive <= loadThreshold ) : "numActive: " + numActive + " > loadThreshold: " + loadThreshold ; keys [ probe ] = key ; values [ probe ] = adjustAmount ; states [ probe ] = ( short ) drift ; numActive ++ ; } else { // adjusting the value of an existing key assert ( keys [ probe ] . equals ( key ) ) ; values [ probe ] += adjustAmount ; } } | Increments the value mapped to the key if the key is present in the map . Otherwise the key is inserted with the putAmount . | 236 | 27 |
31,887 | @ SuppressWarnings ( "unchecked" ) void resize ( final int newSize ) { final Object [ ] oldKeys = keys ; final long [ ] oldValues = values ; final short [ ] oldStates = states ; keys = new Object [ newSize ] ; values = new long [ newSize ] ; states = new short [ newSize ] ; loadThreshold = ( int ) ( newSize * LOAD_FACTOR ) ; lgLength = Integer . numberOfTrailingZeros ( newSize ) ; numActive = 0 ; for ( int i = 0 ; i < oldKeys . length ; i ++ ) { if ( oldStates [ i ] > 0 ) { adjustOrPutValue ( ( T ) oldKeys [ i ] , oldValues [ i ] ) ; } } } | assume newSize is power of 2 | 169 | 8 |
31,888 | long purge ( final int sampleSize ) { final int limit = Math . min ( sampleSize , getNumActive ( ) ) ; int numSamples = 0 ; int i = 0 ; final long [ ] samples = new long [ limit ] ; while ( numSamples < limit ) { if ( isActive ( i ) ) { samples [ numSamples ] = values [ i ] ; numSamples ++ ; } i ++ ; } final long val = QuickSelect . select ( samples , 0 , numSamples - 1 , limit / 2 ) ; adjustAllValuesBy ( - 1 * val ) ; keepOnlyPositiveCounts ( ) ; return val ; } | This function is called when a key is processed that is not currently assigned a counter and all the counters are in use . This function estimates the median of the counters in the sketch via sampling decrements all counts by this estimate throws out all counters that are no longer positive and increments offset accordingly . | 139 | 58 |
31,889 | 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 ; } | 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 . | 88 | 41 |
31,890 | final void updateMemory ( final WritableMemory newWmem ) { wmem = newWmem ; mem = newWmem ; memObj = wmem . getArray ( ) ; memAdd = wmem . getCumulativeOffset ( 0L ) ; } | only called by DirectAuxHashMap | 55 | 8 |
31,891 | static HeapUpdateDoublesSketch copyToHeap ( final DoublesSketch sketch ) { final HeapUpdateDoublesSketch qsCopy ; qsCopy = HeapUpdateDoublesSketch . newInstance ( sketch . getK ( ) ) ; qsCopy . putN ( sketch . getN ( ) ) ; qsCopy . putMinValue ( sketch . getMinValue ( ) ) ; qsCopy . putMaxValue ( sketch . getMaxValue ( ) ) ; qsCopy . putBaseBufferCount ( sketch . getBaseBufferCount ( ) ) ; qsCopy . putBitPattern ( sketch . getBitPattern ( ) ) ; if ( sketch . isCompact ( ) ) { final int combBufItems = Util . computeCombinedBufferItemCapacity ( sketch . getK ( ) , sketch . getN ( ) ) ; final double [ ] combBuf = new double [ combBufItems ] ; qsCopy . putCombinedBuffer ( combBuf ) ; final DoublesSketchAccessor sketchAccessor = DoublesSketchAccessor . wrap ( sketch ) ; final DoublesSketchAccessor copyAccessor = DoublesSketchAccessor . wrap ( qsCopy ) ; // start with BB copyAccessor . putArray ( sketchAccessor . getArray ( 0 , sketchAccessor . numItems ( ) ) , 0 , 0 , sketchAccessor . numItems ( ) ) ; long bitPattern = sketch . getBitPattern ( ) ; for ( int lvl = 0 ; bitPattern != 0L ; ++ lvl , bitPattern >>>= 1 ) { if ( ( bitPattern & 1L ) > 0L ) { sketchAccessor . setLevel ( lvl ) ; copyAccessor . setLevel ( lvl ) ; copyAccessor . putArray ( sketchAccessor . getArray ( 0 , sketchAccessor . numItems ( ) ) , 0 , 0 , sketchAccessor . numItems ( ) ) ; } } } else { final double [ ] combBuf = sketch . getCombinedBuffer ( ) ; qsCopy . putCombinedBuffer ( Arrays . copyOf ( combBuf , combBuf . length ) ) ; } return qsCopy ; } | Returns an on - heap copy of the given sketch | 481 | 10 |
31,892 | static void checkDoublesSerVer ( final int serVer , final int minSupportedSerVer ) { final int max = DoublesSketch . DOUBLES_SER_VER ; if ( ( serVer > max ) || ( serVer < minSupportedSerVer ) ) { throw new SketchesArgumentException ( "Possible corruption: Unsupported Serialization Version: " + serVer ) ; } } | Check the validity of the given serialization version | 88 | 9 |
31,893 | static DirectCompactDoublesSketch wrapInstance ( final Memory srcMem ) { final long memCap = srcMem . getCapacity ( ) ; final int preLongs = extractPreLongs ( srcMem ) ; final int serVer = extractSerVer ( srcMem ) ; final int familyID = extractFamilyID ( srcMem ) ; final int flags = extractFlags ( srcMem ) ; final int k = extractK ( srcMem ) ; final boolean empty = ( flags & EMPTY_FLAG_MASK ) > 0 ; final long n = empty ? 0 : extractN ( srcMem ) ; //VALIDITY CHECKS DirectUpdateDoublesSketchR . checkPreLongs ( preLongs ) ; Util . checkFamilyID ( familyID ) ; DoublesUtil . checkDoublesSerVer ( serVer , MIN_DIRECT_DOUBLES_SER_VER ) ; checkCompact ( serVer , flags ) ; Util . checkK ( k ) ; checkDirectMemCapacity ( k , n , memCap ) ; DirectUpdateDoublesSketchR . checkEmptyAndN ( empty , n ) ; final DirectCompactDoublesSketch dds = new DirectCompactDoublesSketch ( k ) ; dds . mem_ = ( WritableMemory ) srcMem ; return dds ; } | Wrap this sketch around the given compact Memory image of a DoublesSketch . | 290 | 18 |
31,894 | static void checkCompact ( final int serVer , final int flags ) { final int compactFlagMask = COMPACT_FLAG_MASK | ORDERED_FLAG_MASK ; if ( ( serVer != 2 ) && ( ( flags & EMPTY_FLAG_MASK ) == 0 ) && ( ( flags & compactFlagMask ) != compactFlagMask ) ) { throw new SketchesArgumentException ( "Possible corruption: Must be v2, empty, or compact and ordered. Flags field: " + Integer . toBinaryString ( flags ) + ", SerVer: " + serVer ) ; } } | Checks a sketch s serial version and flags to see if the sketch can be wrapped as a DirectCompactDoubleSketch . Throws an exception if the sketch is neither empty nor compact and ordered unles the sketch uses serialization version 2 . | 131 | 51 |
31,895 | 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 first Log2 values of the given source array . | 100 | 17 |
31,896 | 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 ; } | Counts the cardinality of the given source array . | 87 | 11 |
31,897 | public static int hashSearch ( final long [ ] hashTable , final int lgArrLongs , final long hash ) { if ( hash == 0 ) { throw new SketchesArgumentException ( "Given hash cannot be zero: " + hash ) ; } final int arrayMask = ( 1 << lgArrLongs ) - 1 ; // current Size -1 final int stride = getStride ( hash , lgArrLongs ) ; int curProbe = ( int ) ( hash & arrayMask ) ; // search for duplicate or empty slot final int loopIndex = curProbe ; do { final long arrVal = hashTable [ curProbe ] ; if ( arrVal == EMPTY ) { return - 1 ; // not found } else if ( arrVal == hash ) { return curProbe ; // found } curProbe = ( curProbe + stride ) & arrayMask ; } while ( curProbe != loopIndex ) ; return - 1 ; } | This is a classical Knuth - style Open Addressing Double Hash search scheme for on - heap . Returns the index if found - 1 if not found . | 208 | 31 |
31,898 | 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 ; } | Inserts the given long array into the given hash table array of the target size removes any negative input values ignores duplicates and counts the values inserted . The given hash table may have values but they must have been inserted by this method or one of the other OADH insert methods in this class and they may not be dirty . This method performs additional checks against potentially invalid hash values or theta values . Returns the count of values actually inserted . | 156 | 89 |
31,899 | public static int hashSearch ( final Memory mem , final int lgArrLongs , final long hash , final int memOffsetBytes ) { final int arrayMask = ( 1 << lgArrLongs ) - 1 ; final int stride = getStride ( hash , lgArrLongs ) ; int curProbe = ( int ) ( hash & arrayMask ) ; final int loopIndex = curProbe ; do { final int curProbeOffsetBytes = ( curProbe << 3 ) + memOffsetBytes ; final long curArrayHash = mem . getLong ( curProbeOffsetBytes ) ; if ( curArrayHash == EMPTY ) { return - 1 ; } else if ( curArrayHash == hash ) { return curProbe ; } curProbe = ( curProbe + stride ) & arrayMask ; } while ( curProbe != loopIndex ) ; return - 1 ; } | This is a classical Knuth - style Open Addressing Double Hash search scheme for off - heap . Returns the index if found - 1 if not found . | 192 | 31 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.