Oh -- forgot to mention: if you're using an immutable hash, then
`in-immutable-hash-keys` is significantly faster than `in-hash-keys`.
I mean:

(for/set ([k (in-immutable-hash-keys h)]) k)


On Fri, Oct 25, 2019 at 4:37 PM Jon Zeppieri <zeppi...@gmail.com> wrote:
>
> From a little test I just ran, building a set of hash keys, using a
> hash with 100,000 k/v pairs and generating the key set 100 times each:
>
> "list->set"
> cpu time: 3147 real time: 3148 gc time: 1137
>
> "apply"
> cpu time: 3205 real time: 3206 gc time: 1146
>
> "in-hash"
> cpu time: 2791 real time: 2791 gc time: 974
>
> "in-hash-keys"
> cpu time: 2748 real time: 2749 gc time: 981
>
> On Fri, Oct 25, 2019 at 4:27 PM Stephen Chang <stch...@ccs.neu.edu> wrote:
> >
> > I don't know of a more efficient way to convert, but depending on what
> > operations you want, you might be able to compute it directly on the
> > hash, e.g., see hash-has-key?, hash-keys-subset?, hash-union, etc. (I
> > didnt know about some of the functions until recently.)
> >
> > On Fri, Oct 25, 2019 at 4:21 PM Sorawee Porncharoenwase
> > <sorawee.pw...@gmail.com> wrote:
> > >
> > > It also might be worth trying `(for/set ([(k v) (in-hash h)]) k)`.
> > >
> > > On Fri, Oct 25, 2019 at 1:19 PM David Storrs <david.sto...@gmail.com> 
> > > wrote:
> > >>
> > >> On Fri, Oct 25, 2019 at 10:28 AM Thomas Dickerson
> > >> <thomas_dicker...@alumni.brown.edu> wrote:
> > >> >
> > >> > For reasons that are unclear to me, hash-keys and dict-keys both 
> > >> > return a list? instead of a set? (frankly, this seems like a bug in 
> > >> > the API...).
> > >> >
> > >> > Is there a something I can do that's more efficient than just calling 
> > >> > list->set?
> > >>
> > >> You could do   '(apply set list-of-keys)', although I'm not sure if
> > >> that's more efficient or not.  You'd need to benchmark it.
> > >>
> > >>
> > >> >
> > >> > --
> > >> > You received this message because you are subscribed to the Google 
> > >> > Groups "Racket Users" group.
> > >> > To unsubscribe from this group and stop receiving emails from it, send 
> > >> > an email to racket-users+unsubscr...@googlegroups.com.
> > >> > To view this discussion on the web visit 
> > >> > https://groups.google.com/d/msgid/racket-users/36eb8bd7-45eb-4ebb-be30-ebdfd89023fe%40googlegroups.com.
> > >>
> > >> --
> > >> You received this message because you are subscribed to the Google 
> > >> Groups "Racket Users" group.
> > >> To unsubscribe from this group and stop receiving emails from it, send 
> > >> an email to racket-users+unsubscr...@googlegroups.com.
> > >> To view this discussion on the web visit 
> > >> https://groups.google.com/d/msgid/racket-users/CAE8gKodHgEeqffTCCSKDGP26jRt9oYmi42U0Vu%2BMyH6c2TQ5yw%40mail.gmail.com.
> > >
> > > --
> > > You received this message because you are subscribed to the Google Groups 
> > > "Racket Users" group.
> > > To unsubscribe from this group and stop receiving emails from it, send an 
> > > email to racket-users+unsubscr...@googlegroups.com.
> > > To view this discussion on the web visit 
> > > https://groups.google.com/d/msgid/racket-users/CADcuegvk8wqkJsdJNqkQXSHi5FgYGZ4afRODYoZD8FnYmOcxVg%40mail.gmail.com.
> >
> > --
> > You received this message because you are subscribed to the Google Groups 
> > "Racket Users" group.
> > To unsubscribe from this group and stop receiving emails from it, send an 
> > email to racket-users+unsubscr...@googlegroups.com.
> > To view this discussion on the web visit 
> > https://groups.google.com/d/msgid/racket-users/CAFfiA1JXu_rEOP3V7vYO8oLW%2BfgOJrjK9%3DxXhr-WRYNvmVr6fQ%40mail.gmail.com.

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/racket-users/CAKfDxxx%3DgqvtfZiPPiPmZFxA93brAomWukssCg%2BhfKQHsh%2Bcmg%40mail.gmail.com.

Reply via email to