MCPcopy Index your code
hub / github.com/aggregateknowledge/java-hll / addRawProbabilistic

Method addRawProbabilistic

src/main/java/net/agkn/hll/HLL.java:438–472  ·  view source on GitHub ↗

Adds the raw value to the #probabilisticStorage. #type must be HLLType#FULL. @param rawValue the raw value to add to the full probabilistic storage.

(final long rawValue)

Source from the content-addressed store, hash-verified

436 * @param rawValue the raw value to add to the full probabilistic storage.
437 */
438 private void addRawProbabilistic(final long rawValue) {
439 // p(w): position of the least significant set bit (one-indexed)
440 // By contract: p(w) <= 2^(registerValueInBits) - 1 (the max register value)
441 //
442 // By construction of pwMaxMask (see #Constructor()),
443 // lsb(pwMaxMask) = 2^(registerValueInBits) - 2,
444 // thus lsb(any_long | pwMaxMask) <= 2^(registerValueInBits) - 2,
445 // thus 1 + lsb(any_long | pwMaxMask) <= 2^(registerValueInBits) -1.
446 final long substreamValue = (rawValue >>> log2m);
447 final byte p_w;
448
449 if (substreamValue == 0L) {
450 // The paper does not cover p(0x0), so the special value 0 is used.
451 // 0 is the original initialization value of the registers, so by
452 // doing this the multiset simply ignores it. This is acceptable
453 // because the probability is 1/(2^(2^registerSizeInBits)).
454 p_w = 0;
455 } else {
456 p_w = (byte)(1 + BitUtil.leastSignificantBit(substreamValue| pwMaxMask));
457 }
458
459 // Short-circuit if the register is being set to zero, since algorithmically
460 // this corresponds to an "unset" register, and "unset" registers aren't
461 // stored to save memory. (The very reason this sparse implementation
462 // exists.) If a register is set to zero it will break the #algorithmCardinality
463 // code.
464 if(p_w == 0) {
465 return;
466 }
467
468 // NOTE: no +1 as in paper since 0-based indexing
469 final int j = (int)(rawValue & mBitsMask);
470
471 probabilisticStorage.setMaxRegister(j, p_w);
472 }
473
474 // ------------------------------------------------------------------------
475 // Storage helper

Callers 1

addRawMethod · 0.95

Calls 2

leastSignificantBitMethod · 0.95
setMaxRegisterMethod · 0.80

Tested by

no test coverage detected