Skip to content

Hang when expected number of items is zero #17

@blp

Description

@blp

When the expected number of items is zero, the number of hashes becomes u32::MAX.

To see the behavior, try this program:

use fastbloom::BloomFilter;

fn main() {
    for expected in std::iter::once(0).chain((0..10).map(|exponent| 1 << exponent)) {
        let bloom_filter = BloomFilter::with_false_pos(0.001).expected_items(expected);
        println!(
            "expected={expected} num_hashes={}",
            bloom_filter.num_hashes()
        );
    }
}

The output with fastbloom 0.14.0:

expected=0 num_hashes=4294967295
expected=1 num_hashes=354
expected=2 num_hashes=177
expected=4 num_hashes=88
expected=8 num_hashes=44
expected=16 num_hashes=22
expected=32 num_hashes=11
expected=64 num_hashes=10
expected=128 num_hashes=10
expected=256 num_hashes=10
expected=512 num_hashes=10

Computing u32::MAX hashes effectively hangs the program.

The number of hashes for small numbers of expected items also seems very large (354 for 1 item?), but doesn't hang the program at least.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions