using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Misc
{
    //
    public class RList<T>:List<T>
    {
	    int tailer_no;//尾部对应的编号,每个数据，有唯一的编号。当是环状数组，数据会被覆盖，编号就会对应不上序号。序号一定可以转为编号
        int cap;
        public RList(int cap):base(cap) 
        {
            this.cap = cap;
            tailer_no = 0;
        }
        
        public T RAdd(T dat)
        {
            Add(dat);
            tailer_no++;
            T ret = default(T);
            if (Count > cap)
            {
                ret = this.ElementAt(0);
                RemoveAt(0);
            }
            return ret;
        }

        public T[] ToArray(int index, int count)
        {
            return GetRange(index, count).ToArray();
        }

        public int Index2No(int index)
        {
            return index - (this.Count - 1) + tailer_no;
        }

        public int No2Index(int no)
        {
            int index = no - tailer_no + (this.Count - 1);
            return index;
        }

        public int GetLastNo()
        {
            return tailer_no;
        }

        
    }
}
