Esempio n. 1
0
        static void TestOrdersByProductParallel()
        {
            int count = 100;

            // Los datos de entrada
            var data = OrdersByProduct
                       .Samples(count);

            // Asociamos los datos con la regla de combinación
            var input = data
                        .Select(x => new OrdersByProductMonoid(x) as Monoid <OrdersByProduct>)
                        .ToArray();

            // Reducción secuencial
            var seqRes = input.Aggregate(OrdersByProductMonoid.Empty, (a, b) => a * b);

            Console.WriteLine("seqRes: {0}", seqRes);

            // Reducción en paralelo
            // Ejemplo ilustrativo, pueden ser varios servidores.
            var parRes = input.AsParallel().Aggregate(OrdersByProductMonoid.Empty, (a, b) => a * b);

            Console.WriteLine("parRes: {0}", parRes);
            Console.WriteLine("seqRes == parRes: {0}", seqRes == parRes);
            Console.WriteLine();
        }
Esempio n. 2
0
        public override bool Equals(object obj)
        {
            if (obj == null)
            {
                return(false);
            }
            if (!(obj is OrdersByProduct))
            {
                return(false);
            }
            OrdersByProduct other      = (OrdersByProduct)obj;
            var             otherItems = other.Items;

            foreach (var pair in this.Items)
            {
                HashSet <Order> otherOrders;
                if (!otherItems.TryGetValue(pair.Key, out otherOrders))
                {
                    return(false);
                }
                if (!otherOrders.SetEquals(pair.Value))
                {
                    return(false);
                }
            }
            return(true);
        }