static bool IsGroupTagsUnique(List<CityPack> cities, HashSet<string> tags)
 {
     foreach (CityPack pack in cities)
     {
         if (tags.IsSubsetOf(pack.cities) && !tags.IsProperSubsetOf(pack.cities))
         {
             return false;
         }
     }
     return true;
 }
		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));
		}
Exemple #3
0
 public bool IsProperSubsetOf(IEnumerable <string> other)
 {
     return(_hashset.IsProperSubsetOf(other));
 }
 public void IsProperSubsetEmptySetOfTest()
 {
     var set = new HashSet<int>();
     var arr = Enumerable.Range(0, 10).ToArray();
     Assert.IsTrue(set.IsProperSubsetOf(arr));
 }
Exemple #5
0
        public void Should_properly_expose_IsProperSubsetOf()
        {
            var originalSet = new HashSet <Card>()
            {
                Card.Parse("QC"), Card.Parse("TS")
            };
            var byValueSet = new SetByValue <Card>(originalSet);

            Check.That(byValueSet.IsProperSubsetOf(new[] { Card.Parse("QC") })).IsEqualTo(originalSet.IsProperSubsetOf(new[] { Card.Parse("QC") }));
        }
Exemple #6
0
    private bool _ValidateResultMaterials()
    {
        HashSet <Material> hashSet = new HashSet <Material>();

        for (int i = 0; i < this.objsToMesh.Count; i++)
        {
            if (this.objsToMesh[i] != null)
            {
                Material[] gomaterials = MB_Utility.GetGOMaterials(this.objsToMesh[i]);
                for (int j = 0; j < gomaterials.Length; j++)
                {
                    if (gomaterials[j] != null)
                    {
                        hashSet.Add(gomaterials[j]);
                    }
                }
            }
        }
        HashSet <Material> hashSet2 = new HashSet <Material>();

        for (int k = 0; k < this.resultMaterials.Length; k++)
        {
            MB_MultiMaterial mb_MultiMaterial = this.resultMaterials[k];
            if (mb_MultiMaterial.combinedMaterial == null)
            {
                Debug.LogError("Combined Material is null please create and assign a result material.");
                return(false);
            }
            Shader shader = mb_MultiMaterial.combinedMaterial.shader;
            for (int l = 0; l < mb_MultiMaterial.sourceMaterials.Count; l++)
            {
                if (mb_MultiMaterial.sourceMaterials[l] == null)
                {
                    Debug.LogError("There are null entries in the list of Source Materials");
                    return(false);
                }
                if (shader != mb_MultiMaterial.sourceMaterials[l].shader)
                {
                    Debug.LogWarning(string.Concat(new object[]
                    {
                        "Source material ",
                        mb_MultiMaterial.sourceMaterials[l],
                        " does not use shader ",
                        shader,
                        " it may not have the required textures. If not empty textures will be generated."
                    }));
                }
                if (hashSet2.Contains(mb_MultiMaterial.sourceMaterials[l]))
                {
                    Debug.LogError("A Material " + mb_MultiMaterial.sourceMaterials[l] + " appears more than once in the list of source materials in the source material to combined mapping. Each source material must be unique.");
                    return(false);
                }
                hashSet2.Add(mb_MultiMaterial.sourceMaterials[l]);
            }
        }
        if (hashSet.IsProperSubsetOf(hashSet2))
        {
            hashSet2.ExceptWith(hashSet);
            Debug.LogWarning("There are materials in the mapping that are not used on your source objects: " + this.PrintSet(hashSet2));
        }
        if (hashSet2.IsProperSubsetOf(hashSet))
        {
            hashSet.ExceptWith(hashSet2);
            Debug.LogError("There are materials on the objects to combine that are not in the mapping: " + this.PrintSet(hashSet));
            return(false);
        }
        return(true);
    }
