a !cT@sZddlmZddlmZddlmZddlmZddddd Zd d ZGd d d eZ dS))absolute_import)print_function)unicode_literalsreduce)nameZsummary descriptionurlcCs"t|}dg||t|}|S)z, Ordered sset with empty strings prepended. )lensorted)Zssetlengthcurrentlr5/usr/lib/python3.9/site-packages/dnf/match_counter.py_canonize_string_set"src@sfeZdZdZeddZddZddZdd Zd d Z d d Z ddZ ddZ dddZ ddZdS) MatchCounterzMap packages to which of their attributes matched in a search against what values. The mapping is: ``package -> [(key, needle), ... ]``. csfdd}tt||S)Ncs>|d}|d}t|}|dkr6||kr6dt|St|S)Nrr r r )getattrWEIGHTS)matchkeyneedleZhaystackpkgrrweight4s   z*MatchCounter._eval_weights..weight)summap)rmatchesrrrr _eval_weights1s zMatchCounter._eval_weightscsfdd}|S)aGet the key function used for sorting matches. It is not enough to only look at the matches and order them by the sum of their weighted hits. In case this number is the same we have to ensure that the same matched needles are next to each other in the result. Returned function is: pkg -> (weights_sum, canonized_needles_set, -distance) cs|| |jfSN)r#r rselfrrget_keyKsz'MatchCounter._key_func..get_keyr)r&r'rr%r _key_func?s zMatchCounter._key_funccsrtfddDSdS)z0Return the max count of needles of all packages.c3s|]}t|VqdSr$)rmatched_needles).0rr%rr Wz,MatchCounter._max_needles..r)maxr%rr%r _max_needlesTszMatchCounter._max_needlescCs||g||fdSr$) setdefaultappend)r&rrrrrraddZszMatchCounter.addcCs"|D]}td|||fqdS)Nz%s %s)printr&rrrrdump]szMatchCounter.dumpcstfdd|DS)Nc3s|]}t|dVqdS)rN)rr*mrrrr+br,z1MatchCounter.matched_haystacks..setr3rrrmatched_haystacksaszMatchCounter.matched_haystackscCs2g}||D] }|d|vrq ||dq |S)Nr)r0)r&rresultirrr matched_keysds   zMatchCounter.matched_keyscCstdd||DS)Ncss|]}|dVqdS)r Nrr5rrrr+nr,z/MatchCounter.matched_needles..r7r3rrrr)mszMatchCounter.matched_needlesFNcCs |r|n|}t||dS)N)r)keysrr()r&reverseZlimit_tor=rrrrpszMatchCounter.sortedcstfdddS)Ncs|t|Sr$)r)totalrr%rrur,z$MatchCounter.total..rrr%rr%rr?tszMatchCounter.total)FN)__name__ __module__ __qualname____doc__ staticmethodr#r(r.r1r4r9r<r)rr?rrrrr)s   rN) Z __future__rrr functoolsrrrdictrrrrrs