[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: a vector of colors

From: zimoun
Subject: Re: a vector of colors
Date: Mon, 05 Sep 2022 18:37:01 +0200


A bit late. :-)

On mar., 09 août 2022 at 20:58, jgart <> wrote:

> Why was this defined as a vector instead of a list?
> (define %colors
>   ;; See colortbl.h in Graphviz.
>   #("red" "magenta" "blue" "cyan3" "darkseagreen"
>     "peachpuff4" "darkviolet" "dimgrey" "darkgoldenrod"))

and you mean replace ’pop-color’ by,

--8<---------------cut here---------------start------------->8---
(define (pop-color hint)
  "Return a Graphviz color based on HINT, an arbitrary object."
  (let ((index (hash hint (length %colors))))
    (list-ref %colors index)))
--8<---------------cut here---------------end--------------->8---

but I guess ’list-ref’ is slower than ’vector-ref’; as specified by the

        Vectors are sequences of Scheme objects. Unlike lists, the
        length of a vector, once the vector is created, cannot be
        changed. The advantage of vectors over lists is that the time
        required to access one element of a vector given its position
        (synonymous with index), a zero-origin number, is constant,
        whereas lists have an access time linear to the position of the
        accessed element in the list.

However, the difference is probably not visible here.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]