Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
rambaut committed Jan 28, 2025
1 parent d694fac commit 204e952
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 28 deletions.
10 changes: 5 additions & 5 deletions src/dr/app/tools/treeannotator/BiClade.java
Original file line number Diff line number Diff line change
Expand Up @@ -165,18 +165,18 @@ public Object getKey() {
}

public static Object makeKey(Object key1, Object key2) {
FastBitSet bits = new FastBitSet();
BitSet bits = new BitSet();
if (key1 instanceof Integer) {
bits.set((Integer) key1);
} else {
assert key1 instanceof FastBitSet;
bits.or((FastBitSet) key1);
assert key1 instanceof BitSet;
bits.or((BitSet) key1);
}
if (key2 instanceof Integer) {
bits.set((Integer) key2);
} else {
assert key2 instanceof FastBitSet;
bits.or((FastBitSet) key2);
assert key2 instanceof BitSet;
bits.or((BitSet) key2);
}
return bits;
}
Expand Down
11 changes: 5 additions & 6 deletions src/dr/app/tools/treeannotator/Embiggulator.java
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ public void embiggenBiClades(final int minCladeSize, final int minCladeCount) {
long embiggulationCount = 0;

// create and reuse a bitset to avoid reallocating it
final FastBitSet bits = new FastBitSet();
final BitSet bits = new BitSet();

int rejectCount = 0;

Expand All @@ -157,7 +157,7 @@ public void embiggenBiClades(final int minCladeSize, final int minCladeCount) {
// if (superClades1 == null) {
// continue;
// }
FastBitSet bits1 = ((FastBitSet) clade1.getKey());
BitSet bits1 = ((BitSet) clade1.getKey());

for (int j = Math.max(i + 1, sizeIndices[maxSize - clade1.getSize()]); j < n; j++) {
BiClade clade2 = clades[j];
Expand All @@ -173,14 +173,13 @@ public void embiggenBiClades(final int minCladeSize, final int minCladeCount) {
// }
// }

// bits.clear();
// bits.or(bits1);
bits.set(bits1);
bits.clear();
bits.or(bits1);

if (clade2.key instanceof Integer) {
bits.set((Integer) clade2.key);
} else {
bits.or((FastBitSet) clade2.key);
bits.or((BitSet) clade2.key);
}

int size = clade1.size + clade2.size;
Expand Down
23 changes: 6 additions & 17 deletions src/dr/app/tools/treeannotator/FastBitSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -370,28 +370,17 @@ public void and(FastBitSet set) {
* @param set a bit set
*/
public void or(FastBitSet set) {
if (this == set)
return;

int wordsInCommon = Math.min(wordsInUse, set.wordsInUse);
// int wordsInCommon = Math.min(wordsInUse, set.wordsInUse);

if (wordsInUse < set.wordsInUse) {
ensureCapacity(set.wordsInUse);
wordsInUse = set.wordsInUse;
for (int i = 0; i < wordsInUse; i++)
words[i] |= set.words[i];
} else {
for (int i = 0; i < set.wordsInUse; i++)
words[i] |= set.words[i];
}

// Perform logical OR 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,
wordsInUse - wordsInCommon);

// recalculateWordsInUse() is unnecessary
checkInvariants();
}

/**
Expand Down

0 comments on commit 204e952

Please sign in to comment.