bloom-filters: use infix syntax
parent
3e3f08c6e5
commit
e6f8aafe5f
|
@ -1,7 +1,7 @@
|
||||||
! Copyright (C) 2009 Alec Berryman.
|
! Copyright (C) 2009 Alec Berryman.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: accessors arrays bit-arrays fry kernel layouts locals math math.functions
|
USING: accessors arrays bit-arrays fry infix kernel layouts locals math
|
||||||
multiline sequences ;
|
math.functions multiline sequences ;
|
||||||
IN: bloom-filters
|
IN: bloom-filters
|
||||||
|
|
||||||
FROM: math.ranges => [1,b] [0,b) ;
|
FROM: math.ranges => [1,b] [0,b) ;
|
||||||
|
@ -54,12 +54,13 @@ ERROR: invalid-n-objects ;
|
||||||
|
|
||||||
<PRIVATE
|
<PRIVATE
|
||||||
|
|
||||||
! number-bits = -(n-objects * n-hashes) / ln(1 - error-rate ^ 1/n-hashes)
|
! infix doesn't like ^
|
||||||
:: bits-to-satisfy-error-rate ( n-hashes error-rate n-objects -- size )
|
: pow ( x y -- z )
|
||||||
n-objects n-hashes * -1 *
|
^ ; inline
|
||||||
1 error-rate 1 n-hashes / ^ - log
|
|
||||||
/
|
:: bits-to-satisfy-error-rate ( hashes error objects -- size )
|
||||||
ceiling >integer ; ! should check that it's below max-array-capacity
|
[infix -(objects * hashes) / log(1 - pow(error, (1/hashes))) infix]
|
||||||
|
ceiling >integer ;
|
||||||
|
|
||||||
! 100 hashes ought to be enough for anybody.
|
! 100 hashes ought to be enough for anybody.
|
||||||
: n-hashes-range ( -- range )
|
: n-hashes-range ( -- range )
|
||||||
|
@ -118,21 +119,8 @@ PRIVATE>
|
||||||
! See "Bloom Filters in Probabilistic Verification" by Peter C. Dillinger and
|
! See "Bloom Filters in Probabilistic Verification" by Peter C. Dillinger and
|
||||||
! Panagiotis Manolios, section 5.2, "Enhanced Double Hashing":
|
! Panagiotis Manolios, section 5.2, "Enhanced Double Hashing":
|
||||||
! http://www.cc.gatech.edu/~manolios/research/bloom-filters-verification.html
|
! http://www.cc.gatech.edu/~manolios/research/bloom-filters-verification.html
|
||||||
!
|
|
||||||
! This is taken from the definition at the top of page 12:
|
|
||||||
!
|
|
||||||
! F(i) = (A(s) + (i * B(s)) + ((i^3 - i) / 6)) mod m
|
|
||||||
!
|
|
||||||
! Where i is the hash number, A and B are hash functions for object s, and m is
|
|
||||||
! the length of the array.
|
|
||||||
|
|
||||||
:: enhanced-double-hash ( index hash0 hash1 array-size -- hash )
|
:: enhanced-double-hash ( index hash0 hash1 array-size -- hash )
|
||||||
hash0
|
[infix hash0 + (index * hash1) + ((pow(index, 3) - index) / 6) infix]
|
||||||
index hash1 *
|
|
||||||
+
|
|
||||||
index 3 ^ index -
|
|
||||||
6 /
|
|
||||||
+
|
|
||||||
array-size mod ;
|
array-size mod ;
|
||||||
|
|
||||||
: enhanced-double-hashes ( n hash0 hash1 array-size -- seq )
|
: enhanced-double-hashes ( n hash0 hash1 array-size -- seq )
|
||||||
|
|
Loading…
Reference in New Issue