bloom-filters: more speeeeeed.

db4
John Benediktsson 2013-04-03 20:27:23 -07:00
parent c2ab21a14d
commit 1f45b8a4e3
1 changed files with 5 additions and 7 deletions

View File

@ -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 USING: accessors arrays bit-arrays fry kernel layouts locals
math math.functions math.order multiline sequences math math.functions math.order math.private multiline sequences
sequences.private typed ; sequences.private typed ;
FROM: math.ranges => [1,b] ; FROM: math.ranges => [1,b] ;
@ -110,18 +110,16 @@ PRIVATE>
! Dillinger and Panagiotis Manolios, section 5.2, "Enhanced ! Dillinger and Panagiotis Manolios, section 5.2, "Enhanced
! Double Hashing": ! Double Hashing":
! http://www.cc.gatech.edu/~manolios/research/bloom-filters-verification.html ! http://www.cc.gatech.edu/~manolios/research/bloom-filters-verification.html
:: enhanced-double-hash ( index hash0 hash1 -- hash ) TYPED:: enhanced-double-hash ( index: fixnum hash0: fixnum hash1: fixnum -- hash )
hash0 index * hash1 + index 3 ^ index - 6 /i + ; hash0 index fixnum*fast hash1 fixnum+fast
index 3 ^ index - 6 /i + abs ;
: enhanced-double-hashes ( hash0 hash1 n -- seq ) : enhanced-double-hashes ( hash0 hash1 n -- seq )
-rot '[ _ _ enhanced-double-hash ] { } map-integers ; -rot '[ _ _ enhanced-double-hash ] { } map-integers ;
! Make sure it's a fixnum here to speed up double-hashing. ! Make sure it's a fixnum here to speed up double-hashing.
: hashcodes-from-hashcode ( hash0 -- hash0 hash1 )
dup most-positive-fixnum bitxor ;
: hashcodes-from-object ( obj -- n n ) : hashcodes-from-object ( obj -- n n )
hashcode abs hashcodes-from-hashcode ; hashcode >fixnum dup most-positive-fixnum bitxor >fixnum ;
TYPED: set-indices ( indices: array bit-array: bit-array -- ) TYPED: set-indices ( indices: array bit-array: bit-array -- )
[ t ] 2dip [ set-nth-unsafe ] curry with each ; inline [ t ] 2dip [ set-nth-unsafe ] curry with each ; inline