Re: BitSet vs BigInteger (false Android doc)
Patricia Shanahan schrieb:
On 9/2/2011 1:51 PM, Jan Burse wrote:
Patricia Shanahan schrieb:
Also, they have more freedom of action in implementing BitSet
True, actually I was expecting to see a more clever BitSet,
but in JDK 1.6.0_26 its just this long array.
Are you looking at the actual Android implementations for the classes?
Patricia
I don't think that Android uses some special BitSet resp. BigInteger,
since then classes are java.*.
But it looks that nevertheless the implementation in JDK and Android are
not verbatim the same:
Here is the Android BitSet XOR:
public void xor(BitSet bs) {
int bsActualLen = bs.getActualArrayLength();
if (bsActualLen > bits.length) {
long[] tempBits = new long[bsActualLen];
System.arraycopy(bs.bits, 0, tempBits, 0,
bs.actualArrayLength);
for (int i = 0; i < actualArrayLength; i++) {
tempBits[i] ^= bits[i];
}
bits = tempBits;
actualArrayLength = bsActualLen;
isLengthActual = !((actualArrayLength > 0) &&
(bits[actualArrayLength - 1] == 0));
} else {
long[] bsBits = bs.bits;
for (int i = 0; i < bsActualLen; i++) {
bits[i] ^= bsBits[i];
}
if (bsActualLen > actualArrayLength) {
actualArrayLength = bsActualLen;
isLengthActual = true;
}
}
needClear();
}
http://www.java2s.com/Open-Source/Android/android-core/platform-libcore/java/util/BitSet.java.htm
And here is the Oracle JDK BitSet XOR:
public void xor(BitSet set) {
int wordsInCommon = Math.min(wordsInUse, set.wordsInUse);
if (wordsInUse < set.wordsInUse) {
ensureCapacity(set.wordsInUse);
wordsInUse = set.wordsInUse;
}
// Perform logical XOR on words in common
for (int i = 0; i < wordsInCommon; i++)
words[i] ^= set.words[i];
// Copy any remaining words
if (wordsInCommon < set.wordsInUse)
System.arraycopy(set.words, wordsInCommon,
words, wordsInCommon,
set.wordsInUse - wordsInCommon);
recalculateWordsInUse();
checkInvariants();
}
So basically the same representation and algorithm.
The Android seems to stem from Apache Harmony.
http://en.wikipedia.org/wiki/Apache_Harmony#Use_in_Android_SDK
Bye