From 0d31778efe0e28e3c71294afc8a3cf7d149094c4 Mon Sep 17 00:00:00 2001 From: Iulian Dragos Date: Tue, 12 Aug 2008 16:34:31 +0000 Subject: Added David's fix for #1184 and author --- src/library/scala/collection/immutable/TreeHashMap.scala | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/library/scala/collection/immutable/TreeHashMap.scala b/src/library/scala/collection/immutable/TreeHashMap.scala index 1e0dd490fa..27f5112e0c 100644 --- a/src/library/scala/collection/immutable/TreeHashMap.scala +++ b/src/library/scala/collection/immutable/TreeHashMap.scala @@ -1,6 +1,15 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2008, David MacIver ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id: $ package scala.collection.immutable; -object TreeHashMap{ +object TreeHashMap { private[TreeHashMap] val _empty = new TreeHashMap[Any, Nothing](IntMap.empty[Nothing]); def empty[Key, Value] : TreeHashMap[Key, Value] = _empty.asInstanceOf[TreeHashMap[Key, Value]]; @@ -21,6 +30,8 @@ object TreeHashMap{ * * Performancewise, get and update seem to be somewhat slower than with a traditional hash map, but bulk operations * such as filter, foreach and transform appear to get something of a speedup. + * + * @author David MacIver */ class TreeHashMap[Key, +Value] private (private val underlying : IntMap[AssocMap[Key, Value]]) extends scala.collection.immutable.Map[Key, Value]{ def elements : Iterator[(Key, Value)] = new Iterator[(Key, Value)]{ @@ -104,6 +115,7 @@ class TreeHashMap[Key, +Value] private (private val underlying : IntMap[AssocMap case Some(table) => { val newtable = table - key; if (table eq newtable) this; + else if (newtable.isEmpty) TreeHashMap(underlying - h) else TreeHashMap(underlying.update(h, newtable)); } } -- cgit v1.2.3