>> I'd like to do something like this:
>>
[quoted text clipped - 13 lines]
>
> Have you considered using a BitSet instead?
Internally, a BitSet is just an array of ints or longs, and faces the
same problem.
Ehsan Khoddam mohammadi - 05 Jan 2007 02:52 GMT
I think all bitwise operators in java cast vars to integrals like int
and long, so it's prefered to use int and long only
> >> I'd like to do something like this:
> >>
[quoted text clipped - 16 lines]
> Internally, a BitSet is just an array of ints or longs, and faces the
> same problem.
Patricia Shanahan - 05 Jan 2007 05:30 GMT
>>> I'd like to do something like this:
>>>
[quoted text clipped - 16 lines]
> Internally, a BitSet is just an array of ints or longs, and faces the
> same problem.
I'm not sure what you mean by "the same problem". The byte-based method
may be unnecessarily slow, because of the numeric promotions. That does
not apply to BitSet.
The logic for doing a bitwise or in the processor has a finite width,
probably 64 bits. Something, somewhere, must chop the data into 64 bit
chunks and issue a series of commands, one for each chunk. What's so bad
about BitSet doing it?
Patricia
Daniel Pitts - 05 Jan 2007 17:51 GMT
> >> I'd like to do something like this:
> >>
[quoted text clipped - 16 lines]
> Internally, a BitSet is just an array of ints or longs, and faces the
> same problem.
Not exactly the same problem...
BitSet's have the operations defined already, so you don't have a "too
ugly" implementation.
Also, they use integers, for a speed increase of a factor around 4
(could be more).
On most modern processors (as someone else pointed out), you would have
to implement it as a loop through every element anyway. There is no
instruction that I know of that says "For every bit in the range a
through b, or it with the corrisponding bit in the range c through
(c+b-a)"
BitSet is definitly the way to go if you find yourself doing those
operations often.