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

Scala example source code file (ParallelRangeCheck.scala)

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

colltype, colltype, gen, int, parallelrange, parallelrangecheck, parallelrangecheck, parallelseqcheck, range, range, seq, seq, traversable

The Scala ParallelRangeCheck.scala source code

package scala.collection.parallel
package immutable




import org.scalacheck._
import org.scalacheck.Gen
import org.scalacheck.Gen._
import org.scalacheck.Prop._
import org.scalacheck.Properties
import org.scalacheck.Arbitrary._

import scala.collection._
import scala.collection.parallel.ops._




object ParallelRangeCheck extends ParallelSeqCheck[Int]("ParallelRange[Int]") with ops.IntSeqOperators {
  // ForkJoinTasks.defaultForkJoinPool.setMaximumPoolSize(Runtime.getRuntime.availableProcessors * 2)
  // ForkJoinTasks.defaultForkJoinPool.setParallelism(Runtime.getRuntime.availableProcessors * 2)
  
  type CollType = collection.parallel.ParSeq[Int]
  
  def hasStrictOrder = true
  
  def isCheckingViews = false
  
  def ofSize(vals: Seq[Gen[Int]], sz: Int) = unsupported
  
  override def instances(vals: Seq[Gen[Int]]): Gen[Seq[Int]] = sized { start =>
    sized { end =>
      sized { step =>
        new Range(start, end, if (step != 0) step else 1)
      }
    }
  }
  
  def fromSeq(a: Seq[Int]) = a match {
    case r: Range => ParRange(r.start, r.end, r.step, false)
    case _ =>
      val pa = new parallel.mutable.ParArray[Int](a.length)
      for (i <- 0 until a.length) pa(i) = a(i)
      pa
  }
  
  override def traversable2Seq(t: Traversable[Int]): Seq[Int] = t match {
    case r: Range => r
    case _ => t.toSeq
  }
  
  def values = Seq(choose(-100, 100))
  
}
















Other Scala examples (source code examples)

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

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

#1 New Release!

FP Best Seller

 

new blog posts

 

Copyright 1998-2024 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.