public void Clear() { lock (this) { first = null; last = null; current = null; } }
public bool MoveDown(object v) { bool bRet = false; clsListItem obj = first; clsListItem prev, next; while (obj != null) { if (obj.obj == v) { if (obj == last) { break; } current = obj; prev = obj.prev; next = obj.next; // if (next.next == null) { //move to the last last = obj; obj.next = null; obj.prev = next; next.next = obj; } else { next.next.prev = obj; obj.next = next.next; obj.prev = next; next.next = obj; } next.prev = prev; if (prev == null) { first = next; } else { prev.next = next; } return(true); } obj = obj.next; } return(bRet); }
public bool setCurrent(object v) { bool bRet = false; clsListItem obj = first; while (obj != null) { if (obj.obj == v) { current = obj; return(true); } obj = obj.next; } return(bRet); }
public virtual object PopFirst() { lock (this) { if (first != null) { object v = first.obj; first = first.next; if (first != null) { first.prev = null; } current = first; return(v); } return(null); } }
public virtual void Add(object obj) { lock (this) { if (first == null || last == null) { first = new clsListItem(obj); last = first; current = first; } else { current = new clsListItem(obj); current.prev = last; last.next = current; last = current; } } }
/// <summary> /// calling function should place lock to ensure thread-safe /// </summary> public void DeleteCurrent() { if (current != null) { if (current.prev == null) { //it is the first first = current.next; if (first == null) { last = null; } else { first.prev = null; } current = first; } else { if (current.next == null) { //it is the last last = current.prev; current = last; current.next = null; } else { //first and last will not change //connect prev and next together. //current.prev ->current ->current.next current.next.prev = current.prev; current.prev.next = current.next; current = current.next; } } } }