예제 #1
0
        public IAnalysisSet Union(IEnumerable <AnalysisProxy> items, out bool wasChanged)
        {
            AnalysisHashSet otherHc = items as AnalysisHashSet;

            if (otherHc != null)
            {
                bool anyChanged = false;

                if (otherHc._count != 0)
                {
                    // do a fast copy from the other hash set...
                    for (int i = 0; i < otherHc._buckets.Length; i++)
                    {
                        var key = otherHc._buckets[i].Key;
                        if (key != null && key != AnalysisDictionaryRemovedValue.Instance)
                        {
                            anyChanged |= AddOne(key);
                        }
                    }
                }
                wasChanged = anyChanged;
                return(this);
            }

            // some other set, copy it the slow way...
            wasChanged = false;
            foreach (var item in items)
            {
                wasChanged |= AddOne(item);
            }
            return(this);
        }
예제 #2
0
        public IAnalysisSet Clone()
        {
            var buckets = new Bucket[_buckets.Length];

            for (int i = 0; i < buckets.Length; i++)
            {
                buckets[i] = _buckets[i];
            }
            var res = new AnalysisHashSet(Comparer);

            res._buckets = buckets;
            res._count   = _count;
            return(res);
        }
        public void HashSet() {
            var projectEntry = CreateProjectEntry();
            List<AnalysisProxy> values = new List<AnalysisProxy>();
            for (int i = 0; i < 10; i++) {
                values.Add(new TestAnalysisValue(projectEntry).Proxy);
            }

            var set = new AnalysisHashSet();
            for (int i = 0; i < values.Count; i++) {
                Assert.IsFalse(set.Contains(values[i]));
                Assert.AreEqual(set, set.Add(values[i]));
                Assert.AreEqual(i + 1, set.Count);
                Assert.IsTrue(set.Contains(values[i]));

                for (int j = 0; j <= i; j++) {
                    Assert.AreEqual(set, set.Add(values[j]));
                    Assert.AreEqual(i + 1, set.Count);
                }
            }

            foreach (var enumMaker in EnumMaker) {
                set = new AnalysisHashSet();
                for (int i = 0; i < values.Count; i++) {
                    Assert.IsFalse(set.Contains(values[i]));
                    Assert.AreEqual(set, set.Union(enumMaker(values[i])));
                    Assert.AreEqual(i + 1, set.Count);
                    Assert.IsTrue(set.Contains(values[i]));

                    for (int j = 0; j <= i; j++) {
                        Assert.AreEqual(set, set.Union(enumMaker(values[j])));
                        Assert.AreEqual(i + 1, set.Count);
                    }
                }
            }

            set = new AnalysisHashSet();
            for (int i = 0; i < values.Count; i++) {
                Assert.IsFalse(set.Contains(values[i]));
                bool wasChanged;
                Assert.AreEqual(set, set.Add(values[i], out wasChanged));
                Assert.AreEqual(true, wasChanged);
                Assert.AreEqual(i + 1, set.Count);
                Assert.IsTrue(set.Contains(values[i]));

                for (int j = 0; j <= i; j++) {                    
                    Assert.AreEqual(set, set.Add(values[j], out wasChanged));
                    Assert.IsFalse(wasChanged);
                    Assert.AreEqual(i + 1, set.Count);
                }
            }

            foreach (var enumMaker in EnumMaker) {
                set = new AnalysisHashSet();
                for (int i = 0; i < values.Count; i++) {
                    Assert.IsFalse(set.Contains(values[i]));
                    bool wasChanged;
                    Assert.AreEqual(set, set.Union(enumMaker(values[i]), out wasChanged));
                    Assert.IsTrue(wasChanged);
                    Assert.AreEqual(i + 1, set.Count);

                    for (int j = 0; j <= i; j++) {
                        Assert.AreEqual(set, set.Union(enumMaker(values[j]), out wasChanged));
                        Assert.IsFalse(wasChanged);
                        Assert.AreEqual(i + 1, set.Count);
                    }
                }
            }
        }
예제 #4
0
            public IAnalysisSet Union(IEnumerable <AnalysisProxy> items, out bool wasChanged)
            {
                AnalysisProxy ns;

                if (items == null)
                {
                    wasChanged = false;
                    return(this);
                }
                else if ((ns = items as AnalysisProxy) != null)
                {
                    return(Add(ns, out wasChanged));
                }
                else
                {
                    int count = items.Count();
                    if (Value1.IsAlive)
                    {
                        if (!items.Contains(Value1))
                        {
                            count++;
                        }
                    }
                    if (Value2.IsAlive)
                    {
                        if (!items.Contains(Value2))
                        {
                            count++;
                        }
                    }

                    switch (count)
                    {
                    case 0:
                        wasChanged = false;
                        return(AnalysisSetEmptyObject.Instance);

                    case 1:
                        if (Value1.IsAlive)
                        {
                            wasChanged = false;
                            return(Value1);
                        }
                        else if (Value2.IsAlive)
                        {
                            wasChanged = false;
                            return(Value2);
                        }
                        wasChanged = true;
                        return(items.First());

                    case 2:
                        AnalysisProxy first = null;
                        if (Value1.IsAlive)
                        {
                            first = Value1;
                        }
                        if (Value2.IsAlive)
                        {
                            if (first == null)
                            {
                                first = Value2;
                            }
                            else
                            {
                                // items is empty...
                                wasChanged = false;
                                return(this);
                            }
                        }
                        if (first == null)
                        {
                            // Value1 & Value2 are gone
                            wasChanged = true;
                            return(new AnalysisSetTwoObject(items));
                        }
                        // Value1 or Value2 is gone...
                        if (!items.First().IsAlive)
                        {
                            // and so is the 1 item we have...
                            wasChanged = false;
                            return(first);
                        }
                        wasChanged = true;
                        return(new AnalysisSetTwoObject(first, items.First()));

                    default:
                        var res = new AnalysisHashSet();
                        if (Value1.IsAlive)
                        {
                            res.Add(Value1);
                        }
                        if (Value2.IsAlive)
                        {
                            res.Add(Value2);
                        }
                        res.Union(items, out wasChanged);
                        return(res);
                    }
                }
            }
예제 #5
0
 public IAnalysisSet Clone() {            
     var buckets = new Bucket[_buckets.Length];
     for (int i = 0; i < buckets.Length; i++) {
         buckets[i] = _buckets[i];
     }
     var res = new AnalysisHashSet(Comparer);
     res._buckets = buckets;
     res._count = _count;
     return res;
 }