public int AddAfter(int nodeReference, byte[] buffer) { AssertNotBadNodeReference(nodeReference); LinkedListElement nodeReferenceElement = GetElementAt(nodeReference); return(AddAfter(nodeReferenceElement, buffer)); }
public int AddToEnd(byte[] buffer) { LinkedListElement insertingNode = GetNewElement(buffer); Link(GetTail(), insertingNode, GetNullElement()); IncreaseSize(); return(insertingNode.Index); }
public void Update(int nodeReference, byte[] buffer) { AssertNotBadNodeReference(nodeReference); LinkedListElement updatingElement = GetElementAt(nodeReference); updatingElement.Data = buffer; PutElement(updatingElement); }
private LinkedListElement GetTail() { LinkedListElement nullElement = GetNullElement(); if (nullElement.Previous == nullElement.Index) { return(nullElement); } return(GetElementAt(nullElement.Previous)); }
private LinkedListElement GetHead() { LinkedListElement nullElement = GetNullElement(); if (nullElement.Next == nullElement.Index) { return(nullElement); } return(GetElementAt(nullElement.Next)); }
private int AddAfter(LinkedListElement previous, byte[] buffer) { LinkedListElement insertingNode = GetNewElement(buffer); if (previous.Index == insertingNode.Index) { throw new InvalidNodeReference("The node reference passed is not valid"); } LinkedListElement next = GetElementAt(previous.Next); Link(previous, insertingNode, next); IncreaseSize(); return(insertingNode.Index); }
private void Link(LinkedListElement previous, LinkedListElement middle, LinkedListElement next) { SetPreviousNext(previous, middle); if (previous.Index == next.Index) { SetPreviousNext(middle, previous); } else { SetPreviousNext(middle, next); PutElement(next); } PutElement(previous); PutElement(middle); }
public byte[] Remove(int nodeReference) { if (GetSize() == 0) //um, there's nothing in the list? { throw new InvalidOperationException("No elements in list"); } AssertNotBadNodeReference(nodeReference); LinkedListElement removingElement = GetElementAt(nodeReference); LinkedListElement previous = GetElementAt(removingElement.Previous); LinkedListElement next = GetElementAt(removingElement.Next); SetPreviousNext(previous, next); PutElement(previous); PutElement(next); DecreaseSize(); _persistentSimpleCollection.FreeBlock(removingElement.Index); return(removingElement.Data); }
private void SetPreviousNext(LinkedListElement previous, LinkedListElement next) { previous.Next = next.Index; next.Previous = previous.Index; }
private void PutElement(LinkedListElement element) { byte[] elementBytes = element.Serialize(); _persistentSimpleCollection.Put(element.Index, elementBytes); }
private int AddAfter(LinkedListElement previous, byte[] buffer) { LinkedListElement insertingNode = GetNewElement(buffer); if (previous.Index == insertingNode.Index) throw new InvalidNodeReference("The node reference passed is not valid"); LinkedListElement next = GetElementAt(previous.Next); Link(previous, insertingNode, next); IncreaseSize(); return insertingNode.Index; }
private LinkedListElement GetElementAt(int arrayIndex) { LinkedListElement lle = LinkedListElement.Deserialize(_persistentSimpleCollection.Get(arrayIndex), arrayIndex); return(lle); }