示例#1
0
        internal void MergeDictionaries <TK, TV, TNv>(Reducer <TK, TV, TNv> reducer, IDictionary from)
        {
            if (from.GetType() != ReduceResult.GetType())
            {
                return;
            }

            var fromtyped = ((IDictionary <TK, TNv>)from);

            foreach (var kv in fromtyped)
            {
                if (kv.Value is IEnumerable)
                {
                    foreach (var subitem in kv.Value as IEnumerable)
                    {
                        var pos      = ((CustomDictionary <TK, TNv>)ReduceResult).InitOrGetPosition((TK)kv.Key);
                        var value    = ((CustomDictionary <TK, TNv>)ReduceResult).GetAtPosition(pos);
                        var newvalue = reducer.Reduce((TK)kv.Key, (TV)subitem, value);
                        ((CustomDictionary <TK, TNv>)ReduceResult).StoreAtPosition(pos, newvalue);
                    }
                }
                else
                {
                    var pos      = ((CustomDictionary <TK, TNv>)ReduceResult).InitOrGetPosition((TK)kv.Key);
                    var value    = ((CustomDictionary <TK, TNv>)ReduceResult).GetAtPosition(pos);
                    var newvalue = reducer.Reduce(kv.Key, (TV)(object)kv.Value, value);
                    ((CustomDictionary <TK, TNv>)ReduceResult).StoreAtPosition(pos, newvalue);
                }
            }

            from.Clear();
        }
        internal void MergeDictionaries <K, V, NV>(Reducer <K, V, NV> reducer, IDictionary from)
        {
            if (from.GetType() != ReduceResult.GetType())
            {
                return;
            }

            IDictionary <K, NV> fromtyped = ((IDictionary <K, NV>)from);

            foreach (var kv in fromtyped)
            {
                if (kv.Value is IEnumerable)
                {
                    foreach (var subitem in kv.Value as IEnumerable)
                    {
                        int pos      = ((CustomDictionary <K, NV>)ReduceResult).InitOrGetPosition((K)kv.Key);
                        NV  value    = ((CustomDictionary <K, NV>)ReduceResult).GetAtPosition(pos);
                        NV  newvalue = reducer.Reduce((K)kv.Key, (V)subitem, value);
                        ((CustomDictionary <K, NV>)ReduceResult).StoreAtPosition(pos, newvalue);
                    }
                }
                else
                {
                    int pos      = ((CustomDictionary <K, NV>)ReduceResult).InitOrGetPosition((K)kv.Key);
                    NV  value    = ((CustomDictionary <K, NV>)ReduceResult).GetAtPosition(pos);
                    NV  newvalue = reducer.Reduce(kv.Key, (V)(object)kv.Value, value);
                    ((CustomDictionary <K, NV>)ReduceResult).StoreAtPosition(pos, newvalue);
                }
            }

            from.Clear();
        }