Exemple #1
0
        public override Yield Start()
        {
            var mergeSorter = new MergeSorter();

            mergeSorter.Send(new MergeSortMessage {
                Caller = this, Items = Items
            });

            Spawn(mergeSorter);

            return(Receive(m => {
                Results = m.Items;
                return null;
            }));
        }
Exemple #2
0
        public override Yield Start()
        {
            return(Receive(qs => {
                if (qs.Items.Length <= 1)
                {
                    qs.Caller.Send(new MergeSortMessage {
                        Items = qs.Items
                    });
                    return null;
                }
                else
                {
                    int split = qs.Items.Length / 2;
                    int[] first = qs.Items.Take(split).ToArray();
                    int[] second = qs.Items.Skip(split).ToArray();

                    var firstProcess = new MergeSorter();
                    firstProcess.Send(new MergeSortMessage {
                        Caller = this, Items = first
                    });
                    Spawn(firstProcess);
                    var secondProcess = new MergeSorter();
                    secondProcess.Send(new MergeSortMessage {
                        Caller = this, Items = second
                    });
                    Spawn(secondProcess);

                    return Receive(result1 => Receive(result2 => {
                        qs.Caller.Send(new MergeSortMessage {
                            Items = Merge(result1.Items, result2.Items)
                        });
                        return null;
                    }));
                }
            }));
        }