public static void Where_ArgumentNullException() { Assert.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).Where(x => x)); Assert.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).Where((x, index) => x)); Assert.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <bool>().Where((Func <bool, bool>)null)); Assert.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <bool>().Where((Func <bool, int, bool>)null)); }
public static void Select_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).Select(x => x)); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).Select((x, index) => x)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().Select((Func <bool, bool>)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().Select((Func <bool, int, bool>)null)); }
public static void Last_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).Last()); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).LastOrDefault()); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <int>().Last(null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <int>().LastOrDefault(null)); }
public static void Single_ArgumentNullException() { AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).Single()); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).SingleOrDefault()); AssertExtensions.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <int>().Single(null)); AssertExtensions.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <int>().SingleOrDefault(null)); }
public static void First_ArgumentNullException() { Assert.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).First()); Assert.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).FirstOrDefault()); Assert.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <int>().First(null)); Assert.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <int>().FirstOrDefault(null)); }
public static void Aggregate_InvalidOperationException() { Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Aggregate((i, j) => i)); // All other invocations return the seed value. Assert.Equal(-1, ParallelEnumerable.Empty <int>().Aggregate(-1, (i, j) => i + j)); Assert.Equal(-1, ParallelEnumerable.Empty <int>().Aggregate(-1, (i, j) => i + j, i => i)); Assert.Equal(-1, ParallelEnumerable.Empty <int>().Aggregate(-1, (i, j) => i + j, (i, j) => i + j, i => i)); Assert.Equal(-1, ParallelEnumerable.Empty <int>().Aggregate(() => - 1, (i, j) => i + j, (i, j) => i + j, i => i)); }
public static void CountLongCount_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).Count()); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).Count(x => x)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().Count(null)); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).LongCount()); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).LongCount(x => x)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().LongCount(null)); }
public static void CountLongCount_ArgumentNullException() { AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).Count()); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).Count(x => x)); AssertExtensions.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <bool>().Count(null)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).LongCount()); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).LongCount(x => x)); AssertExtensions.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <bool>().LongCount(null)); }
public static IEnumerable <object[]> EmptyData() { foreach (object[] query in UnorderedSources.Ranges(new[] { 0 })) { yield return(new object[] { query[0], 1 }); } yield return(new object[] { Labeled.Label("Empty-Int", ParallelEnumerable.Empty <int>()), 1 }); yield return(new object[] { Labeled.Label("Empty-Decimal", ParallelEnumerable.Empty <decimal>()), 1.5M }); yield return(new object[] { Labeled.Label("Empty-String", ParallelEnumerable.Empty <string>()), "default" }); }
public static void ToDictionary_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <int>)null).ToDictionary(x => x)); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <int>)null).ToDictionary(x => x, EqualityComparer <int> .Default)); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <int>)null).ToDictionary(x => x, y => y)); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <int>)null).ToDictionary(x => x, y => y, EqualityComparer <int> .Default)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <int>().ToDictionary((Func <int, int>)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <int>().ToDictionary((Func <int, int>)null, EqualityComparer <int> .Default)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <int>().ToDictionary((Func <int, int>)null, y => y)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <int>().ToDictionary((Func <int, int>)null, y => y, EqualityComparer <int> .Default)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <int>().ToDictionary(x => x, (Func <int, int>)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <int>().ToDictionary(x => x, (Func <int, int>)null, EqualityComparer <int> .Default)); }
static void PLinqEmpty() { Console.WriteLine("=== " + MethodInfo.GetCurrentMethod().Name + " ==="); var parallel = from p in ParallelEnumerable.Empty <int>() select new { Value = p, Thread.CurrentThread.ManagedThreadId }; foreach (var p in parallel) { Console.WriteLine("Number = {0}, ThreadId = {1}", p.Value, p.ManagedThreadId); } }
private static void Empty <T>() { Assert.Empty(ParallelEnumerable.Empty <T>()); Assert.False(ParallelEnumerable.Empty <T>().Any(x => true)); Assert.False(ParallelEnumerable.Empty <T>().Contains(default(T))); Assert.Equal(0, ParallelEnumerable.Empty <T>().Count()); Assert.Equal(0, ParallelEnumerable.Empty <T>().LongCount()); Assert.Equal(new T[0], ParallelEnumerable.Empty <T>().ToArray()); Assert.Equal(new Dictionary <T, T>(), ParallelEnumerable.Empty <T>().ToDictionary(x => x)); Assert.Equal(new List <T>(), ParallelEnumerable.Empty <T>().ToList()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <T>().First()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <T>().Last()); }
public static void ToLookup_ArgumentNullException() { AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).ToLookup(x => x)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).ToLookup(x => x, EqualityComparer <int> .Default)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).ToLookup(x => x, y => y)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <int>)null).ToLookup(x => x, y => y, EqualityComparer <int> .Default)); AssertExtensions.Throws <ArgumentNullException>("keySelector", () => ParallelEnumerable.Empty <int>().ToLookup((Func <int, int>)null)); AssertExtensions.Throws <ArgumentNullException>("keySelector", () => ParallelEnumerable.Empty <int>().ToLookup((Func <int, int>)null, EqualityComparer <int> .Default)); AssertExtensions.Throws <ArgumentNullException>("keySelector", () => ParallelEnumerable.Empty <int>().ToLookup((Func <int, int>)null, y => y)); AssertExtensions.Throws <ArgumentNullException>("keySelector", () => ParallelEnumerable.Empty <int>().ToLookup((Func <int, int>)null, y => y, EqualityComparer <int> .Default)); AssertExtensions.Throws <ArgumentNullException>("elementSelector", () => ParallelEnumerable.Empty <int>().ToLookup(x => x, (Func <int, int>)null)); AssertExtensions.Throws <ArgumentNullException>("elementSelector", () => ParallelEnumerable.Empty <int>().ToLookup(x => x, (Func <int, int>)null, EqualityComparer <int> .Default)); }
private Pair <IEnumerable <TElement>, TOrderKey> GetValueList(THashKey key) { TBaseElement baseValue = default(TBaseElement) !; if (_base.TryGetValue(key, ref baseValue !)) { return(CreateValuePair(baseValue)); } else { return(new Pair <IEnumerable <TElement>, TOrderKey>(ParallelEnumerable.Empty <TElement>(), EmptyValueKey)); } }
public static void SelectMany_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).SelectMany(x => new[] { x })); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).SelectMany((x, index) => new[] { x })); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().SelectMany((Func <bool, IEnumerable <bool> >)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().SelectMany((Func <bool, int, IEnumerable <bool> >)null)); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).SelectMany(x => new[] { x }, (x, y) => x)); Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).SelectMany((x, index) => new[] { x }, (x, y) => x)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().SelectMany((Func <bool, IEnumerable <bool> >)null, (x, y) => x)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().SelectMany((Func <bool, int, IEnumerable <bool> >)null, (x, y) => x)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().SelectMany(x => new[] { x }, (Func <bool, bool, bool>)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().SelectMany((x, index) => new[] { x }, (Func <bool, bool, bool>)null)); }
public static void SelectMany_ArgumentNullException() { AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).SelectMany(x => new[] { x })); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).SelectMany((x, index) => new[] { x })); AssertExtensions.Throws <ArgumentNullException>("selector", () => ParallelEnumerable.Empty <bool>().SelectMany((Func <bool, IEnumerable <bool> >)null)); AssertExtensions.Throws <ArgumentNullException>("selector", () => ParallelEnumerable.Empty <bool>().SelectMany((Func <bool, int, IEnumerable <bool> >)null)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).SelectMany(x => new[] { x }, (x, y) => x)); AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).SelectMany((x, index) => new[] { x }, (x, y) => x)); AssertExtensions.Throws <ArgumentNullException>("collectionSelector", () => ParallelEnumerable.Empty <bool>().SelectMany((Func <bool, IEnumerable <bool> >)null, (x, y) => x)); AssertExtensions.Throws <ArgumentNullException>("collectionSelector", () => ParallelEnumerable.Empty <bool>().SelectMany((Func <bool, int, IEnumerable <bool> >)null, (x, y) => x)); AssertExtensions.Throws <ArgumentNullException>("resultSelector", () => ParallelEnumerable.Empty <bool>().SelectMany(x => new[] { x }, (Func <bool, bool, bool>)null)); AssertExtensions.Throws <ArgumentNullException>("resultSelector", () => ParallelEnumerable.Empty <bool>().SelectMany((x, index) => new[] { x }, (Func <bool, bool, bool>)null)); }
public static void Max_InvalidOperationException() { Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Max()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <long>().Max()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <float>().Max()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <double>().Max()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <decimal>().Max()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <NotComparable>().Max()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Max(x => (int)x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Max(x => (long)x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Max(x => (float)x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Max(x => (double)x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Max(x => (decimal)x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Max(x => new NotComparable(x))); }
public static void Max_EmptyNullable() { Assert.Null(ParallelEnumerable.Empty <int?>().Max()); Assert.Null(ParallelEnumerable.Empty <long?>().Max()); Assert.Null(ParallelEnumerable.Empty <float?>().Max()); Assert.Null(ParallelEnumerable.Empty <double?>().Max()); Assert.Null(ParallelEnumerable.Empty <decimal?>().Max()); Assert.Null(ParallelEnumerable.Empty <object>().Max()); Assert.Null(ParallelEnumerable.Empty <int>().Max(x => (int?)x)); Assert.Null(ParallelEnumerable.Empty <int>().Max(x => (long?)x)); Assert.Null(ParallelEnumerable.Empty <int>().Max(x => (float?)x)); Assert.Null(ParallelEnumerable.Empty <int>().Max(x => (double?)x)); Assert.Null(ParallelEnumerable.Empty <int>().Max(x => (decimal?)x)); Assert.Null(ParallelEnumerable.Empty <int>().Max(x => new object())); }
public static void Min_InvalidOperationException() { Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Min()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Min(x => x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <long>().Min()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <long>().Min(x => x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <float>().Min()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <float>().Min(x => x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <double>().Min()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <double>().Min(x => x)); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <decimal>().Min()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <decimal>().Min(x => x)); // Nullables return null when empty Assert.Null(ParallelEnumerable.Empty <int?>().Min()); Assert.Null(ParallelEnumerable.Empty <int?>().Min(x => x)); Assert.Null(ParallelEnumerable.Empty <long?>().Min()); Assert.Null(ParallelEnumerable.Empty <long?>().Min(x => x)); Assert.Null(ParallelEnumerable.Empty <float?>().Min()); Assert.Null(ParallelEnumerable.Empty <float?>().Min(x => x)); Assert.Null(ParallelEnumerable.Empty <double?>().Min()); Assert.Null(ParallelEnumerable.Empty <double?>().Min(x => x)); Assert.Null(ParallelEnumerable.Empty <decimal?>().Min()); Assert.Null(ParallelEnumerable.Empty <decimal?>().Min(x => x)); }
public static void All_ArgumentNullException() { Assert.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).All(x => x)); Assert.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <bool>().All(null)); }
public static void Single_Empty() { Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Single()); Assert.Throws <InvalidOperationException>(() => ParallelEnumerable.Empty <int>().Single(x => true)); }
internal override bool MoveNext(ref TOutput currentElement, ref TLeftKey currentKey) { Mutables <TLeftInput, TLeftKey, TRightInput, THashKey, TOutput> mutables = this.m_mutables; if (mutables == null) { mutables = this.m_mutables = new Mutables <TLeftInput, TLeftKey, TRightInput, THashKey, TOutput>(); mutables.m_rightHashLookup = new HashLookup <THashKey, Pair <TRightInput, ListChunk <TRightInput> > >(this.m_keyComparer); Pair <TRightInput, THashKey> pair = new Pair <TRightInput, THashKey>(); int num = 0; int num2 = 0; while (this.m_rightSource.MoveNext(ref pair, ref num)) { if ((num2++ & 0x3f) == 0) { CancellationState.ThrowIfCanceled(this.m_cancellationToken); } TRightInput first = pair.First; THashKey second = pair.Second; if (second != null) { Pair <TRightInput, ListChunk <TRightInput> > pair2 = new Pair <TRightInput, ListChunk <TRightInput> >(); if (!mutables.m_rightHashLookup.TryGetValue(second, ref pair2)) { pair2 = new Pair <TRightInput, ListChunk <TRightInput> >(first, null); if (this.m_groupResultSelector != null) { pair2.Second = new ListChunk <TRightInput>(2); pair2.Second.Add(first); } mutables.m_rightHashLookup.Add(second, pair2); } else { if (pair2.Second == null) { pair2.Second = new ListChunk <TRightInput>(2); mutables.m_rightHashLookup[second] = pair2; } pair2.Second.Add(first); } } } } ListChunk <TRightInput> currentRightMatches = mutables.m_currentRightMatches; if ((currentRightMatches != null) && (mutables.m_currentRightMatchesIndex == currentRightMatches.Count)) { currentRightMatches = mutables.m_currentRightMatches = currentRightMatches.Next; mutables.m_currentRightMatchesIndex = 0; } if (mutables.m_currentRightMatches == null) { Pair <TLeftInput, THashKey> pair3 = new Pair <TLeftInput, THashKey>(); TLeftKey local3 = default(TLeftKey); while (this.m_leftSource.MoveNext(ref pair3, ref local3)) { if ((mutables.m_outputLoopCount++ & 0x3f) == 0) { CancellationState.ThrowIfCanceled(this.m_cancellationToken); } Pair <TRightInput, ListChunk <TRightInput> > pair4 = new Pair <TRightInput, ListChunk <TRightInput> >(); TLeftInput local4 = pair3.First; THashKey key = pair3.Second; if (((key != null) && mutables.m_rightHashLookup.TryGetValue(key, ref pair4)) && (this.m_singleResultSelector != null)) { mutables.m_currentRightMatches = pair4.Second; mutables.m_currentRightMatchesIndex = 0; currentElement = this.m_singleResultSelector(local4, pair4.First); currentKey = local3; if (pair4.Second != null) { mutables.m_currentLeft = local4; mutables.m_currentLeftKey = local3; } return(true); } if (this.m_groupResultSelector != null) { IEnumerable <TRightInput> enumerable = pair4.Second; if (enumerable == null) { enumerable = (IEnumerable <TRightInput>)ParallelEnumerable.Empty <TRightInput>(); } currentElement = this.m_groupResultSelector(local4, enumerable); currentKey = local3; return(true); } } return(false); } currentElement = this.m_singleResultSelector(mutables.m_currentLeft, mutables.m_currentRightMatches.m_chunk[mutables.m_currentRightMatchesIndex]); currentKey = mutables.m_currentLeftKey; mutables.m_currentRightMatchesIndex++; return(true); }
//--------------------------------------------------------------------------------------- // MoveNext implements all the hash-join logic noted earlier. When it is called first, it // will execute the entire inner query tree, and build a hash-table lookup. This is the // Building phase. Then for the first call and all subsequent calls to MoveNext, we will // incrementally perform the Probing phase. We'll keep getting elements from the outer // data source, looking into the hash-table we built, and enumerating the full results. // // This routine supports both inner and outer (group) joins. An outer join will yield a // (possibly empty) list of matching elements from the inner instead of one-at-a-time, // as we do for inner joins. // internal override bool MoveNext(ref TOutput currentElement, ref TLeftKey currentKey) { Contract.Assert(_singleResultSelector != null || _groupResultSelector != null, "expected a compiled result selector"); Contract.Assert(_leftSource != null); Contract.Assert(_rightSource != null); // BUILD phase: If we haven't built the hash-table yet, create that first. Mutables mutables = _mutables; if (mutables == null) { mutables = _mutables = new Mutables(); #if DEBUG int hashLookupCount = 0; int hashKeyCollisions = 0; #endif mutables._rightHashLookup = new HashLookup <THashKey, Pair>(_keyComparer); Pair rightPair = new Pair(default(TRightInput), default(THashKey)); int rightKeyUnused = default(int); int i = 0; while (_rightSource.MoveNext(ref rightPair, ref rightKeyUnused)) { if ((i++ & CancellationState.POLL_INTERVAL) == 0) { CancellationState.ThrowIfCanceled(_cancellationToken); } TRightInput rightElement = (TRightInput)rightPair.First; THashKey rightHashKey = (THashKey)rightPair.Second; // We ignore null keys. if (rightHashKey != null) { #if DEBUG hashLookupCount++; #endif // See if we've already stored an element under the current key. If not, we // lazily allocate a pair to hold the elements mapping to the same key. const int INITIAL_CHUNK_SIZE = 2; Pair currentValue = new Pair(default(TRightInput), default(ListChunk <TRightInput>)); if (!mutables._rightHashLookup.TryGetValue(rightHashKey, ref currentValue)) { currentValue = new Pair(rightElement, null); if (_groupResultSelector != null) { // For group joins, we also add the element to the list. This makes // it easier later to yield the list as-is. currentValue.Second = new ListChunk <TRightInput>(INITIAL_CHUNK_SIZE); ((ListChunk <TRightInput>)currentValue.Second).Add((TRightInput)rightElement); } mutables._rightHashLookup.Add(rightHashKey, currentValue); } else { if (currentValue.Second == null) { // Lazily allocate a list to hold all but the 1st value. We need to // re-store this element because the pair is a value type. currentValue.Second = new ListChunk <TRightInput>(INITIAL_CHUNK_SIZE); mutables._rightHashLookup[rightHashKey] = currentValue; } ((ListChunk <TRightInput>)currentValue.Second).Add((TRightInput)rightElement); #if DEBUG hashKeyCollisions++; #endif } } } #if DEBUG TraceHelpers.TraceInfo("ParallelJoinQueryOperator::MoveNext - built hash table [count = {0}, collisions = {1}]", hashLookupCount, hashKeyCollisions); #endif } // PROBE phase: So long as the source has a next element, return the match. ListChunk <TRightInput> currentRightChunk = mutables._currentRightMatches; if (currentRightChunk != null && mutables._currentRightMatchesIndex == currentRightChunk.Count) { currentRightChunk = mutables._currentRightMatches = currentRightChunk.Next; mutables._currentRightMatchesIndex = 0; } if (mutables._currentRightMatches == null) { // We have to look up the next list of matches in the hash-table. Pair leftPair = new Pair(default(TLeftInput), default(THashKey)); TLeftKey leftKey = default(TLeftKey); while (_leftSource.MoveNext(ref leftPair, ref leftKey)) { if ((mutables._outputLoopCount++ & CancellationState.POLL_INTERVAL) == 0) { CancellationState.ThrowIfCanceled(_cancellationToken); } // Find the match in the hash table. Pair matchValue = new Pair(default(TRightInput), default(ListChunk <TRightInput>)); TLeftInput leftElement = (TLeftInput)leftPair.First; THashKey leftHashKey = (THashKey)leftPair.Second; // Ignore null keys. if (leftHashKey != null) { if (mutables._rightHashLookup.TryGetValue(leftHashKey, ref matchValue)) { // We found a new match. For inner joins, we remember the list in case // there are multiple value under this same key -- the next iteration will pick // them up. For outer joins, we will use the list momentarily. if (_singleResultSelector != null) { mutables._currentRightMatches = (ListChunk <TRightInput>)matchValue.Second; Contract.Assert(mutables._currentRightMatches == null || mutables._currentRightMatches.Count > 0, "we were expecting that the list would be either null or empty"); mutables._currentRightMatchesIndex = 0; // Yield the value. currentElement = _singleResultSelector(leftElement, (TRightInput)matchValue.First); currentKey = leftKey; // If there is a list of matches, remember the left values for next time. if (matchValue.Second != null) { mutables._currentLeft = leftElement; mutables._currentLeftKey = leftKey; } return(true); } } } // For outer joins, we always yield a result. if (_groupResultSelector != null) { // Grab the matches, or create an empty list if there are none. IEnumerable <TRightInput> matches = (ListChunk <TRightInput>)matchValue.Second; if (matches == null) { matches = ParallelEnumerable.Empty <TRightInput>(); } // Generate the current value. currentElement = _groupResultSelector(leftElement, matches); currentKey = leftKey; return(true); } } // If we've reached the end of the data source, we're done. return(false); } // Produce the next element and increment our index within the matches. Contract.Assert(_singleResultSelector != null); Contract.Assert(mutables._currentRightMatches != null); Contract.Assert(0 <= mutables._currentRightMatchesIndex && mutables._currentRightMatchesIndex < mutables._currentRightMatches.Count); currentElement = _singleResultSelector( mutables._currentLeft, mutables._currentRightMatches._chunk[mutables._currentRightMatchesIndex]); currentKey = mutables._currentLeftKey; mutables._currentRightMatchesIndex++; return(true); }
public static void Any_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).Any(x => x)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().Any(null)); }
public static void TakeWhile_ArgumentNullException() { Assert.Throws <ArgumentNullException>(() => ((ParallelQuery <bool>)null).TakeWhile(x => true)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().TakeWhile((Func <bool, bool>)null)); Assert.Throws <ArgumentNullException>(() => ParallelEnumerable.Empty <bool>().TakeWhile((Func <bool, int, bool>)null)); }
public static void SkipWhile_ArgumentNullException() { AssertExtensions.Throws <ArgumentNullException>("source", () => ((ParallelQuery <bool>)null).SkipWhile(x => true)); AssertExtensions.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <bool>().SkipWhile((Func <bool, bool>)null)); AssertExtensions.Throws <ArgumentNullException>("predicate", () => ParallelEnumerable.Empty <bool>().SkipWhile((Func <bool, int, bool>)null)); }