Esempio n. 1
0
        public void Remove(DequeNode <TValue> node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (this.front == this.back)
            {
                this.front = this.back = null;
            }
            else if (this.front == node)
            {
                this.front      = this.front.right;
                this.front.left = null;
            }
            else if (this.back == node)
            {
                this.back       = this.back.left;
                this.back.right = null;
            }
            else
            {
                node.left.right = node.right;
                node.right.left = node.left;
            }

            node.left = node.right = null;
        }
        public override string ToString()
        {
            StringBuilder stringBuilder = new StringBuilder();

            for (DequeNode <TValue> node = this; node != null; node = node.right)
            {
                stringBuilder.Append(node.value + " ");
            }

            return(stringBuilder.ToString());
        }
Esempio n. 3
0
        public DequeNode <TValue> PopBack()
        {
            DequeNode <TValue> node = this.back;

            if (this.front == this.back)
            {
                this.front = this.back = null;
            }
            else
            {
                this.back       = node.left;
                this.back.right = null;
            }

            node.left = node.right = null;
            return(node);
        }
Esempio n. 4
0
        public void PushFront(DequeNode <TValue> node)
        {
            if (node == null)
            {
                throw new ArgumentNullException(nameof(node));
            }

            if (this.front == null)
            {
                node.left  = node.right = null;
                this.front = this.back = node;
            }
            else
            {
                node.left       = null;
                node.right      = this.front;
                this.front.left = node;
                this.front      = node;
            }
        }
            private void Visit(TPage page)
            {
                if (this.visitDictionary.ContainsKey(page))
                {
                    this.visitList.Remove(this.visitDictionary[page]);
                    this.visitList.PushFront(this.visitDictionary[page]);
                    return;
                }

                if (this.historyLength == this.historyCapacity)
                {
                    DequeNode <TPage> node = this.visitList.PopBack();
                    this.visitDictionary.Remove(node.value);
                    this.historyLength -= 1;
                }

                this.visitDictionary[page] = new DequeNode <TPage> {
                    value = page
                };
                this.visitList.PushFront(this.visitDictionary[page]);
                this.historyLength += 1;
            }