Exemple #7
0
 public bool IsProperSubsetOf(IEnumerable <T> other)
 {
     return(StaticEmptySet.IsProperSubsetOf(other));
 }
	bool _ValidateResultMaterials(){ 			
		HashSet<Material> allMatsOnObjs = new HashSet<Material>();
		for (int i = 0; i < objsToMesh.Count; i++){
			if (objsToMesh[i] != null){
				Material[] ms = MB_Utility.GetGOMaterials(objsToMesh[i]);
				for (int j = 0; j < ms.Length; j++){
					if (ms[j] != null) allMatsOnObjs.Add(ms[j]);	
				}
			}
		}
		HashSet<Material> allMatsInMapping = new HashSet<Material>();
		for (int i = 0; i < resultMaterials.Length; i++){
			MB_MultiMaterial mm = resultMaterials[i];
			if (mm.combinedMaterial == null){
				Debug.LogError("Combined Material is null please create and assign a result material.");
				return false;
			}
			Shader targShader = mm.combinedMaterial.shader;
			for (int j = 0; j < mm.sourceMaterials.Count; j++){
				if (mm.sourceMaterials[j] == null){
					Debug.LogError("There are null entries in the list of Source Materials");
					return false;
				}
				if (targShader != mm.sourceMaterials[j].shader){
					Debug.LogWarning("Source material " + mm.sourceMaterials[j] + " does not use shader " + targShader + " it may not have the required textures. If not empty textures will be generated.");	
				}
				if (allMatsInMapping.Contains(mm.sourceMaterials[j])){
					Debug.LogError("A Material " + mm.sourceMaterials[j] + " appears more than once in the list of source materials in the source material to combined mapping. Each source material must be unique.");	
					return false;
				}
				allMatsInMapping.Add(mm.sourceMaterials[j]);
			}
		}
				
		if (allMatsOnObjs.IsProperSubsetOf(allMatsInMapping)){
			allMatsInMapping.ExceptWith(allMatsOnObjs);
			Debug.LogWarning("There are materials in the mapping that are not used on your source objects: " + PrintSet(allMatsInMapping));	
		}
		if (allMatsInMapping.IsProperSubsetOf(allMatsOnObjs)){
			allMatsOnObjs.ExceptWith(allMatsInMapping);
			Debug.LogError("There are materials on the objects to combine that are not in the mapping: " + PrintSet(allMatsOnObjs));	
			return false;
		}		
		return true;
	}
 /// <summary>
 ///     Determines whether the hash set is a proper subset of the specified collection.
 /// </summary>
 /// <param name="other"> The collection to compare to the current hash set. </param>
 /// <returns>
 ///     True if the hash set is a proper subset of other; otherwise, false.
 /// </returns>
 public virtual bool IsProperSubsetOf(IEnumerable <T> other)
 {
     return(_set.IsProperSubsetOf(other));
 }
 ///<inheritdoc/>
 public bool IsProperSubsetOf(IEnumerable <TKey> other)
 {
     lock (_syncLock) return(_hashSet.IsProperSubsetOf(other));
 }
 public bool IsProperSubsetOf(CompletedSuit other)
 {
     return(piecesHashSet.IsProperSubsetOf(other.piecesHashSet));
 }
