Changeset 36631 in project


Ignore:
Timestamp:
09/16/18 22:43:45 (3 months ago)
Author:
kon
Message:

add bool set type, simplify existence test

File:
1 edited

Legend:

Unmodified
Added
Removed
  • release/5/bloom-filter/trunk/bloom-filter.scm

    r36576 r36631  
    5555  (only type-errors-basic signal-bounds-error))
    5656
     57;;;(should be able to get from module)
     58
     59(define-type iset:integer-set *)
     60
    5761;;;
    5862
    59 (define-type iset:integer-set *)
     63(define-type boolean-set iset:integer-set)
    6064
    6165(define-type message-digest-primitive (struct message-digest-primitive))
     
    116120(define-type bloom-filter (struct bloom-filter))
    117121
    118 (: *make-bloom-filter (fixnum fixnum fixnum iset:integer-set bloom-filter-hashers message-digest-primitives -> bloom-filter))
     122(: *make-bloom-filter (fixnum fixnum fixnum boolean-set bloom-filter-hashers message-digest-primitives -> bloom-filter))
    119123(: bloom-filter? (* -> boolean : bloom-filter))
    120124(: *bloom-filter-n (bloom-filter --> fixnum))
     
    122126(: *bloom-filter-m (bloom-filter --> fixnum))
    123127(: *bloom-filter-k (bloom-filter --> fixnum))
    124 (: *bloom-filter-bits (bloom-filter --> iset:integer-set))
    125 (: *bloom-filter-bits-set! (bloom-filter iset:integer-set -> void))
     128(: *bloom-filter-bits (bloom-filter --> boolean-set))
     129(: *bloom-filter-bits-set! (bloom-filter boolean-set -> void))
    126130(: *bloom-filter-hashers (bloom-filter --> bloom-filter-hashers))
    127131(: *bloom-filter-algorithms (bloom-filter --> message-digest-primitives))
     
    345349    (*bloom-filter-m bf)) )
    346350
    347 (: *bit-on! (iset:integer-set fixnum -> iset:integer-set))
     351(: *bit-on! (boolean-set fixnum -> boolean-set))
    348352;
    349353(define (*bit-on! bits idx)
     
    362366    (*bloom-filter-n-set! bf (fx+ (*bloom-filter-n bf) 1)) ) )
    363367
     368(: make-bit-counter (boolean-set -> (fixnum fixnum -> fixnum)))
     369;
     370(define ((make-bit-counter bits) cnt idx)
     371  (if (bit-vector-ref bits idx) (fx+ cnt 1) cnt) )
     372
    364373(: bloom-filter-exists? (bloom-filter * --> boolean))
    365374;
    366375(define (bloom-filter-exists? bf obj)
    367376  (let* (
    368     (bits
    369       (*bloom-filter-bits (check-bloom-filter 'bloom-filter-exists? bf)) )
    370     (bitcnt
    371       (lambda (cnt idx) (if (bit-vector-ref bits idx) (fx+ cnt 1) cnt)) )
    372     (refs
    373       (bloom-filter-foldl bf bitcnt 0 obj)) )
    374     (fx<= (*bloom-filter-k bf) refs) ) )
     377    (bits (*bloom-filter-bits (check-bloom-filter 'bloom-filter-exists? bf)))
     378    (bitcnt (bloom-filter-foldl bf (make-bit-counter bits) 0 obj)) )
     379    (fx<= (*bloom-filter-k bf) bitcnt) ) )
    375380
    376381) ;module bloom-filter
Note: See TracChangeset for help on using the changeset viewer.