equal
deleted
inserted
replaced
434 // Remember: |
434 // Remember: |
435 // - no vars, no ++i, no += |
435 // - no vars, no ++i, no += |
436 // - no mutable data-structures (no Arrays, no ListBuffers) |
436 // - no mutable data-structures (no Arrays, no ListBuffers) |
437 |
437 |
438 // But what the heck....lets try to count to 1 Mio in parallel |
438 // But what the heck....lets try to count to 1 Mio in parallel |
|
439 import scala.collection.parallel.CollectionConverters._ |
439 |
440 |
440 var cnt = 0 |
441 var cnt = 0 |
441 |
442 |
442 for(i <- (1 to 1000000).par) cnt += 1 |
443 for(i <- (1 to 1000000).par) cnt += 1 |
443 |
444 |
450 // two sets? |
451 // two sets? |
451 // A; IMPROPER WAY (mutable counter) |
452 // A; IMPROPER WAY (mutable counter) |
452 |
453 |
453 def count_intersection(A: Set[Int], B: Set[Int]) : Int = { |
454 def count_intersection(A: Set[Int], B: Set[Int]) : Int = { |
454 var count = 0 |
455 var count = 0 |
455 for (x <- A.par; if (B contains x)) count += 1 |
456 for (x <- A; if (B contains x)) count += 1 |
456 count |
457 count |
457 } |
458 } |
458 |
459 |
459 val A = (0 to 999).toSet |
460 val A = (0 to 999).toSet |
460 val B = (0 to 999 by 4).toSet |
461 val B = (0 to 999 by 4).toSet |