Exemple #12
0
 public bool IsProperSubsetOf(IEnumerable <TElement> other) => backingSet.IsProperSubsetOf(other);
    public static void Main()
    {
        HashSet <int> emptySet = new HashSet <int>();

        HashSet <int> A = new HashSet <int>();

        A.Add(1);
        A.Add(2);
        A.Add(3);
        A.Add(4);

        HashSet <int> B = new HashSet <int>();

        B.Add(1);
        B.Add(2);
        B.Add(3);
        B.Add(4);
        B.Add(5);

        Console.Write("Empty Set Contents: ");
        foreach (int i in emptySet)
        {
            Console.Write(i + " ");
        }

        Console.Write("\nSet A Contents: ");
        foreach (int i in A)
        {
            Console.Write(i + " ");
        }

        Console.Write("\nSet B Contents: ");
        foreach (int i in B)
        {
            Console.Write(i + " ");
        }

        Console.WriteLine("\n");

        Console.WriteLine("A.IsProperSubsetOf(B) = " + A.IsProperSubsetOf(B));
        Console.WriteLine("emptySet.IsProperSubsetOf(A) = " + emptySet.IsProperSubsetOf(A));
        Console.WriteLine("emptySet.IsProperSubsetOf(B) = " + emptySet.IsProperSubsetOf(B));
        Console.WriteLine("B.IsproperSubsetOf(A) = " + B.IsProperSubsetOf(A));

        Console.WriteLine("\nAdding the number 5 to set A...");
        A.Add(5);

        Console.Write("\nSet A Contents: ");
        foreach (int i in A)
        {
            Console.Write(i + " ");
        }

        Console.Write("\nSet B Contents: ");
        foreach (int i in B)
        {
            Console.Write(i + " ");
        }

        Console.WriteLine("\nA.IsSubsetOf(B) = " + A.IsSubsetOf(B));
        Console.WriteLine("A.IsProperSubsetOf(B) = " + A.IsProperSubsetOf(B));

        Console.WriteLine("\nAdding the number 6 to set A...");
        A.Add(6);

        Console.Write("\nSet A Contents: ");
        foreach (int i in A)
        {
            Console.Write(i + " ");
        }

        Console.Write("\nSet B Contents: ");
        foreach (int i in B)
        {
            Console.Write(i + " ");
        }

        Console.WriteLine("\nA.IsSubsetOf(B) = " + A.IsSubsetOf(B));
        Console.WriteLine("A.IsProperSubsetOf(B) = " + A.IsProperSubsetOf(B));
        Console.WriteLine("B.IsSubsetOf(A) = " + B.IsSubsetOf(A));
        Console.WriteLine("B.IsProperSubsetOf(A) = " + B.IsProperSubsetOf(A));
    }
        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;
        }
