コード例 #1
0
ファイル: ArrayQueue.cs プロジェクト: vztpv/ClauTextSharp
        public void push(ArrayQueue <T> other) // chk!!
        {
            if (other.empty())
            {
                return;
            }
            int newSize = capacity;

            while (newSize - num < other.size())
            {
                newSize = newSize * 2;
            }
            if (newSize != this.capacity)
            {
                // expand array queue.
                ArrayQueue <T> temp = new ArrayQueue <T>(newSize);
                temp.start = 0;
                //
                for (int i = 0; i < this.size(); ++i)
                {
                    temp.set(i, this.get(i));
                }

                int iend = other.num;
                for (int i = 0; i < iend; ++i)
                {
                    temp.set(i + this.num, other.get(i));
                }

                temp.num      = this.num + other.num;
                this.arr      = temp.arr;
                this.num      = temp.num;
                this.start    = temp.start;
                this.capacity = temp.capacity;
            }
            else
            {
                for (int i = 0; i < other.size(); ++i)
                {
                    this.push((other.get(i)));
                }
            }
        }
コード例 #2
0
ファイル: ArrayQueue.cs プロジェクト: vztpv/ClauTextSharp
        private void expand()
        {
            // expand array queue.
            ArrayQueue <T> temp = new ArrayQueue <T>(capacity * 2);

            //
            for (int i = 0; i < capacity; ++i)
            {
                temp.set(i, arr[(start + i) & (capacity - 1)]);
            }
            temp.start    = 0;
            temp.num      = size();
            this.num      = temp.num;
            this.arr      = temp.arr;
            this.start    = temp.start;
            this.capacity = temp.capacity;
        }