HEX
Server: LiteSpeed
System: Linux shams.tasjeel.ae 5.14.0-611.5.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Tue Nov 11 08:09:09 EST 2025 x86_64
User: infowars (1469)
PHP: 8.2.29
Disabled: NONE
Upload Files
File: //usr/lib/python3.9/site-packages/ipapython/__pycache__/graph.cpython-39.opt-1.pyc
a

}�f�	�@sddlmZGdd�d�ZdS)�)�dequec@sReZdZdZdd�Zdd�Zdd�Zdd	�Zd
d�Zdd
�Z	dd�Z
ddd�ZdS)�Graphz�
    Simple oriented graph structure

    G = (V, E) where G is graph, V set of vertices and E list of edges.
    E = (tail, head) where tail and head are vertices
    cCst�|_g|_t�|_dS�N)�set�vertices�edges�dict�_adj)�self�r�3/usr/lib/python3.9/site-packages/ipapython/graph.py�__init__szGraph.__init__cCs|j�|�g|j|<dSr)r�addr	)r
�vertexrrr�
add_vertexszGraph.add_vertexcCsH||jvrtd��||jvr$td��|j�||f�|j|�|�dS)Nztail is not a vertexzhead is not a vertex)r�
ValueErrorr�appendr	�r
�tail�headrrr�add_edges

zGraph.add_edgecCsLz|j�||f�Wn"ty6td�||���Yn0|j|�|�dS)Nz'graph does not contain edge: ({0}, {1}))r�remove�KeyErrorr�formatr	rrrr�remove_edge"s
�
zGraph.remove_edgecs~z|j���Wn ty0td�����Yn0|j�=|j��D]}�fdd�|D�|dd�<qD�fdd�|jD�|_dS)Nz"graph does not contain vertex: {0}csg|]}|�kr|�qSrr)�.0�v�rrr�
<listcomp>6�z'Graph.remove_vertex.<locals>.<listcomp>cs$g|]}�|d|dfvr|�qS�r�r�r�errrr9s)rrrrrr	�valuesr)r
rZadjrrr�
remove_vertex+s�

�zGraph.remove_vertexcs�fdd�|jD�S)zU
        Get list of vertices where a vertex is on the right side of an edge
        cs g|]}|d�kr|d�qS)r!rrr"�rrrrArz#Graph.get_tails.<locals>.<listcomp>�r)r
rrr&r�	get_tails=szGraph.get_tailscs�fdd�|jD�S)zT
        Get list of vertices where a vertex is on the left side of an edge
        cs g|]}|d�kr|d�qSr rr"�rrrrGrz#Graph.get_heads.<locals>.<listcomp>r')r
rrr)r�	get_headsCszGraph.get_headsNcCsb|stt|j��}t�}t|g�}|r^|��}||vr"|�|�|�t|j�	|g��|�q"|S)z
        Breadth-first search traversal of the graph from `start` vertex.
        Return a set of all visited vertices
        )
�next�iterrrr�popleftr�extendr	�get)r
�startZvisitedZqueuerrrr�bfsIs

z	Graph.bfs)N)�__name__�
__module__�__qualname__�__doc__r
rrrr%r(r*r1rrrrrs
	rN)�collectionsrrrrrr�<module>s