public WeakLinkedNode <T> CleanNext() { var next = Next; Next = null; return(next); }
public void Remove(WeakLinkedNode <T> node) { EnsureClean(); WeakLinkedNode.RemoveNode(ref _head, ref _tail, node); OnCollectionChanged(); EnsureGC(); }
public void Remove(T item) { EnsureClean(); WeakLinkedNode.Remove(ref _head, ref _tail, item); OnCollectionChanged(); EnsureGC(); }
public void Cleanup(Func <T, bool> predicate) { if (_head == null) { return; } WeakLinkedNode.Clean(ref _head, out _tail, predicate); OnCollectionChanged(); }
public WeakLinkedNode <T> Add(T item) { EnsureClean(); var node = WeakLinkedNode.Insert(ref _head, ref _tail, item); OnCollectionChanged(); EnsureGC(); return(node); }
private void EnsureClean() { if (_head == null || IsGCOccurred == false) { return; } WeakLinkedNode.Clean(ref _head, out _tail); OnCollectionChanged(); UpdateGCCounter(); }
public void RemoveAfter() { var remove = Next; if (remove != null) { Next = remove.Next; remove.Next = null; } else { Next = null; } }
public void Clear() { if (_head == null) { return; } while (_head != null) { _head = _head.CleanNext(); } _tail = null; _head = null; OnCollectionChanged(); UpdateGCCounter(); }
internal static WeakLinkedNode <T> CleanImpl(WeakLinkedNode <T> head, out WeakLinkedNode <T> tail, Func <T, bool> predicate = null) { var aliveHead = head; while (aliveHead != null && (aliveHead.IsAlive == false || predicate != null && predicate(aliveHead.Target))) { aliveHead = aliveHead.Next; } if (aliveHead == null) { tail = null; return(null); } var currentAlive = aliveHead; var aliveTail = aliveHead; // Find tail removing dead items while (currentAlive != null) { var current = currentAlive.Next; while (current != null && (current.IsAlive == false || predicate != null && predicate(current.Target))) { current = current.Next; } currentAlive.Next = current; aliveTail = currentAlive; currentAlive = current; } tail = aliveTail; return(aliveHead); }
internal static WeakLinkedNode <T> CleanImpl(WeakLinkedNode <T> head) { return(CleanImpl(head, out _)); }
public void InsertAfter(WeakLinkedNode <T> node) { Next = node; }