idx int64 0 41.2k | question stringlengths 74 4.04k | target stringlengths 7 750 |
|---|---|---|
31,800 | public 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 a long and a seed . |
31,801 | public static SingleItemSketch create ( final String datum , final long seed ) { if ( ( datum == null ) || datum . isEmpty ( ) ) { return null ; } final byte [ ] data = datum . getBytes ( UTF_8 ) ; return new SingleItemSketch ( hash ( data , seed ) [ 0 ] >>> 1 , seed ) ; } | 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 . |
31,802 | public static SingleItemSketch create ( final byte [ ] data , final long seed ) { if ( ( data == null ) || ( data . length == 0 ) ) { return null ; } return new SingleItemSketch ( hash ( data , seed ) [ 0 ] >>> 1 , seed ) ; } | 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 . |
31,803 | public void reset ( ) { isEmpty_ = true ; count_ = 0 ; theta_ = ( long ) ( Long . MAX_VALUE * ( double ) samplingProbability_ ) ; final int startingCapacity = Util . getStartingCapacity ( nomEntries_ , lgResizeFactor_ ) ; lgCurrentCapacity_ = Integer . numberOfTrailingZeros ( startingCapacity ) ; keys_ = new long [ startingCapacity ] ; summaries_ = null ; setRebuildThreshold ( ) ; } | Resets this sketch an empty state . |
31,804 | @ SuppressWarnings ( "unchecked" ) public CompactSketch < S > compact ( ) { if ( getRetainedEntries ( ) == 0 ) { return new CompactSketch < > ( null , null , theta_ , isEmpty_ ) ; } final long [ ] keys = new long [ getRetainedEntries ( ) ] ; final S [ ] summaries = ( S [ ] ) Array . newInstance ( summaries_ . getClass ( ) . getComponentType ( ) , getRetainedEntries ( ) ) ; int i = 0 ; for ( int j = 0 ; j < keys_ . length ; j ++ ) { if ( summaries_ [ j ] != null ) { keys [ i ] = keys_ [ j ] ; summaries [ i ] = ( S ) summaries_ [ j ] . copy ( ) ; i ++ ; } } return new CompactSketch < > ( keys , summaries , theta_ , isEmpty_ ) ; } | Converts the current state of the sketch into a compact sketch |
31,805 | public VarOptItemsSketch < T > getResult ( ) { if ( gadget_ . getNumMarksInH ( ) == 0 ) { return simpleGadgetCoercer ( ) ; } else { final VarOptItemsSketch < T > tmp = detectAndHandleSubcaseOfPseudoExact ( ) ; if ( tmp != null ) { return tmp ; } else { return migrateMarkedItemsByDecreasingK ( ) ; } } } | Gets the varopt sketch resulting from the union of any input sketches . |
31,806 | private VarOptItemsSketch < T > markMovingGadgetCoercer ( ) { final int resultK = gadget_ . getHRegionCount ( ) + gadget_ . getRRegionCount ( ) ; int resultH = 0 ; int resultR = 0 ; int nextRPos = resultK ; final ArrayList < T > data = new ArrayList < > ( resultK + 1 ) ; final ArrayList < Double > weights = new ArrayList < > ( resultK + 1 ) ; for ( int i = 0 ; i < ( resultK + 1 ) ; ++ i ) { data . add ( null ) ; weights . add ( null ) ; } final VarOptItemsSamples < T > sketchSamples = gadget_ . getSketchSamples ( ) ; Iterator < VarOptItemsSamples < T > . WeightedSample > sketchIterator ; sketchIterator = sketchSamples . getRIterator ( ) ; while ( sketchIterator . hasNext ( ) ) { final VarOptItemsSamples < T > . WeightedSample ws = sketchIterator . next ( ) ; data . set ( nextRPos , ws . getItem ( ) ) ; weights . set ( nextRPos , - 1.0 ) ; ++ resultR ; -- nextRPos ; } double transferredWeight = 0 ; sketchIterator = sketchSamples . getHIterator ( ) ; while ( sketchIterator . hasNext ( ) ) { final VarOptItemsSamples < T > . WeightedSample ws = sketchIterator . next ( ) ; if ( ws . getMark ( ) ) { data . set ( nextRPos , ws . getItem ( ) ) ; weights . set ( nextRPos , - 1.0 ) ; transferredWeight += ws . getWeight ( ) ; ++ resultR ; -- nextRPos ; } else { data . set ( resultH , ws . getItem ( ) ) ; weights . set ( resultH , ws . getWeight ( ) ) ; ++ resultH ; } } assert ( resultH + resultR ) == resultK ; assert Math . abs ( transferredWeight - outerTauNumer ) < 1e-10 ; final double resultRWeight = gadget_ . getTotalWtR ( ) + transferredWeight ; final long resultN = n_ ; data . set ( resultH , null ) ; weights . set ( resultH , - 1.0 ) ; return newInstanceFromUnionResult ( data , weights , resultK , resultN , resultH , resultR , resultRWeight ) ; } | This coercer directly transfers marked items from the gadget s H into the result s R . Deciding whether that is a valid thing to do is the responsibility of the caller . Currently this is only used for a subcase of pseudo - exact but later it might be used by other subcases as well . |
31,807 | 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 ++ ) { final long v = srcCache [ i ] ; if ( ( v <= 0L ) || ( v >= thetaLong ) ) { continue ; } cacheOut [ j ++ ] = v ; } assert curCount == j ; if ( dstOrdered && ( curCount > 1 ) ) { Arrays . sort ( cacheOut ) ; } return cacheOut ; } | Compact the given array . The source cache can be a hash table with interstitial zeros or dirty values . |
31,808 | 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 ; } | Compact first 2^lgArrLongs of given array |
31,809 | static final Memory loadCompactMemory ( final long [ ] compactCache , final short seedHash , final int curCount , final long thetaLong , final WritableMemory dstMem , final byte flags , final int preLongs ) { assert ( dstMem != null ) && ( compactCache != null ) ; final int outLongs = preLongs + curCount ; final int outBytes = outLongs << 3 ; final int dstBytes = ( int ) dstMem . getCapacity ( ) ; if ( outBytes > dstBytes ) { throw new SketchesArgumentException ( "Insufficient Memory: " + dstBytes + ", Need: " + outBytes ) ; } final byte famID = ( byte ) Family . COMPACT . getID ( ) ; insertPreLongs ( dstMem , preLongs ) ; insertSerVer ( dstMem , SER_VER ) ; insertFamilyID ( dstMem , famID ) ; insertFlags ( dstMem , flags ) ; insertSeedHash ( dstMem , seedHash ) ; if ( ( preLongs == 1 ) && ( curCount == 1 ) ) { dstMem . putLong ( 8 , compactCache [ 0 ] ) ; return dstMem ; } if ( preLongs > 1 ) { insertCurCount ( dstMem , curCount ) ; insertP ( dstMem , ( float ) 1.0 ) ; } if ( preLongs > 2 ) { insertThetaLong ( dstMem , thetaLong ) ; } if ( curCount > 0 ) { dstMem . putLongArray ( preLongs << 3 , compactCache , 0 , curCount ) ; } return dstMem ; } | compactCache and dstMem must be valid |
31,810 | public static LongsSketch getInstance ( final String string ) { final String [ ] tokens = string . split ( "," ) ; if ( tokens . length < ( STR_PREAMBLE_TOKENS + 2 ) ) { throw new SketchesArgumentException ( "String not long enough: " + tokens . length ) ; } final int serVer = Integer . parseInt ( tokens [ 0 ] ) ; final int famID = Integer . parseInt ( tokens [ 1 ] ) ; final int lgMax = Integer . parseInt ( tokens [ 2 ] ) ; final int flags = Integer . parseInt ( tokens [ 3 ] ) ; final long streamWt = Long . parseLong ( tokens [ 4 ] ) ; final long offset = Long . parseLong ( tokens [ 5 ] ) ; final int numActive = Integer . parseInt ( tokens [ 6 ] ) ; final int lgCur = Integer . numberOfTrailingZeros ( Integer . parseInt ( tokens [ 7 ] ) ) ; if ( serVer != SER_VER ) { throw new SketchesArgumentException ( "Possible Corruption: Bad SerVer: " + serVer ) ; } Family . FREQUENCY . checkFamilyID ( famID ) ; final boolean empty = flags > 0 ; if ( ! empty && ( numActive == 0 ) ) { throw new SketchesArgumentException ( "Possible Corruption: !Empty && NumActive=0; strLen: " + numActive ) ; } final int numTokens = tokens . length ; if ( ( 2 * numActive ) != ( numTokens - STR_PREAMBLE_TOKENS - 2 ) ) { throw new SketchesArgumentException ( "Possible Corruption: Incorrect # of tokens: " + numTokens + ", numActive: " + numActive ) ; } final LongsSketch sketch = new LongsSketch ( lgMax , lgCur ) ; sketch . streamWeight = streamWt ; sketch . offset = offset ; sketch . hashMap = deserializeFromStringArray ( tokens ) ; return sketch ; } | Returns a sketch instance of this class from the given String which must be a String representation of this sketch class . |
31,811 | public String serializeToString ( ) { final StringBuilder sb = new StringBuilder ( ) ; final int serVer = SER_VER ; final int famID = Family . FREQUENCY . getID ( ) ; final int lgMaxMapSz = lgMaxMapSize ; final int flags = ( hashMap . getNumActive ( ) == 0 ) ? EMPTY_FLAG_MASK : 0 ; final String fmt = "%d,%d,%d,%d,%d,%d," ; final String s = String . format ( fmt , serVer , famID , lgMaxMapSz , flags , streamWeight , offset ) ; sb . append ( s ) ; sb . append ( hashMap . serializeToString ( ) ) ; return sb . toString ( ) ; } | Returns a String representation of this sketch |
31,812 | static ReversePurgeLongHashMap deserializeFromStringArray ( final String [ ] tokens ) { final int ignore = STR_PREAMBLE_TOKENS ; final int numActive = Integer . parseInt ( tokens [ ignore ] ) ; final int length = Integer . parseInt ( tokens [ ignore + 1 ] ) ; final ReversePurgeLongHashMap hashMap = new ReversePurgeLongHashMap ( length ) ; int j = 2 + ignore ; for ( int i = 0 ; i < numActive ; i ++ ) { final long key = Long . parseLong ( tokens [ j ++ ] ) ; final long value = Long . parseLong ( tokens [ j ++ ] ) ; hashMap . adjustOrPutValue ( key , value ) ; } return hashMap ; } | Deserializes an array of String tokens into a hash map object of this class . |
31,813 | final int findKey ( final byte [ ] key ) { final int keyLen = key . length ; final long [ ] hash = MurmurHash3 . hash ( key , SEED ) ; int entryIndex = getIndex ( hash [ 0 ] , tableEntries_ ) ; final int stride = getStride ( hash [ 1 ] , tableEntries_ ) ; final int loopIndex = entryIndex ; do { if ( isBitClear ( stateArr_ , entryIndex ) ) { return ~ entryIndex ; } if ( arraysEqual ( key , 0 , keysArr_ , entryIndex * keyLen , keyLen ) ) { return entryIndex ; } entryIndex = ( entryIndex + stride ) % tableEntries_ ; } while ( entryIndex != loopIndex ) ; throw new SketchesArgumentException ( "Key not found and no empty slots!" ) ; } | Returns the entry index for the given key given the array of keys if found . Otherwise returns the one s complement of first empty entry found ; |
31,814 | private static final int findEmpty ( final byte [ ] key , final int tableEntries , final byte [ ] stateArr ) { final long [ ] hash = MurmurHash3 . hash ( key , SEED ) ; int entryIndex = getIndex ( hash [ 0 ] , tableEntries ) ; final int stride = getStride ( hash [ 1 ] , tableEntries ) ; final int loopIndex = entryIndex ; do { if ( isBitClear ( stateArr , entryIndex ) ) { return entryIndex ; } entryIndex = ( entryIndex + stride ) % tableEntries ; } while ( entryIndex != loopIndex ) ; throw new SketchesArgumentException ( "No empty slots." ) ; } | Find the first empty slot for the given key . Only used by resize where it is known that the key does not exist in the table . Throws an exception if no empty slots . |
31,815 | private final boolean updateHll ( final int entryIndex , final int coupon ) { final int newValue = coupon16Value ( coupon ) ; final int hllIdx = coupon & ( k_ - 1 ) ; final int longIdx = hllIdx / 10 ; final int shift = ( ( hllIdx % 10 ) * 6 ) & SIX_BIT_MASK ; long hllLong = arrOfHllArr_ [ ( entryIndex * hllArrLongs_ ) + longIdx ] ; final int oldValue = ( int ) ( hllLong >>> shift ) & SIX_BIT_MASK ; if ( newValue <= oldValue ) { return false ; } final double invPow2Sum = invPow2SumHiArr_ [ entryIndex ] + invPow2SumLoArr_ [ entryIndex ] ; final double oneOverQ = k_ / invPow2Sum ; hipEstAccumArr_ [ entryIndex ] += oneOverQ ; if ( oldValue < 32 ) { invPow2SumHiArr_ [ entryIndex ] -= invPow2 ( oldValue ) ; } else { invPow2SumLoArr_ [ entryIndex ] -= invPow2 ( oldValue ) ; } if ( newValue < 32 ) { invPow2SumHiArr_ [ entryIndex ] += invPow2 ( newValue ) ; } else { invPow2SumLoArr_ [ entryIndex ] += invPow2 ( newValue ) ; } hllLong &= ~ ( 0X3FL << shift ) ; hllLong |= ( ( long ) newValue ) << shift ; arrOfHllArr_ [ ( entryIndex * hllArrLongs_ ) + longIdx ] = hllLong ; return true ; } | This method is specifically tied to the HLL array layout |
31,816 | 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 ) ; } | Given an encoding table that maps unsigned bytes to codewords of length at most 12 this builds a size - 4096 decoding table . |
31,817 | 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 ; assert ( decodedLength == encodedLength ) : "deLen: " + decodedLength + ", enLen: " + encodedLength ; assert ( encodedBitpattern == ( decodeThis & ( ( 1 << decodedLength ) - 1 ) ) ) ; } } | These short arrays are being treated as unsigned |
31,818 | static DoublesUnionImpl directInstance ( final int maxK , final WritableMemory dstMem ) { final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch . newInstance ( maxK , dstMem ) ; final DoublesUnionImpl union = new DoublesUnionImpl ( maxK ) ; union . maxK_ = maxK ; union . gadget_ = sketch ; return union ; } | Returns a empty DoublesUnion object that refers to the given direct off - heap Memory which will be initialized to the empty state . |
31,819 | static DoublesUnionImpl heapifyInstance ( final DoublesSketch sketch ) { final int k = sketch . getK ( ) ; final DoublesUnionImpl union = new DoublesUnionImpl ( k ) ; union . maxK_ = k ; union . gadget_ = copyToHeap ( sketch ) ; return union ; } | Returns a Heap DoublesUnion object that has been initialized with the data from the given sketch . |
31,820 | static DoublesUnionImpl wrapInstance ( final WritableMemory mem ) { final DirectUpdateDoublesSketch sketch = DirectUpdateDoublesSketch . wrapInstance ( mem ) ; 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 . |
31,821 | public static Sketch heapify ( final Memory srcMem , final long seed ) { final int serVer = srcMem . getByte ( SER_VER_BYTE ) ; if ( serVer == 3 ) { final byte famID = srcMem . getByte ( FAMILY_BYTE ) ; final boolean ordered = ( srcMem . getByte ( FLAGS_BYTE ) & ORDERED_FLAG_MASK ) != 0 ; return constructHeapSketch ( famID , ordered , srcMem , seed ) ; } if ( serVer == 1 ) { return ForwardCompatibility . heapify1to3 ( srcMem , seed ) ; } if ( serVer == 2 ) { return ForwardCompatibility . heapify2to3 ( srcMem , seed ) ; } throw new SketchesArgumentException ( "Unknown Serialization Version: " + serVer ) ; } | Heapify takes the sketch image in Memory and instantiates an on - heap Sketch using the given seed . The resulting sketch will not retain any link to the source Memory . |
31,822 | static final boolean isValidSketchID ( final int id ) { return ( id == Family . ALPHA . getID ( ) ) || ( id == Family . QUICKSELECT . getID ( ) ) || ( id == Family . COMPACT . getID ( ) ) ; } | Returns true if given Family id is one of the theta sketches |
31,823 | 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" ) ; } } | Checks Ordered and Compact flags for integrity between sketch and Memory |
31,824 | private static final Sketch constructHeapSketch ( final byte famID , final boolean ordered , final Memory srcMem , final long seed ) { final boolean compact = ( srcMem . getByte ( FLAGS_BYTE ) & COMPACT_FLAG_MASK ) != 0 ; final Family family = idToFamily ( famID ) ; switch ( family ) { case ALPHA : { if ( compact ) { throw new SketchesArgumentException ( "Possibly Corrupted " + family + " image: cannot be compact" ) ; } return HeapAlphaSketch . heapifyInstance ( srcMem , seed ) ; } case QUICKSELECT : { return HeapQuickSelectSketch . heapifyInstance ( srcMem , seed ) ; } case COMPACT : { if ( ! compact ) { throw new SketchesArgumentException ( "Possibly Corrupted " + family + " image: must be compact" ) ; } return ordered ? HeapCompactOrderedSketch . heapifyInstance ( srcMem , seed ) : HeapCompactUnorderedSketch . heapifyInstance ( srcMem , seed ) ; } default : { throw new SketchesArgumentException ( "Sketch cannot heapify family: " + family + " as a Sketch" ) ; } } } | Instantiates a Heap Sketch from Memory . |
31,825 | public static < T > ItemsUnion < T > getInstance ( final Comparator < ? super T > comparator ) { return new ItemsUnion < T > ( PreambleUtil . DEFAULT_K , comparator , null ) ; } | Create an instance of ItemsUnion with the default k |
31,826 | public static < T > ItemsUnion < T > getInstance ( final int maxK , final Comparator < ? super T > comparator ) { return new ItemsUnion < > ( maxK , comparator , null ) ; } | Create an instance of ItemsUnion |
31,827 | public static < T > ItemsUnion < T > getInstance ( final Memory srcMem , final Comparator < ? super T > comparator , final ArrayOfItemsSerDe < T > serDe ) { final ItemsSketch < T > gadget = ItemsSketch . getInstance ( srcMem , comparator , serDe ) ; return new ItemsUnion < > ( gadget . getK ( ) , gadget . getComparator ( ) , gadget ) ; } | Heapify the given srcMem into a Union object . |
31,828 | public static < T > ItemsUnion < T > getInstance ( final ItemsSketch < T > sketch ) { return new ItemsUnion < > ( sketch . getK ( ) , sketch . getComparator ( ) , ItemsSketch . copy ( sketch ) ) ; } | Create an instance of ItemsUnion based on ItemsSketch |
31,829 | public void update ( final ItemsSketch < T > sketchIn ) { gadget_ = updateLogic ( maxK_ , comparator_ , gadget_ , sketchIn ) ; } | Iterative union operation which means this method can be repeatedly called . Merges the given sketch into this union object . The given sketch is not modified . It is required that the ratio of the two K values be a power of 2 . This is easily satisfied if each of the K values is already a power of 2 . If the given sketch is null or empty it is ignored . |
31,830 | public void update ( final Memory srcMem , final ArrayOfItemsSerDe < T > serDe ) { final ItemsSketch < T > that = ItemsSketch . getInstance ( srcMem , comparator_ , serDe ) ; gadget_ = updateLogic ( maxK_ , comparator_ , gadget_ , that ) ; } | Iterative union operation which means this method can be repeatedly called . Merges the given Memory image of a ItemsSketch into this union object . The given Memory object is not modified and a link to it is not retained . It is required that the ratio of the two K values be a power of 2 . This is easily satisfied if each of the K values is already a power of 2 . If the given sketch is null or empty it is ignored . |
31,831 | public ItemsSketch < T > getResult ( ) { if ( gadget_ == null ) { return ItemsSketch . getInstance ( maxK_ , comparator_ ) ; } return ItemsSketch . copy ( gadget_ ) ; } | Gets the result of this Union operation as a copy of the internal state . This enables further union update operations on this state . |
31,832 | static long checkPreambleSize ( final Memory mem ) { final long cap = mem . getCapacity ( ) ; if ( cap < 8 ) { throwNotBigEnough ( cap , 8 ) ; } final long pre0 = mem . getLong ( 0 ) ; final int preLongs = ( int ) ( pre0 & 0X3FL ) ; final int required = Math . max ( preLongs << 3 , 8 ) ; if ( cap < required ) { throwNotBigEnough ( cap , required ) ; } return pre0 ; } | Checks Memory for capacity to hold the preamble and returns the first 8 bytes . |
31,833 | static UnionImpl initNewHeapInstance ( final int lgNomLongs , final long seed , final float p , final ResizeFactor rf ) { final UpdateSketch gadget = new HeapQuickSelectSketch ( lgNomLongs , seed , p , rf , true ) ; final UnionImpl unionImpl = new UnionImpl ( gadget , seed ) ; unionImpl . unionThetaLong_ = gadget . getThetaLong ( ) ; unionImpl . unionEmpty_ = gadget . isEmpty ( ) ; return unionImpl ; } | Construct a new Union SetOperation on the java heap . Called by SetOperationBuilder . |
31,834 | static UnionImpl initNewDirectInstance ( final int lgNomLongs , final long seed , final float p , final ResizeFactor rf , final MemoryRequestServer memReqSvr , final WritableMemory dstMem ) { final UpdateSketch gadget = new DirectQuickSelectSketch ( lgNomLongs , seed , p , rf , memReqSvr , dstMem , true ) ; 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 . |
31,835 | static UnionImpl heapifyInstance ( final Memory srcMem , final long seed ) { Family . UNION . checkFamilyID ( extractFamilyID ( srcMem ) ) ; final UpdateSketch gadget = HeapQuickSelectSketch . heapifyInstance ( srcMem , seed ) ; final UnionImpl unionImpl = new UnionImpl ( gadget , seed ) ; unionImpl . unionThetaLong_ = extractUnionThetaLong ( srcMem ) ; unionImpl . unionEmpty_ = PreambleUtil . isEmpty ( srcMem ) ; return unionImpl ; } | Heapify a Union from a Memory Union object containing data . Called by SetOperation . |
31,836 | static UnionImpl fastWrap ( final WritableMemory srcMem , final long seed ) { Family . UNION . checkFamilyID ( extractFamilyID ( srcMem ) ) ; final UpdateSketch gadget = DirectQuickSelectSketch . fastWritableWrap ( srcMem , seed ) ; final UnionImpl unionImpl = new UnionImpl ( gadget , seed ) ; unionImpl . unionThetaLong_ = extractUnionThetaLong ( srcMem ) ; unionImpl . unionEmpty_ = PreambleUtil . isEmpty ( srcMem ) ; return unionImpl ; } | Fast - wrap a Union object around a Union Memory object containing data . This does NO validity checking of the given Memory . |
31,837 | static UnionImpl wrapInstance ( final Memory srcMem , final long seed ) { Family . UNION . checkFamilyID ( extractFamilyID ( srcMem ) ) ; final UpdateSketch gadget = DirectQuickSelectSketchR . readOnlyWrap ( srcMem , seed ) ; final UnionImpl unionImpl = new UnionImpl ( gadget , seed ) ; unionImpl . unionThetaLong_ = extractUnionThetaLong ( srcMem ) ; unionImpl . unionEmpty_ = PreambleUtil . isEmpty ( srcMem ) ; return unionImpl ; } | Wrap a Union object around a Union Memory object containing data . Called by SetOperation . |
31,838 | private void processVer1 ( final Memory skMem ) { final long thetaLongIn = skMem . getLong ( THETA_LONG ) ; unionThetaLong_ = min ( unionThetaLong_ , thetaLongIn ) ; final int curCount = skMem . getInt ( RETAINED_ENTRIES_INT ) ; final int preLongs = 3 ; for ( int i = 0 ; i < curCount ; i ++ ) { final int offsetBytes = ( preLongs + i ) << 3 ; final long hashIn = skMem . getLong ( offsetBytes ) ; if ( hashIn >= unionThetaLong_ ) { break ; } gadget_ . hashUpdate ( hashIn ) ; } unionThetaLong_ = min ( unionThetaLong_ , gadget_ . getThetaLong ( ) ) ; unionEmpty_ = unionEmpty_ && gadget_ . isEmpty ( ) ; } | can only be compact ordered size > 24 |
31,839 | private void processVer2 ( final Memory skMem ) { Util . checkSeedHashes ( seedHash_ , skMem . getShort ( SEED_HASH_SHORT ) ) ; final int preLongs = skMem . getByte ( PREAMBLE_LONGS_BYTE ) & 0X3F ; final int curCount = skMem . getInt ( RETAINED_ENTRIES_INT ) ; final long thetaLongIn ; if ( preLongs == 1 ) { return ; } if ( preLongs == 2 ) { assert curCount > 0 ; thetaLongIn = Long . MAX_VALUE ; } else { thetaLongIn = skMem . getLong ( THETA_LONG ) ; } unionThetaLong_ = min ( unionThetaLong_ , thetaLongIn ) ; for ( int i = 0 ; i < curCount ; i ++ ) { final int offsetBytes = ( preLongs + i ) << 3 ; final long hashIn = skMem . getLong ( offsetBytes ) ; if ( hashIn >= unionThetaLong_ ) { break ; } gadget_ . hashUpdate ( hashIn ) ; } unionThetaLong_ = min ( unionThetaLong_ , gadget_ . getThetaLong ( ) ) ; unionEmpty_ = unionEmpty_ && gadget_ . isEmpty ( ) ; } | can only be compact ordered size > = 8 |
31,840 | private void processVer3 ( final Memory skMem ) { Util . checkSeedHashes ( seedHash_ , skMem . getShort ( SEED_HASH_SHORT ) ) ; final int preLongs = skMem . getByte ( PREAMBLE_LONGS_BYTE ) & 0X3F ; final int curCount ; final long thetaLongIn ; if ( preLongs == 1 ) { final int flags = skMem . getByte ( FLAGS_BYTE ) ; if ( flags == ( READ_ONLY_FLAG_MASK | COMPACT_FLAG_MASK | ORDERED_FLAG_MASK ) ) { curCount = 1 ; thetaLongIn = Long . MAX_VALUE ; } else { return ; } } else if ( preLongs == 2 ) { curCount = skMem . getInt ( RETAINED_ENTRIES_INT ) ; assert curCount > 0 ; thetaLongIn = Long . MAX_VALUE ; } else { curCount = skMem . getInt ( RETAINED_ENTRIES_INT ) ; assert curCount > 0 ; thetaLongIn = skMem . getLong ( THETA_LONG ) ; } unionThetaLong_ = min ( unionThetaLong_ , thetaLongIn ) ; final boolean ordered = ( skMem . getByte ( FLAGS_BYTE ) & ORDERED_FLAG_MASK ) != 0 ; if ( ordered ) { for ( int i = 0 ; i < curCount ; i ++ ) { final int offsetBytes = ( preLongs + i ) << 3 ; final long hashIn = skMem . getLong ( offsetBytes ) ; if ( hashIn >= unionThetaLong_ ) { break ; } gadget_ . hashUpdate ( hashIn ) ; } } else { final boolean compact = ( skMem . getByte ( FLAGS_BYTE ) & COMPACT_FLAG_MASK ) != 0 ; final int size = ( compact ) ? curCount : 1 << skMem . getByte ( LG_ARR_LONGS_BYTE ) ; for ( int i = 0 ; i < size ; i ++ ) { final int offsetBytes = ( preLongs + i ) << 3 ; final long hashIn = skMem . getLong ( offsetBytes ) ; if ( ( hashIn <= 0L ) || ( hashIn >= unionThetaLong_ ) ) { continue ; } gadget_ . hashUpdate ( hashIn ) ; } } unionThetaLong_ = min ( unionThetaLong_ , gadget_ . getThetaLong ( ) ) ; unionEmpty_ = unionEmpty_ && gadget_ . isEmpty ( ) ; } | could be unordered ordered compact or not size > = 8 |
31,841 | static double usingXArrAndYStride ( final double [ ] xArr , final double yStride , final double x ) { final int xArrLen = xArr . length ; final int xArrLenM1 = xArrLen - 1 ; final int offset ; assert ( ( xArrLen >= 4 ) && ( x >= xArr [ 0 ] ) && ( x <= xArr [ xArrLenM1 ] ) ) ; if ( x == xArr [ xArrLenM1 ] ) { return ( yStride * ( xArrLenM1 ) ) ; } offset = findStraddle ( xArr , x ) ; final int xArrLenM2 = xArrLen - 2 ; assert ( ( offset >= 0 ) && ( offset <= ( xArrLenM2 ) ) ) ; if ( offset == 0 ) { return ( interpolateUsingXArrAndYStride ( xArr , yStride , ( offset - 0 ) , x ) ) ; } else if ( offset == xArrLenM2 ) { return ( interpolateUsingXArrAndYStride ( xArr , yStride , ( offset - 2 ) , x ) ) ; } return ( interpolateUsingXArrAndYStride ( xArr , yStride , ( offset - 1 ) , x ) ) ; } | Used by HllEstimators |
31,842 | public static final Union heapify ( final Memory mem ) { final int lgK = HllUtil . checkLgK ( mem . getByte ( PreambleUtil . LG_K_BYTE ) ) ; final HllSketch sk = HllSketch . heapify ( mem ) ; final Union union = new Union ( lgK ) ; union . update ( sk ) ; return union ; } | Construct a union operator populated with the given Memory image of an HllSketch . |
31,843 | public void update ( final HllSketch sketch ) { gadget . hllSketchImpl = unionImpl ( sketch . hllSketchImpl , gadget . hllSketchImpl , lgMaxK ) ; } | Update this union operator with the given sketch . |
31,844 | private static final HllSketchImpl copyOrDownsampleHll ( final HllSketchImpl srcImpl , final int tgtLgK ) { assert srcImpl . getCurMode ( ) == HLL ; final AbstractHllArray src = ( AbstractHllArray ) srcImpl ; final int srcLgK = src . getLgConfigK ( ) ; if ( ( srcLgK <= tgtLgK ) && ( src . getTgtHllType ( ) == TgtHllType . HLL_8 ) ) { return src . copy ( ) ; } final int minLgK = Math . min ( srcLgK , tgtLgK ) ; final HllArray tgtHllArr = HllArray . newHeapHll ( minLgK , TgtHllType . HLL_8 ) ; final PairIterator srcItr = src . iterator ( ) ; while ( srcItr . nextValid ( ) ) { tgtHllArr . couponUpdate ( srcItr . getPair ( ) ) ; } tgtHllArr . putHipAccum ( src . getHipAccum ( ) ) ; tgtHllArr . putOutOfOrderFlag ( src . isOutOfOrderFlag ( ) ) ; return tgtHllArr ; } | Caller must ultimately manage oooFlag as caller has more info |
31,845 | public Group init ( final String priKey , final int count , final double estimate , final double ub , final double lb , final double fraction , final double rse ) { this . count = count ; est = estimate ; this . ub = ub ; this . lb = lb ; this . fraction = fraction ; this . rse = rse ; this . priKey = priKey ; return this ; } | Specifies the parameters to be listed as columns |
31,846 | public static double getEstimate ( final Memory srcMem ) { checkIfValidThetaSketch ( srcMem ) ; return Sketch . estimate ( getThetaLong ( srcMem ) , getRetainedEntries ( srcMem ) , getEmpty ( srcMem ) ) ; } | Gets the unique count estimate from a valid memory image of a Sketch |
31,847 | protected void rebuild ( final int newCapacity ) { final int numValues = getNumValues ( ) ; checkIfEnoughMemory ( mem_ , newCapacity , numValues ) ; final int currCapacity = getCurrentCapacity ( ) ; final long [ ] keys = new long [ currCapacity ] ; final double [ ] values = new double [ currCapacity * numValues ] ; mem_ . getLongArray ( keysOffset_ , keys , 0 , currCapacity ) ; mem_ . getDoubleArray ( valuesOffset_ , values , 0 , currCapacity * numValues ) ; mem_ . clear ( keysOffset_ , ( ( long ) SIZE_OF_KEY_BYTES * newCapacity ) + ( ( long ) SIZE_OF_VALUE_BYTES * newCapacity * numValues ) ) ; mem_ . putInt ( RETAINED_ENTRIES_INT , 0 ) ; mem_ . putByte ( LG_CUR_CAPACITY_BYTE , ( byte ) Integer . numberOfTrailingZeros ( newCapacity ) ) ; valuesOffset_ = keysOffset_ + ( SIZE_OF_KEY_BYTES * newCapacity ) ; lgCurrentCapacity_ = Integer . numberOfTrailingZeros ( newCapacity ) ; for ( int i = 0 ; i < keys . length ; i ++ ) { if ( ( keys [ i ] != 0 ) && ( keys [ i ] < theta_ ) ) { insert ( keys [ i ] , Arrays . copyOfRange ( values , i * numValues , ( i + 1 ) * numValues ) ) ; } } setRebuildThreshold ( ) ; } | rebuild in the same memory |
31,848 | static HeapAlphaSketch newHeapInstance ( final int lgNomLongs , final long seed , final float p , final ResizeFactor rf ) { if ( lgNomLongs < ALPHA_MIN_LG_NOM_LONGS ) { throw new SketchesArgumentException ( "This sketch requires a minimum nominal entries of " + ( 1 << ALPHA_MIN_LG_NOM_LONGS ) ) ; } final double nomLongs = ( 1L << lgNomLongs ) ; final double alpha = nomLongs / ( nomLongs + 1.0 ) ; final long split1 = ( long ) ( ( ( p * ( alpha + 1.0 ) ) / 2.0 ) * MAX_THETA_LONG_AS_DOUBLE ) ; final HeapAlphaSketch has = new HeapAlphaSketch ( lgNomLongs , seed , p , rf , alpha , split1 ) ; final int lgArrLongs = Util . startingSubMultiple ( lgNomLongs + 1 , rf , MIN_LG_ARR_LONGS ) ; has . lgArrLongs_ = lgArrLongs ; has . hashTableThreshold_ = setHashTableThreshold ( lgNomLongs , lgArrLongs ) ; has . curCount_ = 0 ; has . thetaLong_ = ( long ) ( p * MAX_THETA_LONG_AS_DOUBLE ) ; has . empty_ = true ; has . cache_ = new long [ 1 << lgArrLongs ] ; return has ; } | Get a new sketch instance on the java heap . |
31,849 | static HeapAlphaSketch heapifyInstance ( final Memory srcMem , final long seed ) { final int preambleLongs = extractPreLongs ( srcMem ) ; final int lgNomLongs = extractLgNomLongs ( srcMem ) ; final int lgArrLongs = extractLgArrLongs ( srcMem ) ; checkAlphaFamily ( srcMem , preambleLongs , lgNomLongs ) ; checkMemIntegrity ( srcMem , seed , preambleLongs , lgNomLongs , lgArrLongs ) ; final float p = extractP ( srcMem ) ; final int lgRF = extractLgResizeFactor ( srcMem ) ; final ResizeFactor myRF = ResizeFactor . getRF ( lgRF ) ; final double nomLongs = ( 1L << lgNomLongs ) ; final double alpha = nomLongs / ( nomLongs + 1.0 ) ; final long split1 = ( long ) ( ( ( p * ( alpha + 1.0 ) ) / 2.0 ) * MAX_THETA_LONG_AS_DOUBLE ) ; if ( ( myRF == ResizeFactor . X1 ) && ( lgArrLongs != Util . startingSubMultiple ( lgNomLongs + 1 , myRF , MIN_LG_ARR_LONGS ) ) ) { throw new SketchesArgumentException ( "Possible corruption: ResizeFactor X1, but provided " + "array too small for sketch size" ) ; } final HeapAlphaSketch has = new HeapAlphaSketch ( lgNomLongs , seed , p , myRF , alpha , split1 ) ; has . lgArrLongs_ = lgArrLongs ; has . hashTableThreshold_ = setHashTableThreshold ( lgNomLongs , lgArrLongs ) ; has . curCount_ = extractCurCount ( srcMem ) ; has . thetaLong_ = extractThetaLong ( srcMem ) ; has . empty_ = PreambleUtil . isEmpty ( srcMem ) ; has . cache_ = new long [ 1 << lgArrLongs ] ; srcMem . getLongArray ( preambleLongs << 3 , has . cache_ , 0 , 1 << lgArrLongs ) ; return has ; } | Heapify a sketch from a Memory object containing sketch data . |
31,850 | 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 ; } | Computes whether there have been 0 1 or 2 or more actual insertions into the cache in a numerically safe way . |
31,851 | 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 |
31,852 | 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 |
31,853 | 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 |
31,854 | 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 ) ) ; srcMem . getByteArray ( HLL_BYTE_ARR_START , hllArray . hllByteArr , 0 , hllArray . hllByteArr . length ) ; } | used by heapify by all Heap HLL |
31,855 | 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 ) ; return byteArrOut ; } | Serializes a Memory based compact sketch to a byte array |
31,856 | static final void quickSelectAndRebuild ( final WritableMemory mem , final int preambleLongs , final int lgNomLongs ) { 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 ) ; final int pivot = ( 1 << lgNomLongs ) + 1 ; final long newThetaLong = selectExcludingZeros ( tmpArr , curCount , pivot ) ; insertThetaLong ( mem , newThetaLong ) ; final long [ ] tgtArr = new long [ arrLongs ] ; final int newCurCount = HashOperations . hashArrayInsert ( tmpArr , tgtArr , lgArrLongs , newThetaLong ) ; insertCurCount ( mem , newCurCount ) ; 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 . |
31,857 | static final void resize ( final WritableMemory mem , final int preambleLongs , final int srcLgArrLongs , final int tgtLgArrLongs ) { final int preBytes = preambleLongs << 3 ; final int srcHTLen = 1 << srcLgArrLongs ; final long [ ] srcHTArr = new long [ srcHTLen ] ; mem . getLongArray ( preBytes , srcHTArr , 0 , srcHTLen ) ; final int dstHTLen = 1 << tgtLgArrLongs ; final long [ ] dstHTArr = new long [ dstHTLen ] ; final long thetaLong = extractThetaLong ( mem ) ; HashOperations . hashArrayInsert ( srcHTArr , dstHTArr , tgtLgArrLongs , thetaLong ) ; mem . putLongArray ( preBytes , dstHTArr , 0 , dstHTLen ) ; insertLgArrLongs ( mem , tgtLgArrLongs ) ; } | 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 . |
31,858 | 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 ; |
31,859 | 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 . |
31,860 | 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 . |
31,861 | 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 . |
31,862 | 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 |
31,863 | 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 |
31,864 | 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 ; } | 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 . |
31,865 | 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 . |
31,866 | 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 . |
31,867 | 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 . |
31,868 | 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 . |
31,869 | 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 . |
31,870 | 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 . |
31,871 | Format getFormat ( ) { final int ordinal ; final Flavor f = getFlavor ( ) ; if ( ( f == Flavor . HYBRID ) || ( f == Flavor . SPARSE ) ) { ordinal = 2 | ( mergeFlag ? 0 : 1 ) ; } 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 . |
31,872 | 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 { 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 . |
31,873 | static void refreshKXP ( final CpcSketch sketch , final long [ ] bitMatrix ) { final int k = ( 1 << sketch . lgK ) ; final double [ ] byteSums = new double [ 8 ] ; for ( int j = 0 ; j < 8 ; j ++ ) { byteSums [ j ] = 0.0 ; } for ( int i = 0 ; i < k ; i ++ ) { long row = bitMatrix [ i ] ; for ( int j = 0 ; j < 8 ; j ++ ) { final int byteIdx = ( int ) ( row & 0XFFL ) ; byteSums [ j ] += kxpByteLookup [ byteIdx ] ; row >>>= 8 ; } } double total = 0.0 ; for ( int j = 7 ; j -- > 0 ; ) { final double factor = invPow2 ( 8 * j ) ; total += factor * byteSums [ j ] ; } sketch . kxp = total ; } | Also used in test |
31,874 | 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 ; final long [ ] bitMatrix = CpcUtil . bitMatrixOfSketch ( sketch ) ; 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 ; pattern ^= maskForFlippingEarlyZone ; allSurprisesORed |= pattern ; while ( pattern != 0 ) { final int col = Long . numberOfTrailingZeros ( pattern ) ; pattern = pattern ^ ( 1L << col ) ; 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 ; } } | This moves the sliding window |
31,875 | 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 ) ; } | Call this whenever a new coupon has been collected . |
31,876 | 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 ) ; final long c8pre = sketch . numCoupons << 3 ; final int w8pre = sketch . windowOffset << 3 ; assert c8pre < ( ( 27L + w8pre ) * k ) ; boolean isNovel = false ; final int col = rowCol & 63 ; if ( col < sketch . windowOffset ) { isNovel = PairTable . maybeDelete ( sketch . pairTable , rowCol ) ; } else if ( col < ( sketch . windowOffset + 8 ) ) { 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 { assert col >= ( sketch . windowOffset + 8 ) ; isNovel = PairTable . maybeInsert ( sketch . pairTable , rowCol ) ; } 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 ) ; } } } | The flavor is HYBRID PINNED or SLIDING . |
31,877 | 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 |
31,878 | void hashUpdate ( final long hash0 , final long hash1 ) { int col = Long . numberOfLeadingZeros ( hash1 ) ; if ( col < fiCol ) { return ; } if ( col > 63 ) { 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 ; if ( rowCol == - 1 ) { rowCol ^= ( 1 << 6 ) ; } if ( ( c << 5 ) < ( 3L * k ) ) { updateSparse ( this , rowCol ) ; } else { updateWindowed ( this , rowCol ) ; } } | Used here and for testing |
31,879 | void rowColUpdate ( final int rowCol ) { final int col = rowCol & 63 ; if ( col < fiCol ) { return ; } 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 |
31,880 | static long [ ] getBitMatrix ( final CpcUnion union ) { checkUnionState ( union ) ; return ( union . bitMatrix != null ) ? union . bitMatrix : CpcUtil . bitMatrixOfSketch ( union . accumulator ) ; } | used for testing only |
31,881 | 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 . |
31,882 | public UpdatableSketch < U , S > build ( ) { return new UpdatableSketch < > ( nomEntries_ , resizeFactor_ . lg ( ) , samplingProbability_ , summaryFactory_ ) ; } | Returns an UpdatableSketch with the current configuration of this Builder . |
31,883 | 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 ; final int preBytes = ( preLongs + extra ) << 3 ; final int k = getK ( ) ; combinedBuffer_ = new double [ combBufCap ] ; if ( srcIsCompact ) { srcMem . getDoubleArray ( preBytes , combinedBuffer_ , 0 , combBufCap ) ; if ( serVer == 2 ) { Arrays . sort ( combinedBuffer_ , 0 , baseBufferCount_ ) ; } } else { srcMem . getDoubleArray ( preBytes , combinedBuffer_ , 0 , baseBufferCount_ ) ; Arrays . sort ( combinedBuffer_ , 0 , baseBufferCount_ ) ; 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 . |
31,884 | static final void internalHll4Update ( final AbstractHllArray host , final int slotNo , final int newValue ) { assert ( ( 0 <= slotNo ) && ( slotNo < ( 1 << host . getLgConfigK ( ) ) ) ) ; assert ( newValue > 0 ) ; final int curMin = host . getCurMin ( ) ; AuxHashMap auxHashMap = host . getAuxHashMap ( ) ; final int rawStoredOldValue = host . getSlot ( slotNo ) ; final int lbOnOldValue = rawStoredOldValue + curMin ; if ( newValue > lbOnOldValue ) { final int actualOldValue = ( rawStoredOldValue < AUX_TOKEN ) ? lbOnOldValue : auxHashMap . mustFindValueFor ( slotNo ) ; if ( newValue > actualOldValue ) { AbstractHllArray . hipAndKxQIncrementalUpdate ( host , actualOldValue , newValue ) ; assert ( newValue >= curMin ) : "New value " + newValue + " is less than current minimum " + curMin ; final int shiftedNewValue = newValue - curMin ; assert ( shiftedNewValue >= 0 ) ; if ( rawStoredOldValue == AUX_TOKEN ) { if ( shiftedNewValue >= AUX_TOKEN ) { auxHashMap . mustReplace ( slotNo , newValue ) ; } else { throw new SketchesStateException ( "Impossible case" ) ; } } else { if ( shiftedNewValue >= AUX_TOKEN ) { host . putSlot ( slotNo , AUX_TOKEN ) ; if ( auxHashMap == null ) { auxHashMap = host . getNewAuxHashMap ( ) ; host . putAuxHashMap ( auxHashMap , false ) ; } auxHashMap . mustAdd ( slotNo , newValue ) ; } else { host . putSlot ( slotNo , shiftedNewValue ) ; } } if ( actualOldValue == curMin ) { assert ( host . getNumAtCurMin ( ) >= 1 ) ; host . decNumAtCurMin ( ) ; while ( host . getNumAtCurMin ( ) == 0 ) { shiftToBiggerCurMin ( host ) ; } } } } } | Only called by Hll4Array and DirectHll4Array |
31,885 | 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 |
31,886 | 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 |
31,887 | 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% . |
31,888 | 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 ) ; 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 . |
31,889 | 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 |
31,890 | 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 |
31,891 | 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 . |
31,892 | 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 . |
31,893 | @ SuppressWarnings ( "null" ) 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 + Byte . BYTES + Byte . BYTES + Byte . BYTES + Byte . BYTES ; final boolean isThetaIncluded = theta_ < Long . MAX_VALUE ; if ( isThetaIncluded ) { sizeBytes += Long . BYTES ; } if ( count > 0 ) { sizeBytes += + Integer . BYTES + ( 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 | |
31,894 | static ArrayOfDoublesUnion heapifyUnion ( final Memory mem , final long seed ) { final SerializerDeserializer . SketchType type = SerializerDeserializer . getSketchType ( mem ) ; 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 |
31,895 | 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 ; } 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 ; } 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 . |
31,896 | 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 . |
31,897 | 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 . |
31,898 | 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 . |
31,899 | 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 . |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.