a J{_8@sHddlmZGdddeZGdddeZGdddeZdd Zd S) )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 6/usr/lib/python3.9/site-packages/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 ||jvSr)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 z&DirectedGraph.copy..cSsi|]\}}|t|qSr rrr r r rr)rrrritemsr)r otherr r r copys  zDirectedGraph.copycCs:||jvrtd|j|t|j|<t|j|<dS)zAdd a new vertex to the graph.z vertex existsN)r ValueErroraddrrrrr 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|vo||j|vSr)rrr r#r$r r r connected-szDirectedGraph.connectedcCs6||jvrt||j|||j||dS)zgConnect two existing vertices. Nothing happens if the vertices are already connected. N)rKeyErrorrr rr%r r r connect0s zDirectedGraph.connectccs,|jD]\}}|D]}||fVqq dSr)rr)r r#Zchildrenr$r r r iter_edges:szDirectedGraph.iter_edgescCst|j|Sr)rrrr r r iter_children?szDirectedGraph.iter_childrencCst|j|Sr)rrrr r r iter_parentsBszDirectedGraph.iter_parentsN)__name__ __module__ __qualname____doc__r rrrrr r!r&r(r)r*r+r r r r rs rc@sDeZdZdZddZddZddZeZdd Zd d Z d d Z dS)_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 r Osz_FactoryIterableView.__init__cCsdt|jt|SNz{}({}))formattyper,listr2r r r r __repr__Rsz_FactoryIterableView.__repr__cCs*zt|Wnty$YdS0dS)NFT)nextr2 StopIterationr r r r __bool__Us  z_FactoryIterableView.__bool__cCs|Srr1r r r r r^sz_FactoryIterableView.__iter__cCs|Sz4Provide an candidate iterable for `get_preference()`r1r r r r for_preferenceasz#_FactoryIterableView.for_preferencecsfdd}t|S)5Create a new instance excluding specified candidates.csfddDS)Nc3s|]}|vr|VqdSrr rc candidatesr r irzB_FactoryIterableView.excluding..factory..r1r rBr r r r3hsz/_FactoryIterableView.excluding..factory)r6)r rBr3r rDr excludingesz_FactoryIterableView.excludingN) r,r-r.r/r r8r; __nonzero__rr=rEr r r r r0Fsr0c@sLeZdZdZddZddZddZeZdd Zd d Z d d Z ddZ dS)_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 Zsequencer r r r usz_SequenceIterableView.__init__cCsdt|j|jSr4)r5r6r,rIr r r r r8xsz_SequenceIterableView.__repr__cCs t|jSr)boolrIr r r r r;{sz_SequenceIterableView.__bool__cCs t|jSr)rrIr r r r rsz_SequenceIterableView.__iter__cCs t|jSr)rrIr r r r rsz_SequenceIterableView.__len__cCs|jSr<rHr r r r r=sz$_SequenceIterableView.for_preferencecst|fdd|jDS)r>csg|]}|vr|qSr r r?rAr r rz3_SequenceIterableView.excluding..)r6rI)r rBr rAr rEsz_SequenceIterableView.excludingN) r,r-r.r/r r8r;rFrrr=rEr r r r rGnsrGcCs,t|rt|St|tjs$t|}t|S)zCBuild an iterable view from the value returned by `find_matches()`.)callabler0 isinstancerSequencer7rG)matchesr r r build_iter_views  rPN)compatrobjectrr0rGrPr r r r s B(!