MCPcopy Create free account
hub / github.com/aggregateknowledge/java-hll / clone

Method clone

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

Create a deep copy of this HLL. @see java.lang.Object#clone()

()

Source from the content-addressed store, hash-verified

1039 * @see java.lang.Object#clone()
1040 */
1041 @Override
1042 public HLL clone() throws CloneNotSupportedException {
1043 // NOTE: Since the package-only constructor assumes both explicit and
1044 // sparse are enabled, the easiest thing to do here is to re-derive
1045 // the expthresh parameter and create a new HLL with the public
1046 // constructor.
1047 // TODO: add a more sensible constructor to make this less obfuscated
1048 final int copyExpthresh;
1049 if(explicitAuto) {
1050 copyExpthresh = -1;
1051 } else if(explicitOff) {
1052 copyExpthresh = 0;
1053 } else {
1054 // explicitThreshold is defined as:
1055 //
1056 // this.explicitThreshold = (1 << (expthresh - 1));
1057 //
1058 // Since explicitThreshold is a power of two and only has a single
1059 // bit set, finding the LSB is the same as finding the inverse
1060 copyExpthresh = BitUtil.leastSignificantBit(explicitThreshold) + 1;
1061 }
1062 final HLL copy = new HLL(log2m, regwidth, copyExpthresh, !sparseOff/*sparseOn*/, type);
1063 switch(type) {
1064 case EMPTY:
1065 // nothing to be done
1066 break;
1067 case EXPLICIT:
1068 copy.explicitStorage = this.explicitStorage.clone();
1069 break;
1070 case SPARSE:
1071 copy.sparseProbabilisticStorage = this.sparseProbabilisticStorage.clone();
1072 break;
1073 case FULL:
1074 copy.probabilisticStorage = this.probabilisticStorage.clone();
1075 break;
1076 default:
1077 throw new RuntimeException("Unsupported HLL type " + type);
1078 }
1079 return copy;
1080 }
1081}

Callers 2

assertCardinalityMethod · 0.95
heterogenousUnionMethod · 0.45

Calls 1

leastSignificantBitMethod · 0.95

Tested by 1

assertCardinalityMethod · 0.76