bits-and-blooms / bloom

Go package implementing Bloom filters, used by Milvus and Beego.
BSD 2-Clause "Simplified" License
2.44k stars 232 forks source link

Test locations #36

Closed db7 closed 7 years ago

db7 commented 7 years ago

This PR adds the possibility to test specific locations in a BloomFilter. In some scenarios that data items are tested very frequently for different BloomFilters. We can drastically improve performance if we pre-compute the hash locations of the items and test them.

Here is a simple example of how that could be used.

// precompute k hash locations for an item
locs := Locations(n1, k)

// test the item in multiple filters and return if found
for _, b := range filters {
  if b.TestLocations(locs) {
    return true
  }
}
return false