def _create_filter(self): "Creates a new filter" # Get the initial parameters capacity, prob = self.init_capacity, self.prob # Bound the ultimate probability by adjusting for the initial # From "Scalable Bloom Filters", Almeida 2007 # We use : P <= P0 * (1 / (1 - r)) prob = (1 - self.prob_reduction) * prob # Update our parameters if we have filters if len(self.filters) > 0: # Grow by the scale size capacity = self.filters[-1].info["capacity"] * self.scale_size # Reduce the probability by the probability reduction prob = self.filters[-1].info["prob"] * self.prob_reduction # Compute the new size and K length, k = BloomFilter.params_for_capacity(capacity, prob) # Invoke our callback to get a bitmap bitmap = self.callback(length) # Create a new bloom filter filter = BloomFilter(bitmap, k) # Add the new properties filter.info["prob"] = prob filter.info["capacity"] = capacity return filter
def _initialize(self): "Initializes the probability and capacity of existing filters" # Bound the ultimate probability by adjusting for the initial # From "Scalable Bloom Filters", Almeida 2007 # We use : P <= P0 * (1 / (1 - r)) prob = (1 - self.prob_reduction) * self.prob for filt in self.filters: size = len(filt.bitmap) - 8 * filt.extra_buffer() filt.info["prob"] = prob filt.info["capacity"] = int(BloomFilter.expected_capacity(size, prob)) prob *= self.prob_reduction