public DynamicEdge(T value, int key, DynamicVertex <T> source, DynamicVertex <T> dest) { this.value = value; this.key = key; this.source = source; this.dest = dest; }
public static DynamicVertex <T> Create(T value) { var v = new DynamicVertex <T>() { value = value, adjacent = new List <DynamicEdge <T> >() }; var euler = new List <EulerVertex <DynamicNode <T> > >(); euler.Add(EulerVertex <DynamicNode <T> > .Create(v)); v.euler = euler; return(v); }
public void Cut() { // Don't double cut an edge if (source == null) { return; } // remove edge from adjacent list of each node source.RemoveEdge(this); dest.RemoveEdge(this); if (euler != null) { // if euler is not null, the edge is in forests. // Cut edge from tree for (int i = 0; i < euler.Count; i++) { euler[i].Cut(); } // Find replacement, looping over levels for (int i = level; i >= 0; i--) { var tv = source.euler[i].node.GetRoot(); var tw = dest.euler[i].node.GetRoot(); if (tv.count > tw.count) { RaiseLevelOfTree(tw, i); if (Visit(tw, i)) { break; } } else { RaiseLevelOfTree(tv, i); if (Visit(tv, i)) { break; } } } } source = null; dest = null; euler = null; level = 32; }
public DynamicEdge <T> Link(DynamicVertex <T> other, T value) { var e = new DynamicEdge <T>(value, KeyCounter, this, other); KeyCounter++; if (!euler[0].IsConnected(other.euler[0])) { e.LinkSpanningForests(); } euler[0].SetFlag(true); other.euler[0].SetFlag(true); EdgeListUtility.InsertEdge(adjacent, e); EdgeListUtility.InsertEdge(other.adjacent, e); return(e); }
public bool IsConnected(DynamicVertex <T> other) { return(euler[0].IsConnected(other.euler[0])); }