Skip to content

Commit

Permalink
Removed PollableTreeSet in SortingCollection as it was no longer nece…
Browse files Browse the repository at this point in the history
…ssary. (#642)

Replaced with direct usage of TreeSet.pollFirst(). One advantage (other than removing unneeded code) is that this now only has to search the tree once, instead of twice for poll() then remove().
  • Loading branch information
tfenne authored Jun 17, 2016
1 parent 84dd0b5 commit bcc3f4a
Showing 1 changed file with 4 additions and 22 deletions.
26 changes: 4 additions & 22 deletions src/main/java/htsjdk/samtools/util/SortingCollection.java
Original file line number Diff line number Diff line change
Expand Up @@ -393,10 +393,10 @@ public void remove() {
* location in the PriorityQueue
*/
class MergingIterator implements CloseableIterator<T> {
private final PollableTreeSet<PeekFileRecordIterator> queue;
private final TreeSet<PeekFileRecordIterator> queue;

MergingIterator() {
this.queue = new PollableTreeSet<PeekFileRecordIterator>(new PeekFileRecordIteratorComparator());
this.queue = new TreeSet<PeekFileRecordIterator>(new PeekFileRecordIteratorComparator());
int n = 0;
for (final File f : SortingCollection.this.files) {
final FileRecordIterator it = new FileRecordIterator(f);
Expand All @@ -418,7 +418,7 @@ public T next() {
throw new NoSuchElementException();
}

final PeekFileRecordIterator fileIterator = queue.poll();
final PeekFileRecordIterator fileIterator = queue.pollFirst();
final T ret = fileIterator.next();
if (fileIterator.hasNext()) {
this.queue.add(fileIterator);
Expand All @@ -436,7 +436,7 @@ public void remove() {

public void close() {
while (!this.queue.isEmpty()) {
final PeekFileRecordIterator it = this.queue.poll();
final PeekFileRecordIterator it = this.queue.pollFirst();
((CloseableIterator<T>)it.getUnderlyingIterator()).close();
}
}
Expand Down Expand Up @@ -511,22 +511,4 @@ public int compare(final PeekFileRecordIterator lhs, final PeekFileRecordIterato
else return result;
}
}

/** Little class that provides the Java 1.5 TreeSet with a poll() method */
static class PollableTreeSet<T> extends TreeSet<T> {
PollableTreeSet(final Comparator<? super T> comparator) {
super(comparator);
}

public T poll() {
if (isEmpty()) {
return null;
}
else {
final T t = first();
remove(t);
return t;
}
}
}
}

0 comments on commit bcc3f4a

Please sign in to comment.