Ejemplo n.º 1
0
 def __init__(self,
              capacity,
              error_rate=0.001,
              expiration=60,
              disable_hard_capacity=False):
     self.error_rate = error_rate
     self.capacity = capacity
     self.expiration = expiration
     self.nbr_slices = int(np.ceil(np.log2(1.0 / error_rate)))
     self.bits_per_slice = int(
         np.ceil((capacity * abs(np.log(error_rate))) / (self.nbr_slices *
                                                         (np.log(2)**2))))
     self.nbr_bits = self.nbr_slices * self.bits_per_slice
     self.count = 0
     self.cellarray = np.zeros(self.nbr_bits, dtype=np.uint8)
     self.counter_init = 255
     self.refresh_head = 0
     self.make_hashes = generate_hashfunctions(self.bits_per_slice,
                                               self.nbr_slices)
     # This is the unset ratio ... and we keep it constant at 0.5
     # since the BF will operate most of the time at his optimal
     # set ratio (50 %) and the overall effect of this parameter
     # on the refresh rate is very minimal anyway.
     self.z = 0.5
     self.estimate_z = 0
     self.disable_hard_capacity = disable_hard_capacity
 def __init__(self, delta, epsilon, k):
     self.nbr_bits = int(np.ceil(np.exp(1) / epsilon))
     self.nbr_slices = int(np.ceil(np.log(1 / delta)))
     self.k = k
     self.count = np.zeros((self.nbr_slices, self.nbr_bits), dtype=np.int32)
     self.heap = []
     self.top_k = {}
     self.make_hashes = generate_hashfunctions(self.nbr_bits, self.nbr_slices)
Ejemplo n.º 3
0
 def _initialize_parameters(self):
     self.nbr_slices = int(np.ceil(np.log2(1.0 / self.error_rate)))
     self.bits_per_slice = int(
         np.ceil((self.capacity * abs(np.log(self.error_rate))) /
                 (self.nbr_slices * (np.log(2)**2))))
     self.nbr_bits = self.nbr_slices * self.bits_per_slice
     self.hashes = generate_hashfunctions(self.bits_per_slice,
                                          self.nbr_slices)
Ejemplo n.º 4
0
 def __init__(self, delta, epsilon, k):
     self.nbr_bits = int(np.ceil(np.exp(1) / epsilon))
     self.nbr_slices = int(np.ceil(np.log(1 / delta)))
     self.k = k
     self.count = np.zeros((self.nbr_slices, self.nbr_bits), dtype=np.int32)
     self.heap = []
     self.top_k = {}
     self.make_hashes = generate_hashfunctions(self.nbr_bits,
                                               self.nbr_slices)
Ejemplo n.º 5
0
 def __init__(self, capacity, error_rate):
     self.error_rate = error_rate
     self.capacity = capacity
     self.nbr_slices = int(np.ceil(np.log2(1.0 / error_rate)))
     self.bits_per_slice = int(np.ceil((capacity * abs(np.log(error_rate))) / (self.nbr_slices * (np.log(2) ** 2))))
     self.nbr_bits = self.nbr_slices * self.bits_per_slice
     self.bitarray = np.zeros(self.nbr_bits, dtype=np.bool)
     self.count = 0
     self.hashes = generate_hashfunctions(self.bits_per_slice, self.nbr_slices)
     self.hashed_values = []
Ejemplo n.º 6
0
 def __init__(self, capacity, error_rate):
     self.error_rate = error_rate
     self.capacity = capacity
     self.nbr_slices = int(np.ceil(np.log2(1.0 / error_rate)))
     self.bits_per_slice = int(
         np.ceil((capacity * abs(np.log(error_rate))) / (self.nbr_slices *
                                                         (np.log(2)**2))))
     self.nbr_bits = self.nbr_slices * self.bits_per_slice
     self.initialize_bitarray()
     self.count = 0
     self.hashes = generate_hashfunctions(self.bits_per_slice,
                                          self.nbr_slices)
     self.hashed_values = []
Ejemplo n.º 7
0
 def __init__(self, capacity, error_rate, expiration, name, snapshot_path):
     self.error_rate = error_rate
     self.capacity = capacity
     self.nbr_slices = int(np.ceil(np.log2(1.0 / error_rate)))
     self.bits_per_slice = int(np.ceil((capacity * abs(np.log(error_rate))) / (self.nbr_slices * (np.log(2) ** 2))))
     self.nbr_bits = self.nbr_slices * self.bits_per_slice
     self.initialize_bitarray()
     self.count = 0
     self.hashes = generate_hashfunctions(self.bits_per_slice, self.nbr_slices)
     self.hashed_values = []
     self.name = name
     self.snapshot_path = snapshot_path
     self.expiration = expiration
     self.initialize_period()
     self.snapshot_to_load = None
     self.ready = False
     self.warm_period = None
     self.next_snapshot_load = time.time()
Ejemplo n.º 8
0
 def __init__(self, capacity, error_rate, expiration, name, snapshot_path):
     self.error_rate = error_rate
     self.capacity = capacity
     self.nbr_slices = int(np.ceil(np.log2(1.0 / error_rate)))
     self.bits_per_slice = int(np.ceil((capacity * abs(np.log(error_rate))) / (self.nbr_slices * (np.log(2) ** 2))))
     self.nbr_bits = self.nbr_slices * self.bits_per_slice
     self.initialize_bitarray()
     self.count = 0
     self.hashes = generate_hashfunctions(self.bits_per_slice, self.nbr_slices)
     self.hashed_values = []
     self.name = name
     self.snapshot_path = snapshot_path
     self.expiration = expiration
     self.initialize_period()
     self.snapshot_to_load = None
     self.ready = False
     self.warm_period = None
     self.next_snapshot_load = time.time()
Ejemplo n.º 9
0
 def __init__(self, capacity, error_rate=0.001, expiration=60, disable_hard_capacity=False):
     self.error_rate = error_rate
     self.capacity = capacity
     self.expiration = expiration
     self.nbr_slices = int(np.ceil(np.log2(1.0 / error_rate)))
     self.bits_per_slice = int(np.ceil((capacity * abs(np.log(error_rate))) / (self.nbr_slices * (np.log(2) ** 2))))
     self.nbr_bits = self.nbr_slices * self.bits_per_slice
     self.count = 0
     self.cellarray = np.zeros(self.nbr_bits, dtype=np.uint8)
     self.counter_init = 255
     self.refresh_head = 0
     self.make_hashes = generate_hashfunctions(self.bits_per_slice, self.nbr_slices)
     # This is the unset ratio ... and we keep it constant at 0.5
     # since the BF will operate most of the time at his optimal
     # set ratio (50 %) and the overall effect of this parameter
     # on the refresh rate is very minimal anyway.
     self.z = 0.5
     self.estimate_z = 0
     self.disable_hard_capacity = disable_hard_capacity
Ejemplo n.º 10
0
 def _initialize_parameters(self):
     self.nbr_slices = int(np.ceil(np.log2(1.0 / self.error_rate)))
     self.bits_per_slice = int(np.ceil((self.capacity * abs(np.log(self.error_rate))) / (self.nbr_slices * (np.log(2) ** 2))))
     self.nbr_bits = self.nbr_slices * self.bits_per_slice
     self.hashes = generate_hashfunctions(self.bits_per_slice, self.nbr_slices)