<commit_before><?php

namespace Fhaculty\Graph\Algorithm;

use Fhaculty\Graph\Algorithm\BaseGraph;
use Fhaculty\Graph\Edge\Base as Edge;
use Fhaculty\Graph\Edge\Directed as DirectedEdge;
use Fhaculty\Graph\Graph;
use LogicException;

/**
 * Basic algorithms for working with parallel edges
 *
 * Parallel edges (also called multiple edges or a multi-edge), are two or more
 * edges that are incident to the same two vertices. A simple graph has no
 * multiple edges.
 *
 * @link http://en.wikipedia.org/wiki/Multiple_edges
 */
class Parallel extends BaseGraph
{
    /**
     * checks whether this graph has any parallel edges (aka multigraph)
     *
     * @return boolean
     * @uses Edge::hasEdgeParallel() for every edge
     */
    public function hasEdgeParallel()
    {
        foreach ($this->graph->getEdges() as $edge) {
            if ($this->hasEdgeParallelEdge($edge)) {
                return true;
            }
        }

        return false;
    }


    /**
     * checks whether this edge has any parallel edges
     *
     * @return boolean
     * @uses Edge::getEdgesParallel()
     */
    public function hasEdgeParallelEdge(Edge $edge)
    {
        return !$this->getEdgesParallelEdge($edge)->isEmpty();
    }

    /**
     * get all edges parallel to this edge (excluding self)
     *
     * @return Edge[]
     * @throws LogicException
     */
    public function getEdgesParallelEdge(Edge $edge)
    {
        if ($edge instanceof DirectedEdge) {
            // get all edges between this edge's endpoints
            $edges = $edge->getVertexStart()->getEdgesTo($edge->getVertexEnd())->getVector();
        } else {
            // edge points into both directions (undirected/bidirectional edge)
            // also get all edges in other direction
            $ends  = $edge->getVertices();
            $edges = $ends[0]->getEdges()->getEdgesIntersection($ends[1]->getEdges())->getVector();
        }

        $pos = array_search($edge, $edges, true);

        if ($pos === false) {
            // @codeCoverageIgnoreStart
            throw new LogicException('Internal error: Current edge not found');
            // @codeCoverageIgnoreEnd
        }

        // exclude current edge from parallel edges
        unset($edges[$pos]);

        return new Edges(array_values($edges));
    }
}<commit_msg>Fix getting parallel undirected edges<commit_after><?php

namespace Fhaculty\Graph\Algorithm;

use Fhaculty\Graph\Algorithm\BaseGraph;
use Fhaculty\Graph\Edge\Base as Edge;
use Fhaculty\Graph\Edge\Directed as DirectedEdge;
use Fhaculty\Graph\Set\Edges;
use Fhaculty\Graph\Graph;
use LogicException;

/**
 * Basic algorithms for working with parallel edges
 *
 * Parallel edges (also called multiple edges or a multi-edge), are two or more
 * edges that are incident to the same two vertices. A simple graph has no
 * multiple edges.
 *
 * @link http://en.wikipedia.org/wiki/Multiple_edges
 */
class Parallel extends BaseGraph
{
    /**
     * checks whether this graph has any parallel edges (aka multigraph)
     *
     * @return boolean
     * @uses Edge::hasEdgeParallel() for every edge
     */
    public function hasEdgeParallel()
    {
        foreach ($this->graph->getEdges() as $edge) {
            if ($this->hasEdgeParallelEdge($edge)) {
                return true;
            }
        }

        return false;
    }


    /**
     * checks whether this edge has any parallel edges
     *
     * @return boolean
     * @uses Edge::getEdgesParallel()
     */
    public function hasEdgeParallelEdge(Edge $edge)
    {
        return !$this->getEdgesParallelEdge($edge)->isEmpty();
    }

    /**
     * get set of all Edges parallel to this edge (excluding self)
     *
     * @param Edge $edge
     * @return Edges
     * @throws LogicException
     */
    public function getEdgesParallelEdge(Edge $edge)
    {
        if ($edge instanceof DirectedEdge) {
            // get all edges between this edge's endpoints
            $edges = $edge->getVertexStart()->getEdgesTo($edge->getVertexEnd())->getVector();
        } else {
            // edge points into both directions (undirected/bidirectional edge)
            // also get all edges in other direction
            $ends  = $edge->getVertices();
            $edges = $ends->getVertexFirst()->getEdges()->getEdgesIntersection($ends->getVertexLast()->getEdges())->getVector();
        }

        $pos = array_search($edge, $edges, true);

        if ($pos === false) {
            // @codeCoverageIgnoreStart
            throw new LogicException('Internal error: Current edge not found');
            // @codeCoverageIgnoreEnd
        }

        // exclude current edge from parallel edges
        unset($edges[$pos]);

        return new Edges(array_values($edges));
    }
}
{'fraction_non_alphanumeric': 0.11248428990364474, 'fraction_numerical': 0.00041893590280687055, 'mean_word_length': 2.4034212401995725, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 33, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1677646', 'n_tokens_mistral': 1336, 'n_tokens_neox': 1311, 'n_words': 377}