public static IEnumerable <Slice> EncodeRange <T>(this IValueEncoder <T> encoder, [NotNull] IEnumerable <T> values) { if (encoder == null) { throw new ArgumentNullException("encoder"); } if (values == null) { throw new ArgumentNullException("values"); } // note: T=>Slice usually is used for writing batches as fast as possible, which means that keys will be consumed immediately and don't need to be streamed var array = values as T[]; if (array != null) { // optimized path for arrays return(EncodeRange <T>(encoder, array)); } var coll = values as ICollection <T>; if (coll != null) { // optimized path when we know the count var slices = new List <Slice>(coll.Count); foreach (var value in coll) { slices.Add(encoder.EncodeValue(value)); } return(slices); } return(values.Select(value => encoder.EncodeValue(value))); }
public static IEnumerable <TStorage> SelectValues <TValue, TStorage, TAny>([NotNull] this IValueEncoder <TValue, TStorage> encoder, [NotNull] IEnumerable <KeyValuePair <TAny, TValue> > items) { Contract.NotNull(encoder, nameof(encoder)); Contract.NotNull(items, nameof(items)); return(items.Select(item => encoder.EncodeValue(item.Value))); }
public static IEnumerable <TStorage> SelectValues <TValue, TStorage, TElement>([NotNull] this IValueEncoder <TValue, TStorage> encoder, [NotNull] IEnumerable <TElement> items, [NotNull] Func <TElement, TValue> selector) { Contract.NotNull(encoder, nameof(encoder)); Contract.NotNull(items, nameof(items)); Contract.NotNull(selector, nameof(selector)); return(items.Select(item => encoder.EncodeValue(selector(item)))); }
public static List <TStorage> EncodeValues <TValue, TStorage, TElement>([NotNull] this IValueEncoder <TValue, TStorage> encoder, [NotNull, InstantHandle] IEnumerable <TElement> items, [NotNull, InstantHandle] Func <TElement, TValue> selector) { Contract.NotNull(encoder, nameof(encoder)); Contract.NotNull(items, nameof(items)); Contract.NotNull(selector, nameof(selector)); if (items is ICollection <TElement> coll) { var res = new List <TStorage>(coll.Count); foreach (var item in items) { res.Add(encoder.EncodeValue(selector(item))); } return(res); } return(items.Select(item => encoder.EncodeValue(selector(item))).ToList()); }
public static TStorage[] EncodeValues <TValue, TStorage>([NotNull] this IValueEncoder <TValue, TStorage> encoder, [NotNull] params TValue[] values) { Contract.NotNull(encoder, nameof(encoder)); Contract.NotNull(values, nameof(values)); var slices = new TStorage[values.Length]; for (int i = 0; i < values.Length; i++) { slices[i] = encoder.EncodeValue(values[i]); } return(slices); }
public static IEnumerable <Slice> EncodeValues <T>([NotNull] this IValueEncoder <T> encoder, [NotNull] IEnumerable <T> values) { Contract.NotNull(encoder, nameof(encoder)); Contract.NotNull(values, nameof(values)); // note: T=>Slice usually is used for writing batches as fast as possible, which means that keys will be consumed immediately and don't need to be streamed if (values is T[] array) { // optimized path for arrays return(EncodeValues <T>(encoder, array)); } if (values is ICollection <T> coll) { // optimized path when we know the count var slices = new List <Slice>(coll.Count); foreach (var value in coll) { slices.Add(encoder.EncodeValue(value)); } return(slices); } return(values.Select(value => encoder.EncodeValue(value))); }
public static List <TStorage> EncodeValues <TValue, TStorage>([NotNull] this IValueEncoder <TValue, TStorage> encoder, [NotNull, InstantHandle] IEnumerable <TValue> values) { Contract.NotNull(encoder, nameof(encoder)); Contract.NotNull(values, nameof(values)); if (values is ICollection <TValue> coll) { var res = new List <TStorage>(coll.Count); foreach (var value in values) { res.Add(encoder.EncodeValue(value)); } return(res); } return(values.Select(encoder.EncodeValue).ToList()); }
public static Slice[] EncodeRange <T>(this IValueEncoder <T> encoder, [NotNull] T[] values) { if (encoder == null) { throw new ArgumentNullException("encoder"); } if (values == null) { throw new ArgumentNullException("values"); } var slices = new Slice[values.Length]; for (int i = 0; i < values.Length; i++) { slices[i] = encoder.EncodeValue(values[i]); } return(slices); }