public override E Put(E element) { //validate element if (element == null) { throw new ArgumentNullException("Null element is not supported."); } if (!(element is LightWeightGSet.LinkedElement)) { throw new HadoopIllegalArgumentException("!(element instanceof LinkedElement), element.getClass()=" + element.GetType()); } LightWeightGSet.LinkedElement e = (LightWeightGSet.LinkedElement)element; //find index int index = GetIndex(element); //remove if it already exists E existing = Remove(index, element); //insert the element to the head of the linked list modification++; size++; e.SetNext(entries[index]); entries[index] = e; return(existing); }
public override void Remove() { this.EnsureNext(); if (this.cur == null) { throw new InvalidOperationException("There is no current element " + "to remove"); } this._enclosing._enclosing.Remove((K)this.cur); this.iterModification++; this.cur = null; }
public override E Next() { this.EnsureNext(); if (this.next == null) { throw new InvalidOperationException("There are no more elements"); } this.cur = this.next; this.next = null; return(this._enclosing.Convert(this.cur)); }
/// <summary>Print detailed information of this object.</summary> public virtual void PrintDetails(TextWriter @out) { @out.Write(this + ", entries = ["); for (int i = 0; i < entries.Length; i++) { if (entries[i] != null) { LightWeightGSet.LinkedElement e = entries[i]; @out.Write("\n " + i + ": " + e); for (e = e.GetNext(); e != null; e = e.GetNext()) { @out.Write(" -> " + e); } } } @out.WriteLine("\n]"); }
/// <summary> /// Remove the element corresponding to the key, /// given key.hashCode() == index. /// </summary> /// <returns> /// If such element exists, return it. /// Otherwise, return null. /// </returns> private E Remove(int index, K key) { if (entries[index] == null) { return(null); } else { if (entries[index].Equals(key)) { //remove the head of the linked list modification++; size--; LightWeightGSet.LinkedElement e = entries[index]; entries[index] = e.GetNext(); e.SetNext(null); return(Convert(e)); } else { //head != null and key is not equal to head //search the element LightWeightGSet.LinkedElement prev = entries[index]; for (LightWeightGSet.LinkedElement curr = prev.GetNext(); curr != null;) { if (curr.Equals(key)) { //found the element, remove it modification++; size--; prev.SetNext(curr.GetNext()); curr.SetNext(null); return(Convert(curr)); } else { prev = curr; curr = curr.GetNext(); } } //element not found return(null); } } }
public override E Get(K key) { //validate key if (key == null) { throw new ArgumentNullException("key == null"); } //find element int index = GetIndex(key); for (LightWeightGSet.LinkedElement e = entries[index]; e != null; e = e.GetNext()) { if (e.Equals(key)) { return(Convert(e)); } } //element not found return(null); }
private void EnsureNext() { if (this.trackModification && this._enclosing.modification != this.iterModification) { throw new ConcurrentModificationException("modification=" + this._enclosing.modification + " != iterModification = " + this.iterModification); } if (this.next != null) { return; } if (this.cur == null) { return; } this.next = this.cur.GetNext(); if (this.next == null) { this.next = this.NextNonemptyEntry(); } }
public virtual void SetNext(LightWeightGSet.LinkedElement next) { this.nextLinkedElement = next; }
public virtual void SetNext(LightWeightGSet.LinkedElement e) { next = e; }
internal TestElement(int val) { this.val = val; this.next = null; }
private E Convert(LightWeightGSet.LinkedElement e) { E r = (E)e; return(r); }
public void SetNext(LightWeightGSet.LinkedElement next) { // LightWeightGSet.LinkedElement this.nextElement = next; }