public IEnumerable <T> GetValuesAndReturnArray <T>(DataColumnStatistics statistics, IEqualityComparer <T> equalityComparer, IComparer <T> comparer) { AssertNotConsumed(); T[] typed = (T[])_array; if (statistics == null) { for (int i = 0; i < Count; i++) { yield return(typed[i]); } ReturnArray(); yield break; } // there's a big win here if you can use the ctor from NET Standard 2.1 that has a capacity, which avoids GC overhead of resize #if NETSTANDARD2_1 HashSet <T> hashSet = new HashSet <T>(Count, equalityComparer); #else HashSet <T> hashSet = new HashSet <T>(equalityComparer); #endif T min = default; T max = default; for (int i = 0; i < Count; i++) { T current = typed[i]; yield return(current); hashSet.Add(current); if (i == 0) { min = current; max = current; } else { int cmin = comparer.Compare(min, current); int cmax = comparer.Compare(max, current); if (cmin > 0) { min = current; } if (cmax < 0) { max = current; } } } statistics.MinValue = min; statistics.MaxValue = max; statistics.DistinctCount = hashSet.Count; ReturnArray(); _consumed = true; }
public void Write(Thrift.SchemaElement tse, BinaryWriter writer, ArrayView values, DataColumnStatistics statistics) { throw new NotSupportedException(); }
public virtual void Write(Thrift.SchemaElement tse, BinaryWriter writer, ArrayView values, DataColumnStatistics statistics) { foreach (TSystemType one in values.GetValuesAndReturnArray(statistics, this, this)) { WriteOne(writer, one); } }
public virtual void Write(Thrift.SchemaElement tse, BinaryWriter writer, IList values, DataColumnStatistics statistics) { // casing to an array of TSystemType means we avoid Array.GetValue calls, which are slow var typedArray = (TSystemType[])values; foreach (TSystemType one in typedArray) { WriteOne(writer, one); } // calculate statistics if required if (statistics != null) { //number of distinct values statistics.DistinctCount = ((TSystemType[])values).Distinct(this).Count(); TSystemType min = default; TSystemType max = default; for (int i = 0; i < typedArray.Length; i++) { if (i == 0) { min = typedArray[0]; max = typedArray[0]; } else { TSystemType current = typedArray[i]; int cmin = Compare(min, current); int cmax = Compare(max, current); if (cmin > 0) { min = current; } if (cmax < 0) { max = current; } } } statistics.MinValue = min; statistics.MaxValue = max; } }