/** * This goes from most recent to least recent data point */ public IEnumerator GetEnumerator() { CacheLinkedList <T> cll = this; do { yield return(cll.Head); cll = cll.Tail; }while(cll != null); }
/** * Takes the MAX_COUNT / 2 entries at most and returns a new CacheLinkedList */ public static CacheLinkedList <T> Take(CacheLinkedList <T> cll) { int count = 0; List <T> new_cll = new List <T>(MAX_COUNT / 2); while (cll != null && count++ < MAX_COUNT / 2) { new_cll.Add(cll.Head); cll = cll.Tail; } cll = null; for (int i = new_cll.Count - 1; i >= 0; i--) { cll += new_cll[i]; } return(cll); }
/** * Makes a new list by appending this new object. * Does not change the old list. */ public CacheLinkedList(CacheLinkedList <T> cll, T o) { if (cll != null) { if (cll.count == MAX_COUNT) { cll = Take(cll); } _count = cll.count + 1; } else { _count = 1; } _head = o; _tail = cll; }
public CacheLinkedList(T o) { _count = 1; _head = o; _tail = null; }