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

Scala example source code file (CountList.scala)

This example Scala source code file (CountList.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

array, companion, countlist, countlist, int, int, list, list, resettable, string, string

The Scala CountList.scala source code

package scala.collection.parallel.benchmarks.parallel_array




object CountList extends Companion {
  def benchName = "count-list";
  def apply(sz: Int, parallelism: Int, what: String) = new CountList(sz, parallelism, what)
  override def comparisons = List("jsr")
  override def defaultSize = 1000
  
  val listCreator = (i: Int) => (0 until (i % 50 + 50)).toList
  val pred = (lst: List[Int]) => check(lst)
  val predjsr = new extra166y.Ops.Predicate[List[Int]] {
    def op(lst: List[Int]) = check(lst)
  }
  
  def check(lst: List[Int]) = lst.foldLeft(0)((sum, n) => sum + n * n) % 2 == 0
}

class CountList(sz: Int, p: Int, what: String)
extends Resettable(sz, p, what, CountList.listCreator, new Array[Any](_), classOf[List[Int]]) {
  def companion = CountList
  override def repetitionsPerRun = 250
  
  def runpar = pa.count(CountList.pred)
  def runseq = sequentialCount(CountList.pred, sz)
  def runjsr = jsrarr.withFilter(CountList.predjsr).size
  def comparisonMap = collection.Map("jsr" -> runjsr _)
}

Other Scala examples (source code examples)

Here is a short list of links related to this Scala CountList.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.