Esempio n. 1
0
        public void intersect(NatSet other)
        {
            Contract.Requires(other != null);
            Contract.Requires(other != this);
            Contract.Ensures(Contract.OldValue(other) == other);
            Contract.Ensures(Contract.ForAll(0, this.sm.Length,
                                             i => this.sm[i] ? (other.sm[i] && Contract.OldValue(this.sm)[i]) : (!other.sm[i] || !Contract.OldValue(this.sm)[i])));

            Contract.Ensures(
                (this.rest.Count > 0) ?
                Contract.ForAll(0, this.rest.Count,
                                i => (other.rest.Contains(this.rest.ElementAt(i)) && Contract.OldValue(this.rest).Contains(this.rest.ElementAt(i))))
                : (Contract.OldValue(rest).Count > 0) ?
                Contract.ForAll(0, Contract.OldValue(this.rest).Count,
                                i => (!other.rest.Contains(Contract.OldValue(this.rest).ElementAt(i))))
                : true);

            for (int i = 0; (i < this.sm.Length && i < other.sm.Length); i++)
            {
                if ((other.sm[i] != this.sm[i]) && this.sm[i])
                {
                    remove(i);
                }
            }


            for (int i = 0; i < this.rest.Count; i++)
            {
                if (!other.rest.Contains(this.rest.ElementAt(i)))
                {
                    remove(this.rest.ElementAt(i));
                }
            }
        }
Esempio n. 2
0
        public void union(NatSet other)
        {
            Contract.Requires(other != null);
            Contract.Requires(other != this);
            Contract.Ensures(Contract.OldValue(other) == other);
            Contract.Ensures(Contract.ForAll(0, this.sm.Length,
                                             i => this.sm[i] ? (other.sm[i] || Contract.OldValue(this.sm)[i]) : (!other.sm[i] && !(Contract.OldValue(this.sm)[i]))));

            Contract.Ensures(
                (this.rest.Count > 0) ?
                Contract.ForAll(0, this.rest.Count,
                                i => (other.rest.Contains(this.rest.ElementAt(i)) || Contract.OldValue(this.rest).Contains(this.rest.ElementAt(i))))
                : Contract.OldValue(this.rest).Count == 0 && other.rest.Count == 0);

            for (int i = 0; i < other.sm.Length; i++)
            {
                if (other.sm[i])
                {
                    insert(i);
                }
            }

            for (int i = 0; i < other.rest.Count; i++)
            {
                insert(other.rest.ElementAt(i));
            }
        }
Esempio n. 3
0
        public void intersectFixedTest()
        {
            NatSet other = new NatSet();

            insert(20);
            insert(25);
            insert(105);
            insert(120);
            other.insert(20);
            other.insert(105);
            other.insert(115);

            this.intersect(other);
        }
Esempio n. 4
0
        public void unionFixedTest()
        {
            NatSet other = new NatSet();

            insert(20);
            insert(25);
            insert(105);
            insert(120);
            other.insert(20);
            other.insert(105);
            other.insert(115);

            this.union(other);
        }