class_docstr: Probabilistic set membership testing for large sets
class_docstr_tok: ["Probabilistic","set","membership","testing","for","large","sets"]
code: def __init__(
      self,
      max_elements=10000,
      error_rate=0.1,
      probe_bitnoer=get_filter_bitno_probes,
      filename=None,
      start_fresh=False,
  ):
      # pylint: disable=R0913
      # R0913: We want a few arguments
      if max_elements <= 0:
          raise ValueError("ideal_num_elements_n must be > 0")
      if not (0 < error_rate < 1):
          raise ValueError(
              "error_rate_p must be between 0 and 1 exclusive"
          )
  
      self.error_rate_p = error_rate
      # With fewer elements, we should do very well. With more elements, our
      # error rate "guarantee" drops rapidly.
      self.ideal_num_elements_n = max_elements
  
      numerator = (
          -1 * self.ideal_num_elements_n * math.log(self.error_rate_p)
      )
      denominator = math.log(2) ** 2
      real_num_bits_m = numerator / denominator
      self.num_bits_m = int(math.ceil(real_num_bits_m))
  
      if filename is None:
          self.backend = Array_backend(self.num_bits_m)
      elif isinstance(filename, tuple) and isinstance(filename[1], int):
          if start_fresh:
              try_unlink(filename[0])
          if filename[1] == -1:
              self.backend = Mmap_backend(self.num_bits_m, filename[0])
          else:
              self.backend = Array_then_file_seek_backend(
                  self.num_bits_m,
                  filename[0],
                  filename[1],
              )
      else:
          if start_fresh:
              try_unlink(filename)
          self.backend = File_seek_backend(self.num_bits_m, filename)
  
      # AKA num_offsetters
      # Verified against
      # https://en.wikipedia.org/wiki/Bloom_filter#Probability_of_false_positives
      real_num_probes_k = (
          self.num_bits_m / self.ideal_num_elements_n
      ) * math.log(2)
      self.num_probes_k = int(math.ceil(real_num_probes_k))
      self.probe_bitnoer = probe_bitnoer
  
imports: import array
  import math
  import os
  import random
label_desc: Use image node_id 1 to create a new BloomFilter object from inherited base classes: object with example: obj = BloomFilter(max_elements, error_rate, probe_bitnoer, filename, start_fresh)