本文整理汇总了C#中ICollection.Except方法的典型用法代码示例。如果您正苦于以下问题:C# ICollection.Except方法的具体用法?C# ICollection.Except怎么用?C# ICollection.Except使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类ICollection
的用法示例。
在下文中一共展示了ICollection.Except方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CalculateSwaps
private ICollection<PlayerModel> CalculateSwaps(ICollection<PlayerModel> originalTeam, ICollection<PlayerModel> team1, ICollection<PlayerModel> team2)
{
ICollection<PlayerModel> team1SwappedPlayers = originalTeam.Except(team1).ToList();
//There should be at most 2 swaps per team, so if we get more than 2 swaps in team 1, then finding who changed to team 2 will be less than 2.
if (team1SwappedPlayers.Count > 2)
{
return originalTeam.Except(team2).ToList();
}
return team1SwappedPlayers;
}
示例2: FindAndSaveNewApps
private int FindAndSaveNewApps(ICollection<int> partition) {
ICollection<App> existingApps = repository.App.Retrieve(partition);
ICollection<int> diffs = partition.Except(existingApps.Select(a => a.Id)).ToArray();
logger.Debug("Found {0} apps that does not exists in database", diffs.Count);
ICollection<App> apps = appParser.RetrieveApps(diffs);
if (apps == null) {
return 0;
}
Stopwatch watch = new Stopwatch();
watch.Start();
foreach (App app in apps) {
repository.App.Save(app);
indexer.AddApp(app);
}
watch.Stop();
logger.Debug("Saved {0} apps using {1}ms", apps.Count, watch.ElapsedMilliseconds);
watch.Reset();
watch.Start();
indexer.Flush();
watch.Stop();
logger.Debug("Indexed {0} apps using {1}ms", apps.Count, watch.ElapsedMilliseconds);
return apps.Count;
}
示例3: BuildTableList
private static string[] BuildTableList(ICollection<string> allTables, ICollection<Relationship> allRelationships)
{
var tablesToDelete = new List<string>();
while (allTables.Any())
{
string[] leafTables = allTables.Except(allRelationships.Select(rel => rel.PrimaryKeyTable)).ToArray();
if(leafTables.Length == 0)
{
tablesToDelete.AddRange(allTables);
break;
}
tablesToDelete.AddRange(leafTables);
foreach (string leafTable in leafTables)
{
allTables.Remove(leafTable);
Relationship[] relToRemove =
allRelationships.Where(rel => rel.ForeignKeyTable == leafTable).ToArray();
foreach (Relationship rel in relToRemove)
{
allRelationships.Remove(rel);
}
}
}
return tablesToDelete.ToArray();
}
示例4: Compute
/// <summary>Compute the area under the ROC curve (AUC) of a list of ranked items</summary>
/// <remarks>
/// See http://recsyswiki.com/wiki/Area_Under_the_ROC_Curve
/// </remarks>
/// <param name="ranked_items">a list of ranked item IDs, the highest-ranking item first</param>
/// <param name="relevant_items">a collection of positive/correct item IDs</param>
/// <param name="num_dropped_items">the number of relevant items that were not ranked (considered to be ranked below all ranked_items)</param>
/// <returns>the AUC for the given data</returns>
public static double Compute(IList<int> ranked_items, ICollection<int> relevant_items, int num_dropped_items)
{
var relevant_items_in_list = relevant_items.Intersect(ranked_items);
int num_relevant_items = relevant_items_in_list.Count();
int num_eval_items = ranked_items.Count + num_dropped_items;
int num_eval_pairs = (num_eval_items - num_relevant_items) * num_relevant_items;
if (num_eval_pairs < 0)
throw new Exception("num_eval_pairs cannot be less than 0");
if (num_eval_pairs == 0)
return 0.5;
int num_correct_pairs = 0;
int hit_count = 0;
foreach (int item_id in ranked_items)
if (!relevant_items.Contains(item_id))
num_correct_pairs += hit_count;
else
hit_count++;
int missing_relevant_items = relevant_items.Except(ranked_items).Count();
num_correct_pairs += hit_count * (num_dropped_items - missing_relevant_items);
return (double) num_correct_pairs / num_eval_pairs;
}
示例5: CacheDirections
private static void CacheDirections(ICollection<Direction> directions, int routeId)
{
var directionIds = from d in directions select d.Id;
//cache the results in the database.
//Insert any Directions that don't already exist
using (var db = MadMetroDataContext.NewInstance())
{
var existingDirections = (from d in db.Directions where directionIds.Contains(d.Id) select d).ToArray();
foreach (var newDirection in directions.Except(existingDirections))
{
db.Directions.InsertOnSubmit(newDirection);
}
//delete existing RouteDirection rows and just re-add
var existingRouteDirections = from rd in db.RouteDirections
where directionIds.Contains(rd.DirectionId) && rd.RouteId == routeId
select rd;
foreach(var existingRouteDirection in existingRouteDirections)
{
db.RouteDirections.DeleteOnSubmit(existingRouteDirection);
}
db.SubmitChanges();
foreach(var directionId in directionIds)
{
db.RouteDirections.InsertOnSubmit(new RouteDirection{DirectionId = directionId, RouteId = routeId});
}
db.SubmitChanges();
}
}
示例6: IsRuleMet
public bool IsRuleMet(ICollection<string> data, ICollection<string> criteriaData)
{
if (data.Count() != 1 && criteriaData.Count() != 1)
{
return !criteriaData.Except(data).Any();
}
return data.First().Contains(criteriaData.First());
}
示例7: ReturnsEnumerationOfMethodData
private void ReturnsEnumerationOfMethodData(
[Frozen] Mock<IArgumentNullExceptionFixture> fixtureMock,
ICollection<MethodData> expectedData,
MethodInfo unused1,
CustomAttribute sut)
{
// Arrange
fixtureMock.Setup(f => f.GetData()).Returns(expectedData);
// Act
List<MethodData> actualData =
sut.GetData(unused1)
.SelectMany(d => d.OfType<MethodData>())
.ToList();
// Assert
Assert.Equal(expectedData.Count, actualData.Count);
Assert.False(expectedData.Except(actualData).Any());
}
开发者ID:AutoTestNET,项目名称:AutoTest.ArgumentNullException,代码行数:19,代码来源:RequiresArgumentNullExceptionAttributeShould.cs
示例8: BuildTableList
static string[] BuildTableList(ICollection<string> allTables, ICollection<Relationship> allRelationships)
{
var tablesToDelete = new List<string>();
while (allTables.Any())
{
var leafTables = allTables.Except(allRelationships.Select(rel => rel.PrimaryKeyTable)).ToList();
tablesToDelete.AddRange(leafTables);
leafTables.ForEach(lt =>
{
allTables.Remove(lt);
var relToRemove = allRelationships.Where(rel => rel.ForeignKeyTable == lt).ToList();
relToRemove.ForEach(toRemove => allRelationships.Remove(toRemove));
});
}
return tablesToDelete.ToArray();
}
示例9: AP
/// <summary>Compute the average precision (AP) of a list of ranked items</summary>
/// <remarks>See p. 147 of Introduction to Information Retrieval by Manning, Raghavan, Schütze.</remarks>
/// <param name="ranked_items">a list of ranked item IDs, the highest-ranking item first</param>
/// <param name="correct_items">a collection of positive/correct item IDs</param>
/// <param name="ignore_items">a collection of item IDs which should be ignored for the evaluation</param>
/// <returns>the AP for the given list</returns>
public static double AP(
IList<int> ranked_items,
ICollection<int> correct_items,
ICollection<int> ignore_items = null)
{
if (ignore_items == null)
ignore_items = new int[0];
int hit_count = 0;
double avg_prec_sum = 0;
int left_out = 0;
for (int i = 0; i < ranked_items.Count; i++)
{
int item_id = ranked_items[i];
if (ignore_items.Contains(item_id))
{
left_out++;
continue;
}
if (!correct_items.Contains(item_id))
continue;
hit_count++;
avg_prec_sum += (double) hit_count / (i + 1 - left_out);
}
if (hit_count != 0)
{
int num_correct_items_not_ignored = correct_items.Except(ignore_items).Count();
return avg_prec_sum / num_correct_items_not_ignored;
}
else
return 0;
}
示例10: GetMinimumWaitingTimeForInnerNodes
private static double GetMinimumWaitingTimeForInnerNodes(ICollection<int> path, IList<double> waitingTime)
{
IEnumerable<int> innerNodes =
path.Except(new Collection<int> {path.ElementAt(0), path.ElementAt(path.Count - 1)});
return innerNodes.Select(t => waitingTime[t]).Min();
}
示例11: DoWork
//.........这里部分代码省略.........
else continue;
//add to relation if it doesnt' contains yet
var parentRelation = allRelationsById[clcID];
bool isContains = false;
foreach (var m in parentRelation.Members)
{
if (m.Reference == way.ID)
{
isContains = true;
break;
}
}
if (!isContains)
{
parentRelation.Members.Add(new OSMRelation.Member(OSMKeys.WayType,way.ID,OSMKeys.RoleOuter));
}
}
Log.getInstance().writeLine("Adding ways to relations: complete");
//create index of relations by used ways
Dictionary<int, List<OSMRelation>> relationsByUsedWays = GetRelationsByUsedWays(allRelationsById.Values,ways);
var intersections = OSMWay.GetIntersections(ways);
var splittedWays = new List<OSMWay>();
//foreach (var currentWay in ways)
Parallel.ForEach(ways, parallelOptions, currentWay =>
{
var partialWays = currentWay.SplitN(intersections);
lock (splittedWays)
{
splittedWays.AddRange(partialWays);
}
//add partial ways to original way's relations
var affectedRelations = relationsByUsedWays[currentWay.ID];
foreach (var rel in affectedRelations)
{
lock (rel.Members)
{
OSMRelation.Member oldMember = rel.Members.Where(x => x.Reference == currentWay.ID).First();
//add new partial ways
foreach (var newWay in partialWays)
{
rel.Members.Add(new OSMRelation.Member(oldMember.Type, newWay.ID, oldMember.Role));
}
//remove old way
rel.Members.Remove(oldMember);
}
}
});
//}
intersections = null;
Log.getInstance().writeLine("Way splitting: complete");
//reindex because of earlier change (ways=>partial ways)
relationsByUsedWays = GetRelationsByUsedWays(allRelationsById.Values,splittedWays);
OverlapsEqualityComparer comparer = new OverlapsEqualityComparer();
var filtered = new Dictionary<OSMWay, int>(comparer);
var unneccesaryWays = new HashSet<OSMWay>();
foreach (var way in splittedWays)
{
if (filtered.ContainsKey(way))
{
foreach (var rel in relationsByUsedWays[way.ID])
{
foreach (var member in rel.Members)
{
if (member.Reference == way.ID) member.Reference = filtered[way];
}
}
unneccesaryWays.Add(way);
}
else
{
filtered.Add(way, way.ID);
}
}
filtered = null;
splittedWays.RemoveAll(x => unneccesaryWays.Contains(x));
unneccesaryWays = null;
Log.getInstance().writeLine("Merge Overlaping ways: complete");
//remove empty relations
newRelations = allRelationsById.Values.Where(x => x.Members.Count > 0).ToList();
Log.getInstance().writeLine("Remove empty relations: complete");
//convert back 1 member relations to ways
var oneMemberRelations = newRelations.Where(r => r.Members.Count == 1 && r.Members.First().Role.Equals(OSMKeys.RoleOuter));
waysById = splittedWays.ToDictionary(x => x.ID);
foreach (var rel in oneMemberRelations)
{
waysById[rel.Members.First().Reference].Tags = rel.Tags;
}
newRelations = newRelations.Except(oneMemberRelations).ToList();
Log.getInstance().writeLine("Convert 1 member relations to simple way (all: "+oneMemberRelations.Count()+"): complete");
newWays = waysById.Values;
}
示例12: Convert
/// <summary>
/// Rename "new" methods that override a final base method.
/// </summary>
public void Convert(ReachableContext reachableContext)
{
// Collect all names
var newSlotMethods = reachableContext.ReachableTypes
.SelectMany(x => x.Methods)
.Where(m => m.IsHideBySig && !m.IsStatic
&& !m.IsRuntimeSpecialName
&& !m.DeclaringType.IsInterface
&& (m.GetDexOrJavaImportAttribute() == null))
.ToList();
if (newSlotMethods.Count == 0)
return;
// Go over each method, find methods to rename
var methodsToRename = new HashSet<MethodDefinition>();
foreach (var method in newSlotMethods)
{
// Is the direct base method final?
var baseMethod = method.GetBaseMethod();
if (baseMethod == null)
continue;
if ((baseMethod.IsVirtual || baseMethod.IsAbstract) && !baseMethod.IsFinal)
continue;
methodsToRename.Add(method);
methodsToRename.Add(baseMethod);
}
if (methodsToRename.Count == 0)
return;
// Initialize some sets
reachableMethods = reachableContext.ReachableTypes.SelectMany(x => x.Methods)
.Where(m => m.IsReachable)
.ToList();
methodNames = new NameSet(reachableMethods.Select(m => m.Name));
var reachableMethodReferences = InterfaceHelper.GetReachableMethodReferencesByName(reachableMethods);
var baseMethodToImplementation = reachableMethods.Except(methodsToRename)
.SelectMany(m => m.GetBaseMethods(),
(e, m) => new { Impl = e, Base = m })
.ToLookup(p => p.Base, p => p.Impl);
// Rename methods that need renaming
foreach (var method in methodsToRename)
{
// Create new name
var newName = methodNames.GetUniqueName(method.Name);
// Find all methods that derive from method
var groupMethods = new HashSet<MethodDefinition> { method };
foreach (var otherMethod in baseMethodToImplementation[method])
{
// Rename this other method as well
groupMethods.Add(otherMethod);
}
// Add explicit implementations for interface methods
foreach (var iMethod in method.GetBaseInterfaceMethods())
{
var iMethodIsJavaWithGenericParams = iMethod.IsJavaMethodWithGenericParams();
var explicitName = methodNames.GetUniqueName(method.DeclaringType.Name + "_" + iMethod.Name);
var stub = InterfaceHelper.CreateExplicitStub(method.DeclaringType, method, explicitName, iMethod, iMethodIsJavaWithGenericParams);
stub.IsPrivate = true;
stub.IsFinal = false;
stub.IsVirtual = true;
}
// Rename all methods in the group
foreach (var m in groupMethods)
{
InterfaceHelper.Rename(m, newName, reachableMethodReferences);
}
}
}
示例13: FindSolution
/// <summary>
/// Finds a solution for the passed packing problem instance data.
/// </summary>
/// <param name="stripWidth">
/// Width of the strip the items have to be packed into.
/// </param>
/// <param name="items">
/// Items that have to be packed.
/// </param>
/// <returns>
/// Maximum strip height that has been used.
/// </returns>
public override float FindSolution(float stripWidth, ICollection<PackingItem> items)
{
// Check strip width.
if (!stripWidth.Equals(AssumedStripWidth))
{
throw new ArgumentOutOfRangeException(
"stripWidth", string.Format("This algorithm assumes a strip width of {0}.", AssumedStripWidth));
}
// Construct lists for big and very small items
var bigItems = new List<PackingItem>();
var verySmallItems = new List<PackingItem>();
// Iterate over all items.
foreach (var item in items)
{
// Check their dimensions.
double width = item.Rectangle.Width;
double height = item.Rectangle.Height;
if ((height > AssumedMaximumItemWidthAndHeight) || (width > AssumedMaximumItemWidthAndHeight))
{
throw new ArgumentOutOfRangeException(
string.Format(
"This algorithm assumes item " + "widths and heights of at most {0}.",
AssumedMaximumItemWidthAndHeight));
}
if ((width > BigItemWidth) && (height > BigItemHeight))
{
// Item is a big item.
bigItems.Add(item);
// Rotate it so that its width is not smaller than its height.
if (width < height)
{
item.Rotate();
}
}
else if (height < width)
{
// Rotate items so that their height is greater than their width as specified by the long version of the paper.
item.Rotate();
}
// Check if we have a very small item now.
if (item.Rectangle.Width <= VerySmallItemWidth)
{
verySmallItems.Add(item);
}
}
// Remove all items that have been assigned to other lists.
items = new List<PackingItem>(items.Except(bigItems));
items = new List<PackingItem>(items.Except(verySmallItems));
// Sort big items by decreasing width.
bigItems = bigItems.OrderByDescending(item => item.Rectangle.Width).ToList();
// Remember the height of the strip used for the big items only.
float h1 = 0;
// Remember the height of the strip the first item of width at most 2/3 is packed (h1' in the paper).
float h2 = 0;
// 1. Place all big items
foreach (var bigItem in bigItems)
{
// Construct new level for the current big item.
var level = this.AddLevel(h1);
// Place the item.
bigItem.Rectangle.X = 0;
bigItem.Rectangle.Y = h1;
level.AddItem(bigItem);
h1 += bigItem.Rectangle.Height;
// Check whether h2 (h1' in the paper) has to be set.
if ((h2 <= 0f) && (bigItem.Rectangle.Width <= ItemWidthForBeginOfSubstrip))
{
h2 = h1;
}
}
if (h2 <= 0f)
{
//.........这里部分代码省略.........
示例14: CheckIndexRange
/// <summary>
/// Check that records in an index range have the expected values.
/// </summary>
/// <param name="sesid">The session to use.</param>
/// <param name="tableid">The cursor with the index range setup.</param>
/// <param name="columnid">The column to retrieve.</param>
/// <param name="expected">The values we expect.</param>
private static void CheckIndexRange(JET_SESID sesid, JET_TABLEID tableid, JET_COLUMNID columnid, ICollection<string> expected)
{
ICollection<string> actual = new List<string>();
do
{
actual.Add(Api.RetrieveColumnAsString(sesid, tableid, columnid));
}
while (Api.TryMoveNext(sesid, tableid));
Assert.AreEqual(expected.Count, actual.Count, "Wrong number of records returned");
Assert.AreEqual(expected.Except(actual).Count(), 0, "Wrong elements returned");
}
示例15: Equals
private static bool Equals(ICollection<VirtualKey> key1, ICollection<VirtualKey> key2)
{
return key1.Count == key2.Count && !key1.Except(key2).Any();
}