Rename to bit-vector-popcount

This commit is contained in:
Jens Axel Søgaard 2012-11-28 21:38:02 +01:00
parent fc4010d327
commit 07b8507ce9
3 changed files with 8 additions and 8 deletions

View File

@ -93,9 +93,9 @@
(bit-vector-copy bv start end)])])
bit-vector-copy))
(define (bit-vector-count bv)
(define (bit-vector-popcount bv)
(for/sum ([fx (in-fxvector (bit-vector-words bv))])
(fxcount fx)))
(fxpopcount fx)))
(define-vector-wraps "bit-vector"
bit-vector? bit-vector-length bit-vector-ref bit-vector-set! make-bit-vector
@ -167,7 +167,7 @@
(-> bit-vector? exact-nonnegative-integer? boolean? any)]
[bit-vector-length
(-> bit-vector? any)]
[bit-vector-count
[bit-vector-popcount
(-> bit-vector? any)]
(rename bit-vector-copy*
bit-vector-copy

View File

@ -1,7 +1,7 @@
#lang racket
(require racket/unsafe/ops
(for-syntax racket/fixnum racket/vector))
(provide fxcount)
(provide fxpopcount)
;; Count set bits for 30 bit number in 5 steps.
;; for 62 bit number in 6.
@ -20,7 +20,7 @@
#x3FFF0000FFFF0000
#x3FFFFFFF00000000))
(define-syntax (mk-fxcount stx)
(define-syntax (mk-fxpopcount stx)
(syntax-case stx ()
[(_ name)
;; Choose at compile time what word length is
@ -37,5 +37,5 @@
(unsafe-fxand n #,f))])
n)))]))
(mk-fxcount fxcount)
(mk-fxpopcount fxpopcount)

View File

@ -98,7 +98,7 @@
(bit-vector-set! bv 400 #t)
(check-equal? bv (for/bit-vector ([i 1000]) (= i 400)))))
(test-case "bit-vector-count"
(test-case "bit-vector-popcount"
(let ()
(define (test)
(define fill (odd? (random 2)))
@ -107,6 +107,6 @@
(for ([n (in-set ns)]) (bit-vector-set! bv n (not fill)))
(define count
(if fill (- 1000 (set-count ns)) (set-count ns)))
(check-equal? (bit-vector-count bv) count))
(check-equal? (bit-vector-popcount bv) count))
(for ([i (in-range 100)])
(test))))