Esempio n. 1
0
        protected void MoveToTail(NuGenCacheEntry e)
        {
            // tail element
            if (e == tail)
            {
                return;
            }

            // head element
            if (e == head)
            {
                head      = head.next;
                tail.next = e;
                e.prev    = tail;
                e.next    = null;
                tail      = e;
                return;
            }
            // inner element
            e.prev.next = e.next;
            e.next.prev = e.prev;
            tail.next   = e;
            e.prev      = tail;
            e.next      = null;
            tail        = e;
        }
Esempio n. 2
0
        public object Get(object key)
        {
            if (!hashtable.ContainsKey(key))
            {
                return(null);
            }
            NuGenCacheEntry e = (NuGenCacheEntry)hashtable[key];

            MoveToTail(e);
            return(e.val);
        }
Esempio n. 3
0
		public void Insert(object key, object val)
		{
						
			// if key exists replace it and return
			if (hashtable.ContainsKey(key))
			{
				((NuGenCacheEntry)hashtable[key]).val = val;
				return;
			}

			// remove lru entry if element count equals capacity
			if (size == capacity) RemoveFromHead();

			NuGenCacheEntry e = new NuGenCacheEntry(key, val);
			AddToTail(e);
			hashtable[key] = e;
		}
Esempio n. 4
0
        protected void AddToTail(NuGenCacheEntry e)
        {
            size++;

            if (tail == null)
            {
                head   = tail = e;
                e.prev = null;
                e.next = null;
                return;
            }

            tail.next = e;
            e.prev    = tail;
            e.next    = null;
            tail      = e;
        }
Esempio n. 5
0
        public void Insert(object key, object val)
        {
            // if key exists replace it and return
            if (hashtable.ContainsKey(key))
            {
                ((NuGenCacheEntry)hashtable[key]).val = val;
                return;
            }

            // remove lru entry if element count equals capacity
            if (size == capacity)
            {
                RemoveFromHead();
            }

            NuGenCacheEntry e = new NuGenCacheEntry(key, val);

            AddToTail(e);
            hashtable[key] = e;
        }
Esempio n. 6
0
		protected void AddToTail(NuGenCacheEntry e)
		{
			size++;

			if (tail == null)
			{
				head = tail = e;
				e.prev = null;
				e.next = null;
				return;
			}

			tail.next = e;
			e.prev = tail;
			e.next = null;
			tail = e;
		}
Esempio n. 7
0
		protected void MoveToTail(NuGenCacheEntry e)
		{
						
			// tail element
			if (e == tail) return;

			// head element
			if (e == head)
			{
				head = head.next;
				tail.next = e;
				e.prev = tail;
				e.next = null;
				tail = e;
				return;
			}
			// inner element
			e.prev.next = e.next;
			e.next.prev = e.prev;
			tail.next = e;
			e.prev = tail;
			e.next = null;
			tail = e;
		}