Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added isEmpty method to HyperLogLog and UltraLogLog #317

Merged
merged 1 commit into from
Jan 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2023 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -142,6 +142,13 @@ interface DistinctCounter<T extends DistinctCounter<T, R>, R extends DistinctCou
*/
double getStateChangeProbability();

/**
* Returns {@code true} if the sketch is empty, corresponding to the initial state.
*
* @return {@code true} if the sketch is empty
*/
boolean isEmpty();

/**
* An estimator for a distinct counter.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -477,6 +477,19 @@ public double getStateChangeProbability() {
return DistinctCountUtil.unsignedLongToDouble(sum) * 0x1p-64;
}

/**
* Returns {@code true} if the sketch is empty, corresponding to the initial state.
*
* @return {@code true} if the sketch is empty
*/
@Override
public boolean isEmpty() {
for (byte b : state) {
if (b != 0) return false;
}
return true;
}

/**
* Resets this sketch to its initial state representing an empty set.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -386,6 +386,19 @@ public double getStateChangeProbability() {
return DistinctCountUtil.unsignedLongToDouble(sum) * 0x1p-64;
}

/**
* Returns {@code true} if the sketch is empty, corresponding to the initial state.
*
* @return {@code true} if the sketch is empty
*/
@Override
public boolean isEmpty() {
for (byte b : state) {
if (b != 0) return false;
}
return true;
}

/**
* Resets this sketch to its initial state representing an empty set.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -1043,6 +1043,21 @@ void testChangeProbabilityAndFinitenessOfEstimators() {
}
}

@Test
void testIsEmpty() {
SplittableRandom random = new SplittableRandom(0x309a6777250910bcL);

for (int p = getMinP(); p <= getMaxP(); ++p) {
T sketch = create(p);
for (int i = 0; i < 5; ++i) {
assertThat(sketch.isEmpty()).isTrue();
sketch.add(random.nextLong());
assertThat(sketch.isEmpty()).isFalse();
sketch.reset();
}
}
}

@Test
void testToken() {
for (int p = getMinP(); p <= Math.min(getMaxP(), 10); ++p) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Dynatrace LLC
* Copyright 2024-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2023-2024 Dynatrace LLC
* Copyright 2023-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2024 Dynatrace LLC
* Copyright 2024-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2022-2024 Dynatrace LLC
* Copyright 2022-2025 Dynatrace LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down
Loading