9 [global::__DynamicallyInvokable]
16 internal int hashCode;
18 internal TElement[] elements;
22 internal Grouping hashNext;
24 internal Grouping next;
26 public TKey Key => key;
48 if (index < 0 || index >= count)
50 throw Error.ArgumentOutOfRange(
"index");
52 return elements[index];
56 throw Error.NotSupported();
60 internal void Add(TElement element)
62 if (elements.Length == count)
64 Array.Resize(ref elements, checked(count * 2));
66 elements[count] = element;
72 for (
int i = 0; i < count; i++)
74 yield
return elements[i];
85 throw Error.NotSupported();
90 throw Error.NotSupported();
95 return Array.IndexOf(elements, item, 0, count) >= 0;
100 Array.
Copy(elements, 0, array, arrayIndex, count);
105 throw Error.NotSupported();
110 return Array.IndexOf(elements, item, 0, count);
115 throw Error.NotSupported();
120 throw Error.NotSupported();
126 private Grouping[] groupings;
128 private Grouping lastGrouping;
134 [global::__DynamicallyInvokable]
137 [global::__DynamicallyInvokable]
147 [global::__DynamicallyInvokable]
150 [global::__DynamicallyInvokable]
153 Grouping grouping = GetGrouping(key, create:
false);
154 if (grouping !=
null)
158 return EmptyEnumerable<TElement>.Instance;
166 throw Error.ArgumentNull(
"source");
168 if (keySelector ==
null)
170 throw Error.ArgumentNull(
"keySelector");
172 if (elementSelector ==
null)
174 throw Error.ArgumentNull(
"elementSelector");
176 Lookup<TKey, TElement> lookup =
new Lookup<TKey, TElement>(comparer);
177 foreach (TSource item
in source)
179 lookup.GetGrouping(keySelector(item), create:
true).Add(elementSelector(item));
186 Lookup<TKey, TElement> lookup =
new Lookup<TKey, TElement>(comparer);
187 foreach (TElement item
in source)
189 TKey val = keySelector(item);
192 lookup.GetGrouping(val, create:
true).Add(item);
200 if (comparer ==
null)
204 this.comparer = comparer;
205 groupings =
new Grouping[7];
212 [global::__DynamicallyInvokable]
215 return GetGrouping(key, create:
false) !=
null;
220 [global::__DynamicallyInvokable]
223 Grouping g = lastGrouping;
231 while (g != lastGrouping);
239 [global::__DynamicallyInvokable]
242 Grouping g = lastGrouping;
250 if (g.count != g.elements.Length)
252 Array.Resize(ref g.elements, g.count);
254 yield
return resultSelector(g.key, g.elements);
256 while (g != lastGrouping);
261 [global::__DynamicallyInvokable]
267 internal int InternalGetHashCode(TKey key)
276 internal Grouping GetGrouping(TKey key,
bool create)
278 int num = InternalGetHashCode(key);
279 for (Grouping grouping = groupings[num % groupings.Length]; grouping !=
null; grouping = grouping.hashNext)
281 if (grouping.hashCode == num && comparer.
Equals(grouping.key, key))
288 if (count == groupings.Length)
292 int num2 = num % groupings.Length;
293 Grouping grouping2 =
new Grouping();
295 grouping2.hashCode = num;
296 grouping2.elements =
new TElement[1];
297 grouping2.hashNext = groupings[num2];
298 groupings[num2] = grouping2;
299 if (lastGrouping ==
null)
301 grouping2.next = grouping2;
305 grouping2.next = lastGrouping.next;
306 lastGrouping.next = grouping2;
308 lastGrouping = grouping2;
315 private void Resize()
317 int num = checked(count * 2 + 1);
318 Grouping[] array =
new Grouping[num];
319 Grouping next = lastGrouping;
323 int num2 = next.hashCode % num;
324 next.hashNext = array[num2];
327 while (next != lastGrouping);
Provides a base class for implementations of the T:System.Collections.Generic.IEqualityComparer`1 gen...
Represents a non-generic collection of objects that can be individually accessed by index.
void RemoveAt(int index)
Removes the T:System.Collections.IList item at the specified index.
void Insert(int index, object value)
Inserts an item to the T:System.Collections.IList at the specified index.
IEnumerable< TResult > ApplyResultSelector< TResult >(Func< TKey, IEnumerable< TElement >, TResult > resultSelector)
Applies a transform function to each key and its associated values and returns the results.
IEnumerator< IGrouping< TKey, TElement > > GetEnumerator()
Returns a generic enumerator that iterates through the T:System.Linq.Lookup`2.
int IndexOf(object value)
Determines the index of a specific item in the T:System.Collections.IList.
Represents a collection of objects that have a common key.
static EqualityComparer< T > Default
Returns a default equality comparer for the type specified by the generic argument.
Exposes an enumerator, which supports a simple iteration over a non-generic collection....
new bool Equals(object x, object y)
Determines whether the specified objects are equal.
Provides methods for creating, manipulating, searching, and sorting arrays, thereby serving as the ba...
Defines an indexer, size property, and Boolean search method for data structures that map keys to T:S...
Represents a collection of keys each mapped to one or more values.
IEnumerator GetEnumerator()
Returns an enumerator that iterates through a collection.
int GetHashCode(object obj)
Returns a hash code for the specified object.
static void Copy(Array sourceArray, Array destinationArray, int length)
Copies a range of elements from an T:System.Array starting at the first element and pastes them into ...
int Count
Gets the number of key/value collection pairs in the T:System.Linq.Lookup`2.
int Count
Gets the number of elements contained in the T:System.Collections.ICollection.
Defines size, enumerators, and synchronization methods for all nongeneric collections.
void CopyTo(Array array, int index)
Copies the elements of the T:System.Collections.ICollection to an T:System.Array, starting at a parti...
bool Contains(TKey key)
Determines whether a specified key is in the T:System.Linq.Lookup`2.