//<snippet02> static void Main() { HashSet <int> lowNumbers = new HashSet <int>(); HashSet <int> allNumbers = new HashSet <int>(); for (int i = 1; i < 5; i++) { lowNumbers.Add(i); } for (int i = 0; i < 10; i++) { allNumbers.Add(i); } Console.Write("lowNumbers contains {0} elements: ", lowNumbers.Count); DisplaySet(lowNumbers); Console.Write("allNumbers contains {0} elements: ", allNumbers.Count); DisplaySet(allNumbers); Console.WriteLine("lowNumbers overlaps allNumbers: {0}", lowNumbers.Overlaps(allNumbers)); Console.WriteLine("allNumbers and lowNumbers are equal sets: {0}", allNumbers.SetEquals(lowNumbers)); // Show the results of sub/superset testing Console.WriteLine("lowNumbers is a subset of allNumbers: {0}", lowNumbers.IsSubsetOf(allNumbers)); Console.WriteLine("allNumbers is a superset of lowNumbers: {0}", allNumbers.IsSupersetOf(lowNumbers)); Console.WriteLine("lowNumbers is a proper subset of allNumbers: {0}", lowNumbers.IsProperSubsetOf(allNumbers)); Console.WriteLine("allNumbers is a proper superset of lowNumbers: {0}", allNumbers.IsProperSupersetOf(lowNumbers)); // Modify allNumbers to remove numbers that are not in lowNumbers. allNumbers.IntersectWith(lowNumbers); Console.Write("allNumbers contains {0} elements: ", allNumbers.Count); DisplaySet(allNumbers); Console.WriteLine("allNumbers and lowNumbers are equal sets: {0}", allNumbers.SetEquals(lowNumbers)); // Show the results of sub/superset testing with the modified set. Console.WriteLine("lowNumbers is a subset of allNumbers: {0}", lowNumbers.IsSubsetOf(allNumbers)); Console.WriteLine("allNumbers is a superset of lowNumbers: {0}", allNumbers.IsSupersetOf(lowNumbers)); Console.WriteLine("lowNumbers is a proper subset of allNumbers: {0}", lowNumbers.IsProperSubsetOf(allNumbers)); Console.WriteLine("allNumbers is a proper superset of lowNumbers: {0}", allNumbers.IsProperSupersetOf(lowNumbers)); }
public void UsingHashSet_IsSupersetOf() { var setA = new HashSet <int>(new int[] { 1, 2, 3, 4 }); var setB = new int[] { 1, 3, 4 }; var setC = new int[] { 1, 2, 3, 4 }; Assert.True(setA.IsSupersetOf(setB)); //All setB values are in setA Assert.True(setA.IsProperSupersetOf(setB)); //All setB values are in setA, with additional values in setA Assert.True(setA.IsSupersetOf(setC)); //All setC values are in setA Assert.False(setA.IsProperSupersetOf(setC)); //All setA and setC has same values }
public void TestProperSupersetOfComparer() { var data = new[] { "a", "B", "c", "D" }; var other1 = new[] { "A", "a", "d", "D" }; var other2 = new[] { "A", "a", "B", "D", "C", "c" }; var set = new HashSet <string>(data, StringComparer.OrdinalIgnoreCase); Assert.IsTrue(set.IsProperSupersetOf(other1)); Assert.IsFalse(set.IsProperSupersetOf(other2)); }
public void TestProperSupersetOf() { var data = new[] { 1, 2, 3, 4, 5 }; var other = new[] { 2, 3, 4 }; var other2 = new[] { 1, 2, 3, 4, 5 }; var other3 = new[] { 4, 5, 6 }; var set = new HashSet <int>(data); Assert.IsTrue(set.IsProperSupersetOf(other)); Assert.IsFalse(set.IsProperSupersetOf(other2)); Assert.IsFalse(set.IsProperSupersetOf(other3)); }
public bool IsProperSupersetOf(IEnumerable <T> other) { lock (mySet) { return(mySet.IsProperSupersetOf(other)); } }
// Test reading methods void f4() { var v5 = new Dictionary <int, int>(); // BAD v5.ContainsKey(1); v5.ContainsValue(1); v5.GetEnumerator(); var tmp = new HashSet <int>(); var v6 = new HashSet <int>(); // BAD v6.IsSubsetOf(tmp); v6.IsProperSubsetOf(tmp); v6.IsSupersetOf(tmp); v6.IsProperSupersetOf(tmp); var v7 = new LinkedList <int>(); // BAD v7.Contains(1); var v8 = new Queue <int>(); // BAD v8.Dequeue(); v8.Peek(); v8.ToArray(); var v9 = new Stack <int>(); // BAD v9.Pop(); var v10 = new List <int>(); // BAD: property access var x = v10.Count; }
public bool IsProperSupersetOf(IEnumerable <T> other) { lock (this.LockObject) { return(_hashSet.IsProperSupersetOf(other)); } }
public SubjectCompareOutcome CompareTwoSchedules(ScheduleOfRITEs s1, ScheduleOfRITEs s2) { HashSet <RITE> list1 = s1.ScheduleList; HashSet <RITE> list2 = s2.ScheduleList; if (list1.Count == list2.Count && list1.IsSubsetOf(list2)) { return(SubjectCompareOutcome.Equal); } else if (list1.Count < list2.Count && list1.IsProperSubsetOf(list2)) { return(SubjectCompareOutcome.Parent); } else if (list1.Count > list2.Count && list1.IsProperSupersetOf(list2)) { return(SubjectCompareOutcome.Child); } else if (list1.Overlaps(list2)) { return(SubjectCompareOutcome.Overlap); } else { return(SubjectCompareOutcome.Disjoin); } }
private void VerifyBasic(List <CharacterGroup> narratorGroups, int numberOfNarratorsExpectedToBeAssignedToASingleAuthor) { CharacterGroupGenerator.TrialGroupConfiguration.DistributeBooksAmongNarratorGroups(m_authorStats, narratorGroups); for (int i = 0; i < narratorGroups.Count; i++) { var group = narratorGroups[i]; var booksAssignedToNarrator = group.CharacterIds.Select(CharacterVerseData.GetBookCodeFromStandardCharacterId).ToList(); if (i < numberOfNarratorsExpectedToBeAssignedToASingleAuthor) { var author = BiblicalAuthors.GetAuthorOfBook(booksAssignedToNarrator[0]).Name; Assert.IsTrue(booksAssignedToNarrator.SetEquals(m_authorStats.Single(a => a.Author.Name == author).BookIds)); } else { // This is a narrator group that is expected to be assigned to multiple authors. For each author, // the set of books for this narrator MUST contain ALL the books for that author, plus at least one // other book. var set = new HashSet <string>(booksAssignedToNarrator); foreach (var bookId in booksAssignedToNarrator) { var author = BiblicalAuthors.GetAuthorOfBook(bookId).Name; Assert.IsTrue(set.IsProperSupersetOf(m_authorStats.Single(a => a.Author.Name == author).BookIds)); } } } }
public void TestIsProperSupersetOf() { HashSet <int> set = GetEmptyIntSet(); Assert.IsFalse(set.IsProperSupersetOf(new int[] { 1 })); Assert.IsFalse(set.IsProperSupersetOf(new FclGeneric.List <int>())); set.Add(1); set.Add(2); set.Add(3); var set2 = GetIntSetFromOneToFive(); Assert.IsTrue(set2.IsProperSupersetOf(set)); Assert.IsFalse(set.IsProperSupersetOf(new int[] { 1, 2, 3 })); Assert.IsTrue(set.IsProperSupersetOf(new FclGeneric.List <int>())); }
public bool IsProperSupersetOf(IEnumerable <T> other) { lock (SyncRoot) { return(set.IsProperSupersetOf(other)); } }
public bool IsProperSupersetOf(IEnumerable <T> other) { lock (_lock) { return(_internalHashSet.IsProperSupersetOf(other)); } }
public void IsProperSupersetOfEmptyArr() { var arr = new int[0]; var set = new HashSet <int>(); set.Add(0); Assert.IsTrue(set.IsProperSupersetOf(arr)); }
public void TestSubSetSuperSet () { var aSet = new HashSet<int> { 1, 2 }; var bSet = new HashSet<int> { 1 }; Assert.IsTrue (aSet.IsSubsetOf (aSet)); Assert.IsTrue (bSet.IsSubsetOf (aSet)); Assert.IsTrue (bSet.IsProperSubsetOf (aSet)); Assert.IsFalse (aSet.IsProperSubsetOf (aSet)); Assert.IsTrue (aSet.IsSupersetOf (aSet)); Assert.IsTrue (aSet.IsSupersetOf (bSet)); Assert.IsTrue (aSet.IsProperSupersetOf (bSet)); Assert.IsFalse (aSet.IsProperSupersetOf (aSet)); }
public bool IsProperSupersetOf(IEnumerable <T> other) { locker.EnterReadLock(); var isProperSupersetOf = hashSet.IsProperSupersetOf(other); locker.ExitReadLock(); return(isProperSupersetOf); }
private static bool HashSetNotProperMethod(string[] magazine, string[] ransom) { var magazineHash = new HashSet <string>(magazine, StringComparer.Ordinal); var ransomHash = new HashSet <string>(ransom, StringComparer.Ordinal); var result = ransomHash.IsSubsetOf(magazine) || magazineHash.IsProperSupersetOf(ransomHash); return(result); }
public void IsProperSupersetFailureOfTest() { var set = new HashSet <int>(); var arr = Enumerable.Range(0, 10).ToArray(); set.UnionWith(arr); Assert.IsFalse(set.IsProperSupersetOf(arr)); }
public bool IsProperSupersetOf(IEnumerable <T> other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } return(hashSet.IsProperSupersetOf(other)); }
void AlwaysFalse() { var set = new HashSet <int>(); set.IsProperSubsetOf(set); // Noncompliant {{Change one instance of 'set' to a different value; Comparing to itself always returns false.}} // Secondary@-1 set.IsProperSupersetOf(set); // Noncompliant // Secondary@-1 }
static void ComPareSets(HashSet <Date> s1, HashSet <Date> s2) { // Some comparison operators. Console.WriteLine(s1.IsSubsetOf(s2)); Console.WriteLine(s1.IsProperSubsetOf(s2)); Console.WriteLine(s1.IsSupersetOf(s2)); Console.WriteLine(s1.IsProperSupersetOf(s2)); Console.WriteLine(s1.Overlaps(s2)); Console.WriteLine(s1.SetEquals(s2)); }
public void SubsetsAndSupersets() { var set0 = new HashSet <int>(); var set1 = new HashSet <int>(new[] { 0, 1, 2, 3 }); var set2 = new HashSet <int>(new[] { 0, 1, 2, 3 }); var set3 = new HashSet <int>(new[] { 0, 1, 2, 3, 4 }); var set4 = new HashSet <int>(new[] { 0, 1, 2, 3, 5 }); Assert.That(() => { set1.IsProperSubsetOf(null); }, Throws.TypeOf(typeof(ArgumentNullException))); Assert.That(() => { set1.IsProperSupersetOf(null); }, Throws.TypeOf(typeof(ArgumentNullException))); Assert.That(() => { set1.IsSubsetOf(null); }, Throws.TypeOf(typeof(ArgumentNullException))); Assert.That(() => { set1.IsSupersetOf(null); }, Throws.TypeOf(typeof(ArgumentNullException))); Assert.IsTrue(set1.IsSubsetOf(set1)); Assert.IsTrue(set1.IsSubsetOf(set2)); Assert.IsTrue(set1.IsSubsetOf(set3)); Assert.IsFalse(set3.IsSubsetOf(set4)); Assert.IsFalse(set1.IsProperSubsetOf(set1)); Assert.IsFalse(set1.IsProperSubsetOf(set2)); Assert.IsTrue(set1.IsProperSubsetOf(set3)); Assert.IsFalse(set3.IsProperSubsetOf(set4)); Assert.IsFalse(set3.IsSubsetOf(set2)); Assert.IsFalse(set3.IsProperSubsetOf(set2)); Assert.IsTrue(set3.IsSupersetOf(set3)); Assert.IsTrue(set3.IsSupersetOf(set2)); Assert.IsFalse(set3.IsSupersetOf(set4)); Assert.IsFalse(set3.IsProperSupersetOf(set3)); Assert.IsTrue(set3.IsProperSupersetOf(set2)); Assert.IsFalse(set3.IsProperSupersetOf(set4)); // Empty set. Assert.IsTrue(set0.IsSubsetOf(set0)); Assert.IsTrue(set0.IsSubsetOf(set1)); Assert.IsFalse(set0.IsProperSubsetOf(set0)); Assert.IsTrue(set0.IsProperSubsetOf(set1)); Assert.IsTrue(set0.IsSupersetOf(set0)); Assert.IsFalse(set0.IsProperSupersetOf(set0)); Assert.IsFalse(set0.IsSupersetOf(set1)); Assert.IsTrue(set0.IsProperSubsetOf(set1)); Assert.IsFalse(set1.IsSubsetOf(set0)); Assert.IsFalse(set1.IsProperSubsetOf(set0)); Assert.IsTrue(set1.IsSupersetOf(set0)); Assert.IsTrue(set1.IsProperSupersetOf(set0)); }
/// <see cref="ISet<T>.IsProperSubsetOf"/> public bool IsProperSubsetOf(IEnumerable <T> other) { if (other == null) { throw new ArgumentNullException("other"); } HashSet <T> otherHashSet = new HashSet <T>(other); return(otherHashSet.IsProperSupersetOf(this)); }
/// <summary> /// Determines whether the current set is a correct superset of a specified collection. /// </summary> /// <returns> /// true if the <see cref="T:System.Collections.Generic.ISet`1"/> object is a correct superset of <paramref name="other"/>; otherwise, false. /// </returns> /// <param name="other">The collection to compare to the current set. </param><exception cref="T:System.ArgumentNullException"><paramref name="other"/> is null.</exception> public bool IsProperSupersetOf(IEnumerable <T> other) { List <WeakReference <T> > tempList = new List <WeakReference <T> >(); foreach (T o in other) { tempList.Add(new WeakReference <T>(o)); } return(_internalCollection.IsProperSupersetOf(tempList)); }
/// <inheritdoc /> public bool IsProperSubsetOf(IEnumerable <ProductionItem <TTokenKind> > other) { if (other == null) { throw new ArgumentNullException(nameof(other)); } var otherHashset = new HashSet <ProductionItem <TTokenKind> >(other); return(otherHashset.IsProperSupersetOf(this)); }
public bool IsProperSupersetOf(IEnumerable <T> other) { SemaphoreSlim.Wait(); try { return(BackingCollection.IsProperSupersetOf(other)); } finally { SemaphoreSlim.Release(); } }
public void IsProperSupersetOfTest() { var arrayTemp = new int[3] { 1, 2, 3 }; Assert.IsFalse(set.IsProperSupersetOf(arrayTemp)); Assert.IsTrue(set.IsProperSupersetOf(set)); set = new HashSet <int> { 1, 2, 3 }; Assert.IsFalse(set.IsProperSupersetOf(arrayTemp)); set.Add(12); Assert.IsTrue(set.IsProperSupersetOf(arrayTemp)); set = new HashSet <int> { 1, 2, 43, 33 }; Assert.IsFalse(set.IsProperSupersetOf(arrayTemp)); }
public void TestSubSetSuperSet() { var aSet = new HashSet <int> { 1, 2 }; var bSet = new HashSet <int> { 1 }; Assert.IsTrue(aSet.IsSubsetOf(aSet)); Assert.IsTrue(bSet.IsSubsetOf(aSet)); Assert.IsTrue(bSet.IsProperSubsetOf(aSet)); Assert.IsFalse(aSet.IsProperSubsetOf(aSet)); Assert.IsTrue(aSet.IsSupersetOf(aSet)); Assert.IsTrue(aSet.IsSupersetOf(bSet)); Assert.IsTrue(aSet.IsProperSupersetOf(bSet)); Assert.IsFalse(aSet.IsProperSupersetOf(aSet)); }
/// <summary> /// Provides an implementation of <see cref="ISet{T}.IsProperSubsetOf"/>. /// </summary> /// <typeparam name="T">The type of values in the collections.</typeparam> /// <param name="source">The source collection that is implementing <see cref="ISet{T}"/>.</param> /// <param name="other">The other enumerable.</param> /// <returns>The result of <see cref="ISet{T}.IsProperSubsetOf"/>.</returns> /// <remarks> /// <para> /// From <see href="https://msdn.microsoft.com/en-us/library/dd321100(v=vs.110).aspx"/>; /// Determines whether the current set is a proper (strict) subset of a specified collection. /// </para><para> /// If the current set is a proper subset of other, other must have at least one element that the current /// set does not have. /// </para><para> /// An empty set is a proper subset of any other collection.Therefore, this method returns true if the /// current set is empty, unless the other parameter is also an empty set. /// </para><para> /// This method always returns false if the current set has more or the same number of elements than other. /// </para> /// </remarks> public static bool IsProperSubsetOf <T>(ISet <T> source, HashSet <T> other) { Contracts.Requires.That(source != null); ISetContracts.IsProperSubsetOf(other); if (source.Count >= other.Count) { return(false); } return(other.IsProperSupersetOf(source)); }
/// <summary> /// 是否为指定集合的真超集 /// </summary> /// <param name="other">指定集合</param> public bool IsProperSupersetOf(IEnumerable <T> other) { _rwLock.AcquireWriterLock(Timeout.Infinite); try { return(_infos.IsProperSupersetOf(other)); } finally { _rwLock.ReleaseWriterLock(); } }
public void Should_properly_expose_IsProperSupersetOf() { var originalSet = new HashSet <Card>() { Card.Parse("QC"), Card.Parse("TS") }; var byValueSet = new SetByValue <Card>(originalSet); Check.That(byValueSet.IsProperSupersetOf(new[] { Card.Parse("QC") })) .IsTrue() .And.IsEqualTo(originalSet.IsProperSupersetOf(new[] { Card.Parse("QC") })); }
public void ComputeIsProperSupersetOf() { var cities = new HashSet <string> { "Los Angeles", "Houston", "New York", "Atlanta", "Washington, D.C.", "Miami" }; var eastCities = new string[] { "New York", "Atlanta", "Washington, D.C.", "Miami" }; var eastCitiesExtended = new string[] { "Los Angeles", "Houston", "New York", "Atlanta", "Washington, D.C.", "Miami" }; // proper superset = superset and at least one additional member Assert.True(cities.IsProperSupersetOf(eastCities)); Assert.False(cities.IsProperSupersetOf(eastCitiesExtended)); }
private static OverloadGroupEquivalenceInfo GetOverloadGroupEquivalence(Dictionary<string, List<RuntimeArgument>> groupDefinitions) { OverloadGroupEquivalenceInfo info = new OverloadGroupEquivalenceInfo(); if (!groupDefinitions.IsNullOrEmpty()) { string[] array = new string[groupDefinitions.Count]; groupDefinitions.Keys.CopyTo(array, 0); for (int i = 0; i < array.Length; i++) { string str = array[i]; HashSet<RuntimeArgument> set = new HashSet<RuntimeArgument>(groupDefinitions[str]); for (int j = i + 1; j < array.Length; j++) { string str2 = array[j]; HashSet<RuntimeArgument> other = new HashSet<RuntimeArgument>(groupDefinitions[str2]); if (set.IsProperSupersetOf(other)) { info.SetAsSuperset(str, str2); } else if (set.IsProperSubsetOf(other)) { info.SetAsSuperset(str2, str); } else if (set.SetEquals(other)) { info.SetAsEquivalent(str, str2); } else if (set.Overlaps(other)) { info.SetAsOverlapping(str, str2); } else { info.SetAsDisjoint(str, str2); } } } } return info; }
public override Implementation VisitImplementation(Implementation node) { HashSet<Variable> start = new HashSet<Variable>(globalVarToDomainName.Keys); for (int i = 0; i < node.InParams.Count; i++) { string domainName = FindDomainName(node.Proc.InParams[i]); if (domainName != null) { inoutParamToDomainName[node.InParams[i]] = domainName; start.Add(node.InParams[i]); } } for (int i = 0; i < node.OutParams.Count; i++) { string domainName = FindDomainName(node.Proc.OutParams[i]); if (domainName != null) { inoutParamToDomainName[node.OutParams[i]] = domainName; } } var oldErrorCount = this.errorCount; var impl = base.VisitImplementation(node); if (oldErrorCount < this.errorCount) return impl; Stack<Block> dfsStack = new Stack<Block>(); HashSet<Block> dfsStackAsSet = new HashSet<Block>(); availableLinearVars[node.Blocks[0]] = start; dfsStack.Push(node.Blocks[0]); dfsStackAsSet.Add(node.Blocks[0]); while (dfsStack.Count > 0) { Block b = dfsStack.Pop(); dfsStackAsSet.Remove(b); HashSet<Variable> end = PropagateAvailableLinearVarsAcrossBlock(b); if (b.TransferCmd is ReturnCmd) { foreach (GlobalVariable g in globalVarToDomainName.Keys.Except(end)) { Error(b.TransferCmd, string.Format("Global variable {0} must be available at a return", g.Name)); } foreach (Variable v in node.OutParams) { if (FindDomainName(v) == null || end.Contains(v)) continue; Error(b.TransferCmd, string.Format("Output variable {0} must be available at a return", v.Name)); } continue; } GotoCmd gotoCmd = b.TransferCmd as GotoCmd; foreach (Block target in gotoCmd.labelTargets) { if (!availableLinearVars.ContainsKey(target)) { availableLinearVars[target] = new HashSet<Variable>(end); dfsStack.Push(target); dfsStackAsSet.Add(target); } else { var savedAvailableVars = new HashSet<Variable>(availableLinearVars[target]); availableLinearVars[target].IntersectWith(end); if (savedAvailableVars.IsProperSupersetOf(availableLinearVars[target]) && !dfsStackAsSet.Contains(target)) { dfsStack.Push(target); dfsStackAsSet.Add(target); } } } } return impl; }
public void SubsetsAndSupersets() { var set0 = new HashSet<int>(); var set1 = new HashSet<int>(new[] { 0, 1, 2, 3 }); var set2 = new HashSet<int>(new[] { 0, 1, 2, 3 }); var set3 = new HashSet<int>(new[] { 0, 1, 2, 3, 4 }); var set4 = new HashSet<int>(new[] { 0, 1, 2, 3, 5 }); Assert.That(() => { set1.IsProperSubsetOf(null); }, Throws.TypeOf(typeof(ArgumentNullException))); Assert.That(() => { set1.IsProperSupersetOf(null); }, Throws.TypeOf(typeof(ArgumentNullException))); Assert.That(() => { set1.IsSubsetOf(null); }, Throws.TypeOf(typeof(ArgumentNullException))); Assert.That(() => { set1.IsSupersetOf(null); }, Throws.TypeOf(typeof(ArgumentNullException))); Assert.IsTrue(set1.IsSubsetOf(set1)); Assert.IsTrue(set1.IsSubsetOf(set2)); Assert.IsTrue(set1.IsSubsetOf(set3)); Assert.IsFalse(set3.IsSubsetOf(set4)); Assert.IsFalse(set1.IsProperSubsetOf(set1)); Assert.IsFalse(set1.IsProperSubsetOf(set2)); Assert.IsTrue(set1.IsProperSubsetOf(set3)); Assert.IsFalse(set3.IsProperSubsetOf(set4)); Assert.IsFalse(set3.IsSubsetOf(set2)); Assert.IsFalse(set3.IsProperSubsetOf(set2)); Assert.IsTrue(set3.IsSupersetOf(set3)); Assert.IsTrue(set3.IsSupersetOf(set2)); Assert.IsFalse(set3.IsSupersetOf(set4)); Assert.IsFalse(set3.IsProperSupersetOf(set3)); Assert.IsTrue(set3.IsProperSupersetOf(set2)); Assert.IsFalse(set3.IsProperSupersetOf(set4)); // Empty set. Assert.IsTrue(set0.IsSubsetOf(set0)); Assert.IsTrue(set0.IsSubsetOf(set1)); Assert.IsFalse(set0.IsProperSubsetOf(set0)); Assert.IsTrue(set0.IsProperSubsetOf(set1)); Assert.IsTrue(set0.IsSupersetOf(set0)); Assert.IsFalse(set0.IsProperSupersetOf(set0)); Assert.IsFalse(set0.IsSupersetOf(set1)); Assert.IsTrue(set0.IsProperSubsetOf(set1)); Assert.IsFalse(set1.IsSubsetOf(set0)); Assert.IsFalse(set1.IsProperSubsetOf(set0)); Assert.IsTrue(set1.IsSupersetOf(set0)); Assert.IsTrue(set1.IsProperSupersetOf(set0)); }
public override Implementation VisitImplementation(Implementation node) { node.PruneUnreachableBlocks(); node.ComputePredecessorsForBlocks(); GraphUtil.Graph<Block> graph = Program.GraphFromImpl(node); graph.ComputeLoops(); HashSet<Variable> start = new HashSet<Variable>(globalVarToDomainName.Keys); for (int i = 0; i < node.InParams.Count; i++) { Variable v = node.Proc.InParams[i]; string domainName = FindDomainName(v); if (domainName != null) { var kind = FindLinearKind(v); inParamToLinearQualifier[node.InParams[i]] = new LinearQualifier(domainName, kind); if (kind == LinearKind.LINEAR || kind == LinearKind.LINEAR_IN) { start.Add(node.InParams[i]); } } } for (int i = 0; i < node.OutParams.Count; i++) { string domainName = FindDomainName(node.Proc.OutParams[i]); if (domainName != null) { outParamToDomainName[node.OutParams[i]] = domainName; } } var oldErrorCount = this.errorCount; var impl = base.VisitImplementation(node); if (oldErrorCount < this.errorCount) return impl; Stack<Block> dfsStack = new Stack<Block>(); HashSet<Block> dfsStackAsSet = new HashSet<Block>(); availableLinearVars[node.Blocks[0]] = start; dfsStack.Push(node.Blocks[0]); dfsStackAsSet.Add(node.Blocks[0]); while (dfsStack.Count > 0) { Block b = dfsStack.Pop(); dfsStackAsSet.Remove(b); HashSet<Variable> end = PropagateAvailableLinearVarsAcrossBlock(b); if (b.TransferCmd is ReturnCmd) { foreach (GlobalVariable g in globalVarToDomainName.Keys.Except(end)) { Error(b.TransferCmd, string.Format("Global variable {0} must be available at a return", g.Name)); } foreach (Variable v in node.InParams) { if (FindDomainName(v) == null || FindLinearKind(v) == LinearKind.LINEAR_IN || end.Contains(v)) continue; Error(b.TransferCmd, string.Format("Input variable {0} must be available at a return", v.Name)); } foreach (Variable v in node.OutParams) { if (FindDomainName(v) == null || end.Contains(v)) continue; Error(b.TransferCmd, string.Format("Output variable {0} must be available at a return", v.Name)); } continue; } GotoCmd gotoCmd = b.TransferCmd as GotoCmd; foreach (Block target in gotoCmd.labelTargets) { if (!availableLinearVars.ContainsKey(target)) { availableLinearVars[target] = new HashSet<Variable>(end); dfsStack.Push(target); dfsStackAsSet.Add(target); } else { var savedAvailableVars = new HashSet<Variable>(availableLinearVars[target]); availableLinearVars[target].IntersectWith(end); if (savedAvailableVars.IsProperSupersetOf(availableLinearVars[target]) && !dfsStackAsSet.Contains(target)) { dfsStack.Push(target); dfsStackAsSet.Add(target); } } } } if (graph.Reducible) { foreach (Block header in graph.Headers) { foreach (GlobalVariable g in globalVarToDomainName.Keys.Except(availableLinearVars[header])) { Error(header, string.Format("Global variable {0} must be available at a loop head", g.Name)); } } } return impl; }
static OverloadGroupEquivalenceInfo GetOverloadGroupEquivalence(Dictionary<string, List<RuntimeArgument>> groupDefinitions) { OverloadGroupEquivalenceInfo overloadGroupsInfo = new OverloadGroupEquivalenceInfo(); if (!groupDefinitions.IsNullOrEmpty()) { string[] groupNames = new string[groupDefinitions.Count]; groupDefinitions.Keys.CopyTo(groupNames, 0); for (int i = 0; i < groupNames.Length; i++) { string group1 = groupNames[i]; HashSet<RuntimeArgument> group1Args = new HashSet<RuntimeArgument>(groupDefinitions[group1]); for (int j = i + 1; j < groupNames.Length; j++) { string group2 = groupNames[j]; HashSet<RuntimeArgument> group2Args = new HashSet<RuntimeArgument>(groupDefinitions[group2]); if (group1Args.IsProperSupersetOf(group2Args)) { overloadGroupsInfo.SetAsSuperset(group1, group2); } else if (group1Args.IsProperSubsetOf(group2Args)) { overloadGroupsInfo.SetAsSuperset(group2, group1); } else if (group1Args.SetEquals(group2Args)) { overloadGroupsInfo.SetAsEquivalent(group1, group2); } else if (group1Args.Overlaps(group2Args)) { overloadGroupsInfo.SetAsOverlapping(group1, group2); } else // the groups are disjoint. { overloadGroupsInfo.SetAsDisjoint(group1, group2); } } } } return overloadGroupsInfo; }
public void IsProperSupersetOfTest() { var set = new HashSet<int>(); var arr = Enumerable.Range(0, 10).ToArray(); set.UnionWith(arr); set.Add(11); Assert.IsTrue(set.IsProperSupersetOf(arr)); }
public void IsProperSupersetOfEmptyArr() { var arr = new int[0]; var set=new HashSet<int>(); set.Add(0); Assert.IsTrue(set.IsProperSupersetOf(arr)); }