Computes the union of two HLLs of the same type, and stores the result in this instance. @param other the other HLL instance to union into this one. This cannot be null .
(final HLL other)
| 816 | * cannot be <code>null</code>. |
| 817 | */ |
| 818 | private void homogeneousUnion(final HLL other) { |
| 819 | switch(type) { |
| 820 | case EMPTY: |
| 821 | // union of empty and empty is empty |
| 822 | return; |
| 823 | case EXPLICIT: |
| 824 | for(final long value : other.explicitStorage) { |
| 825 | addRaw(value); |
| 826 | } |
| 827 | // NOTE: #addRaw() will handle promotion, if necessary |
| 828 | return; |
| 829 | case SPARSE: |
| 830 | for(final int registerIndex : other.sparseProbabilisticStorage.keySet()) { |
| 831 | final byte registerValue = other.sparseProbabilisticStorage.get(registerIndex); |
| 832 | final byte currentRegisterValue = sparseProbabilisticStorage.get(registerIndex); |
| 833 | if(registerValue > currentRegisterValue) { |
| 834 | sparseProbabilisticStorage.put(registerIndex, registerValue); |
| 835 | } |
| 836 | } |
| 837 | |
| 838 | // promotion, if necessary |
| 839 | if(sparseProbabilisticStorage.size() > sparseThreshold) { |
| 840 | initializeStorage(HLLType.FULL); |
| 841 | for(final int registerIndex : sparseProbabilisticStorage.keySet()) { |
| 842 | final byte registerValue = sparseProbabilisticStorage.get(registerIndex); |
| 843 | probabilisticStorage.setMaxRegister(registerIndex, registerValue); |
| 844 | } |
| 845 | sparseProbabilisticStorage = null; |
| 846 | } |
| 847 | return; |
| 848 | case FULL: |
| 849 | for(int i=0; i<m; i++) { |
| 850 | final long registerValue = other.probabilisticStorage.getRegister(i); |
| 851 | probabilisticStorage.setMaxRegister(i, registerValue); |
| 852 | } |
| 853 | return; |
| 854 | default: |
| 855 | throw new RuntimeException("Unsupported HLL type " + type); |
| 856 | } |
| 857 | } |
| 858 | |
| 859 | // ======================================================================== |
| 860 | // Serialization |
no test coverage detected