Hello Thomas,
Not to ruin your day or anything, but I think you broke the BitFiueld
code with your change :).
Consider the following data:
long[] data;
...
data[0] = 0x00000000000000FF;
data[1] = 0x0000000000000000;
data[2] = 0xFFFFFFFFFFFFFF;
...
fromIndex = 16;
The function below will not find the correct result. You did not fix
the original problem with the "data[0] == 0" check, but you have added
the limit of the 64 bits in the inner loop and broke the code.
You should probably add a BitField unit test with the data above.
Alex
================================================
public int nextSetBit(int fromIndex) {
int i = fromIndex >> ADDRESS_BITS;
int max = data.length;
int maxAddress = data.length << ADDRESS_BITS;
for (; i < max; i++) {
if (data[i] == 0) {
continue;
}
int j = Math.max(fromIndex, i << ADDRESS_BITS);
for (int end = Math.min(maxAddress, j + 64); j < end; j++)
{
if (get(j)) {
return j;
}
}
}
return -1;
}
On Oct 15, 3:11 pm, "Thomas Mueller" <[EMAIL PROTECTED]>
wrote:
> Hi,
>
> > I've taken another look at your BitField code. I think that your
> > functions nextSetBit and nextClearBit do not work as intended in every
> > case.
>
> You are right... I fixed it. I'm not sure if it will have a big
> effect, because I never saw those methods in any profiling data
> recently, but anyway my implementation was really bad. I didn't use
> the special tricks to find the next set bit in one long, so it could
> still be improved a bit if required.
>
> http://code.google.com/p/h2database/source/browse/trunk/h2/src/main/o...
>
> Thanks for the links!
>
> Regards,
> Thomas
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "H2
Database" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/h2-database?hl=en
-~----------~----~----~----~------~----~------~--~---