public BTreeNodeElement(T value) { this.value = value; NextInterval = new BTreeNodeElementInterstice <T>(this, null); PreviousInterval = new BTreeNodeElementInterstice <T>(null, this); identifier = Guid.NewGuid(); }
public override string ToString() { var builder = new StringBuilder(); BTreeNodeElement <T> start = FirstElement; while (start != null) { builder.Append(start + " - "); start = start.Next; } builder.Append(string.Format("self = {0}, parent = {1}", identifier, Parent == null ? "NULL" : Parent.Identifier.ToString())); builder.AppendLine(); BTreeNodeElementInterstice <T> startInterstice = FirstInterstice; while (startInterstice != null) { if (!(startInterstice.NodePointer is NullBTreeNode <T>)) { builder.AppendLine(startInterstice.NodePointer.ToString()); } startInterstice = startInterstice.Next; } return(builder.ToString()); }
private void InsertInCurrentNode(BTreeNodeElement <T> element) { if (firstInterstice == null) { element.PreviousInterval.Smaller = null; element.NextInterval.Larger = null; firstInterstice = element.PreviousInterval; element.PreviousInterval.Container = element.NextInterval.Container = this; return; } BTreeNodeElementInterstice <T> insertionInterstice = IntersticeToSearch(element.Value); if (insertionInterstice.Smaller != null) { insertionInterstice.Smaller.NextInterval = element.PreviousInterval; } if (insertionInterstice.Larger != null) { insertionInterstice.Larger.PreviousInterval = element.NextInterval; } element.PreviousInterval.Smaller = insertionInterstice.Smaller; element.NextInterval.Larger = insertionInterstice.Larger; if (insertionInterstice == firstInterstice) { firstInterstice = element.PreviousInterval; } }
public BTreeNodeElement <T> Search(T value) { BTreeNodeElement <T> element = ElementContaining(value); if (element != null) { return(element); } BTreeNodeElementInterstice <T> interstice = IntersticeToSearch(value); if (interstice == null || interstice.NodePointer is NullBTreeNode <T> ) { return(new NullBTreeNodeElement <T>()); } return(interstice.NodePointer.Search(value)); }
public BTreeNode <T> Find(T value) { BTreeNodeElement <T> node = ElementContaining(value); if (node != null) { return(this); } BTreeNodeElementInterstice <T> interstice = IntersticeToSearch(value); if (interstice == null || interstice.NodePointer is NullBTreeNode <T> ) { return(this); } return(interstice.NodePointer.Find(value)); }
private BTreeNodeElementInterstice <T> IntersticeToSearch(T value) { BTreeNodeElementInterstice <T> counter = firstInterstice; while (counter != null) { if (counter.Smaller == null && counter.Larger != null && counter.Larger.Value.CompareTo(value) > 0 || counter.Smaller != null && counter.Larger == null && counter.Smaller.Value.CompareTo(value) < 0 || counter.Smaller != null && counter.Larger != null && counter.Smaller.Value.CompareTo(value) < 0 && counter.Larger.Value.CompareTo(value) > 0) { return(counter); } counter = counter.Next; } return(null); }
public void TerminateForwardLink() { NextInterval = new BTreeNodeElementInterstice <T>(this, null); }