o knh8@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 =/usr/local/lib/python3.10/dist-packages/resolvelib/structs.py__init__s zDirectedGraph.__init__cC t|jSr)iterrr r r r __iter__  zDirectedGraph.__iter__cCrr)lenrr r r r __len__rzDirectedGraph.__len__cCs ||jvSr)rr keyr r r __contains__rzDirectedGraph.__contains__cCsBt}t|j|_dd|jD|_dd|jD|_|S)z$Return a shallow copy of this graph.cSi|] \}}|t|qSr r.0kvr r r z&DirectedGraph.copy..cSrr rrr r r rr)rrrritemsr)r otherr r r copys  zDirectedGraph.copycCs:||jvr td|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||qdS)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||jvr t||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]}||fVq qdSr)rr)r r&childrenr'r r r iter_edges:s  zDirectedGraph.iter_edgescCt|j|Sr)rrrr r r iter_children?zDirectedGraph.iter_childrencCr.r)rrrr r r iter_parentsBr0zDirectedGraph.iter_parentsN)__name__ __module__ __qualname____doc__r rrrr!r#r$r)r+r-r/r1r 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. cC ||_dSr_factory)r factoryr r r r Orz_FactoryIterableView.__init__cCsdt|jt|SNz{}({}))formattyper2listr9r r r r __repr__Rsz_FactoryIterableView.__repr__cCs(z t|WdStyYdSw)NFT)nextr9 StopIterationr r r r __bool__Us  z_FactoryIterableView.__bool__cC|Srr8r r r r r^sz_FactoryIterableView.__iter__cCrCz4Provide an candidate iterable for `get_preference()`r8r r r r for_preferenceasz#_FactoryIterableView.for_preferencecsfdd}t|S)5Create a new instance excluding specified candidates.csfddDS)Nc3s|] }|vr|VqdSrr rc candidatesr r iszB_FactoryIterableView.excluding..factory..r8r rJr r r r:hsz/_FactoryIterableView.excluding..factory)r=)r rJr:r rLr excludinges z_FactoryIterableView.excludingN) r2r3r4r5r r?rB __nonzero__rrErMr r r r r6Fs r6c@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`. cCr7r _sequence)r sequencer r r r urz_SequenceIterableView.__init__cCsdt|j|jSr;)r<r=r2rQr r r r r?xsz_SequenceIterableView.__repr__cCrr)boolrQr r r r rB{rz_SequenceIterableView.__bool__cCrr)rrQr r r r rrz_SequenceIterableView.__iter__cCrr)rrQr r r r rrz_SequenceIterableView.__len__cCs|jSrDrPr r r r rEsz$_SequenceIterableView.for_preferencecst|fdd|jDS)rFcsg|]}|vr|qSr r rGrIr r sz3_SequenceIterableView.excluding..)r=rQ)r rJr rIr rMsz_SequenceIterableView.excludingN) r2r3r4r5r r?rBrNrrrErMr r r r rOns rOcCs,t|rt|St|tjst|}t|S)zCBuild an iterable view from the value returned by `find_matches()`.)callabler6 isinstancerSequencer>rO)matchesr r r build_iter_views  rYN)compatrobjectrr6rOrYr r r r s B( !