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

Method heterogenousUnion

src/main/java/net/agkn/hll/HLL.java:653–809  ·  view source on GitHub ↗
(final HLL other)

Source from the content-addressed store, hash-verified

651 * cannot be <code>null</code>.
652 */
653 /*package, for testing*/ void heterogenousUnion(final HLL other) {
654 /*
655 * The logic here is divided into two sections: unions with an EMPTY
656 * HLL, and unions between EXPLICIT/SPARSE/FULL
657 * HLL.
658 *
659 * Between those two sections, all possible heterogeneous unions are
660 * covered. Should another type be added to HLLType whose unions
661 * are not easily reduced (say, as EMPTY's are below) this may be more
662 * easily implemented as Strategies. However, that is unnecessary as it
663 * stands.
664 */
665
666 // ....................................................................
667 // Union with an EMPTY
668 if(HLLType.EMPTY.equals(type)) {
669 // NOTE: The union of empty with non-empty HLL is just a
670 // clone of the non-empty.
671
672 switch(other.getType()) {
673 case EXPLICIT: {
674 // src: EXPLICIT
675 // dest: EMPTY
676
677 if(other.explicitStorage.size() <= explicitThreshold) {
678 type = HLLType.EXPLICIT;
679 explicitStorage = other.explicitStorage.clone();
680 } else {
681 if(!sparseOff) {
682 initializeStorage(HLLType.SPARSE);
683 } else {
684 initializeStorage(HLLType.FULL);
685 }
686 for(final long value : other.explicitStorage) {
687 addRaw(value);
688 }
689 }
690 return;
691 }
692 case SPARSE: {
693 // src: SPARSE
694 // dest: EMPTY
695
696 if(!sparseOff) {
697 type = HLLType.SPARSE;
698 sparseProbabilisticStorage = other.sparseProbabilisticStorage.clone();
699 } else {
700 initializeStorage(HLLType.FULL);
701 for(final int registerIndex : other.sparseProbabilisticStorage.keySet()) {
702 final byte registerValue = other.sparseProbabilisticStorage.get(registerIndex);
703 probabilisticStorage.setMaxRegister(registerIndex, registerValue);
704 }
705 }
706 return;
707 }
708 default/*case FULL*/: {
709 // src: FULL
710 // dest: EMPTY

Callers 1

unionMethod · 0.95

Calls 5

initializeStorageMethod · 0.95
addRawMethod · 0.95
setMaxRegisterMethod · 0.80
getTypeMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected