Skip to content

Commit

Permalink
feat: #369: bloomUtil exposes addressOf and filterOf methods to build…
Browse files Browse the repository at this point in the history
… from ExpandedBlockDetail
  • Loading branch information
lucanicoladebiasi committed Apr 15, 2024
1 parent 942f647 commit 4f235e5
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
4 changes: 2 additions & 2 deletions packages/core/src/bloom/bloom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@ function addWithUInt32Wrap(a: number, b: number): number {
* @return {number} - The number of bits per key.
*/
function calculateBitsPerKey(k: number): number {
if (k < 1) return 2;
return k > 30 ? 44 : Math.ceil(k / 0.69);
if (k <= 1) return 2;
return k >= 30 ? 44 : Math.ceil(k / 0.69);
}

/**
Expand Down
5 changes: 4 additions & 1 deletion packages/core/src/utils/bloom/bloom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,10 @@ const BLOOM_REGEX = /^(0x)?[0-9a-f]{16,}$/i;
/**
* Bloom Filter *k* parameter set to 5 (hence 5 hashes functions are
* used in filter generation) is computed supposing to express the
* 20 bytes long address in 1 byte, hence k =
* 20 bytes long address in 1 byte, hence k = 8 * ln(2) approximated to 5,
* leading to a Bloom Filter size of between 8 and 16 bytes to encode
* the addresses of a Thor block with a probability of false positives much
* smaller than 1%.
*/
const BLOOM_DEFAULT_K = 5;

Expand Down

0 comments on commit 4f235e5

Please sign in to comment.