private static void AddToList <T>(IList <T> storage, T item, Func <T, T, bool> filter) { if (Enumerable.Count(Processor.Where(storage, delegate(T i) { return(filter(i, item)); })) == 0) { storage.Add(item); } }
public static void WriterAsReadOnlyCollection() { using var writer = new PooledArrayBufferWriter <int>(); IReadOnlyList <int> collection = writer; Empty(collection); writer.Add(42); Equal(1, writer.WrittenCount); Equal(1, collection.Count); Equal(42, collection[0]); Throws <IndexOutOfRangeException>(() => collection[1]); Equal(42, Enumerable.First(collection)); Equal(1, Enumerable.Count(collection)); writer.AddAll(new[] { 43, 44 }); Equal(3, writer.WrittenCount); Equal(3, collection.Count); Equal(42, collection[0]); Equal(43, collection[1]); Equal(44, collection[2]); Throws <IndexOutOfRangeException>(() => collection[3]); Equal(3, Enumerable.Count(collection)); Equal(new[] { 42, 43, 44 }, Enumerable.ToArray(collection)); }
protected string GetWithClause(IEnumerable <ProviderPropertyExpression> properties) { bool withNoLock = GetProviderPropertyValue <WithNoLockExpression, bool>(properties, false); IEnumerable <string> indexNames = GetProviderPropertyValue <IndexNamesExpression, IEnumerable <string> >( properties, new string[] { }); bool forceIndex = Enumerable.Count(indexNames) > 0 && GetProviderPropertyValue <ForceIndexExpression, bool>(properties, false); if (!withNoLock && !forceIndex) { return(String.Empty); } if (withNoLock && !forceIndex) { return(" WITH(NOLOCK) "); } if (forceIndex && !withNoLock) { return(string.Format(" WITH(INDEX({0})) ", string.Join(",", Enumerable.ToArray(indexNames)))); } return(string.Format(" WITH(NOLOCK,INDEX({0})) ", string.Join(",", Enumerable.ToArray(indexNames)))); }
private void Source2CollectionChanged(object sender, NotifyCollectionChangedEventArgs e) { int sourceCount = SL.Count(source); switch (e.Action) { case NotifyCollectionChangedAction.Add: e = new NotifyCollectionChangedEventArgs(e.Action, e.NewItems, sourceCount + e.NewStartingIndex); break; case NotifyCollectionChangedAction.Move: e = new NotifyCollectionChangedEventArgs(e.Action, e.NewItems, sourceCount + e.NewStartingIndex, sourceCount + e.OldStartingIndex); break; case NotifyCollectionChangedAction.Remove: e = new NotifyCollectionChangedEventArgs(e.Action, e.OldItems, sourceCount + e.OldStartingIndex); break; case NotifyCollectionChangedAction.Replace: e = new NotifyCollectionChangedEventArgs(e.Action, e.NewItems, e.OldItems, sourceCount + e.OldStartingIndex); break; case NotifyCollectionChangedAction.Reset: OnCleared(); return; default: throw new InvalidOperationException(); } OnCollectionChanged(e); }
public static void WriterAsList() { using var writer = new PooledArrayBufferWriter <int>(); IList <int> list = writer; False(list.IsReadOnly); Empty(writer); True(list.IndexOf(0) < 0); False(list.Contains(0)); False(list.Remove(0)); Throws <ArgumentOutOfRangeException>(() => list.RemoveAt(0)); list.Add(42); Equal(1, writer.WrittenCount); Equal(1, list.Count); Equal(42, list[0]); True(list.Contains(42)); False(list.Contains(0)); Equal(0, list.IndexOf(42)); Throws <ArgumentOutOfRangeException>(() => list[1]); Equal(42, Enumerable.First(list)); Equal(1, Enumerable.Count(list)); list[0] = 10; Equal(10, writer.WrittenArray[0]); list.Insert(0, 42); Equal(2, writer.WrittenCount); Equal(2, list.Count); True(list.Contains(10)); True(list.Contains(42)); Equal(0, list.IndexOf(42)); Equal(1, list.IndexOf(10)); Equal(42, list[0]); Equal(10, list[1]); list.RemoveAt(0); Equal(1, writer.WrittenCount); Equal(1, list.Count); Equal(10, list[0]); True(list.Contains(10)); False(list.Contains(42)); True(list.Remove(10)); Empty(list); Throws <ArgumentOutOfRangeException>(() => list.Insert(1, 56)); list.Insert(0, 56); Equal(1, writer.WrittenCount); Equal(1, list.Count); Equal(56, list[0]); //check insertion with overflow for (var i = writer.Capacity; i > 0; i--) { list.Insert(0, i + 100); } }
public override INotificationResult Notify(IList <INotificationResult> sources) { var notification = CollectionChangedNotificationResult <TSource> .Create(this); var added = notification.AddedItems; var removed = notification.RemovedItems; var moved = notification.MovedItems; foreach (ICollectionChangedNotificationResult change in sources) { if (change.IsReset) { OnCleared(); notification.TurnIntoReset(); return(notification); } var offset = change.Source == source ? 0 : SL.Count(source); if (change.AddedItems != null) { added.AddRange(SL.Cast <TSource>(change.AddedItems)); if (change.NewItemsStartIndex != -1) { notification.UpdateNewStartIndex(offset + change.NewItemsStartIndex); } } if (change.RemovedItems != null) { removed.AddRange(SL.Cast <TSource>(change.RemovedItems)); if (change.OldItemsStartIndex != -1) { notification.UpdateOldStartIndex(offset + change.OldItemsStartIndex); } } if (change.MovedItems != null) { moved.AddRange(SL.Cast <TSource>(change.MovedItems)); if (change.NewItemsStartIndex != -1) { notification.UpdateNewStartIndex(offset + change.NewItemsStartIndex); } if (change.OldItemsStartIndex != -1) { notification.UpdateOldStartIndex(offset + change.OldItemsStartIndex); } } } RaiseEvents(added, removed, moved, notification.OldItemsStartIndex, notification.NewItemsStartIndex); return(notification); }
public void WhereCount_long_Test() { using (var array = new NativeArray <long>(114514, Allocator.Temp)) { InitializeLongArray(array); sw.Start(); for (var i = 0; i < Count; i++) { array.Append(1000).Where(new DetectOdd()).Append(1000).Count(); } Debug.Log(sw.Stop().ToString()); sw.Start(); for (var i = 0; i < Count; i++) { LE.Count(LE.Append(LE.Where(LE.Append(array, 1000), x => (x & 1) == 1), 1000)); } Debug.Log(sw.Stop().ToString()); } }
protected virtual void VisitCollectionBinaryExpression(StringBuilder builder, CollectionBinaryExpression exp) { if (exp == null) { return; } if (Enumerable.Count(Caster.Cast <object>(exp.Right.Collection)) == 0) { return; } StringBuilder sb = new StringBuilder(); VisitExpression(sb, exp.Left); sb.Append(GetCollectionExpressionString(exp.Op)); VisitExpression(sb, exp.Right); if (sb.Length > 0) { builder.AppendFormat("({0})", sb); } }