Пример #1
0
        public static IMap <BasicBlock, IMSet <BasicBlock> > Dominators(BasicBlock root)
        {
            var preorder = PreOrder(root);
            var map      = new Map <BasicBlock, IntSet>(preorder.Count);

            for (var i = 0; i < preorder.Count; i++)
            {
                var vec = new IntSet(preorder.Count);
                if (preorder[i].Equals(root))
                {
                    vec[i] = true;
                }
                else
                {
                    vec.SetAll(true);
                }
                map.Add(preorder[i], vec);
            }
            var change = default(bool);

            do
            {
                change = false;
                for (var i = 0; i < preorder.Count; i++)
                {
                    var bb = preorder[i];
                    if (!bb.Equals(root))
                    {
                        var vec = new IntSet(preorder.Count);
                        vec.SetAll(true);
                        foreach (var s in bb.Sources)
                        {
                            vec.IntersectInPlace(map[s]);
                        }
                        vec[i] = true;
                        if (!vec.Equals(map[bb]))
                        {
                            map[bb] = vec;
                            change  = true;
                        }
                    }
                }
            }while (change);
            var res = new Map <BasicBlock, IMSet <BasicBlock> >();

            for (var i = 0; i < preorder.Count; i++)
            {
                var set = new Set <BasicBlock>();
                var vec = map[preorder[i]];
                foreach (var j in vec)
                {
                    set.Add(preorder[j]);
                }
                res.Add(preorder[i], set);
            }
            return(res);
        }
Пример #2
0
        public void equility_and_hash_works_according_to_the_content(IntSet x, IntSet y)
        {
            bool equals    = x.Equals(y);
            bool setEquals = x.SetEquals(y);
            bool hsEquals  = new HashSet <int>(x).SetEquals(new HashSet <int>(y));

            Assert.AreEqual(hsEquals, equals);
            Assert.AreEqual(hsEquals, setEquals);
            if (equals)
            {
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
        }
Пример #3
0
        public void equility_and_hash_works_according_to_the_content(IntSet x, IntSet y)
        {
            bool equals    = x.Equals(y);
            bool setEquals = x.SetEquals(y);
            bool hsEquals  = new HashSet <int>(x).SetEquals(new HashSet <int>(y));

            Assert.AreEqual(hsEquals, equals);
            Assert.AreEqual(hsEquals, setEquals);
            if (equals)
            {
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
            else
            {
                // Uncomment for hashing failure statistics
                // Assert.AreNotEqual(x.GetHashCode(), y.GetHashCode());
            }
        }
Пример #4
0
        public void equility_and_hash_to_set_with_different_size_works_according_to_the_content(IntSet x, IntSet yOfSameType)
        {
            BitSetType otherSetType = new BitSetType(10);
            var        y            = yOfSameType.Intersect(otherSetType.All);
            bool       equals       = x.Equals(y);
            bool       setEquals    = x.SetEquals(y);
            bool       hsEquals     = new HashSet <int>(x).SetEquals(new HashSet <int>(y));

            Assert.AreEqual(hsEquals, equals);
            Assert.AreEqual(hsEquals, setEquals);
            if (equals)
            {
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
            else
            {
                // Uncomment for hashing failure statistics
                // Assert.AreNotEqual(x.GetHashCode(), y.GetHashCode());
            }
        }
Пример #5
0
        public void equility_and_hash_works_according_to_the_content(IntSet x, IntSet y)
        {
            bool equals = x.Equals(y);
            bool setEquals = x.SetEquals(y);
            bool hsEquals = new HashSet<int>(x).SetEquals(new HashSet<int>(y));

            Assert.AreEqual(hsEquals, equals);
            Assert.AreEqual(hsEquals, setEquals);
            if (equals)
            {
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
            else
            {
                // Uncomment for hashing failure statistics
                // Assert.AreNotEqual(x.GetHashCode(), y.GetHashCode());
            }
        }
Пример #6
0
        public void equility_and_hash_to_set_with_different_size_works_according_to_the_content(IntSet x, IntSet yOfSameType)
        {
            BitSetType otherSetType = new BitSetType(10);
            var y = yOfSameType.Intersect(otherSetType.All);
            bool equals = x.Equals(y);
            bool setEquals = x.SetEquals(y);
            bool hsEquals = new HashSet<int>(x).SetEquals(new HashSet<int>(y));

            Assert.AreEqual(hsEquals, equals);
            Assert.AreEqual(hsEquals, setEquals);
            if (equals)
            {
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
            else
            {
                // Uncomment for hashing failure statistics
                // Assert.AreNotEqual(x.GetHashCode(), y.GetHashCode());
            }
        }
Пример #7
0
 public static IMap<BasicBlock, IMSet<BasicBlock>> Dominators(BasicBlock root)
 {
     var preorder = PreOrder(root);
     var map = new Map<BasicBlock, IntSet>(preorder.Count);
     for (var i = 0; i < preorder.Count; i++)
     {
         var vec = new IntSet(preorder.Count);
         if (preorder[i].Equals(root))
             vec[i] = true;
         else
             vec.SetAll(true);
         map.Add(preorder[i], vec);
     }
     var change = default(bool);
     do
     {
         change = false;
         for (var i = 0; i < preorder.Count; i++)
         {
             var bb = preorder[i];
             if (!bb.Equals(root))
             {
                 var vec = new IntSet(preorder.Count);
                 vec.SetAll(true);
                 foreach (var s in bb.Sources)
                     vec.IntersectInPlace(map[s]);
                 vec[i] = true;
                 if (!vec.Equals(map[bb]))
                 {
                     map[bb] = vec;
                     change = true;
                 }
             }
         }
     }
     while (change);
     var res = new Map<BasicBlock, IMSet<BasicBlock>>();
     for (var i = 0; i < preorder.Count; i++)
     {
         var set = new Set<BasicBlock>();
         var vec = map[preorder[i]];
         foreach (var j in vec)
             set.Add(preorder[j]);
         res.Add(preorder[i], set);
     }
     return res;
 }
        public void equility_and_hash_works_according_to_the_content(IntSet x, IntSet y)
        {
            bool equals = x.Equals(y);
            bool setEquals = x.SetEquals(y);
            bool hsEquals = new HashSet<int>(x).SetEquals(new HashSet<int>(y));

            Assert.AreEqual(hsEquals, equals);
            Assert.AreEqual(hsEquals, setEquals);
            if (equals)
            {
                Assert.AreEqual(x.GetHashCode(), y.GetHashCode());
            }
        }