Exemple #15
0
        public static List <Loop> FindLoops(List <BasicBlock> blocks)
        {
            // Great reference:  T Mowry's slides on loop invariant code motion
            // http://www.cs.cmu.edu/afs/cs/academic/class/15745-s11/public/lectures/L7-LICM.pdf
            //
            // We assume a reversible flow graph
            //

            // 1.  Find back edges
            List <KeyValuePair <BasicBlock, BasicBlock> > BackEdges = new List <KeyValuePair <BasicBlock, BasicBlock> >();

            foreach (BasicBlock b in blocks)
            {
                foreach (BasicBlock s in b.Successors)
                {
                    if (s.Dominates(b))
                    {
                        BackEdges.Add(new KeyValuePair <BasicBlock, BasicBlock>(b, s));
                    }
                }
            }

            // 2.  Identify natural loop for each backedge
            //    by walking graph upwards to dominator
            //
            //  The natural loop of a back edge is the set of blocks dominated by the head
            //    and which can reach the tail without traversing any backedge
            //
            HashSet <BasicBlock>[] LoopSets = new HashSet <BasicBlock> [BackEdges.Count];
            for (int i = 0; i < BackEdges.Count; i++)
            {
                LoopSets[i] = new HashSet <BasicBlock>();
            }

            Stack <BasicBlock> S = new Stack <BasicBlock>();

            for (int i = 0; i < BackEdges.Count; i++)
            {
                BasicBlock header = BackEdges[i].Value;
                S.Push(BackEdges[i].Key);
                LoopSets[i].Add(BackEdges[i].Key);

                do
                {
                    BasicBlock n = S.Pop();
                    if (n != header)
                    {
                        foreach (BasicBlock p in n.Predecessors)
                        {
                            if (!LoopSets[i].Contains(p))
                            {
                                LoopSets[i].Add(p);
                                S.Push(p);
                            }
                        }
                    }
                } while (S.Count > 0);
            }

            //
            // 3.  Merge loops with same header wherever one is not a proper subset of the other
            //
            List <Loop> loops = new List <Loop>();

            for (int i = 0; i < BackEdges.Count; i++)
            {
                BasicBlock           header = BackEdges[i].Value;
                HashSet <BasicBlock> loop   = LoopSets[i];
                if (loop == null)
                {
                    continue; // this loop was merged earlier
                }
                // find other loops with same header and merge with them with in with this one
                for (int j = i + 1; j < BackEdges.Count; j++)
                {
                    if (BackEdges[j].Value == header)
                    {
                        HashSet <BasicBlock> otherLoop = LoopSets[j];
                        if (loop.IsProperSubsetOf(otherLoop))
                        {
                            continue;
                        }
                        if (otherLoop.IsProperSupersetOf(loop))
                        {
                            continue;
                        }

                        LoopSets[i].UnionWith(LoopSets[j]);
                        LoopSets[j] = null;
                    }
                }
                loops.Add(new Loop(header, loop));
            }


            // Determine nestedness for remaining loops
            //   Loops are now either disjoint, or one is fully nested in the other
            // loop i is nested in loop j if j's header dominates i's header
            //   or they have the same header and j is larger
            int nLoops = loops.Count;

            List <int>[] LoopAncestors = new List <int> [nLoops];
            for (int i = 0; i < nLoops; i++)
            {
                List <int> ancestors = new List <int>();
                Loop       li        = loops[i];

                for (int j = 0; j < nLoops; j++)
                {
                    if (i == j)
                    {
                        continue;
                    }

                    Loop lj = loops[j];
                    if (li.Header != lj.Header)
                    {
                        if (lj.Header.Dominates(li.Header))
                        {
                            ancestors.Add(j);
                        }
                    }
                    else
                    {
                        if (lj.BlockCount > li.BlockCount)
                        {
                            ancestors.Add(j);
                        }
                    }
                }

                LoopAncestors[i] = ancestors;
            }

            int[] DescendentCounts = new int[nLoops];
            for (int i = 0; i < nLoops; i++)
            {
                foreach (int k in LoopAncestors[i])
                {
                    DescendentCounts[k]++;
                }
            }


            // Find innermost parent for each loop,
            //  which is the one with the lowest descendent count
            for (int i = 0; i < nLoops; i++)
            {
                List <int> ancestors = LoopAncestors[i];
                if (ancestors.Count != 0)
                {
                    int nImmediateParent = ancestors[0];
                    for (int j = 1; j < ancestors.Count; j++)
                    {
                        if (DescendentCounts[ancestors[j]] < DescendentCounts[nImmediateParent])
                        {
                            nImmediateParent = ancestors[j];
                        }
                    }

                    loops[i].Parent = loops[nImmediateParent];
                }
            }

            // sort loops inner to outer
            loops.Sort(
                delegate(Loop x, Loop y)
            {
                if (x == y)
                {
                    return(0);
                }
                while (true)
                {
                    x = x.Parent;
                    if (x == null)
                    {
                        return(-1);
                    }
                    else if (x == y)
                    {
                        return(1);
                    }
                }
            }
                );

            // Identify innermost loop for each block
            foreach (Loop l in loops)
            {
                foreach (BasicBlock b in l.Blocks)
                {
                    if (b.InnerMostLoop == null)
                    {
                        b.InnerMostLoop = l;
                    }
                    else if (l.IsNestedIn(b.InnerMostLoop))
                    {
                        b.InnerMostLoop = l;
                    }
                }
            }

            return(loops);
        }
