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

Scala example source code file (HashTrieSplit.scala)

This example Scala source code file (HashTrieSplit.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, array, first, first, int, original, original, second, test, test

The Scala HashTrieSplit.scala source code






import collection._




// checks whether hash tries split their iterators correctly
// even after some elements have been traversed
object Test {
  def main(args: Array[String]) {
    doesSplitOk
  }
  
  def doesSplitOk = {
    val sz = 2000
    var ht = new parallel.immutable.ParHashMap[Int, Int]
    // println("creating trie")
    for (i <- 0 until sz) ht += ((i + sz, i))
    // println("created trie")
    for (n <- 0 until (sz - 1)) {
      // println("---------> n = " + n)
      val pit = ht.parallelIterator
      val pit2 = ht.parallelIterator
      var i = 0
      while (i < n) {
        pit.next
        pit2.next
        i += 1
      }
      // println("splitting")
      val pits = pit.split
      val fst = pits(0).toSet
      val snd = pits(1).toSet
      val orig = pit2.toSet
      if (orig.size != (fst.size + snd.size) || orig != (fst ++ snd)) {
        println("Original: " + orig)
        println("First: " + fst)
        println("Second: " + snd)
        assert(false)
      }
    }
  }
}

Other Scala examples (source code examples)

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