예제 #1
0
        public WeakLinkedNode <T> CleanNext()
        {
            var next = Next;

            Next = null;

            return(next);
        }
예제 #2
0
        public void Remove(WeakLinkedNode <T> node)
        {
            EnsureClean();

            WeakLinkedNode.RemoveNode(ref _head, ref _tail, node);

            OnCollectionChanged();

            EnsureGC();
        }
예제 #3
0
        public void Remove(T item)
        {
            EnsureClean();

            WeakLinkedNode.Remove(ref _head, ref _tail, item);

            OnCollectionChanged();

            EnsureGC();
        }
예제 #4
0
        public void Cleanup(Func <T, bool> predicate)
        {
            if (_head == null)
            {
                return;
            }

            WeakLinkedNode.Clean(ref _head, out _tail, predicate);

            OnCollectionChanged();
        }
예제 #5
0
        public WeakLinkedNode <T> Add(T item)
        {
            EnsureClean();

            var node = WeakLinkedNode.Insert(ref _head, ref _tail, item);

            OnCollectionChanged();

            EnsureGC();

            return(node);
        }
예제 #6
0
        private void EnsureClean()
        {
            if (_head == null || IsGCOccurred == false)
            {
                return;
            }

            WeakLinkedNode.Clean(ref _head, out _tail);

            OnCollectionChanged();

            UpdateGCCounter();
        }
예제 #7
0
        public void RemoveAfter()
        {
            var remove = Next;

            if (remove != null)
            {
                Next        = remove.Next;
                remove.Next = null;
            }
            else
            {
                Next = null;
            }
        }
예제 #8
0
        public void Clear()
        {
            if (_head == null)
            {
                return;
            }

            while (_head != null)
            {
                _head = _head.CleanNext();
            }

            _tail = null;
            _head = null;

            OnCollectionChanged();

            UpdateGCCounter();
        }
예제 #9
0
        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);
        }
예제 #10
0
 internal static WeakLinkedNode <T> CleanImpl(WeakLinkedNode <T> head)
 {
     return(CleanImpl(head, out _));
 }
예제 #11
0
 public void InsertAfter(WeakLinkedNode <T> node)
 {
     Next = node;
 }