Пример #1
0
        public override bool Get(ref T t)
        {
            var result = false;

            t.Value = default(TV);
            LinkedListNode <T> rNode;

            if (LruFunction.SearchData <T, TK, TV>(mLink, t.Key, out rNode))
            {
                LruFunction.Sort(mLink, rNode);
                result = true;
            }
            else
            {
                LinkedListNode <Tuple <T, int> > rHisNode;
                if (LruFunction.SearchHistoryData <T, TK, TV>(mLinkedList_his, t.Key, out rHisNode))
                {
                    var k = rHisNode.Value.Item2 + 1;
                    if (k >= K)
                    {
                        mLinkedList_his.Remove(rHisNode);
                        Set(rHisNode.Value.Item1);
                    }
                    else
                    {
                        rHisNode.Value = new Tuple <T, int>(rHisNode.Value.Item1, k);
                        LruFunction.Sort(mLinkedList_his, rHisNode);
                    }
                    result = true;
                }
            }
            return(result);
        }
Пример #2
0
        /// <summary>
        /// 访问数据项
        /// </summary>
        /// <param name="t"></param>
        /// <returns></returns>
        public override bool Get(ref T t)
        {
            t.Value = default(TV);
            LinkedListNode <T> rNode;

            if (LruFunction.SearchData <T, TK, TV>(mLink, t.Key, out rNode))
            {
                //将查找的节点移动到链表头部
                LruFunction.Sort(mLink, rNode);
                return(true);
            }
            return(false);
        }
Пример #3
0
        public override bool Get(ref T t)
        {
            var result = false;
            LinkedListNode <T> rNode;
            T temp;

            if (LruFunction.SearchData <T, TK, TV>(mLink, t.Key, out rNode))
            {
                LruFunction.Sort(mLink, rNode);
                result = true;
            }
            else if (LruFunction.SearchQueue <T, TK, TV>(mHisQueue, t.Key, out temp))
            {
                mHisQueue.Enqueue(temp);
                t      = temp;
                result = true;
            }
            return(result);
        }
Пример #4
0
        /// <summary>
        /// 添加数据项
        /// </summary>
        /// <param name="t"></param>
        public override void Set(T t)
        {
            while (mLink.Count > Cap)
            {
                mLink.RemoveLast();
            }
            LinkedListNode <T> rNode;

            if (LruFunction.SearchData <T, TK, TV>(mLink, t.Key, out rNode))
            {
                //将查找的节点移动到链表头部
                LruFunction.Sort(mLink, rNode);
            }
            else
            {
                mLink.RemoveLast();
                mLink.AddFirst(t);
            }
        }
Пример #5
0
        public override void Set(T t)
        {
            T temp;

            if (LruFunction.SearchQueue <T, TK, TV>(mHisQueue, t.Key, out temp))
            {
                while (mLink.Count > Cap)
                {
                    mLink.RemoveLast();
                }
                mLink.AddFirst(t);
            }
            else
            {
                while (mHisQueue.Count > CapHistory)
                {
                    mHisQueue.Dequeue();
                }
                mHisQueue.Enqueue(t);
            }
        }