Exemple #16
0
 public bool IsProperSubsetOf(IEnumerable <T> other)
 {
     return(set.IsProperSubsetOf(other));
 }
        public bool IsProperSubsetOf(IEnumerable <T> other)
        {
            bool isProperSubsetOf = hashSet.IsProperSubsetOf(other);

            return(isProperSubsetOf);
        }
        public void ShouldReturnProperSubsetOfNumberRange()
        {
            int minNumber = 3;
            int maxNumber = 15;

            UniqueRandomNumberGenerator g = new UniqueRandomNumberGenerator(minNumber, maxNumber);

            ReadOnlyCollection<int> numbers = g.RemainingNumbers;
            HashSet<int> initialSet = new HashSet<int>(numbers);

            const int GeneratedRandomNumberCount = 3;

            // Sanity check on test data
            Debug.Assert(
                GeneratedRandomNumberCount < initialSet.Count,
                String.Format("The generated random number count {0} must be less than the count of initial numbers {1} for this test.", GeneratedRandomNumberCount, initialSet.Count));

            Debug.WriteLine("Random Numbers");
            int number = 0;

            HashSet<int> actual = new HashSet<int>();
            for (int i = 1; i <= GeneratedRandomNumberCount; i++)
            {
                number = g.NewRandomNumber();
                actual.Add(number);
            }

            Assert.IsTrue(
                actual.IsProperSubsetOf(initialSet),
                "Generated numbers should be a subset of the set corresponding to the initial range.");
        }
Exemple #19
0
        public static bool IsProperSubsetOf <T>(IEnumerable <T> set1, IEnumerable <T> set2)
        {
            var newSet = new HashSet <T>(set1);

            return(newSet.IsProperSubsetOf(set2));
        }
 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 bool IsProperSubsetOf(IEnumerable <T> other)
 => items.IsProperSubsetOf(other);
 public bool IsProperSubsetOf(IEnumerable <EmailAddress> other) => hashset.IsProperSubsetOf(other);
 public bool IsProperSubsetOf(IEnumerable <T> other)
 {
     return(collection.IsProperSubsetOf(other));
 }
Exemple #24
0
 /// <summary>
 /// Check if this is a proper subset of <paramref name="set"/>.
 /// </summary>
 /// <param name="set">The second set.</param>
 /// <returns>this ⊂ <paramref name="set"/>.</returns>
 public bool IsProperSubset(Set <T> set)
 {
     return(Elements.IsProperSubsetOf(set.Elements));
 }
Exemple #25
0
 //--------------------------------------------------------------------------------------------------------------------------------
 public bool IsProperSubsetOf(EnumHashSet <T> other)
 {
     return(Raw.IsProperSubsetOf(other.Raw));
 }
Exemple #26
0
 public bool IsProperSubsetOf(IEnumerable <IModel> other)
 {
     return(_set.IsProperSubsetOf(other));
 }
Exemple #27
0
 public static bool IsProperSubsetOf <T>(HashSet <T> hashSet, IEnumerable <T> other)
 {
     (hashSet as Mock <T>)?.CheckDataRace(false);
     return(hashSet.IsProperSubsetOf(other));
 }
Exemple #28
0
 public void IsProperSubsetOfTest()
 {
     var set = new HashSet<int>();
     var arr = Enumerable.Range(0, 10).ToArray();
     set.UnionWith(arr);
     set.Remove(0);
     Assert.IsTrue(set.IsProperSubsetOf(arr));
 }
Exemple #29
0
 public bool IsProperSubsetOf(IEnumerable <T> set) => content.IsProperSubsetOf(set);
Exemple #30
0
 public bool IsProperSubsetOf(IEnumerable <T> other) => baseSet.IsProperSubsetOf(other);
Exemple #31
0
 public bool IsProperSubsetOf(IEnumerable <TVal> other)
 => hashSet.IsProperSubsetOf(other);
 /// <summary>
 ///     Determines whether the hash set is a proper subset of the specified collection.
 /// </summary>
 /// <param name="other"> The collection to compare to the current hash set. </param>
 /// <returns>
 ///     True if the hash set is a proper subset of other; otherwise, false.
 /// </returns>
 public virtual bool IsProperSubsetOf(IEnumerable <T> other) => _set.IsProperSubsetOf(other);
Exemple #33
0
 public bool IsProperSubsetOf(IEnumerable <string> other) => Flags.IsProperSubsetOf(other);
