From 97575b0c8edcfbac29ca9bb52672cf134c1f5972 Mon Sep 17 00:00:00 2001 From: AlexanderSaydakov Date: Thu, 30 May 2024 17:07:29 -0700 Subject: [PATCH 1/3] fixed find_run_start() and removed adjustment in insert_new_run() --- .../quotientfilter/QuotientFilter.java | 32 ++++++++----------- 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java b/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java index db1da48ad..f890f53bc 100644 --- a/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java +++ b/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java @@ -291,23 +291,20 @@ long find_cluster_start(long index) { // given a canonical slot A, finds the actual index B of where the run belonging to slot A now resides // since the run might have been shifted to the right due to collisions long find_run_start(long index) { - long current_index = index; - int runs_to_skip_counter = 1; - while (is_shifted(current_index)) { - if (is_occupied(current_index)) { - runs_to_skip_counter++; - } - current_index = (current_index - 1) & getMask(); + int num_runs_to_skip = 0; + while (is_shifted(index)) { + index = (index - 1) & getMask(); + if (is_occupied(index)) { + num_runs_to_skip++; } - while (true) { - if (!is_continuation(current_index)) { - runs_to_skip_counter--; - if (runs_to_skip_counter == 0) { - return current_index; - } - } - current_index = (current_index + 1) & getMask(); + } + while (num_runs_to_skip > 0) { + index = (index + 1) & getMask(); + if (!is_continuation(index)) { + num_runs_to_skip--; } + } + return index; } // given the start of a run, scan the run and return the index of the first matching fingerprint @@ -391,10 +388,9 @@ long find_new_run_location(long index) { } boolean insert_new_run(long canonical_slot, long long_fp) { - long preexisting_run_start_index = find_run_start(canonical_slot); // scans the cluster leftwards and then to the right until reaching our run's would be location - long start_of_this_new_run = find_new_run_location(preexisting_run_start_index); // If there is already a run at the would-be location, find its end and insert the new run after it + long start_of_this_new_run = find_run_start(canonical_slot); boolean slot_initially_empty = is_slot_empty(start_of_this_new_run); - + // modify some metadata flags to mark the new run set_occupied(canonical_slot, true); if (start_of_this_new_run != canonical_slot) { From 8a8bfbc97735614b53e246282553ab3ec9a5235e Mon Sep 17 00:00:00 2001 From: AlexanderSaydakov Date: Thu, 30 May 2024 17:10:05 -0700 Subject: [PATCH 2/3] removed whitespace --- .../datasketches/filters/quotientfilter/QuotientFilter.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java b/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java index f890f53bc..0a8923acf 100644 --- a/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java +++ b/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java @@ -390,7 +390,7 @@ long find_new_run_location(long index) { boolean insert_new_run(long canonical_slot, long long_fp) { long start_of_this_new_run = find_run_start(canonical_slot); boolean slot_initially_empty = is_slot_empty(start_of_this_new_run); - + // modify some metadata flags to mark the new run set_occupied(canonical_slot, true); if (start_of_this_new_run != canonical_slot) { From 31fd85d4e3c40dd45245eed97b2e1d81bbf57c77 Mon Sep 17 00:00:00 2001 From: AlexanderSaydakov Date: Thu, 30 May 2024 17:21:03 -0700 Subject: [PATCH 3/3] removed unnecessary method --- .../filters/quotientfilter/QuotientFilter.java | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java b/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java index 0a8923acf..e2db67c58 100644 --- a/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java +++ b/src/main/java/org/apache/datasketches/filters/quotientfilter/QuotientFilter.java @@ -376,17 +376,6 @@ long swap_fingerprints(long index, long new_fingerprint) { return existing; } - // return the first slot to the right where the current run starting at the index parameter ends - long find_new_run_location(long index) { - if (!is_slot_empty(index)) { - index = (index + 1) & getMask(); - } - while (is_continuation(index)) { - index = (index + 1) & getMask(); - } - return index; - } - boolean insert_new_run(long canonical_slot, long long_fp) { long start_of_this_new_run = find_run_start(canonical_slot); boolean slot_initially_empty = is_slot_empty(start_of_this_new_run);