Adds rawValue directly to the HLL. @param rawValue the value to be added. It is very important that this value already be hashed with a strong (but not necessarily cryptographic) hash function. For instance, the Murmur3 implementation in <a hre
(final long rawValue)
| 325 | * of the hash provided in the PostgreSQL implementation. |
| 326 | */ |
| 327 | public void addRaw(final long rawValue) { |
| 328 | switch(type) { |
| 329 | case EMPTY: { |
| 330 | // NOTE: EMPTY type is always promoted on #addRaw() |
| 331 | if(explicitThreshold > 0) { |
| 332 | initializeStorage(HLLType.EXPLICIT); |
| 333 | explicitStorage.add(rawValue); |
| 334 | } else if(!sparseOff) { |
| 335 | initializeStorage(HLLType.SPARSE); |
| 336 | addRawSparseProbabilistic(rawValue); |
| 337 | } else { |
| 338 | initializeStorage(HLLType.FULL); |
| 339 | addRawProbabilistic(rawValue); |
| 340 | } |
| 341 | return; |
| 342 | } |
| 343 | case EXPLICIT: { |
| 344 | explicitStorage.add(rawValue); |
| 345 | |
| 346 | // promotion, if necessary |
| 347 | if(explicitStorage.size() > explicitThreshold) { |
| 348 | if(!sparseOff) { |
| 349 | initializeStorage(HLLType.SPARSE); |
| 350 | for(final long value : explicitStorage) { |
| 351 | addRawSparseProbabilistic(value); |
| 352 | } |
| 353 | } else { |
| 354 | initializeStorage(HLLType.FULL); |
| 355 | for(final long value : explicitStorage) { |
| 356 | addRawProbabilistic(value); |
| 357 | } |
| 358 | } |
| 359 | explicitStorage = null; |
| 360 | } |
| 361 | return; |
| 362 | } |
| 363 | case SPARSE: { |
| 364 | addRawSparseProbabilistic(rawValue); |
| 365 | |
| 366 | // promotion, if necessary |
| 367 | if(sparseProbabilisticStorage.size() > sparseThreshold) { |
| 368 | initializeStorage(HLLType.FULL); |
| 369 | for(final int registerIndex : sparseProbabilisticStorage.keySet()) { |
| 370 | final byte registerValue = sparseProbabilisticStorage.get(registerIndex); |
| 371 | probabilisticStorage.setMaxRegister(registerIndex, registerValue); |
| 372 | } |
| 373 | sparseProbabilisticStorage = null; |
| 374 | } |
| 375 | return; |
| 376 | } |
| 377 | case FULL: |
| 378 | addRawProbabilistic(rawValue); |
| 379 | return; |
| 380 | default: |
| 381 | throw new RuntimeException("Unsupported HLL type " + type); |
| 382 | } |
| 383 | } |
| 384 |