diff options
author | mihaylov <mihaylov@epfl.ch> | 2007-06-13 12:14:15 +0000 |
---|---|---|
committer | mihaylov <mihaylov@epfl.ch> | 2007-06-13 12:14:15 +0000 |
commit | a384720d2cfbd1ea61c4d605af75be6aebccd389 (patch) | |
tree | 53f1dc034bb51e2bd5eebaaaac3f646c341a681a /src/library | |
parent | 2d28f7fcc3e2cfcce127b8e0e5851df7bca66df0 (diff) | |
download | scala-a384720d2cfbd1ea61c4d605af75be6aebccd389.tar.gz scala-a384720d2cfbd1ea61c4d605af75be6aebccd389.tar.bz2 scala-a384720d2cfbd1ea61c4d605af75be6aebccd389.zip |
Integrated J2ME version of the library as of re...
Integrated J2ME version of the library as of rev 12002
Diffstat (limited to 'src/library')
12 files changed, 37 insertions, 13 deletions
diff --git a/src/library/scala/Math.scala b/src/library/scala/Math.scala index c5dc0ede1f..a9db1a3692 100644 --- a/src/library/scala/Math.scala +++ b/src/library/scala/Math.scala @@ -117,6 +117,7 @@ object Math { def exp(x: Double): Double = java.lang.Math.exp(x) def log(x: Double): Double = java.lang.Math.log(x) def sqrt(x: Double): Double = java.lang.Math.sqrt(x) + def sqrt(x: Int): Int = java.lang.Math.sqrt(x.toDouble).toInt def IEEEremainder(x: Double, y: Double): Double = java.lang.Math.IEEEremainder(x, y) def ceil(x: Double): Double = java.lang.Math.ceil(x) diff --git a/src/library/scala/collection/immutable/HashMap.scala b/src/library/scala/collection/immutable/HashMap.scala index c91f0c7a43..17d9a38931 100644 --- a/src/library/scala/collection/immutable/HashMap.scala +++ b/src/library/scala/collection/immutable/HashMap.scala @@ -103,7 +103,7 @@ class HashMap[A, B] extends Map[A,B] with mutable.HashTable[A] { private def getValue(e: Entry) = e.value.asInstanceOf[B] - private def logLimit: Int = Math.sqrt(table.length.toDouble).toInt + private def logLimit: Int = Math.sqrt(table.length).toInt private def markUpdated(key: A, ov: Option[B], delta: Int) { val lv = loadFactor diff --git a/src/library/scala/collection/immutable/HashSet.scala b/src/library/scala/collection/immutable/HashSet.scala index 13bd8386a3..4de43cad46 100644 --- a/src/library/scala/collection/immutable/HashSet.scala +++ b/src/library/scala/collection/immutable/HashSet.scala @@ -89,7 +89,7 @@ class HashSet[A] extends Set[A] with mutable.FlatHashTable[A] { super.elements } - private def logLimit: Int = Math.sqrt(table.length.toDouble).toInt + private def logLimit: Int = Math.sqrt(table.length).toInt private def markUpdated(elem: A, del: Boolean) { val lv = loadFactor diff --git a/src/library/scala/collection/mutable/Buffer.scala b/src/library/scala/collection/mutable/Buffer.scala index ee7091ff20..0d8c4539e1 100644 --- a/src/library/scala/collection/mutable/Buffer.scala +++ b/src/library/scala/collection/mutable/Buffer.scala @@ -26,6 +26,7 @@ import Predef._ trait Buffer[A] extends AnyRef with Seq[A] with Scriptable[Message[(Location, A)]] + with CloneableCollection { /** Append a single element to this buffer. diff --git a/src/library/scala/collection/mutable/CloneableCollection.scala b/src/library/scala/collection/mutable/CloneableCollection.scala new file mode 100644 index 0000000000..f00cec798d --- /dev/null +++ b/src/library/scala/collection/mutable/CloneableCollection.scala @@ -0,0 +1,19 @@ +/* __ *\ +** ________ ___ / / ___ Scala API ** +** / __/ __// _ | / / / _ | (c) 2003-2007, LAMP/EPFL ** +** __\ \/ /__/ __ |/ /__/ __ | http://scala-lang.org/ ** +** /____/\___/_/ |_/____/_/ | | ** +** |/ ** +\* */ + +// $Id$ + + +package scala.collection.mutable + +/** The J2ME version of the library defined this trait with a clone method + * to substitute for the lack of Object.clone there + */ +trait CloneableCollection { + override def clone(): AnyRef = super.clone() +} diff --git a/src/library/scala/collection/mutable/FlatHashTable.scala b/src/library/scala/collection/mutable/FlatHashTable.scala index 80150e6e47..05d08b3eb2 100644 --- a/src/library/scala/collection/mutable/FlatHashTable.scala +++ b/src/library/scala/collection/mutable/FlatHashTable.scala @@ -14,9 +14,10 @@ import Predef._ trait FlatHashTable[A] { - /** The load factor for the hash table; must be < 0.5f + /** The load factor for the hash table; must be < 500 (0.5) */ - protected def loadFactor: Float = 0.45f + protected def loadFactor: Int = 450 + protected final def loadFactorDenum = 1000 /** The initial size of the hash table. */ @@ -151,8 +152,8 @@ trait FlatHashTable[A] { private def newThreshold(size: Int) = { val lf = loadFactor - assert(lf < 0.5f, "loadFactor too large; must be < 0.5") - (size * lf).asInstanceOf[Int] + assert(lf < (loadFactorDenum / 2), "loadFactor too large; must be < 0.5") + (size.toLong * lf / loadFactorDenum ).toInt } protected def clear() { diff --git a/src/library/scala/collection/mutable/HashTable.scala b/src/library/scala/collection/mutable/HashTable.scala index e82a27e506..dbdb232a57 100644 --- a/src/library/scala/collection/mutable/HashTable.scala +++ b/src/library/scala/collection/mutable/HashTable.scala @@ -32,9 +32,10 @@ trait HashTable[A] extends AnyRef { protected type Entry >: Null <: HashEntry[A, Entry] - /** The load factor for the hash table. + /** The load factor for the hash table (in 0.001 step). */ - protected def loadFactor: Float = 0.75f + protected def loadFactor: Int = 750 // corresponds to 75% + protected final val loadFactorDenum = 1000; /** The initial size of the hash table. */ @@ -125,7 +126,7 @@ trait HashTable[A] extends AnyRef { } private def newThreshold(size: Int) = - (size * loadFactor).asInstanceOf[Int] + ((size.toLong * loadFactor)/loadFactorDenum).toInt private def resize(newSize: Int) = { val oldTable = table diff --git a/src/library/scala/collection/mutable/Map.scala b/src/library/scala/collection/mutable/Map.scala index 44b18e20ae..807ce14d90 100644 --- a/src/library/scala/collection/mutable/Map.scala +++ b/src/library/scala/collection/mutable/Map.scala @@ -42,6 +42,7 @@ object Map { trait Map[A, B] extends AnyRef with collection.Map[A, B] with Scriptable[Message[(A, B)]] + with CloneableCollection { /** This method allows one to add a new mapping from <code>key</code> * to <code>value</code> to the map. If the map already contains a diff --git a/src/library/scala/collection/mutable/PriorityQueue.scala b/src/library/scala/collection/mutable/PriorityQueue.scala index 6e86a2f818..0772c545e9 100644 --- a/src/library/scala/collection/mutable/PriorityQueue.scala +++ b/src/library/scala/collection/mutable/PriorityQueue.scala @@ -23,7 +23,7 @@ package scala.collection.mutable */ @serializable @cloneable -class PriorityQueue[A <% Ordered[A]] extends ResizableArray[A] { +class PriorityQueue[A <% Ordered[A]] extends ResizableArray[A] with CloneableCollection { size0 = size0 + 1 // we do not use array(0) protected def fixUp(as: Array[A], m: Int): Unit = { diff --git a/src/library/scala/collection/mutable/Queue.scala b/src/library/scala/collection/mutable/Queue.scala index 2b4138caa2..d654a82888 100644 --- a/src/library/scala/collection/mutable/Queue.scala +++ b/src/library/scala/collection/mutable/Queue.scala @@ -21,7 +21,7 @@ package scala.collection.mutable * @version 1.1, 03/05/2004 */ @serializable @cloneable -class Queue[A] extends MutableList[A] { +class Queue[A] extends MutableList[A] with CloneableCollection { /** Checks if the queue is empty. * diff --git a/src/library/scala/collection/mutable/Set.scala b/src/library/scala/collection/mutable/Set.scala index faa712edf8..1d68687f26 100644 --- a/src/library/scala/collection/mutable/Set.scala +++ b/src/library/scala/collection/mutable/Set.scala @@ -37,7 +37,7 @@ object Set { * @version 1.1, 09/05/2004 */ @cloneable -trait Set[A] extends collection.Set[A] with Scriptable[Message[A]] { +trait Set[A] extends collection.Set[A] with Scriptable[Message[A]] with CloneableCollection { /** This method allows one to add or remove an element <code>elem</code> * from this set depending on the value of parameter <code>included</code>. diff --git a/src/library/scala/collection/mutable/Stack.scala b/src/library/scala/collection/mutable/Stack.scala index 9fb44e6528..be95aee1a5 100644 --- a/src/library/scala/collection/mutable/Stack.scala +++ b/src/library/scala/collection/mutable/Stack.scala @@ -19,7 +19,7 @@ package scala.collection.mutable * @version 1.1, 03/05/2004 */ @serializable @cloneable -class Stack[A] extends MutableList[A] { +class Stack[A] extends MutableList[A] with CloneableCollection { /** Checks if the stack is empty. * |