+
    2jE9                       R t ^ RIHt ^ RIHt ^ RIHt ^ RIHtH	t	H
t
Ht ^RIHt ^RIHtHtHt ]'       d   ^ RIHt ^RIHtHt R	R
.t]! 4       t]! RR7       ! R R	]
]]3,          4      4       t ! R R
]
]]3,          4      tR# )a?  Partial solution: ordered assignment list with decision levels.

The partial solution is a chronological trail of assignments.  Each
assignment constrains a package's allowed versions and is either a
decision (the resolver picks a specific version to try) or a
derivation (a constraint deduced by unit propagation).

Each decision opens a new "decision level".  Backtracking removes
all assignments above a target level, which is cheaper than copying
the entire state on every decision.

Reference: https://github.com/dart-lang/pub/blob/master/doc/solver.md#partial-solution
)annotations)defaultdict)	dataclass)TYPE_CHECKINGAnyGenericcast)Range)PackageTypeRangeProtocolVersionType)Sequence)IncompatibilityTerm
AssignmentPartialSolutionT)slotsc                      ] tR t^(t$ RtR]R&    R]R&    R]R&    R]R	&    ^ tR]R
&    RtR]R&    RtR]R&    Rt	R]R&    Rt
R]R&    RtR]R&    ^ tR]R&   RtR# )r   z-A single entry in the partial solution trail.r
   packageRangeProtocol[VersionType]accumulated_rangeintdecision_levelboolis_decisiontrail_indexNzVersionType | Noneversionz0Incompatibility[PackageType, VersionType] | NonecauseTpositive!RangeProtocol[VersionType] | Nonecum_positivecum_negativepackage_index )__name__
__module____qualname____firstlineno____doc____annotations__r   r   r   r   r    r!   r"   __static_attributes__r#       h/home/user/billing-ledger-validation/.venv/lib/python3.14/site-packages/nab_resolver/partial_solution.pyr   r   (   s    7311J;LK9"&G&6>BE;BQHdG6:L3:M6:L3:MM39r+   c                      ] tR t^NtRt]3R R llt]R R l4       t]R R l4       t	R R	 lt
R
 R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR R ltR  R! ltR"tR## )$r   zTracks the resolver's current partial solution as a decision trail.

This is the PubGrub equivalent of a SAT solver's assignment trail.
See: https://en.wikipedia.org/wiki/Conflict-driven_clause_learning#Organization
c                    V ^8  d   QhRRRR/# )   
range_typeztype[RangeProtocol[Any]]returnNoner#   )formats   "r,   __annotate__PartialSolution.__annotate__U   s      #;  r+   c                    Wn         . V n        ^ V n        / V n        / V n        / V n        \        4       V n        / V n        \        \        4      V n        R# )z%Initialize an empty partial solution.N)_range_type_assignments_decision_level_positive_ranges_negative_ranges_decided_versionsset
_undecided_effective_range_cacher   list_assignments_by_package)selfr0   s   &&r,   __init__PartialSolution.__init__U   sZ    %HJ OQOQAC -0E
  	#  	$r+   c                   V ^8  d   QhRR/# r/   r1   r   r#   )r3   s   "r,   r4   r5   l   s     $ $ $r+   c                    V P                   # )z"Return the current decision depth.)r9   rB   s   &r,   r   PartialSolution.decision_levelk   s     ###r+   c                   V ^8  d   QhRR/# rF   r#   )r3   s   "r,   r4   r5   q   s     & &c &r+   c                ,    \        V P                  4      # )z8Return the number of assignments currently on the trail.)lenr8   rH   s   &r,   trail_lengthPartialSolution.trail_lengthp   s     4$$%%r+   c                    V ^8  d   QhRRRR/# )r/   r   r
   r1   z.Sequence[Assignment[PackageType, VersionType]]r#   )r3   s   "r,   r4   r5   u   s     
 
"
	7
r+   c                H    V P                   P                  V4      pVf   R# V# )zpReturn the chronological assignment trail for ``package``.