Exemple #34
0
        bool _ValidateResultMaterials()
        {
            HashSet <Material> allMatsOnObjs = new HashSet <Material>();

            for (int i = 0; i < objsToMesh.Count; i++)
            {
                if (objsToMesh[i] != null)
                {
                    Material[] ms = MeshBakerUtility.GetGOMaterials(objsToMesh[i]);
                    for (int j = 0; j < ms.Length; j++)
                    {
                        if (ms[j] != null)
                        {
                            allMatsOnObjs.Add(ms[j]);
                        }
                    }
                }
            }
            HashSet <Material> allMatsInMapping = new HashSet <Material>();

            for (int i = 0; i < resultMaterials.Length; i++)
            {
                MultiMaterial mm = resultMaterials[i];
                if (mm.combinedMaterial == null)
                {
                    Debug.LogError("Combined Material is null please create and assign a result material.");
                    return(false);
                }
                Shader targShader = mm.combinedMaterial.shader;
                for (int j = 0; j < mm.sourceMaterials.Count; j++)
                {
                    if (mm.sourceMaterials[j] == null)
                    {
                        Debug.LogError("There are null entries in the list of Source Materials");
                        return(false);
                    }
                    if (targShader != mm.sourceMaterials[j].shader)
                    {
                        Debug.LogWarning("Source material " + mm.sourceMaterials[j] + " does not use shader " + targShader + " it may not have the required textures. If not empty textures will be generated.");
                    }
                    if (allMatsInMapping.Contains(mm.sourceMaterials[j]))
                    {
                        Debug.LogError("A Material " + mm.sourceMaterials[j] + " appears more than once in the list of source materials in the source material to combined mapping. Each source material must be unique.");
                        return(false);
                    }
                    allMatsInMapping.Add(mm.sourceMaterials[j]);
                }
            }

            if (allMatsOnObjs.IsProperSubsetOf(allMatsInMapping))
            {
                allMatsInMapping.ExceptWith(allMatsOnObjs);
                Debug.LogWarning("There are materials in the mapping that are not used on your source objects: " + PrintSet(allMatsInMapping));
            }
            if (allMatsInMapping.IsProperSubsetOf(allMatsOnObjs))
            {
                allMatsOnObjs.ExceptWith(allMatsInMapping);
                Debug.LogError("There are materials on the objects to combine that are not in the mapping: " + PrintSet(allMatsOnObjs));
                return(false);
            }
            return(true);
        }
 /// <summary>
 /// Is proper subset of
 /// </summary>
 /// <param name="other">Other</param>
 /// <returns>"true" if it is a proper subset of other, otherwise "false"</returns>
 public bool IsProperSubsetOf(IEnumerable <Regex> other) => patterns.IsProperSubsetOf(other);
        public void ShouldReturnProperSubsetOfNumberArray()
        {
            int[] numbers = new int[] { 1, 2, 3, 4, 3, 6, 4, 8, 17, 42, 6 };
            ConcurrentBag<int> initialBag = new ConcurrentBag<int>(numbers);
            UniqueRandomNumberGenerator g = new UniqueRandomNumberGenerator(numbers);
            const int GeneratedRandomNumberCount = 3;

            // Sanity check on test data
            Debug.Assert(
                GeneratedRandomNumberCount < initialBag.Count,
                String.Format("The generated random number count {0} must be less than the count of initial numbers {1} for this test.", GeneratedRandomNumberCount, initialBag.Count));

            Debug.WriteLine("Random Numbers");
            int number = 0;

            ConcurrentBag<int> actualBag = new ConcurrentBag<int>();

            for (int i = 1; i <= GeneratedRandomNumberCount; i++)
            {
                number = g.NewRandomNumber();
                actualBag.Add(number);
            }

            HashSet<int> initialSet = new HashSet<int>(initialBag.AsEnumerable());
            HashSet<int> actualSet = new HashSet<int>(actualBag.AsEnumerable());

            Assert.IsTrue(
                actualSet.IsProperSubsetOf(initialSet),
                "Generated numbers should be a subset of the initial numbers.");
        }
