On Saturday, 8 October 2016 at 22:48:53 UTC, vino wrote:
Hi,

Can some one guide me on how to implement the weighted round robin, below is what i tried or any other better ways to do it

Main Requirement : Incoming socket connection has to be sent to 3 servers in the weighted round robin fashion.

Prog:1
import std.stdio;
import std.range;
import std.range.primitives;

void main()
{
    auto a = [1,2,3]; // E.g :Server Array
    auto b = [1,2,3,4,5]; // E.g: Socket Array
    auto r = roundRobin(a, b);
    writeln(r);
}
OUTPUT : [1, 1, 2, 2, 3, 3, 4, 5]
Requirement : [1, 1, 2, 2, 3, 3,1,4,2,5]

    auto r = roundRobin(a.cycle, b.cycle);

Beware though that this yields an infinite range. If you just need one round, you can use:

    import std.algorithm.comparison : max;
    writeln(r.take(max(a.length, b.length)));

Reply via email to