Read-only view; callers must not mutate the result.
r#   )rA   get)rB   r   entriess   && r,   assignments_forPartialSolution.assignments_foru   s)     ..227;?Ir+   c                    V ^8  d   QhRRRR/# r/   r   r
   r1   r   r#   )r3   s   "r,   r4   r5      s      ; +L r+   c                J   V P                   P                  V\        4      pV\        Jd   \        RV4      # V P                  P                  V4      pV P
                  P                  V4      pVf   Vf   RpMVf   Vf   Q hV( pMVf   TpMW4,
          pWPP                   V&   V# )z|Get the combined allowed range for a package, or None if unassigned.

Computes ``positive - negative``, cached per package.
r   N)r?   rQ   _UNSETr   r:   r;   )rB   r   cachedr   negativeresults   &&    r,   rQ   PartialSolution.get   s    
 ,,00&A;VDD((,,W5((,,W5 08<F '''YFF(F/5##G,r+   c               $    V ^8  d   QhRRRRRR/# )r/   r   r
   r   r   r1   r2   r#   )r3   s   "r,   r4   r5      s!     + +k +K +D +r+   c                :   V ;P                   ^,          un         V P                  P                  V4      pW0P                  V&   W P                  V&   V P
                  P                  VR4       V P                  P                  V4       V P                  V,          p\        VVV P                   R\        V P                  4      VRVV P                  P                  V4      \        V4      R7
      pV P                  P                  V4       VP                  V4       R# )z9Record a decision: pick a specific version for a package.NT)
r   r   r   r   r   r   r   r    r!   r"   )r9   r7   	singletonr:   r<   r?   popr>   discardrA   r   rL   r8   r;   rQ   append)rB   r   r   exact_rangepackage_entries
assignments   &&&   r,   decidePartialSolution.decide   s    !&&009)4g&*1w'##''6(66w?)//D--.$..227;o.

 	  ,z*r+   c          
     ,    V ^8  d   QhRRRRRRRRR	R
/# )r/   r   r
   
constraintr   r   r   r   z)Incompatibility[PackageType, VersionType]r1   r2   r#   )r3   s   "r,   r4   r5      s<     -+ -+-+ /-+
 -+ 9-+ 
-+r+   c               f   V'       d   WP                   9   d   V P                   V,          V,          pM!V P                  P                  4       V,          pWPP                   V&   WP                  9  d   V P                  P                  V4       MZWP                  9   d   V P                  V,          V,          pM!V P                  P                  4       V,          pWPP                  V&   V P                  P                  VR4       V P                  V,          p\        VVV P                  R\        V P                  4      VVV P                   P                  V4      V P                  P                  V4      \        V4      R7
      pV P                  P!                  V4       VP!                  V4       R# )z}Record a derivation from unit propagation.

See: https://github.com/dart-lang/pub/blob/master/doc/solver.md#unit-propagation
NF)
r   r   r   r   r   r   r   r    r!   r"   )r:   r7   fullr<   r>   addr;   emptyr?   r`   rA   r   r9   rL   r8   rQ   rb   )rB   r   ri   r   r   	new_rangerd   re   s   &&&$$   r,   derivePartialSolution.derive   sb    /// 11':ZG	 ,,113j@	-6!!'*444##G, /// 11':ZG	 ,,224zA	-6!!'*##''666w?'//D--...227;..227;o.

 	  ,z*r+   c                    V ^8  d   QhRRRR/# )r/   target_levelr   r1   r2   r#   )r3   s   "r,   r4   r5      s     , ,c ,d ,r+   c                   V P                   '       d?   V P                   R,          P                  V8  d   V P                   P                  4        KP  Wn        . pV P                  P                  4        F  w  r4V'       d+   VR,          P                  V8  d   VP                  4        K2  V'       g   VP                  V4       V P                  P                  VR4       V P                  P                  VR4       V P                  P                  VR4       V P                  P                  V4       K  V P                  W44       K  	  V F  pV P                  V K  	  V P                  P                  4        R# )a|  Remove all assignments above target_level.

Non-chronological backjumping: skips past irrelevant decision levels
directly to the cause of the conflict.  Relies on
``Assignment.accumulated_range`` already being cumulative, so each
package's surviving state can be rebuilt without re-intersecting.
See: https://github.com/dart-lang/pub/blob/master/doc/solver.md#conflict-resolution
N)r8   r   r`   r9   rA   itemsrb   r:   r;   r<   r>   ra   %_update_package_state_after_backtrackr?   clear)rB   rr   empty_packagesr   rR   s   &&   r,   	backtrackPartialSolution.backtrack   s     D$5$5b$9$H$H<$W!!#+,. $ < < B B DGgbk88<G%%g.%%))'48%%))'48&&**7D9''0::7L !E &G,,W5 & 	##))+r+   c               $    V ^8  d   QhRRRRRR/# )r/   r   r
   rR   z*list[Assignment[PackageType, VersionType]]r1   r2   r#   )r3   s   "r,   r4   r5     s(     +- +-+- <+- 
	+-r+   c                n   RpRpRpV F[  pVP                   '       d   VP                  pVP                  pK/  VP                  '       d   VP                  pKO  VP                  pK]  	  Vf   V P                  P                  VR4       MW0P                  V&   Vf   V P                  P                  VR4       MW@P                  V&   Vf   V P                  P                  VR4       MWPP                  V&   Ve"   Vf   V P                  P                  V4       R# V P                  P                  V4       R# )aE  Recompute positive/negative/decided state for a package.

Each ``Assignment.accumulated_range`` is already cumulative, so the
latest entry of each kind is enough to rebuild state.  Trail levels
never decrease, so popping a decision pops every later entry for the
same package; a surviving decision is always the current one.
N)r   r   r   r   r:   r`   r;   r<   r>   rl   ra   )rB   r   rR   last_poslast_neglast_decision_versionre   s   &&&    r,   rv   5PartialSolution._update_package_state_after_backtrack  s    7;6:48!J%%%%77(2(:(:%$$$%77%77 " !!%%gt4-5!!'*!!%%gt4-5!!'* (""&&w5.C""7+$9$AOO(OO##G,r+   c                   V ^8  d   QhRR/# )r/   r1   zdict[PackageType, VersionType]r#   )r3   s   "r,   r4   r5   3  s     , ,9 ,r+   c                ,    \        V P                  4      # )z8Return the current decision map: ``{package: version}``.)dictr<   rH   s   &r,   	decisionsPartialSolution.decisions3  s    D**++r+   c                   V ^8  d   QhRR/# )r/   r1   zset[PackageType]r#   )r3   s   "r,   r4   r5   7  s     $ $$4 $r+   c                ,    \        V P                  4      # )zReturn packages with positive constraints but no decision yet.

Packages with only negative derivations (learned exclusions) are not
yet known to be required.  Returns a fresh copy so callers can mutate
without disturbing solver state.
)r=   r>   rH   s   &r,   undecided_packages"PartialSolution.undecided_packages7  s     4??##r+   c                    V ^8  d   QhRRRR/# )r/   r   r
   r1   r   r#   )r3   s   "r,   r4   r5   @  s     U U{ Ut Ur+   c                J    WP                   9   ;'       g    WP                  9   # )zAReturn True if the package has a positive constraint or decision.)r:   r<   rB   r   s   &&r,   has_positive_constraint'PartialSolution.has_positive_constraint@  s"    ///TT7>T>T3TTr+   c                   V ^8  d   QhRR/# )r/   r1   z-dict[PackageType, RangeProtocol[VersionType]]r#   )r3   s   "r,   r4   r5   D  s     + +!N +r+   c                ,    \        V P                  4      # )z9Return a copy of the positive-range map for each package.)r   r:   rH   s   &r,   positive_rangesPartialSolution.positive_rangesD  s    D))**r+   c                    V ^8  d   QhRRRR/# rV   r#   )r3   s   "r,   r4   r5   H  s     2 2k 26W 2r+   c                8    V P                   P                  V4      # )zBReturn the package's accumulated positive range, or None if unset.)r:   rQ   r   s   &&r,   positive_rangePartialSolution.positive_rangeH  s    $$((11r+   c               (    V ^8  d   QhRRRRRRRR/# )r/   re   z$Assignment[PackageType, VersionType]termTerm[PackageType, VersionType]is_positiver   r1   r#   )r3   s   "r,   r4   r5   L  s2     ) )8) -)
 ) 
)r+   c                   VP                   pV'       d   Vf   R# Vf   VP                  f   Q hVP                  ( pM#VP                  f   TpMWAP                  ,
          pVP                  V4      # )zWhether the trail up to and including ``assignment`` satisfies term.

Positive terms need a positive assignment first; negatives alone
only exclude versions.
F)r    r!   	satisfies)rB   re   r   r   r    	effectives   &&&$  r,   _satisfied_atPartialSolution._satisfied_atL  sn     "..</**666#000I$$,$I$'>'>>I~~i((r+   c                    V ^8  d   QhRRRR/# )r/   r   r   r1   z+Assignment[PackageType, VersionType] | Noner#   )r3   s   "r,   r4   r5   f  s      2	4r+   c                   V P                   P                  VP                  R4      p\        V4      pV^ 8X  d   R# VP	                  4       pV P                  W#^,
          ,          WR7      '       g   R# ^ V^,
          reWV8  d>   WV,           ^,          pV P                  W',          WR7      '       d   TpK8  V^,           pKC  W%,          # )a^  Find the earliest assignment that causes the term to be satisfied.

The effective range only narrows along the trail, so ``term.satisfies``
is monotonic: once an entry satisfies the term, every later one does
too.  That lets a binary search replace the linear scan.
See: https://github.com/dart-lang/pub/blob/master/doc/solver.md#conflict-resolution
N)r   r#   )rA   rQ   r   rL   r   r   )rB   r   rR   countr   lowhighmids   &&      r,   	satisfierPartialSolution.satisfierf  s     ..224<<DGA:&&(!!'!)"4d!TTuqyTj:!#C!!',!NNAg|r+   )	r8   rA   r<   r9   r?   r;   r:   r7   r>   N)r$   r%   r&   r'   r(   r	   rC   propertyr   rM   rS   rQ   rf   ro   ry   rv   r   r   r   r   r   r   r   r*   r#   r+   r,   r   r   N   s     ?D , $ $ & &
6+4-+^,B+-Z,$U+2)4 r+   N)r(   
__future__r   collectionsr   dataclassesr   typingr   r   r   r   rangesr	   typesr
   r   r   collections.abcr   r   r   __all__objectrX   r   r   r#   r+   r,   <module>r      s    # # ! 4 4  : :(,  
 ":k12 ": ":Jrgk;67 rr+   