Created
March 4, 2016 03:39
-
-
Save neuecc/3502484809b7a7871ff9 to your computer and use it in GitHub Desktop.
ToDictionaryBatching
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| public static class DictionaryPerfomanceExtensions | |
| { | |
| public static void ToDictionaryBatching<T, TKey1>(this T[] array, | |
| Func<T, TKey1> keySelector1, out Dictionary<TKey1, T> dictionary1 | |
| ) | |
| { | |
| dictionary1 = new Dictionary<TKey1, T>(array.Length); | |
| for (int i = 0; i < array.Length; i++) | |
| { | |
| dictionary1.Add(keySelector1(array[i]), array[i]); | |
| } | |
| } | |
| public static void ToDictionaryBatching<T, TKey1, TKey2>(this T[] array, | |
| Func<T, TKey1> keySelector1, out Dictionary<TKey1, T> dictionary1, | |
| Func<T, TKey2> keySelector2, out Dictionary<TKey2, T> dictionary2 | |
| ) | |
| { | |
| dictionary1 = new Dictionary<TKey1, T>(array.Length); | |
| dictionary2 = new Dictionary<TKey2, T>(array.Length); | |
| for (int i = 0; i < array.Length; i++) | |
| { | |
| dictionary1.Add(keySelector1(array[i]), array[i]); | |
| dictionary2.Add(keySelector2(array[i]), array[i]); | |
| } | |
| } | |
| public static void ToDictionaryBatching<T, TKey1, TKey2, TKey3>(this T[] array, | |
| Func<T, TKey1> keySelector1, out Dictionary<TKey1, T> dictionary1, | |
| Func<T, TKey2> keySelector2, out Dictionary<TKey2, T> dictionary2, | |
| Func<T, TKey3> keySelector3, out Dictionary<TKey3, T> dictionary3 | |
| ) | |
| { | |
| dictionary1 = new Dictionary<TKey1, T>(array.Length); | |
| dictionary2 = new Dictionary<TKey2, T>(array.Length); | |
| dictionary3 = new Dictionary<TKey3, T>(array.Length); | |
| for (int i = 0; i < array.Length; i++) | |
| { | |
| dictionary1.Add(keySelector1(array[i]), array[i]); | |
| dictionary2.Add(keySelector2(array[i]), array[i]); | |
| dictionary3.Add(keySelector3(array[i]), array[i]); | |
| } | |
| } | |
| public static void ToDictionaryBatching<T, TKey1, TKey2, TKey3, TKey4>(this T[] array, | |
| Func<T, TKey1> keySelector1, out Dictionary<TKey1, T> dictionary1, | |
| Func<T, TKey2> keySelector2, out Dictionary<TKey2, T> dictionary2, | |
| Func<T, TKey3> keySelector3, out Dictionary<TKey3, T> dictionary3, | |
| Func<T, TKey4> keySelector4, out Dictionary<TKey4, T> dictionary4 | |
| ) | |
| { | |
| dictionary1 = new Dictionary<TKey1, T>(array.Length); | |
| dictionary2 = new Dictionary<TKey2, T>(array.Length); | |
| dictionary3 = new Dictionary<TKey3, T>(array.Length); | |
| dictionary4 = new Dictionary<TKey4, T>(array.Length); | |
| for (int i = 0; i < array.Length; i++) | |
| { | |
| dictionary1.Add(keySelector1(array[i]), array[i]); | |
| dictionary2.Add(keySelector2(array[i]), array[i]); | |
| dictionary3.Add(keySelector3(array[i]), array[i]); | |
| dictionary4.Add(keySelector4(array[i]), array[i]); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment