From b862308a6c707e83a819a6227c563f4c5e70b71c Mon Sep 17 00:00:00 2001 From: Nils Homer Date: Mon, 1 Nov 2021 14:11:31 -0700 Subject: [PATCH] SimpleCounter iterators are in insertion order --- .../com/fulcrumgenomics/commons/util/SimpleCounter.scala | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/src/main/scala/com/fulcrumgenomics/commons/util/SimpleCounter.scala b/src/main/scala/com/fulcrumgenomics/commons/util/SimpleCounter.scala index 9f9e570..5c5d327 100644 --- a/src/main/scala/com/fulcrumgenomics/commons/util/SimpleCounter.scala +++ b/src/main/scala/com/fulcrumgenomics/commons/util/SimpleCounter.scala @@ -38,11 +38,12 @@ object SimpleCounter { /** * Super-simple class for counting occurrences of any kind of object. Will return - * zero for any item that has not been counted yet. + * zero for any item that has not been counted yet. The iterator and all traversal + * methods of this class visit elements in the order they were inserted. */ class SimpleCounter[T]extends Iterable[(T, Long)] { - /** Creates the map in which we store the counts. */ - protected def makeMap(): mutable.Map[T, Long] = new mutable.HashMap() + /** Creates the map in which we store the counts, with iteration in insertion order. */ + protected def makeMap(): mutable.Map[T, Long] = new mutable.LinkedHashMap() private val counts: mutable.Map[T, Long] = makeMap().withDefaultValue(0L)