⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 setasarray.cs

📁 Data Structures and Algorithms with Object-Oriented Design Patterns in C# 这本书的范例代码dll自己反编译的source
💻 CS
字号:
namespace Opus6
{
    using System;
    using System.Collections;

    [Copyright("Copyright (c) 2001 by Bruno R. Preiss, P.Eng."), Version("$Id: SetAsArray.cs,v 1.5 2001/10/28 19:50:09 brpreiss Exp $")]
    public class SetAsArray : AbstractSet, Set, SearchableContainer, Container, IComparable, IEnumerable
    {
        public SetAsArray(int n) : base(n)
        {
            this.array = new bool[base.universeSize];
            for (int num1 = 0; num1 < base.universeSize; num1++)
            {
                this.array[num1] = false;
            }
        }

        public override void Accept(Visitor visitor)
        {
            for (int num1 = 0; num1 < base.universeSize; num1++)
            {
                if (this.IsMember(num1))
                {
                    visitor.Visit(num1);
                }
            }
        }

        public override int CompareTo(object arg)
        {
            throw new MethodNotImplementedException();
        }

        public virtual Set Difference(Set set)
        {
            SetAsArray array1 = (SetAsArray) set;
            if (base.universeSize != array1.universeSize)
            {
                throw new ArgumentException("mismatched sets");
            }
            SetAsArray array2 = new SetAsArray(base.universeSize);
            for (int num1 = 0; num1 < base.universeSize; num1++)
            {
                array2.array[num1] = this.array[num1] & !array1.array[num1];
            }
            return array2;
        }

        public virtual bool Equals(Set set)
        {
            SetAsArray array1 = (SetAsArray) set;
            if (base.universeSize != array1.universeSize)
            {
                throw new ArgumentException("mismatched sets");
            }
            for (int num1 = 0; num1 < base.universeSize; num1++)
            {
                if (this.array[num1] != array1.array[num1])
                {
                    return false;
                }
            }
            return true;
        }

        public override IEnumerator GetEnumerator()
        {
            return new Opus6.SetAsArray.Enumerator(this);
        }

        public override void Insert(int item)
        {
            this.array[item] = true;
        }

        public virtual Set Intersection(Set set)
        {
            SetAsArray array1 = (SetAsArray) set;
            if (base.universeSize != array1.universeSize)
            {
                throw new ArgumentException("mismatched sets");
            }
            SetAsArray array2 = new SetAsArray(base.universeSize);
            for (int num1 = 0; num1 < base.universeSize; num1++)
            {
                array2.array[num1] = this.array[num1] & array1.array[num1];
            }
            return array2;
        }

        public override bool IsMember(int item)
        {
            return this.array[item];
        }

        public virtual bool IsSubset(Set set)
        {
            SetAsArray array1 = (SetAsArray) set;
            if (base.universeSize != array1.universeSize)
            {
                throw new ArgumentException("mismatched sets");
            }
            for (int num1 = 0; num1 < base.universeSize; num1++)
            {
                if (this.array[num1] && !array1.array[num1])
                {
                    return false;
                }
            }
            return true;
        }

        public static void Main()
        {
            AbstractSet.TestSet(new SetAsArray(0x20), new SetAsArray(0x20), new SetAsArray(0x20));
        }

        public override void Purge()
        {
            for (int num1 = 0; num1 < base.universeSize; num1++)
            {
                this.array[num1] = false;
            }
        }

        public virtual Set Union(Set set)
        {
            SetAsArray array1 = (SetAsArray) set;
            if (base.universeSize != array1.universeSize)
            {
                throw new ArgumentException("mismatched sets");
            }
            SetAsArray array2 = new SetAsArray(base.universeSize);
            for (int num1 = 0; num1 < base.universeSize; num1++)
            {
                array2.array[num1] = this.array[num1] | array1.array[num1];
            }
            return array2;
        }

        public override void Withdraw(int item)
        {
            this.array[item] = false;
        }


        public override int Count
        {
            get
            {
                int num1 = 0;
                for (int num2 = 0; num2 < base.universeSize; num2++)
                {
                    if (this.IsMember(num2))
                    {
                        num1++;
                    }
                }
                return num1;
            }
        }

        public override bool IsEmpty
        {
            get
            {
                for (int num1 = 0; num1 < base.universeSize; num1++)
                {
                    if (this.IsMember(num1))
                    {
                        return false;
                    }
                }
                return true;
            }
        }

        public override bool IsFull
        {
            get
            {
                for (int num1 = 0; num1 < base.universeSize; num1++)
                {
                    if (!this.IsMember(num1))
                    {
                        return false;
                    }
                }
                return true;
            }
        }


        protected bool[] array;


        private class Enumerator : IEnumerator
        {
            internal Enumerator(SetAsArray set)
            {
                this.item = -1;
                this.set = set;
            }

            public bool MoveNext()
            {
                this.item++;
                while (this.item < this.set.UniverseSize)
                {
                    if (this.set.IsMember(this.item))
                    {
                        break;
                    }
                    this.item++;
                }
                if (this.item == this.set.UniverseSize)
                {
                    this.item = -1;
                }
                return (this.item >= 0);
            }

            public void Reset()
            {
                this.item = 1;
            }


            public object Current
            {
                get
                {
                    if (this.item < 0)
                    {
                        throw new InvalidOperationException();
                    }
                    return this.item;
                }
            }


            private int item;
            private SetAsArray set;
        }
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -