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(); }
private void Reduce <TNk, TNv, TRnv>( Reducer <TNk, TNv, TRnv> reducer, CircularArray <TNk, TNv> dictMap, IDictionary <TNk, TRnv> dictRed) { reducer.Parameters = this.Parameters; while (dictMap.MapInProgress || dictMap.HasNext) { while (PartialSaveInProgress) // a short save and we continue { Thread.Sleep(100); } TNk key; TNv val; if (!dictMap.Pop(out key, out val)) { Thread.Sleep(1); continue; } var pos = ((CustomDictionary <TNk, TRnv>)dictRed).InitOrGetPosition(key); var reducedValue = ((CustomDictionary <TNk, TRnv>)dictRed).GetAtPosition(pos); var newReducedValue = reducer.Reduce(key, val, reducedValue); ((CustomDictionary <TNk, TRnv>)dictRed).StoreAtPosition(pos, newReducedValue); } reducer.BeforeSave(dictRed); }
private void Reduce <NK, NV, RNV>(Reducer <NK, NV, RNV> reducer, CircularArray <NK, NV> dictMap, IDictionary <NK, RNV> dictRed) { reducer.Parameters = this.Parameters; NK key; NV val; //int reduceTooFastCount = 0; while (dictMap.MapInProgress || dictMap.HasNext) { while (PartialSaveInProgress) // a short save and we continue { Thread.Sleep(100); } if (!dictMap.Pop(out key, out val)) { Thread.Sleep(1); continue; } int pos = ((CustomDictionary <NK, RNV>)dictRed).InitOrGetPosition(key); RNV reducedValue = ((CustomDictionary <NK, RNV>)dictRed).GetAtPosition(pos); RNV newReducedValue = reducer.Reduce(key, val, reducedValue); ((CustomDictionary <NK, RNV>)dictRed).StoreAtPosition(pos, newReducedValue); } reducer.BeforeSave(dictRed); }