using MemoryPools.Collections.Specialized; using System; using System.Collections.Generic; namespace MemoryPools.Collections.Linq { public static partial class PoolingEnumerable { public static PoolingList AsPoolingList(this IEnumerable source) { var collection = Pool>.Get().Init(); collection.AddRange(source); return collection; } public static PoolingList AsPoolingList(this IPoolingEnumerable source) { var collection = Pool>.Get().Init(); collection.AddRange(source); return collection; } public static PoolingDictionary AsPoolingDictionary(this IEnumerable> source) { return AsPoolingDictionary(source.AsPooling()); } public static PoolingDictionary AsPoolingDictionary(this IPoolingEnumerable> source) { var collection = Pool>.Get().Init(); collection.AddRange(source); return collection; } public static PoolingDictionary AsPoolingDictionary(this IEnumerable source, Func keySelector, Func valueSelector) { return AsPoolingDictionary(source.AsPooling(), keySelector, valueSelector); } public static PoolingDictionary AsPoolingDictionary(this IPoolingEnumerable source, Func keySelector, Func valueSelector) { var collection = Pool>.Get().Init(); collection.AddRange( source .Select((keySelector, valueSelector), (ctx, x) => new KeyValuePair(ctx.keySelector(x), ctx.valueSelector(x))) ); return collection; } public static void AddRange(this PoolingList target, IEnumerable src) { foreach (var item in src) { target.Add(item); } } public static void AddRange(this PoolingList target, IPoolingEnumerable src) { foreach (var item in src) { target.Add(item); } } public static void AddRange(this PoolingDictionary target, IEnumerable> src) { foreach (var item in src) { target.Add(item.Key, item.Value); } } public static void AddRange(this PoolingDictionary target, IPoolingEnumerable> src) { foreach (var item in src) { target.Add(item.Key, item.Value); } } public static void AddRangeSafe(this PoolingDictionary target, IEnumerable> src) { foreach (var item in src) { target[item.Key] = item.Value; } } public static void AddRangeSafe(this PoolingDictionary target, IPoolingEnumerable> src) { foreach (var item in src) { target[item.Key] = item.Value; } } } }