summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Odersky <odersky@gmail.com>2008-04-21 10:26:54 +0000
committerMartin Odersky <odersky@gmail.com>2008-04-21 10:26:54 +0000
commite744a804175228b9438db2eca4ea49bd52e6b32d (patch)
treeb042ac47d01e78e63538c866b34b2e3e7bce21ed
parentbaad2fbd4e0d013f65e0232ce0aaa534ade8bd40 (diff)
downloadscala-e744a804175228b9438db2eca4ea49bd52e6b32d.tar.gz
scala-e744a804175228b9438db2eca4ea49bd52e6b32d.tar.bz2
scala-e744a804175228b9438db2eca4ea49bd52e6b32d.zip
fixed #768 for HashSet.
-rw-r--r--src/library/scala/Array.scala37
-rw-r--r--src/library/scala/collection/immutable/HashMap.scala6
-rw-r--r--src/library/scala/collection/immutable/HashSet.scala8
3 files changed, 48 insertions, 3 deletions
diff --git a/src/library/scala/Array.scala b/src/library/scala/Array.scala
index edd508e6ef..05335ddfd2 100644
--- a/src/library/scala/Array.scala
+++ b/src/library/scala/Array.scala
@@ -184,6 +184,43 @@ object Array {
a
}
+ /** Create an array containing the values of a given function <code>f</code>
+ * over given range <code>[0..n)</code>
+ */
+ def fromFunction[A](f: Int => A)(n: Int): Array[A] = {
+ val a = new Array[A](n)
+ var i = 0
+ while (i < n) {
+ a(i) = f(i)
+ i += 1
+ }
+ a
+ }
+
+ /** Create an array containing the values of a given function <code>f</code>
+ * over given range <code>[0..n1, 0..n2)</code>
+ */
+ def fromFunction[A](f: (Int, Int) => A)(n1: Int, n2: Int): Array[Array[A]] =
+ fromFunction(i => fromFunction(f(i, _))(n2))(n1)
+
+ /** Create an array containing the values of a given function <code>f</code>
+ * over given range <code>[0..n1, 0..n2, 0..n3)</code>
+ */
+ def fromFunction[A](f: (Int, Int, Int) => A)(n1: Int, n2: Int, n3: Int): Array[Array[Array[A]]] =
+ fromFunction(i => fromFunction(f(i, _, _))(n2, n3))(n1)
+
+ /** Create an array containing the values of a given function <code>f</code>
+ * over given range <code>[0..n1, 0..n2, 0..n3, 0..n4)</code>
+ */
+ def fromFunction[A](f: (Int, Int, Int, Int) => A)(n1: Int, n2: Int, n3: Int, n4: Int): Array[Array[Array[Array[A]]]] =
+ fromFunction(i => fromFunction(f(i, _, _, _))(n2, n3, n4))(n1)
+
+ /** Create an array containing the values of a given function <code>f</code>
+ * over given range <code>[0..n1, 0..n2, 0..n3, 0..n4, 0..n5)</code>
+ */
+ def fromFunction[A](f: (Int, Int, Int, Int, Int) => A)(n1: Int, n2: Int, n3: Int, n4: Int, n5: Int): Array[Array[Array[Array[Array[A]]]]] =
+ fromFunction(i => fromFunction(f(i, _, _, _, _))(n2, n3, n4, n5))(n1)
+
/** This method is called as a result of a pattern match { case Array(...) => } or val Array(...) = ....
*
* @param x the selector value
diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala
index 450e66f304..248b4b2714 100644
--- a/src/library/scala/collection/immutable/HashMap.scala
+++ b/src/library/scala/collection/immutable/HashMap.scala
@@ -28,7 +28,11 @@ object HashMap {
def apply[A, B](elems: (A, B)*) = empty[A, B] ++ elems
}
-/** This class implements immutable maps using a hash table.
+/** This class implements immutable maps/sets using a hash table.
+ * It is optimized for sequential accesses where the last updated table is accessed most often.
+ * It supports with reasonable efficiency accesses to previous versions of the table by keeping
+ * a change log that's regularly compacted.
+ * It needs to synchronize most methods, so it is less suitable for highly concurrent accesses.
*
* @author Martin Odersky
* @version 2.0, 19/01/2007
diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala
index 22488ec79f..0bcc58693d 100644
--- a/src/library/scala/collection/immutable/HashSet.scala
+++ b/src/library/scala/collection/immutable/HashSet.scala
@@ -26,7 +26,11 @@ object HashSet {
def apply[A](elems: A*) = empty[A] ++ elems
}
-/** This class implements immutable sets using a hash table.
+/** This class implements immutable maps/sets using a hash table.
+ * It is optimized for sequential accesses where the last updated table is accessed most often.
+ * It supports with reasonable efficiency accesses to previous versions of the table by keeping
+ * a change log that's regularly compacted.
+ * It needs to synchronize most methods, so it is less suitable for highly concurrent accesses.
*
* @author Martin Odersky
* @version 2.0, 19/01/2007
@@ -80,7 +84,7 @@ class HashSet[A] extends Set[A] with mutable.FlatHashTable[A] {
cnt += 1
m = m.later
}
- s += tableSize
+ s += m.tableSize
if (cnt > logLimit) makeCopy(m)
s
}