Exemplo n.º 1
0
 internal IntrusiveIterator(IntrusiveCollection <E> _enclosing)
 {
     this._enclosing = _enclosing;
     // + IntrusiveCollection.this + "]";
     this.cur  = this._enclosing.root;
     this.next = null;
 }
Exemplo n.º 2
0
 public void SetNext <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                           next)
     where _T0 : IntrusiveCollection.Element
 {
     Preconditions.CheckState(list == this._enclosing._enclosing);
     this.first = next;
 }
Exemplo n.º 3
0
 public void SetPrev <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                           prev)
     where _T0 : IntrusiveCollection.Element
 {
     Preconditions.CheckState(list == this._enclosing._enclosing);
     this.last = prev;
 }
Exemplo n.º 4
0
 public void SetPrev <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                           prev)
     where _T0 : IntrusiveCollection.Element
 {
     // IntrusiveCollection.Element
     System.Diagnostics.Debug.Assert(list == pool.GetDirectiveList());
     this.prev = prev;
 }
Exemplo n.º 5
0
 public void SetNext <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                           next)
     where _T0 : IntrusiveCollection.Element
 {
     // IntrusiveCollection.Element
     System.Diagnostics.Debug.Assert(list == pool.GetDirectiveList());
     this.next = next;
 }
Exemplo n.º 6
0
 public override bool HasNext()
 {
     if (this.next == null)
     {
         this.next = this.cur.GetNext(this._enclosing._enclosing);
     }
     return(this.next != this._enclosing.root);
 }
Exemplo n.º 7
0
 public void RemoveInternal <_T0>(IntrusiveCollection <_T0> list)
     where _T0 : IntrusiveCollection.Element
 {
     // IntrusiveCollection.Element
     System.Diagnostics.Debug.Assert(list == pool.GetDirectiveList());
     this.pool = null;
     this.prev = null;
     this.next = null;
 }
Exemplo n.º 8
0
 public override void Remove()
 {
     if (this.cur == null)
     {
         throw new InvalidOperationException("Already called remove " + "once on this element."
                                             );
     }
     this.next = this._enclosing.RemoveElement(this.cur);
     this.cur  = null;
 }
Exemplo n.º 9
0
 //
 // IntrusiveCollection.Element implementation
 //
 public void InsertInternal <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                                  prev, IntrusiveCollection.Element next)
     where _T0 : IntrusiveCollection.Element
 {
     // IntrusiveCollection.Element
     System.Diagnostics.Debug.Assert(this.pool == null);
     this.pool = ((CachePool.DirectiveList)list).GetCachePool();
     this.prev = prev;
     this.next = next;
 }
Exemplo n.º 10
0
 private IntrusiveCollection.Element RemoveElement(IntrusiveCollection.Element elem
                                                   )
 {
     IntrusiveCollection.Element prev = elem.GetPrev(this);
     IntrusiveCollection.Element next = elem.GetNext(this);
     elem.RemoveInternal(this);
     prev.SetNext(this, next);
     next.SetPrev(this, prev);
     size--;
     return(next);
 }
Exemplo n.º 11
0
 public virtual bool Contains(object o)
 {
     try
     {
         IntrusiveCollection.Element element = (IntrusiveCollection.Element)o;
         return(element.IsInList(this));
     }
     catch (InvalidCastException)
     {
         return(false);
     }
 }
Exemplo n.º 12
0
 public override E Next()
 {
     if (this.next == null)
     {
         this.next = this.cur.GetNext(this._enclosing._enclosing);
     }
     if (this.next == this._enclosing.root)
     {
         throw new NoSuchElementException();
     }
     this.cur  = this.next;
     this.next = null;
     return((E)this.cur);
 }
Exemplo n.º 13
0
        public virtual bool RetainAll <_T0>(ICollection <_T0> collection)
        {
            bool changed = false;

            for (IEnumerator <E> iter = GetEnumerator(); iter.HasNext();)
            {
                IntrusiveCollection.Element elem = iter.Next();
                if (!collection.Contains(elem))
                {
                    iter.Remove();
                    changed = true;
                }
            }
            return(changed);
        }
Exemplo n.º 14
0
 public void SetNext <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                           next)
     where _T0 : IntrusiveCollection.Element
 {
     for (int i = 0; i < triplets.Length; i += 3)
     {
         if (triplets[i] == list)
         {
             triplets[i + 2] = next;
             return;
         }
     }
     throw new RuntimeException("Called setNext on an element that wasn't " + "in the list."
                                );
 }
Exemplo n.º 15
0
 public virtual bool Remove(object o)
 {
     try
     {
         IntrusiveCollection.Element elem = (IntrusiveCollection.Element)o;
         if (!elem.IsInList(this))
         {
             return(false);
         }
         RemoveElement(elem);
         return(true);
     }
     catch (InvalidCastException)
     {
         return(false);
     }
 }
Exemplo n.º 16
0
 /// <summary>Add an element to the front of the list.</summary>
 /// <param name="elem">The new element to add.</param>
 public virtual bool AddFirst(IntrusiveCollection.Element elem)
 {
     if (elem == null)
     {
         return(false);
     }
     if (elem.IsInList(this))
     {
         return(false);
     }
     IntrusiveCollection.Element next = root.GetNext(this);
     next.SetPrev(this, elem);
     root.SetNext(this, elem);
     elem.InsertInternal(this, root, next);
     size++;
     return(true);
 }
Exemplo n.º 17
0
 /// <summary>Add an element to the end of the list.</summary>
 /// <param name="elem">The new element to add.</param>
 public virtual bool AddItem(E elem)
 {
     if (elem == null)
     {
         return(false);
     }
     if (elem.IsInList(this))
     {
         return(false);
     }
     IntrusiveCollection.Element prev = root.GetPrev(this);
     prev.SetNext(this, elem);
     root.SetPrev(this, elem);
     elem.InsertInternal(this, prev, root);
     size++;
     return(true);
 }
Exemplo n.º 18
0
 public void InsertInternal <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                                  prev, IntrusiveCollection.Element next)
     where _T0 : IntrusiveCollection.Element
 {
     for (int i = 0; i < triplets.Length; i += 3)
     {
         if (triplets[i] == list)
         {
             throw new RuntimeException("Trying to re-insert an element that " + "is already in the list."
                                        );
         }
     }
     object[] newTriplets = Arrays.CopyOf(triplets, triplets.Length + 3);
     newTriplets[triplets.Length]     = list;
     newTriplets[triplets.Length + 1] = prev;
     newTriplets[triplets.Length + 2] = next;
     triplets = newTriplets;
 }
Exemplo n.º 19
0
 public IntrusiveCollection()
 {
     root = new _Element_89(this);
 }
Exemplo n.º 20
0
 // We keep references to the first and last elements for easy access.
 public void InsertInternal <_T0>(IntrusiveCollection <_T0> list, IntrusiveCollection.Element
                                  prev, IntrusiveCollection.Element next)
     where _T0 : IntrusiveCollection.Element
 {
     throw new RuntimeException("Can't insert root element");
 }