Class SortingLongCollection

java.lang.Object
htsjdk.samtools.util.SortingLongCollection

public class SortingLongCollection extends Object
Accumulate a list of longs that can then be sorted in natural order and iterated over. If there are more values accumulated than a specified maximum, values are spilled to disk.

Note that because this class returns primitive longs rather than Longs, it does not conform to any of the Collection iteration interfaces. Use as follows:

1. ctor 2. call add() as many times as desired. 3. call doneAddingStartIteration(). 4. call hasNext() and next() until exhausted or had enough. 5. optionally call cleanup() to free space in temporary directory as soon as possible.

If there are few enough values so that they all can be kept in RAM, then the array is sorted and iterated over trivially.

If there are more values that can fit in RAM, then values are sorted and written to a temp file when the max number to be stored in RAM is reached. Multiple temp files are then merged during iteration via PriorityQueue.

c.f. SortingCollection for more details.

  • Field Details

    • SIZEOF

      public static final int SIZEOF
      See Also:
    • MAX_ITEMS_IN_RAM

      public static final int MAX_ITEMS_IN_RAM
  • Constructor Details

    • SortingLongCollection

      public SortingLongCollection(int maxValuesInRam, File... tmpDir)
      Prepare to accumulate values to be sorted
      Parameters:
      maxValuesInRam - how many values to accumulate before spilling to disk
      tmpDir - Where to write files of values that will not fit in RAM
    • SortingLongCollection

      public SortingLongCollection(int maxValuesInRam, Path... tmpDir)
      Prepare to accumulate values to be sorted
      Parameters:
      maxValuesInRam - how many values to accumulate before spilling to disk
      tmpDir - Where to write files of values that will not fit in RAM
  • Method Details

    • add

      public void add(long value)
      Add a value to the collection.
      Parameters:
      value -
    • doneAddingStartIteration

      public void doneAddingStartIteration()
      This method must be called after done adding, and before calling hasNext() or next().
    • cleanup

      public void cleanup()
      Delete any temporary files. After this method is called, no other method calls should be made on this object.
    • hasNext

      public boolean hasNext()
      Call only after doneAddingStartIteration() has been called.
      Returns:
      true if there is another value to be gotten.
    • next

      public long next()
      Call only if hasNext() == true.
      Returns:
      next value from collection, in natural sort order.