Made mutable.{Set, BitSet} platform-independent

git-svn-id: http://lampsvn.epfl.ch/svn-repos/scala/scala/trunk@10901 5e8d7ff9-d8ef-0310-90f0-a4852d11357a
This commit is contained in:
mihaylov 2007-05-01 11:47:56 +00:00
parent 373fa9f9ac
commit f9a81714a6
7 changed files with 91 additions and 50 deletions

View File

@ -607,7 +607,7 @@ MSIL
<include name="scala/Console.scala" />
<include name="scala/Application.scala" />
<include name="scala/ByNameFunction.scala" />
<include name="scala/*Attribute.scala" />
<include name="scala/*Annotation.scala" />
<include name="scala/Function*.scala" />
<include name="scala/Tuple*.scala" />
<include name="scala/Product*.scala" />

View File

@ -17,6 +17,7 @@ import Predef._
object Platform {
type StackOverflowError = System.StackOverflowException
type ConcurrentModificationException = System.Exception
/**
* @param src ..
@ -41,6 +42,8 @@ object Platform {
def createArray(elemClass: Class, length: Int): AnyRef =
System.Array.CreateInstance(elemClass, length);
def arrayclear(arr: Array[Int]): Unit = System.Array.Clear(arr.asInstanceOf[System.Array], 0, arr.length)
def getClassForName(name: String): Class = System.Type.GetType(name)
val EOL = System.Environment.NewLine

View File

@ -24,7 +24,7 @@ package scala.collection.mutable
@serializable
class BitSet(initSize: Int) extends collection.BitSet with Set[Int] {
import compat.Platform.arraycopy
import compat.Platform.{arraycopy, arrayclear}
/** default constructor, initial size of 512 bits. */
def this() = this(0)
@ -78,7 +78,7 @@ class BitSet(initSize: Int) extends collection.BitSet with Set[Int] {
/** Clears all bits of the set.
*/
override def clear(): Unit = {
java.util.Arrays.fill(arr, 0)
arrayclear(arr)
size = 0
}

View File

@ -12,6 +12,8 @@
package scala.collection.mutable
import compat.Platform.ConcurrentModificationException
/** The canonical factory methods for <a href="Set.html">mutable sets</a>.
* Currently these return <a href="HashSet.html">HashSet's</a>.
*/
@ -202,15 +204,15 @@ trait Set[A] extends collection.Set[A] with Scriptable[Message[A]] {
* @return a set with the same elements.
*/
override def clone(): Set[A] = super.clone().asInstanceOf[Set[A]]
/** Return a read-only projection of this set */
def readOnly : scala.collection.Set[A] = new scala.collection.Set[A] {
/** used to trigger version checking in JCL and hopefully the mutable collections */
override val hashCode = Set.this.hashCode
private def check =
if (false && hashCode != Set.this.hashCode)
throw new java.util.ConcurrentModificationException
private def check =
if (false && hashCode != Set.this.hashCode)
throw new ConcurrentModificationException
def contains(item : A) = {
check
Set.this.contains(item)

View File

@ -18,6 +18,7 @@ import Predef._
object Platform {
type StackOverflowError = java.lang.StackOverflowError
type ConcurrentModificationException = java.util.ConcurrentModificationException
/**
* @param src ..
@ -39,6 +40,8 @@ object Platform {
def createArray(elemClass: Class, length: Int): AnyRef =
java.lang.reflect.Array.newInstance(elemClass, length)
def arrayclear(arr: Array[Int]): Unit = java.util.Arrays.fill(arr, 0)
def getClassForName(name: String): Class = java.lang.Class.forName(name)
val EOL = System.getProperty("line.separator", "\n")

View File

@ -1,22 +1,22 @@
list0 = List(6,3,1,8,7,1,2,5,8,4,3,4,8)
list1 = List(1,1,2,3,3,4,4,5,6,7,8,8,8)
list2 = List(1,1,2,3,3,4,4,5,6,7,8,8,8)
list3 = List(1,1,2,3,3,4,4,5,6,7,8,8,8)
list4 = List(1,1,2,3,3,4,4,5,6,7,8,8,8)
list5 = List(8,8,8,7,6,5,4,4,3,3,2,1,1)
list6 = List(8,8,8,7,6,5,4,4,3,3,2,1,1)
list0 = List(6, 3, 1, 8, 7, 1, 2, 5, 8, 4, 3, 4, 8)
list1 = List(1, 1, 2, 3, 3, 4, 4, 5, 6, 7, 8, 8, 8)
list2 = List(1, 1, 2, 3, 3, 4, 4, 5, 6, 7, 8, 8, 8)
list3 = List(1, 1, 2, 3, 3, 4, 4, 5, 6, 7, 8, 8, 8)
list4 = List(1, 1, 2, 3, 3, 4, 4, 5, 6, 7, 8, 8, 8)
list5 = List(8, 8, 8, 7, 6, 5, 4, 4, 3, 3, 2, 1, 1)
list6 = List(8, 8, 8, 7, 6, 5, 4, 4, 3, 3, 2, 1, 1)
list0: List() -> List()
list1: List(0) -> List(0)
list2: List(0,1) -> List(0,1)
list3: List(1,0) -> List(0,1)
list4: List(0,1,2) -> List(0,1,2)
list5: List(1,0,2) -> List(0,1,2)
list6: List(0,1,2) -> List(0,1,2)
list7: List(1,0,2) -> List(0,1,2)
list8: List(2,0,1) -> List(0,1,2)
list9: List(2,1,0) -> List(0,1,2)
listA: List(6,3,1,8,7,1,2,5,8,4) -> List(1,1,2,3,4,5,6,7,8,8)
list2: List(0, 1) -> List(0, 1)
list3: List(1, 0) -> List(0, 1)
list4: List(0, 1, 2) -> List(0, 1, 2)
list5: List(1, 0, 2) -> List(0, 1, 2)
list6: List(0, 1, 2) -> List(0, 1, 2)
list7: List(1, 0, 2) -> List(0, 1, 2)
list8: List(2, 0, 1) -> List(0, 1, 2)
list9: List(2, 1, 0) -> List(0, 1, 2)
listA: List(6, 3, 1, 8, 7, 1, 2, 5, 8, 4) -> List(1, 1, 2, 3, 4, 5, 6, 7, 8, 8)
f(x) = 5x^3+7x^2+5x+9
f(0) = 9
@ -24,41 +24,41 @@ f(1) = 26
f(2) = 87
f(3) = 222
v1 = List(2,3,4)
v2 = List(6,7,8)
v1 = List(2, 3, 4)
v2 = List(6, 7, 8)
id = List(List(1,0,0),List(0,1,0),List(0,0,1))
m1 = List(List(2,0,0),List(0,2,0),List(0,0,2))
m2 = List(List(1,2,3),List(4,5,6),List(7,8,9))
id = List(List(1, 0, 0), List(0, 1, 0), List(0, 0, 1))
m1 = List(List(2, 0, 0), List(0, 2, 0), List(0, 0, 2))
m2 = List(List(1, 2, 3), List(4, 5, 6), List(7, 8, 9))
v1 * v1 = 29
v1 * v2 = 65
v2 * v1 = 65
v1 * v2 = 65
id * v1 = List(2,3,4)
m1 * v1 = List(4,6,8)
m2 * v1 = List(20,47,74)
id * v1 = List(2, 3, 4)
m1 * v1 = List(4, 6, 8)
m2 * v1 = List(20, 47, 74)
trn(id) = List(List(1,0,0),List(0,1,0),List(0,0,1))
trn(m1) = List(List(2,0,0),List(0,2,0),List(0,0,2))
trn(m2) = List(List(1,4,7),List(2,5,8),List(3,6,9))
trn(id) = List(List(1, 0, 0), List(0, 1, 0), List(0, 0, 1))
trn(m1) = List(List(2, 0, 0), List(0, 2, 0), List(0, 0, 2))
trn(m2) = List(List(1, 4, 7), List(2, 5, 8), List(3, 6, 9))
List(v1) * id = List(List(2,3,4))
List(v1) * m1 = List(List(4,6,8))
List(v1) * m2 = List(List(42,51,60))
List(v1) * id = List(List(2, 3, 4))
List(v1) * m1 = List(List(4, 6, 8))
List(v1) * m2 = List(List(42, 51, 60))
id * List(v1) = List(List(2,3,4),List(0,0,0),List(0,0,0))
m1 * List(v1) = List(List(4,6,8),List(0,0,0),List(0,0,0))
m2 * List(v1) = List(List(2,3,4),List(8,12,16),List(14,21,28))
id * List(v1) = List(List(2, 3, 4), List(0, 0, 0), List(0, 0, 0))
m1 * List(v1) = List(List(4, 6, 8), List(0, 0, 0), List(0, 0, 0))
m2 * List(v1) = List(List(2, 3, 4), List(8, 12, 16), List(14, 21, 28))
id * id = List(List(1,0,0),List(0,1,0),List(0,0,1))
id * m1 = List(List(2,0,0),List(0,2,0),List(0,0,2))
m1 * id = List(List(2,0,0),List(0,2,0),List(0,0,2))
m1 * m1 = List(List(4,0,0),List(0,4,0),List(0,0,4))
id * m2 = List(List(1,2,3),List(4,5,6),List(7,8,9))
m2 * id = List(List(1,2,3),List(4,5,6),List(7,8,9))
m1 * m2 = List(List(2,4,6),List(8,10,12),List(14,16,18))
m2 * m1 = List(List(2,4,6),List(8,10,12),List(14,16,18))
m2 * m2 = List(List(30,36,42),List(66,81,96),List(102,126,150))
id * id = List(List(1, 0, 0), List(0, 1, 0), List(0, 0, 1))
id * m1 = List(List(2, 0, 0), List(0, 2, 0), List(0, 0, 2))
m1 * id = List(List(2, 0, 0), List(0, 2, 0), List(0, 0, 2))
m1 * m1 = List(List(4, 0, 0), List(0, 4, 0), List(0, 0, 4))
id * m2 = List(List(1, 2, 3), List(4, 5, 6), List(7, 8, 9))
m2 * id = List(List(1, 2, 3), List(4, 5, 6), List(7, 8, 9))
m1 * m2 = List(List(2, 4, 6), List(8, 10, 12), List(14, 16, 18))
m2 * m1 = List(List(2, 4, 6), List(8, 10, 12), List(14, 16, 18))
m2 * m2 = List(List(30, 36, 42), List(66, 81, 96), List(102, 126, 150))

View File

@ -0,0 +1,33 @@
ms0 = Set(2)
ms1 = Set(2)
ms2 = Set(2)
mb0 = False
mb1 = True
mb2 = False
xs0 = List(2)
xs1 = List(2)
xs2 = List(2)
ma0 = List(4)
ma1 = List(4)
ma2 = List(4)
mi0 = Set(2)
mi1 = Set(2)
mi2 = Set(2)
is0 = Set()
is1 = Set()
is2 = Set(2)
is3 = Set()
ib0 = False
ib1 = False
ib2 = True
ib3 = False
ys0 = List()
ys1 = List()
ys2 = List(2)
ys3 = List()
ia0 = List(0)
ia1 = List(0)
ia2 = List(4)
ia3 = List()