From 97f874943d8339dcbf173f133771b8b6979b7c42 Mon Sep 17 00:00:00 2001 From: Vladimir Prus Date: Mon, 19 Jan 2026 19:13:22 +0000 Subject: [PATCH] XorBinaryFuse: throw on failure Filling the fingerprints array with 0xFF would create a filter that generates false negatives. --- .../main/java/org/fastfilter/xor/XorBinaryFuse16.java | 9 +++------ .../main/java/org/fastfilter/xor/XorBinaryFuse32.java | 9 +++------ .../src/main/java/org/fastfilter/xor/XorBinaryFuse8.java | 9 +++------ 3 files changed, 9 insertions(+), 18 deletions(-) diff --git a/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse16.java b/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse16.java index aad3c77..0f497db 100644 --- a/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse16.java +++ b/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse16.java @@ -200,12 +200,9 @@ private void addAll(long[] keys) { if (hashIndex > 100) { // if construction doesn't succeed eventually, - // then there is likely a problem with the hash function - // let us not crash the system: - for(int i = 0; i < fingerprints.length; i++) { - fingerprints[i] = (short)0xFFFF; - } - return; + // then there is likely a problem with the hash function. + // It's better fail that either produce non-functional or incorrect filter. + throw new IllegalArgumentException("could not construct filter"); } // use a new random numbers seed = Hash.randomSeed(); diff --git a/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse32.java b/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse32.java index d3f6125..67900a6 100644 --- a/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse32.java +++ b/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse32.java @@ -200,12 +200,9 @@ private void addAll(long[] keys) { if (hashIndex > 100) { // if construction doesn't succeed eventually, - // then there is likely a problem with the hash function - // let us not crash the system: - for (int i = 0; i < fingerprints.length; i++) { - fingerprints[i] = (int) 0xFFFFFFFF; - } - return; + // then there is likely a problem with the hash function. + // It's better fail that either produce non-functional or incorrect filter. + throw new IllegalArgumentException("could not construct filter"); } // use a new random numbers seed = Hash.randomSeed(); diff --git a/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java b/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java index dfd5f45..81e42f1 100644 --- a/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java +++ b/fastfilter/src/main/java/org/fastfilter/xor/XorBinaryFuse8.java @@ -200,12 +200,9 @@ private void addAll(long[] keys) { if (hashIndex > 100) { // if construction doesn't succeed eventually, - // then there is likely a problem with the hash function - // let us not crash the system: - for(int i = 0; i < fingerprints.length; i++) { - fingerprints[i] = (byte)0xFF; - } - return; + // then there is likely a problem with the hash function. + // It's better fail that either produce non-functional or incorrect filter. + throw new IllegalArgumentException("could not construct filter"); } // use a new random numbers seed = Hash.randomSeed();