Exemple #37
0
 public bool IsProperSubsetOf(IEnumerable <IVariant> other) =>
 _hashSet.IsProperSubsetOf(other);
Exemple #38
0
        //static Dictionary<string, int> TYPE_SIZES = new Dictionary<string, int>() { {"int", 4}, {"int?", 8}, {"float", 4}, {"float?", 8}, {"double", 8}, {"double?", 12},
        //    {"long", 8}, {"long?", 12}, {"DateTime", 8}, {"DateTime?", 12}, {"char", 2}, {"char?", 4}, {"string", 20}, {"string?", 20}, {"binary", 20 }, {"binary?", 20},
        //    {"Guid", 16}, {"Guid?", 20} };

        //static int DEFAULT_TYPE_SIZE = 20;

        private static void ComputeImprovementStats(ScopeMethodAnalysisResult result, ref ScopeAnalysisStats stats,
                                                    XElement vDef, Dictionary <string, string> pIdMapping)
        {
            stats.ColumnIndexAccesses  += result.ColumnIndexAccesses;
            stats.ColumnStringAccesses += result.ColumnStringAccesses;

            if (vDef == null || pIdMapping == null)
            {
                return;
            }

            var column = result.UsedColumnsSummary;

            if (column.IsBottom || column.IsTop)
            {
                return;
            }

            var pTypeFullName = result.ProcessorType.FullName();

            Utils.WriteLine("Checking column usage for " + pTypeFullName);

            if (!pIdMapping.ContainsKey(pTypeFullName))
            {
                Utils.WriteLine("WARNING: could not match processor mapping: " + pTypeFullName);
                return;
            }

            stats.Mapped += 1;
            try
            {
                var id        = pIdMapping[pTypeFullName];
                var operators = vDef.Descendants("operator");
                // Id can appear several times in the xml file since the same reducer can be used multiple times
                // and contained within different Scope vertices.
                var process = operators.Where(op => op.Attribute("id") != null && op.Attribute("id").Value.Equals(id)).ToList().First();

                // TODO: make parsing take into account commas in generics. Current approach
                // does not invalidate results, but is not clean.
                var input_schema = process.Descendants("input").Single().Attribute("schema").Value.Split(',');
                var inputSchema  = new Dictionary <string, string>();
                foreach (var input in input_schema)
                {
                    if (!input.Contains(":"))
                    {
                        continue;
                    }
                    var parts = input.Split(':');
                    var name  = parts[0].Trim();
                    var type  = parts[1].Trim();
                    inputSchema[name] = type;
                }
                var inputColumns = inputSchema.Keys.ToList();

                // TODO: make parsing take into account commas in generics. Current approach
                // does not invalidate results, but is not clean.
                var output_schema = process.Descendants("output").Single().Attribute("schema").Value.Split(',');
                var outputSchema  = new Dictionary <string, string>();
                foreach (var output in output_schema)
                {
                    if (!output.Contains(":"))
                    {
                        continue;
                    }
                    var parts = output.Split(':');
                    var name  = parts[0].Trim();
                    var type  = parts[1].Trim();
                    outputSchema[name] = type;
                }
                var outputColumns = outputSchema.Keys.ToList();


                var usedColumns = new HashSet <string>();
                foreach (var c in column.Elements)
                {
                    var val = c.Value;
                    if (val is string)
                    {
                        usedColumns.Add(val as string);
                    }
                    else if (val is int)
                    {
                        int index = Int32.Parse(val.ToString());
                        if (index >= 0 && index < inputColumns.Count)
                        {
                            usedColumns.Add(inputColumns[index]);
                        }
                        if (index >= 0 && index < outputColumns.Count)
                        {
                            usedColumns.Add(outputColumns[index]);
                        }

                        if ((index >= inputColumns.Count && index >= outputColumns.Count) || index < 0)
                        {
                            Utils.WriteLine("WARNING: some index was out of schema range: " + index);
                        }
                    }
                    else
                    {
                        Utils.WriteLine("WARNING: other value type used for indexing besides string and int: " + val);
                        return;
                    }
                }


                // Compute stats for schema input-output union.
                var allSchemaColumns = new HashSet <string>(inputColumns.Union(outputColumns));
                var redundants       = allSchemaColumns.Except(usedColumns);
                if (redundants.Any())
                {
                    stats.UnionColumnsUnused += 1;

                    var savings = redundants.Count();

                    stats.UnionColumnsSavings            += savings;
                    stats.UnionColumnsSavingsPercentages += savings / (double)allSchemaColumns.Count;

                    Utils.WriteLine(String.Format("SAVINGS (union) ({0}): used union columns subset of defined columns: {1}", result.Method.FullName(), savings));
                }
                else
                {
                    stats.UnionColumnsAllUsed += 1;
                    Utils.WriteLine("ALL USED (union): all union columns used.");
                }

                if (allSchemaColumns.IsProperSubsetOf(usedColumns))
                {
                    Utils.WriteLine("OVERAPPROXIMATION: redundant used columns: " + String.Join(" ", usedColumns.Except(allSchemaColumns)));
                    stats.Warnings += 1;
                }

                // Compute stats for input schema.
                redundants = inputColumns.Except(usedColumns);
                if (redundants.Any())
                {
                    stats.InputColumnsUnused += 1;

                    var savings = redundants.Count();

                    stats.InputColumnsSavings            += savings;
                    stats.InputColumnsSavingsPercentages += savings / (double)inputColumns.Count;

                    //var redundantInputByteSize = ComputeColumnsSize(redundants.Except(outputColumns), inputSchema);
                    //var inputByteSize = ComputeColumnsSize(inputColumns, inputSchema);

                    //stats.InputColumnsByteSavings += redundantInputByteSize;
                    //stats.InputColumnsByteSavingsPercentages += redundantInputByteSize / (double)inputByteSize;

                    Utils.WriteLine(String.Format("SAVINGS (input) ({0}): used input columns subset of defined columns: {1}", result.Method.FullName(), savings));
                }
                else
                {
                    stats.InputColumnsAllUsed += 1;
                    Utils.WriteLine("All USED (input): all input columns used.");
                }

                // Compute stats for input schema.
                redundants = outputColumns.Except(usedColumns);
                if (redundants.Any())
                {
                    stats.OutputColumnsUnused += 1;

                    var savings = redundants.Count();

                    stats.OutputColumnsSavings            += savings;
                    stats.OutputColumnsSavingsPercentages += savings / (double)outputColumns.Count;

                    Utils.WriteLine(String.Format("SAVINGS (output) ({0}): used output columns subset of defined columns: {1}", result.Method.FullName(), savings));
                }
                else
                {
                    stats.OutputColumnsAllUsed += 1;
                    Utils.WriteLine("All USED (output): all output columns used.");
                }
            }
            catch (Exception e)
            {
                Utils.WriteLine(String.Format("ERROR: failed to compute column usage for {0} {1}", pTypeFullName, e.Message));
            }
        }
Exemple #39
0
 /// <inheritdoc />
 public bool IsProperSubsetOf(IEnumerable <T> other)
 {
     lock (_lock) return(_set.IsProperSubsetOf(other));
 }
        public static bool IsQualifiedSubset(QualifiedSubset subsetToTest, AccessStructure miniamlAccess)
        {
            foreach (var qualifiedSet in miniamlAccess.Accesses)
               {
               if (!(qualifiedSet is QualifiedSubset)) continue;
               HashSet<int> a = new HashSet<int>(subsetToTest.Parties.Select(x => x.GetPartyId()));
               var qs = (QualifiedSubset)qualifiedSet;
               HashSet<int> b = new HashSet<int>(qs.Parties.Select(x => x.GetPartyId()));

               if (b.IsProperSubsetOf(a) || b.IsSubsetOf(a)) return true;
               }
               return false;
        }
Exemple #41
0
        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));
        }