Why no collections for booleans?

36 views
Skip to first unread message

shaun....@gmail.com

unread,
May 8, 2014, 4:24:18 PM5/8/14
to java-high-performance...@googlegroups.com
Looking at com.carrotsearch.hppc.generator.Type, booleans seem to have been explicitly left out and I'm curious as to the reasoning.

Dawid Weiss

unread,
May 8, 2014, 5:22:44 PM5/8/14
to java-high-performance-primitive-collections
At the JVM level an array of booleans is an array of bytes anyway, so:

- for a list, there's really no space (or performance) gain,
- for a Map<x, boolean> it's essentially the same as a set (unless you
mean to use it as a tri-state set, in which case map<x,byte> is
equivalent),
- for a Set<boolean> it's typically better to use a bitset.
- Map<boolean,x> is not really interesting :)

One could argue that a bitset could be used for maps or arrays, but
then it's really duplicating code and hiding the obvious (it's a
bitset!) behind some decoration layer, which was not what HPPC was
intended for.

Dawid


On Thu, May 8, 2014 at 10:24 PM, <shaun....@gmail.com> wrote:
> Looking at com.carrotsearch.hppc.generator.Type, booleans seem to have been
> explicitly left out and I'm curious as to the reasoning.
>
> --
> You received this message because you are subscribed to the Google Groups
> "High Performance Primitive Collections for Java" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to
> java-high-performance-primi...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

Dawid Weiss

unread,
May 8, 2014, 5:24:40 PM5/8/14
to java-high-performance-primitive-collections
> - for a Set<boolean> it's typically better to use a bitset.

I wasn't clear here -- a set of booleans meaning int-indexed map or
simply an array. A Set<boolean> doesn't make much sense, obviously.

D.
Reply all
Reply to author
Forward
0 new messages