Пример #1
0
    protected void RemoveNode(UniNode node)
    {
        for (int i = 0; i < m_nodes.Count; i++)
        {
            m_nodes[i].RemoveLinks(node);
        }

        m_nodes.Remove(node);
    }
Пример #2
0
    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);
    }
Пример #3
0
    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);
    }
Пример #4
0
    public TLink[] GetLinksValues(TNode nodeValue, LinkType linkType)
    {
        UniNode node = GetNode(nodeValue);

        if (node == null)
        {
            return(null);
        }

        return(node.GetLinksValues(linkType));
    }
Пример #5
0
        public bool HasLink(UniNode other, LinkType linkType)
        {
            foreach (UniLink link in m_links)
            {
                if ((link.other == other) && (link.type == linkType))
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #6
0
        public bool HasLink(UniNode other)
        {
            foreach (UniLink link in m_links)
            {
                if (link.other == other)
                {
                    return(true);
                }
            }

            return(false);
        }
Пример #7
0
    /// <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);
    }
Пример #8
0
    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]);
    }
Пример #9
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);
 }
Пример #10
0
        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);
            }
        }
Пример #11
0
    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);
    }
Пример #12
0
        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());
        }
Пример #13
0
        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());
        }
Пример #14
0
    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);
    }
Пример #15
0
    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);
    }
Пример #16
0
 public UniLink(UniNode other, TLink value, LinkType type)
 {
     m_other = other;
     m_value = value;
     m_type  = type;
 }
Пример #17
0
 protected bool HasLink(UniNode from, UniNode to, LinkType linkType, TLink linkValue)
 {
     return(GetLink(from, to, linkType, linkValue) != null);
 }