[racket-dev] [plt] Push #21533: master branch updated

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Tue Nov 16 16:39:32 EST 2010

I added (but have not pushed, apprently) queue-map. Mind if we keep
that one instead?

Also, I think that a rename like the below is a bad idea if the queues
have been released already.

Robby

On Tue, Nov 16, 2010 at 3:37 PM,  <rafkind at racket-lang.org> wrote:
> rafkind has updated `master' from b8bbed6eb4 to 7b24eaf58e.
>  http://git.racket-lang.org/plt/b8bbed6eb4..7b24eaf58e
>
> =====[ 2 Commits ]======================================================
>
> Directory summary:
>  22.4% collects/data/scribblings/
>  35.6% collects/data/
>  41.8% collects/tests/data/
>
> ~~~~~~~~~~
>
> 73be679 Jon Rafkind <rafkind at racket-lang.org> 2010-11-16 12:02
> :
> | add queue->list
> :
>  M collects/data/queue.rkt               |   20 +++++++++++++++++++-
>  M collects/data/scribblings/queue.scrbl |   12 ++++++++++++
>  M collects/tests/data/queue.rkt         |   12 +++++++++++-
>
> ~~~~~~~~~~
>
> 7b24eaf Jon Rafkind <rafkind at racket-lang.org> 2010-11-16 14:36
> :
> | rename queue-count to queue-length
> :
>  M collects/data/queue.rkt               |    6 +++---
>  M collects/data/scribblings/queue.scrbl |    8 ++++----
>  M collects/tests/data/queue.rkt         |   14 +++++++-------
>
> =====[ Overall Diff ]===================================================
>
> collects/data/queue.rkt
> ~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/data/queue.rkt
> +++ NEW/collects/data/queue.rkt
> @@ -31,7 +31,24 @@
>     (set-queue-head! q (link-tail old))
>     (link-value old)))
>
> -(define (queue-count queue)
> +(define (queue->list queue)
> +  (let loop ([link (queue-head queue)]
> +             [out '()])
> +    (if (not link)
> +      (reverse out)
> +      (loop (link-tail link) (cons (link-value link) out)))))
> +
> +;; queue->vector could be implemented as (list->vector (queue->list q))
> +;; but this is somewhat slow. a direct translation between queue's and
> +;; vector's should be fast so the ideal situation is not to use a list
> +;; as an intermediate data structure.
> +;; maybe add the elements to a gvector and use gvector->vector?
> +
> +;; could use (length (queue->list q)) here but that would double
> +;; the time it takes to get the length
> +;; probably if `queue->vector' gets implemented it would be better to
> +;; do (vector-length (queue->vector q))
> +(define (queue-length queue)
>   (let loop ([link (queue-head queue)]
>              [count 0])
>     (if (not link)
> @@ -56,6 +73,7 @@
>  [queue? (-> any/c boolean?)]
>  [make-queue (-> queue/c)]
>  [queue-empty? (-> queue/c boolean?)]
> - [queue-count (-> queue/c integer?)])
> + [queue-length (-> queue/c integer?)]
> + [queue->list (-> queue/c (listof any/c))])
>
>  (provide enqueue! dequeue!)
>
> collects/data/scribblings/queue.scrbl
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/data/scribblings/queue.scrbl
> +++ NEW/collects/data/scribblings/queue.scrbl
> @@ -34,17 +34,29 @@ thread-unsafe way.
>     (dequeue! q)]
>  }
>
> - at defproc[(queue-count [queue queue/c]) integer?]{
> + at defproc[(queue->list [queue queue/c]) (listof any/c)]{
> +  Returns an immutable list containing the elements of the queue
> +  in the order the elements were added.
> +
> +  @defexamples[#:eval qeval
> +    (define queue (make-queue))
> +    (enqueue! queue 8)
> +    (enqueue! queue 9)
> +    (enqueue! queue 0)
> +    (queue->list queue)]
> +}
> +
> + at defproc[(queue-length [queue queue/c]) integer?]{
>   Returns the number of elements in the queue.
>
>   @defexamples[#:eval qeval
>     (define queue (make-queue))
> -    (queue-count queue)
> +    (queue-length queue)
>     (enqueue! queue 5)
>     (enqueue! queue 12)
> -    (queue-count queue)
> +    (queue-length queue)
>     (dequeue! queue)
> -    (queue-count queue)]
> +    (queue-length queue)]
>  }
>
>  @defproc[(queue-empty? [q queue/c]) boolean?]{
>
> collects/tests/data/queue.rkt
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --- OLD/collects/tests/data/queue.rkt
> +++ NEW/collects/tests/data/queue.rkt
> @@ -34,21 +34,21 @@
>          (dequeue! q)
>          (dequeue! q)
>          (check-true (queue-empty? q)))))
> -   (test-suite "count"
> -     (test-case "count empty"
> +   (test-suite "length"
> +     (test-case "length empty"
>        (let* ([queue (make-queue)])
> -         (check-equal? (queue-count queue) 0)))
> -     (test-case "count enqueue once"
> +         (check-equal? (queue-length queue) 0)))
> +     (test-case "length enqueue once"
>        (let* ([queue (make-queue)])
>          (enqueue! queue 5)
> -         (check-equal? (queue-count queue) 1)))
> -     (test-case "count enqueue thrice dequeue once"
> +         (check-equal? (queue-length queue) 1)))
> +     (test-case "length enqueue thrice dequeue once"
>        (let* ([queue (make-queue)])
>          (enqueue! queue 5)
>          (enqueue! queue 9)
>          (enqueue! queue 12)
>          (dequeue! queue)
> -         (check-equal? (queue-count queue) 2))))
> +         (check-equal? (queue-length queue) 2))))
>    (test-suite "dequeue!"
>      (test-case "make-queue"
>        (check-exn exn:fail? (lambda () (dequeue! (make-queue)))))
> @@ -63,4 +63,14 @@
>          (enqueue! q 2)
>          (check-equal? (dequeue! q) 1)
>          (check-equal? (dequeue! q) 2)
> -         (check-exn exn:fail? (lambda () (dequeue! q))))))))
> +         (check-exn exn:fail? (lambda () (dequeue! q))))))
> +   (test-suite "queue misc"
> +     (test-case "queue to empty list"
> +       (let ([queue (make-queue)])
> +         (check-equal? (queue->list queue) '())))
> +     (test-case "queue length"
> +       (let ([queue (make-queue)])
> +         (enqueue! queue 1)
> +         (enqueue! queue 2)
> +         (enqueue! queue 3)
> +         (check-equal? (queue->list queue) '(1 2 3)))))))
>


Posted on the dev mailing list.