Changeset 36748 in project


Ignore:
Timestamp:
11/01/18 15:16:47 (2 weeks ago)
Author:
kon
Message:

share code as inline

Location:
release/5/bloom-filter/trunk
Files:
2 edited

Legend:

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

    r36576 r36748  
    44((synopsis "Bloom Filter")
    55 (category data)
    6  (version "2.2.0")
     6 (version "2.2.1")
    77 (author "[[kon lovett]]")
    88 (license "BSD")
  • release/5/bloom-filter/trunk/bloom-filter.scm

    r36631 r36748  
    349349    (*bloom-filter-m bf)) )
    350350
    351 (: *bit-on! (boolean-set fixnum -> boolean-set))
    352 ;
    353 (define (*bit-on! bits idx)
     351(: bit-on! (boolean-set fixnum -> boolean-set))
     352;
     353(define (bit-on! bits idx)
    354354  (bit-vector-set! bits idx #t)
    355355  bits )
    356356
     357(: *make-bit-counter (boolean-set -> (fixnum fixnum -> fixnum)))
     358;
     359(define-inline (*make-bit-counter bits)
     360  (lambda (cnt idx) (if (bit-vector-ref bits idx) (fx+ cnt 1) cnt)) )
     361
     362(: *bloom-filter-exists? (bloom-filter * --> boolean))
     363;
     364(define-inline (*bloom-filter-exists? bf obj)
     365  (let* (
     366    (bits (*bloom-filter-bits bf))
     367    (bitcnt (bloom-filter-foldl bf (*make-bit-counter bits) 0 obj)) )
     368    (fx<= (*bloom-filter-k bf) bitcnt) ) )
     369
     370(: bloom-filter-exists? (bloom-filter * --> boolean))
     371;
     372(define (bloom-filter-exists? bf obj)
     373  (*bloom-filter-exists? (check-bloom-filter 'bloom-filter-exists? bf) obj) )
     374
    357375(: bloom-filter-set! (bloom-filter * -> void))
    358376;
    359377(define (bloom-filter-set! bf obj)
    360378  ;tracks actual pop (n) so cannot "reset"
    361   (unless (bloom-filter-exists? (check-bloom-filter 'bloom-filter-set! bf) obj)
     379  (unless (*bloom-filter-exists? (check-bloom-filter 'bloom-filter-set! bf) obj)
    362380    ;spray rep bits
    363     (let ((bits (bloom-filter-foldl bf *bit-on! (*bloom-filter-bits bf) obj)))
     381    (let ((bits (bloom-filter-foldl bf bit-on! (*bloom-filter-bits bf) obj)))
    364382      (*bloom-filter-bits-set! bf bits) )
    365383    ;bump actual pop
    366384    (*bloom-filter-n-set! bf (fx+ (*bloom-filter-n bf) 1)) ) )
    367385
    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 
    373 (: bloom-filter-exists? (bloom-filter * --> boolean))
    374 ;
    375 (define (bloom-filter-exists? bf obj)
    376   (let* (
    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) ) )
    380 
    381386) ;module bloom-filter
Note: See TracChangeset for help on using the changeset viewer.