public IGraphNode <T> AddNode(T elem) { AdjListGraphNode <T> node = new AdjListGraphNode <T>(elem); nodes.Add(node, node); return(node); }
public AdjListGraphEdge(AdjListGraphNode <T> n1, AdjListGraphNode <T> n2, float w, bool directionless) { undirected = directionless; m_node1 = n1; m_node2 = n2; weight = w; }
public IEnumerable <IGraphEdge <T> > GetEdges(IGraphNode <T> node) { Debug.Assert(node is AdjListGraphNode <T>); AdjListGraphNode <T> n = node as AdjListGraphNode <T>; foreach (AdjListGraphEdge <T> edge in n.edges) { yield return(edge); } }
public IGraphEdge <T> GetEdge(IGraphNode <T> n1, IGraphNode <T> n2) { Debug.Assert(n1 is AdjListGraphNode <T>); Debug.Assert(n2 is AdjListGraphNode <T>); AdjListGraphNode <T> node1 = n1 as AdjListGraphNode <T>; AdjListGraphNode <T> node2 = n2 as AdjListGraphNode <T>; Debug.Assert(nodes.ContainsKey(node1)); Debug.Assert(nodes.ContainsKey(node2)); return(node1.edges.Find((edge) => edge.node2.Equals(node2))); }
public override bool Equals(object obj) { if (obj is AdjListGraphNode <T> ) { AdjListGraphNode <T> node = obj as AdjListGraphNode <T>; return(storedData.Equals(node.storedData)); } else { return(false); } }
public IGraphNode <T> GetNode(T elem) { AdjListGraphNode <T> node = new AdjListGraphNode <T>(elem); if (nodes.TryGetValue(node, out node)) { return(node); } else { return(null); } }
public IGraphEdge <T> AddDirectedEdge(IGraphNode <T> n1, IGraphNode <T> n2, float weight = 1) { Debug.Assert(n1 is AdjListGraphNode <T>); Debug.Assert(n2 is AdjListGraphNode <T>); AdjListGraphNode <T> node1 = n1 as AdjListGraphNode <T>; AdjListGraphNode <T> node2 = n2 as AdjListGraphNode <T>; Debug.Assert(nodes.ContainsKey(node1)); Debug.Assert(nodes.ContainsKey(node2)); AdjListGraphEdge <T> edge = new AdjListGraphEdge <T>(node1, node2, weight, false); edges.Add(edge); node1.edges.Add(edge); return(edge); }