boxedfloatarray.scala

来自「JAVA 语言的函数式编程扩展」· SCALA 代码 · 共 66 行

SCALA
66
字号
/*                     __                                               *\**     ________ ___   / /  ___     Scala API                            ****    / __/ __// _ | / /  / _ |    (c) 2002-2007, LAMP/EPFL             ****  __\ \/ /__/ __ |/ /__/ __ |    http://scala-lang.org/               **** /____/\___/_/ |_/____/_/ | |                                         ****                          |/                                          **\*                                                                      */// $Id: BoxedFloatArray.scala 13589 2007-12-19 10:38:50Z odersky $package scala.runtimeimport Predef._@serializablefinal class BoxedFloatArray(val value: Array[Float]) extends BoxedArray {  def length: Int = value.length  def apply(index: Int): Any = Float.box(value(index))  def update(index: Int, elem: Any) {    value(index) = Float.unbox(elem.asInstanceOf[AnyRef])  }  def unbox(elemTag: String): AnyRef = value  def unbox(elemClass: Class[_]): AnyRef = value  override def equals(other: Any) =    value == other ||    other.isInstanceOf[BoxedFloatArray] && value == other.asInstanceOf[BoxedFloatArray].value  override def hashCode(): Int = value.hashCode()  def subArray(start: Int, end: Int): Array[Float] = {    val result = new Array[Float](end - start)    Array.copy(value, start, result, 0, end - start)    result  }  final override def filter(p: Any => Boolean): BoxedArray = {    val include = new Array[Boolean](value.length)    var len = 0    var i = 0    while (i < value.length) {      if (p(value(i))) { include(i) = true; len += 1 }      i += 1    }    val result = new Array[Float](len)    len = 0    i = 0    while (len < result.length) {      if (include(i)) { result(len) = value(i); len += 1 }      i += 1    }    new BoxedFloatArray(result)  }  override protected def newArray(length : Int, elements : Iterator[Any]) = {    val result = new Array[Float](length)    elements.map(_.asInstanceOf[Float]).copyToArray(result, 0)    new BoxedFloatArray(result)  }}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?