protected void RemoveNode(UniNode node) { for (int i = 0; i < m_nodes.Count; i++) { m_nodes[i].RemoveLinks(node); } m_nodes.Remove(node); }
protected void AddLink(UniNode from, UniNode to, TLink linkValue, TLink reverseWayValue, LinkType linkType) { UniLink linkFromOrigin = new UniLink(to, linkValue, linkType); from.AddLink(linkFromOrigin); UniLink linkFromDest = new UniLink(from, reverseWayValue, ReverseDirection(linkType)); to.AddLink(linkFromDest); }
protected UniNode AddNodeR(TNode nodeValue) { if (m_nodes == null) { m_nodes = new List <UniNode>(); } UniNode node = new UniNode(nodeValue); m_nodes.Add(node); return(node); }
public TLink[] GetLinksValues(TNode nodeValue, LinkType linkType) { UniNode node = GetNode(nodeValue); if (node == null) { return(null); } return(node.GetLinksValues(linkType)); }
public bool HasLink(UniNode other, LinkType linkType) { foreach (UniLink link in m_links) { if ((link.other == other) && (link.type == linkType)) { return(true); } } return(false); }
public bool HasLink(UniNode other) { foreach (UniLink link in m_links) { if (link.other == other) { return(true); } } return(false); }
/// <summary> /// Creates and adds a link between nodes having given values. /// If multiple nodes have the same value, it is only added to the first one. /// </summary> /// <param name="fromValue">Value of the origin node.</param> /// <param name="toValue">Value of the destination node.</param> /// <param name="linkValue">Value attached to the new link.</param> /// <param name="linkType">Type of link.</param> /// <param name="reverseWayValue">A second link is created, whose type is linkType reversed and value is this parameter.</param> public void AddLink(TNode fromValue, TNode toValue, TLink linkValue, TLink reverseWayValue, LinkType linkType) { UniNode from = GetNode(fromValue); UniNode to = GetNode(toValue); if ((from == null) || (to == null)) { return; } AddLink(from, to, linkValue, reverseWayValue, linkType); }
protected UniLink GetLink(UniNode from, UniNode to, LinkType linkType) { if ((m_nodes == null) || (from == null) || (to == null)) { return(null); } UniLink[] links = from.GetLinks(to, linkType); if ((links == null) || (links.Length == 0)) { return(null); } return(links[0]); }
public UniLink GetLink(UniNode other, LinkType linkType) { if (m_links == null) { return(null); } foreach (UniLink link in m_links) { if ((link.other == other) && (link.type == linkType)) { return(link); } } return(null); }
public void RemoveLinks(UniNode node) { List <UniLink> linksToRemove = new List <UniLink>(); foreach (UniLink link in m_links) { if (link.other == node) { linksToRemove.Add(link); } } foreach (UniLink link in linksToRemove) { m_links.Remove(link); } }
protected int GetNodeIndex(UniNode node) { if (m_nodes == null) { return(-1); } for (int i = 0; i < m_nodes.Count; i++) { if (m_nodes[i] == node) { return(i); } } return(-1); }
public UniLink[] GetLinks(UniNode other, LinkType linkType) { if (m_links == null) { return(null); } List <UniLink> linksWithOther = new List <UniLink>(); foreach (UniLink link in m_links) { if ((link.other == other) && (link.type == linkType)) { linksWithOther.Add(link); } } return(linksWithOther.ToArray()); }
public UniNode[] GetLinkedNodes(bool removeDoubles = true) { List <UniNode> linkedNodes = new List <UniNode>(); for (int i = 0; i < m_links.Count; i++) { UniNode other = m_links[i].other; if (removeDoubles) { if (!linkedNodes.Contains(other)) { linkedNodes.Add(other); } } else { linkedNodes.Add(other); } } return(linkedNodes.ToArray()); }
public TLink GetLinkValueBetween(TNode fromValue, TNode toValue, LinkType linkType) { UniNode from = GetNode(fromValue); if (from == null) { return(default(TLink)); } UniNode to = GetNode(toValue); if (to == null) { return(default(TLink)); } UniLink link = from.GetLink(to, linkType); if (link == null) { return(default(TLink)); } return(link.value); }
protected UniLink GetLink(UniNode from, UniNode to, LinkType linkType, TLink linkValue) { if ((m_nodes == null) || (from == null) || (to == null)) { return(null); } UniLink[] links = from.GetLinks(to, linkType); if ((links == null) || (links.Length == 0)) { return(null); } for (int i = 0; i < links.Length; i++) { if (links[i].MatchesValue(linkValue)) { return(links[i]); } } return(null); }
public UniLink(UniNode other, TLink value, LinkType type) { m_other = other; m_value = value; m_type = type; }
protected bool HasLink(UniNode from, UniNode to, LinkType linkType, TLink linkValue) { return(GetLink(from, to, linkType, linkValue) != null); }