Пример #1
0
        /**
         * {@inheritDoc}
         */
        public override HashSet <E> edgesOf(V vertex)
        {
            ArrayUnenforcedSet <E> inAndOut = new ArrayUnenforcedSet <E>(getEdgeContainer(vertex).incoming);

            inAndOut.AddRange(getEdgeContainer(vertex).outgoing);

            // we have two copies for each self-loop - remove one of them.
            if (abstractBaseGraph.isAllowingLoops())
            {
                HashSet <E> loops = getAllEdges(vertex, vertex);

                for (int i = 0; i < inAndOut.Count;)
                {
                    E e = inAndOut[i];

                    if (loops.Contains(e))
                    {
                        inAndOut.RemoveAt(i);
                        loops.Remove(e); // so we remove it only once
                    }
                    else
                    {
                        i++;
                    }
                }
            }

            return(new HashSet <E>(inAndOut));
        }
        public override E getEdge(V sourceVertex, V targetVertex)
        {
            ArrayUnenforcedSet <E> edges = null;

            touchingVerticesToEdgeMap.TryGetValue(new KeyValuePair <V, V>(sourceVertex, targetVertex), out edges);
            if (edges == null || edges.Count == 0)
            {
                return(default(E));
            }
            else
            {
                return(edges[0]);
            }
        }
 public override HashSet <E> getAllEdges(V sourceVertex, V targetVertex)
 {
     if (abstractBaseGraph.containsVertex(sourceVertex) &&
         abstractBaseGraph.containsVertex(targetVertex))
     {
         ArrayUnenforcedSet <E> edges = null;
         touchingVerticesToEdgeMap.TryGetValue(new KeyValuePair <V, V>(sourceVertex, targetVertex), out edges);
         return(edges == null ? new HashSet <E>() : new HashSet <E>(edges));
     }
     else
     {
         return(null);
     }
 }
Пример #4
0
        /**
         * {@inheritDoc}
         */
        public override HashSet <E> getAllEdges(V sourceVertex, V targetVertex)
        {
            List <E> edges = null;

            if (abstractBaseGraph.containsVertex(sourceVertex) &&
                abstractBaseGraph.containsVertex(targetVertex))
            {
                edges = new ArrayUnenforcedSet <E>();

                DirectedEdgeContainer <V, E> ec = getEdgeContainer(sourceVertex);

                foreach (E e in ec.outgoing)
                {
                    if (abstractBaseGraph.getEdgeTarget(e).Equals(targetVertex))
                    {
                        edges.Add(e);
                    }
                }
            }

            return(new HashSet <E>(edges));
        }
        public override void addEdgeToTouchingVertices(E e)
        {
            V source = abstractBaseGraph.getEdgeSource(e);
            V target = abstractBaseGraph.getEdgeTarget(e);

            getEdgeContainer(source).addOutgoingEdge(e);
            getEdgeContainer(target).addIncomingEdge(e);

            KeyValuePair <V, V>    vertexPair = new KeyValuePair <V, V>(source, target);
            ArrayUnenforcedSet <E> edgeSet    = null;

            touchingVerticesToEdgeMap.TryGetValue(vertexPair, out edgeSet);
            if (edgeSet != null)
            {
                edgeSet.Add(e);
            }
            else
            {
                edgeSet = new ArrayUnenforcedSet <E>();
                edgeSet.Add(e);
                touchingVerticesToEdgeMap[vertexPair] = edgeSet;
            }
        }
        public override void removeEdgeFromTouchingVertices(E e)
        {
            V source = abstractBaseGraph.getEdgeSource(e);
            V target = abstractBaseGraph.getEdgeTarget(e);

            getEdgeContainer(source).removeOutgoingEdge(e);
            getEdgeContainer(target).removeIncomingEdge(e);

            // Remove the edge from the touchingVerticesToEdgeMap. If there are no more remaining edges
            // for a pair
            // of touching vertices, remove the pair from the map.
            KeyValuePair <V, V>    vertexPair = new KeyValuePair <V, V>(source, target);
            ArrayUnenforcedSet <E> edgeSet    = touchingVerticesToEdgeMap[vertexPair];

            if (edgeSet != null)
            {
                edgeSet.Remove(e);
                if (edgeSet.Count == 0)
                {
                    touchingVerticesToEdgeMap.Remove(vertexPair);
                }
            }
        }