alvinalexander.com | career | drupal | java | mac | mysql | perl | scala | uml | unix  

Scala example source code file (IntAccess.scala)

This example Scala source code file (IntAccess.scala) is included in the DevDaily.com "Java Source Code Warehouse" project. The intent of this project is to help you "Learn Java by Example" TM.

Java - Scala tags/keywords

benchcompanion, int, int, intaccess, intaccess, list, resetting, resetting, string, string, unknownmanif

The Scala IntAccess.scala source code

package scala.collection.parallel.benchmarks.arrays


import scala.collection.parallel.benchmarks._



object IntAccess extends BenchCompanion {
  def collectionName = "array";
  def benchName = "access-int";
  def apply(sz: Int, p: Int, what: String) = new IntAccess(sz, p, what)
  override def comparisons = List("any", "cast", "manif", "unknown")
  override def defaultSize = 100000
}


class IntAccess(sz: Int, p: Int, what: String)
extends Resetting(n => n, sz, p, what) with UnknownManif[Int] {
  def companion = IntAccess
  
  def runseq {}
  def runpar {}
  
  def runany = {
    var i = 0
    while (i < sz) {
      val d = anyarray(i).asInstanceOf[Int]
      i += 1
    }
  }
  
  def runcast = {
    var i = 0
    while (i < sz) {
      val d = Arrays.apply(castarray, i).asInstanceOf[Int]
      i += 1
    }
  }
  
  def runmanif = {
    var i = 0
    while (i < sz) {
      val d = manifarray(i)
      if (op(d)) i += 1
      i += 1
    }
  }
  
  def op(a: Int) = a < 0
  
  def comparisonMap = collection.Map("any" -> runany _, "cast" -> runcast _,
                                     "manif" -> runmanif _, "unknown" -> rununknown _)
  
}














Other Scala examples (source code examples)

Here is a short list of links related to this Scala IntAccess.scala source code file:

... this post is sponsored by my books ...

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.

A percentage of advertising revenue from
pages under the /java/jwarehouse URI on this website is
paid back to open source projects.