lib/bitcoin/bloom_filter.rb
#
# calculate filter size and number of funcs.
# See: https://github.com/bitcoin/bips/blob/master/bip-0037.mediawiki
#
calculate filter size and number of funcs.
calculate filter size and number of funcs .
def init_filter(elements, fp_rate)
      ln2 = Math.log(2)
      calc_m = (-Math.log(fp_rate) * elements / ln2 / ln2 / 8).floor
      @filter_size = [1, [calc_m, MAX_FILTER_SIZE].min].max
      @filter = "\x00" * @filter_size
      calc_k = (@filter_size * 8 * ln2 / elements).floor
      @nfunc = [1, [calc_k, MAX_HASH_FUNCS].min].max
    end
def init_filter ( elements , fp_rate ) ln2 = Math . log ( 2 ) calc_m = ( - Math . log ( fp_rate ) * elements / ln2 / ln2 / 8 ) . floor @filter_size = [ 1 , [ calc_m , MAX_FILTER_SIZE ] . min ] . max @filter = "\x00" * @filter_size calc_k = ( @filter_size * 8 * ln2 / elements ) . floor @nfunc = [ 1 , [ calc_k , MAX_HASH_FUNCS ] . min ] . max end
calculate filter size and number of funcs.
calculate filter size and number of funcs .
# using #ceil instead of #floor may be better, but it's bitcoinj's way
elements
<not_specific>
fp_rate
<not_specific>