1 ! Copyright (C) 2012 John Benediktsson
2 ! See http://factorcode.org/license.txt for BSD license
3 USING: arrays kernel layouts locals math math.functions
4 math.order math.statistics sequences ;
7 GENERIC: trailing-zeros ( m -- n )
9 M: fixnum trailing-zeros
11 0 [ over even? ] [ [ 2/ ] [ 1 + ] bi* ] while nip
14 :: estimate-cardinality ( seq k -- n )
16 num_buckets 0 <array> :> max_zeros
19 h num_buckets 1 - bitand :> bucket
20 h k neg shift :> bucket_hash
22 bucket_hash trailing-zeros max
25 max_zeros [ mean 2 swap ^ ] [ length * ] bi 0.79402 * ;