public ImmutableList <T> Remove(IEnumerable <T> oldItems) { var list = new List <T>(_data); list.RemoveMany(oldItems); return(new ImmutableList <T>(list)); }
public void TestRemoveMany() { var collection = new List <int> { 0, 1, 2 }; collection.RemoveMany(new[] { 1, 2 }); Assert.AreEqual(1, collection.Count); }
private IList <VisualStudioEventArgs> PruneAndOrderEvents(IList <VisualStudioEventArgs> eventsWorkingQueue) { var returnEvents = new List <VisualStudioEventArgs>(eventsWorkingQueue); //For any Project events, remove any other events that deal with that Project //(we're going to have to completly rescan the project anyway) returnEvents.RemoveMany( eventsWorkingQueue .OfType <VisualStudioProjectEventArgs>() .SelectMany(projectEvent => eventsWorkingQueue .Where( projectItemEvent => projectItemEvent.ProjectFullPath == projectEvent.ProjectFullPath && !(projectItemEvent is VisualStudioProjectEventArgs)))); return(returnEvents); }
/// <summary> /// From a production, derive a set of productions for each combination of skipping nullable nonterminals. /// E.g., for production S -> AbB and nullable {A, B}, we get productions /// S -> AbB | Ab | bB | b /// </summary> /// <returns></returns> private static List<Production> Nullate(Production originalProduction, Dictionary<Nonterminal, double> nullableProbabilities) { var results = new List<Production>(); results.Add(originalProduction); if (originalProduction.IsEmpty) { return results; } for (int i = originalProduction.Rhs.Count - 1; i >= 0; i--) { var newResults = new List<Production>(); var toRemove = new List<Production>(); foreach (var production in results) { var word = production.Rhs[i]; var nt = word as Nonterminal; if (nt == null) { continue; } if (!nullableProbabilities.ContainsKey(nt)) { continue; } // var with = production.Clone(); var without = production.DeepClone(); without.Rhs.RemoveAt(i); var chanceNull = nullableProbabilities[nt]; var newWithoutWeight = without.Weight * chanceNull; var newWithWeight = production.Weight * (1.0 - chanceNull); if (newWithoutWeight > 0.0) { without.Weight = newWithoutWeight; newResults.Add(without); } if (newWithWeight <= 0.0) { toRemove.Add(production); } else { production.Weight = newWithWeight; } } results.AddRange(newResults); // TODO: we should just make it so that if a weight is set to 0, the production gets removed from the grammar automatically, and that operation should be fast results.RemoveMany(toRemove); } // NullateAux(production, nullableSet, 0, result); if (results.Count == 0) { return results; } // Get rid of productions with zero weight //for (int i = results.Count - 1; i >= 0; i--) { // var result = results[i]; // if (result.Weight == 0.0) { // results.RemoveAt(i); // } //} return results; }
public void RemoveManyWillRemoveARange() { _list.AddRange(Enumerable.Range(1, 10)); _list.RemoveMany(Enumerable.Range(2, 8)); CollectionAssert.AreEquivalent(new[] { 1, 10 }, _list); }
public void RemoveManyWillRemoveARange() { _list.AddRange(Enumerable.Range(1, 10)); _list.RemoveMany(Enumerable.Range(2, 8)); _list.Should().BeEquivalentTo(new[] { 1, 10 }); }
/// <summary> /// From a production, derive a set of productions for each combination of skipping nullable nonterminals. /// E.g., for production S -> AbB and nullable {A, B}, we get productions /// S -> AbB | Ab | bB | b /// </summary> /// <returns></returns> private static List <Production> Nullate(Production originalProduction, Dictionary <Nonterminal, double> nullableProbabilities) { var results = new List <Production>(); results.Add(originalProduction); if (originalProduction.IsEmpty) { return(results); } for (int i = originalProduction.Rhs.Count - 1; i >= 0; i--) { var newResults = new List <Production>(); var toRemove = new List <Production>(); foreach (var production in results) { var word = production.Rhs[i]; var nt = word as Nonterminal; if (nt == null) { continue; } if (!nullableProbabilities.ContainsKey(nt)) { continue; } // var with = production.Clone(); var without = production.DeepClone(); without.Rhs.RemoveAt(i); var chanceNull = nullableProbabilities[nt]; var newWithoutWeight = without.Weight * chanceNull; var newWithWeight = production.Weight * (1.0 - chanceNull); if (newWithoutWeight > 0.0) { without.Weight = newWithoutWeight; newResults.Add(without); } if (newWithWeight <= 0.0) { toRemove.Add(production); } else { production.Weight = newWithWeight; } } results.AddRange(newResults); // TODO: we should just make it so that if a weight is set to 0, the production gets removed from the grammar automatically, and that operation should be fast results.RemoveMany(toRemove); } // NullateAux(production, nullableSet, 0, result); if (results.Count == 0) { return(results); } // Get rid of productions with zero weight //for (int i = results.Count - 1; i >= 0; i--) { // var result = results[i]; // if (result.Weight == 0.0) { // results.RemoveAt(i); // } //} return(results); }
public void DoesNotRemoveDuplicates() { _list.AddRange(new[] { 1, 1, 1, 5, 6, 7 }); _list.RemoveMany(new[] { 1, 1, 7 }); _list.Should().BeEquivalentTo(new[] { 1, 5, 6 }); }
private IList<VisualStudioEventArgs> PruneAndOrderEvents(IList<VisualStudioEventArgs> eventsWorkingQueue) { var returnEvents = new List<VisualStudioEventArgs>(eventsWorkingQueue); //For any Project events, remove any other events that deal with that Project //(we're going to have to completly rescan the project anyway) returnEvents.RemoveMany( eventsWorkingQueue .OfType<VisualStudioProjectEventArgs>() .SelectMany(projectEvent => eventsWorkingQueue .Where( projectItemEvent => projectItemEvent.ProjectFullPath == projectEvent.ProjectFullPath && !(projectItemEvent is VisualStudioProjectEventArgs)))); return returnEvents; }