rabbah commented on a change in pull request #2360: Choose target invoker based 
on specific invoker load.
URL: 
https://github.com/apache/incubator-openwhisk/pull/2360#discussion_r122934822
 
 

 ##########
 File path: 
core/controller/src/main/scala/whisk/core/loadBalancer/LoadBalancerService.scala
 ##########
 @@ -312,14 +312,13 @@ object LoadBalancerService {
         override def apply(key: I) = getOrElseUpdate(key, f(key))
     }
 
-    /** All prime coprime numbers until x including 1. Result is memoized. */
-    val coprimePrimeNumbersUntil: Int => IndexedSeq[Int] = 
LoadBalancerService.memoize {
-        case x =>
-            1 +: (1 to x).foldLeft(IndexedSeq.empty[Int])((primes, cur) => {
-                if (x % cur != 0 && !primes.exists(cur % _ == 0)) {
-                    primes :+ cur
-                } else primes
-            })
+    /** Eclidean algorithm to determine the greatest-common-divisor */
+    @tailrec
+    def gcd(a: Int, b: Int): Int = if (b == 0) a else gcd(b, a % b)
+
+    /** All coprime numbers until x including 1. Result is memoized. */
+    val coprimeNumbersUntil: Int => IndexedSeq[Int] = 
LoadBalancerService.memoize {
+        case x => (1 to x).filter(i => gcd(i, x) == 1)
 
 Review comment:
   Note that the previous algorithm computed a set of coprime numbers which are 
also pairwise coprime; this algorithm does not. I _thought_ that was a desired 
property because the alternative can lead to overlaps in the search sequence.
   
 
----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to