> Miguel,
>
> Serialization is such a wonderful exercise. It's like teaching: you
> don't really understand it until you have to explain it.
>
> Bitmaps:
>
> final static int[] allocateBitmap(int count) {
> return new int[(count + 31) >> 5];
> }
>
> final static void setBit(int[] bitmap, int i) {
> bitmap[(i >> 5)] |= 1 << (~i & 31);
> }
>
> final static void clearBit(int[] bitmap, int i) {
> bitmap[(i >> 5)] &= ~(1 << (~i & 31));
> }
>
> final static boolean getBit(int[] bitmap, int i) {
> return (bitmap[(i >> 5)] << (i & 31)) < 0;
> }
>
> final static void setAllBits(int[] bitmap, int count) {
> int i = count >> 5;
> if ((count & 31) != 0)
> bitmap[i] = 0x80000000 >> (count - 1);
> while (--i >= 0)
> bitmap[i] = -1;
> }
>
> final static void clearBitmap(int[] bitmap) {
> for (int i = bitmap.length; --i >= 0; )
> bitmap[i] = 0;
> }
>
>
>
> Is there some good reason we are hand-coding bitmaps here instead of
> just using bitsets?
Performance on these hand-coded bitmaps is significantly higher than for
BitSet instances.
These are simple routines are final static. The JIT (Just In Time)
compiler will 'open code' these routines and put the instructions in-line.
getBit(), setBit() and clearBit() will turn into 2 or 3 in-line machine
instructions.
Contrast this with calls to methods in the BitSet class, where several
levels of function call are made. Function calls are very expensive
relative to in-line instructions. In addition, the BitSet performs tests
on the underlying vector length to determine whether or not the underlying
vector should be grown (in the case of setBit()).
(There was also another minor issue in that the Java 1.1 BitSets are not
as good as the Java 1.3+ BitSets ... not as good in that they did not have
as much functionality.)
I don't recall everyplace where bitmaps are used. In the case of the Eval
engine, you could switch to BitSets without any performance impact.
Actually, I think those are already BitSets :-)
The place where I would leave the hand-coded bitmaps in place is in the
graphics engine, where perforamnce is important.
I recommend using the hand-coded bitmaps in the graphics engine and using
BitSets for everything else.
Miguel
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Jmol-developers mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jmol-developers