U ʗRe@sbddlZddlmZGdddeZGdddejZGdd d eZGd d d eZd d Z dS)N)collections_abcc@speZdZdZddZddZddZdd Zd d Zd d Z ddZ ddZ ddZ ddZ ddZddZdS) DirectedGraphz&A graph structure with directed edges.cCst|_i|_i|_dSN)set _vertices _forwards _backwardsselfr /builddir/build/BUILDROOT/alt-python38-pip-22.2.1-2.el8.x86_64/opt/alt/python38/lib/python3.8/site-packages/pip/_vendor/resolvelib/structs.py__init__ szDirectedGraph.__init__cCs t|jSr)iterrr r r r __iter__szDirectedGraph.__iter__cCs t|jSr)lenrr r r r __len__szDirectedGraph.__len__cCs ||jkSr)rr keyr r r __contains__szDirectedGraph.__contains__cCsBt}t|j|_dd|jD|_dd|jD|_|S)z$Return a shallow copy of this graph.cSsi|]\}}|t|qSr r.0kvr r r sz&DirectedGraph.copy..cSsi|]\}}|t|qSr rrr r r rs)rrrritemsr )r otherr r r copys  zDirectedGraph.copycCs:||jkrtd|j|t|j|<t|j|<dS)zAdd a new vertex to the graph.z vertex existsN)r ValueErroraddrrr rr r r r s    zDirectedGraph.addcCsT|j||j|D]}|j||q|j|D]}|j||q:dS)zCRemove a vertex from the graph, disconnecting all edges from/to it.N)rremoverpopr )r rftr r r r!'s  zDirectedGraph.removecCs||j|ko||j|kSr)r rr r#r$r r r connected/szDirectedGraph.connectedcCs6||jkrt||j|||j||dS)zgConnect two existing vertices. Nothing happens if the vertices are already connected. N)rKeyErrorrr r r%r r r connect2s zDirectedGraph.connectccs,|jD]\}}|D]}||fVqq dSr)rr)r r#childrenr$r r r iter_edges<szDirectedGraph.iter_edgescCst|j|Sr)rrrr r r iter_childrenAszDirectedGraph.iter_childrencCst|j|Sr)rr rr r r iter_parentsDszDirectedGraph.iter_parentsN)__name__ __module__ __qualname____doc__rrrrrr r!r&r(r*r+r,r r r r rs rc@sJeZdZdddZddZddZeZdd Zd d Zd d Z ddZ dS)IteratorMappingNcCs||_||_|pi|_dSr)_mapping _accessor_appends)r mappingaccessorappendsr r r rIszIteratorMapping.__init__cCsd|j|j|jS)Nz!IteratorMapping({!r}, {!r}, {!r}))formatr2r3r4r r r r __repr__Ns zIteratorMapping.__repr__cCst|jp |jSr)boolr2r4r r r r __bool__UszIteratorMapping.__bool__cCs||jkp||jkSr)r2r4rr r r rZszIteratorMapping.__contains__cCsNz|j|}Wn"tk r0t|j|YSXt|||j|dS)Nr )r2r'rr4 itertoolschainr3get)r rrr r r __getitem__]s zIteratorMapping.__getitem__cs"fddjD}tj|S)Nc3s|]}|jkr|VqdSrr2rrr r r es z+IteratorMapping.__iter__..)r4r<r=r2r morer r r rdszIteratorMapping.__iter__cs&tfddjD}tj|S)Nc3s|]}|jkrdVqdS)rNr@rAr r r rBis z*IteratorMapping.__len__..)sumr4rr2rCr r r rhszIteratorMapping.__len__)N) r-r.r/rr9r; __nonzero__rr?rrr r r r r1Hs r1c@s4eZdZdZddZddZddZeZdd Zd S) _FactoryIterableViewa:Wrap an iterator factory returned by `find_matches()`. Calling `iter()` on this class would invoke the underlying iterator factory, making it a "collection with ordering" that can be iterated through multiple times, but lacks random access methods presented in built-in Python sequence types. cCs ||_dSr_factory)r factoryr r r rvsz_FactoryIterableView.__init__cCsdt|jt|SNz{}({}))r8typer-listrIr r r r r9ysz_FactoryIterableView.__repr__cCs,zt|Wntk r&YdSXdS)NFT)nextrI StopIterationr r r r r;|s z_FactoryIterableView.__bool__cCs|SrrHr r r r rsz_FactoryIterableView.__iter__N r-r.r/r0rr9r;rFrr r r r rGms rGc@s4eZdZdZddZddZddZeZdd Zd S) _SequenceIterableViewzWrap an iterable returned by find_matches(). This is essentially just a proxy to the underlying sequence that provides the same interface as `_FactoryIterableView`. cCs ||_dSr) _sequence)r sequencer r r rsz_SequenceIterableView.__init__cCsdt|j|jSrK)r8rLr-rRr r r r r9sz_SequenceIterableView.__repr__cCs t|jSr)r:rRr r r r r;sz_SequenceIterableView.__bool__cCs t|jSr)rrRr r r r rsz_SequenceIterableView.__iter__NrPr r r r rQs rQcCs,t|rt|St|tjs$t|}t|S)zCBuild an iterable view from the value returned by `find_matches()`.)callablerG isinstancerSequencerMrQ)matchesr r r build_iter_views  rX) r<compatrobjectrMappingr1rGrQrXr r r r s  B%