public IEnumerable <TEdge> GetOutgoingEdges(TVertex vertex)
 {
     if (!OutgoingEdges.ContainsKey(vertex))
     {
         return(Enumerable.Empty <TEdge>());
     }
     return(OutgoingEdges[vertex].SelectMany(v => v.Value));
 }
Exemplo n.º 2
0
 public bool AddVertex(TVertex vertex)
 {
     if (OutgoingEdges.ContainsKey(vertex))
     {
         return(false);
     }
     OutgoingEdges[vertex] = InnerMap;
     IncomingEdges[vertex] = InnerMap;
     return(true);
 }
Exemplo n.º 3
0
 public bool RemoveVertex(TVertex vertex)
 {
     if (!OutgoingEdges.ContainsKey(vertex))
     {
         return(false);
     }
     foreach (var other in OutgoingEdges[vertex].Keys)
     {
         IncomingEdges[other].Remove(vertex);
     }
     foreach (var other in IncomingEdges[vertex].Keys)
     {
         OutgoingEdges[other].Remove(vertex);
     }
     OutgoingEdges.Remove(vertex);
     IncomingEdges.Remove(vertex);
     return(true);
 }
Exemplo n.º 4
0
 public bool RemoveEdges(TVertex source, TVertex dest)
 {
     if (!OutgoingEdges.ContainsKey(source))
     {
         return(false);
     }
     if (!IncomingEdges.ContainsKey(dest))
     {
         return(false);
     }
     if (!OutgoingEdges[source].ContainsKey(dest))
     {
         return(false);
     }
     OutgoingEdges[source].Remove(dest);
     IncomingEdges[dest].Remove(source);
     return(true);
 }
Exemplo n.º 5
0
            // Remove v and all v's edges and update incoming edge count accordingly
            public void RemoveNodeAndAllOutgoingEdges(TableExpression v)
            {
                if (OutgoingEdges.ContainsKey(v))
                {
                    // Remove all edges
                    IList <TableExpression> edges;
                    if (OutgoingEdges.TryGetValue(v, out edges))
                    {
                        while (edges.Any())
                        {
                            var u = edges[0];
                            edges.RemoveAt(0);
                            IncomingEdgesCount[u]--;
                        }
                    }

                    // Remove node
                    OutgoingEdges.Remove(v);
                    IncomingEdgesCount.Remove(v);
                }
            }
Exemplo n.º 6
0
        public bool RemoveEdge(TVertex source, TVertex dest, TEdge data)
        {
            if (!OutgoingEdges.ContainsKey(source))
            {
                return(false);
            }
            if (!IncomingEdges.ContainsKey(dest))
            {
                return(false);
            }
            if (!OutgoingEdges[source].ContainsKey(dest))
            {
                return(false);
            }

            bool foundOut = OutgoingEdges.ContainsKey(source) && OutgoingEdges[source].ContainsKey(dest) && OutgoingEdges[source][dest].Remove(data);
            bool foundIn  = IncomingEdges.ContainsKey(dest) && IncomingEdges[dest].ContainsKey(source) && IncomingEdges[dest][source].Remove(data);

            if (foundOut && !foundIn)
            {
                throw new Exception("Edge found in outgoing but not incoming"); // TODO: Specialized Exception
            }
            if (foundIn && !foundOut)
            {
                throw new Exception("Edge found in incoming but not outgoing"); // TODO: Specialized Exception
            }
            if (OutgoingEdges.ContainsKey(source) && (!OutgoingEdges[source].ContainsKey(dest) || OutgoingEdges[source][dest].Count == 0))
            {
                OutgoingEdges[source].Remove(dest);
            }
            if (IncomingEdges.ContainsKey(dest) && (!IncomingEdges[dest].ContainsKey(source) || IncomingEdges[dest][source].Count == 0))
            {
                IncomingEdges[dest].Remove(source);
            }

            return(foundOut);
        }
 public bool ContainsVertex(TVertex vertex)
 => OutgoingEdges.ContainsKey(vertex);