public void PopTestHelper <K, V>(K key, V value)
        {
            CircularArray <K, V> target = new CircularArray <K, V>();

            target.Push(key, value);

            Assert.IsTrue(target.HasNext);
            Assert.IsTrue(target.Pop(out key, out value));

            Assert.IsFalse(target.HasNext);
            Assert.IsFalse(target.Pop(out key, out value));
        }
Example #2
0
        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);
        }