diff options
author | Martin Odersky <odersky@gmail.com> | 2009-05-08 16:33:15 +0000 |
---|---|---|
committer | Martin Odersky <odersky@gmail.com> | 2009-05-08 16:33:15 +0000 |
commit | 14a631a5fec42d04d0723355a0b93e482b5e4662 (patch) | |
tree | f639c2a22e89e193b9abea391993ecfd4d5326ee /src/library/scala/collection/mutable/OpenHashMap.scala | |
parent | 2379eb4ebbd28c8892b50a1d9fa8a687099eea4d (diff) | |
download | scala-14a631a5fec42d04d0723355a0b93e482b5e4662.tar.gz scala-14a631a5fec42d04d0723355a0b93e482b5e4662.tar.bz2 scala-14a631a5fec42d04d0723355a0b93e482b5e4662.zip |
massive new collections checkin.
Diffstat (limited to 'src/library/scala/collection/mutable/OpenHashMap.scala')
-rw-r--r-- | src/library/scala/collection/mutable/OpenHashMap.scala | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/src/library/scala/collection/mutable/OpenHashMap.scala b/src/library/scala/collection/mutable/OpenHashMap.scala index b0b35960e2..f4ae7204aa 100644 --- a/src/library/scala/collection/mutable/OpenHashMap.scala +++ b/src/library/scala/collection/mutable/OpenHashMap.scala @@ -18,6 +18,8 @@ object OpenHashMap{ dict; } + def empty[K, V] = new OpenHashMap[K, V]; + private[mutable] class Entry[Key, Value](val key : Key, val hash : Int, var value : Option[Value]) @@ -48,6 +50,8 @@ import OpenHashMap.Entry; class OpenHashMap[Key, Value](initialSize : Int) extends scala.collection.mutable.Map[Key, Value]{ def this() = this(8); + override def empty = OpenHashMap.empty + private[this] val actualInitialSize = OpenHashMap.nextPowerOfTwo(initialSize); private var mask = actualInitialSize - 1;; @@ -58,7 +62,7 @@ class OpenHashMap[Key, Value](initialSize : Int) extends scala.collection.mutabl // Used for tracking inserts so that iterators can determine in concurrent modification has occurred. private[this] var modCount = 0; - def size = _size; + override def size = _size; private[this] def size_=(s : Int) = _size = s; protected def hashOf(key : Key) = { @@ -200,12 +204,15 @@ class OpenHashMap[Key, Value](initialSize : Int) extends scala.collection.mutabl private[this] def foreachUndeletedEntry(f : Entry[Key, Value] => Unit){ table.foreach(entry => if (entry != null && entry.value != None) f(entry)); } - - override def transform(f : (Key, Value) => Value) = + override def transform(f : (Key, Value) => Value) = { foreachUndeletedEntry(entry => entry.value = Some(f(entry.key, entry.value.get))); + this + } - override def retain(f : (Key, Value) => Boolean) = + override def retain(f : (Key, Value) => Boolean) = { foreachUndeletedEntry(entry => if (!f(entry.key, entry.value.get)) {entry.value = None; size -= 1; deleted += 1} ); + this + } override def stringPrefix = "OpenHashMap" } |