Esempio n. 1
0
        public WeakLinkedNode <T> CleanNext()
        {
            var next = Next;

            Next = null;

            return(next);
        }
Esempio n. 2
0
        public void Remove(WeakLinkedNode <T> node)
        {
            EnsureClean();

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

            OnCollectionChanged();

            EnsureGC();
        }
Esempio n. 3
0
        public void Remove(T item)
        {
            EnsureClean();

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

            OnCollectionChanged();

            EnsureGC();
        }
Esempio n. 4
0
        public void Cleanup(Func <T, bool> predicate)
        {
            if (_head == null)
            {
                return;
            }

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

            OnCollectionChanged();
        }
Esempio n. 5
0
        public WeakLinkedNode <T> Add(T item)
        {
            EnsureClean();

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

            OnCollectionChanged();

            EnsureGC();

            return(node);
        }
Esempio n. 6
0
        private void EnsureClean()
        {
            if (_head == null || IsGCOccurred == false)
            {
                return;
            }

            WeakLinkedNode.Clean(ref _head, out _tail);

            OnCollectionChanged();

            UpdateGCCounter();
        }
Esempio n. 7
0
        public void RemoveAfter()
        {
            var remove = Next;

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

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

            _tail = null;
            _head = null;

            OnCollectionChanged();

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