3 ft`T@sZddlmZddlmZddlmZddlmZddddd Zd d ZGd d d eZ dS))absolute_import)print_function)unicode_literals)reduce)nameZsummary descriptionZurlcCs"t|}dg||t|}|S)z, Ordered sset with empty strings prepended. )lensorted)ZssetZlengthZcurrentlr#/usr/lib/python3.6/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)matchkeyneedleZhaystack)pkgrrweight4s   z*MatchCounter._eval_weights..weight)summap)rZmatchesrr)rr _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) csj|| |jfS)N)rr )r)selfrrget_keyKsz'MatchCounter._key_func..get_keyr)rrr)rr _key_func?s zMatchCounter._key_funccsrtfddDSdS)z0Return the max count of needles of all packages.c3s|]}tj|VqdS)N)r matched_needles).0r)rrr Wsz,MatchCounter._max_needles..r)max)rr)rr _max_needlesTszMatchCounter._max_needlescCs|j|gj||fdS)N) setdefaultappend)rrrrrrraddZszMatchCounter.addcCs&x |D]}td|||fqWdS)Nz%s %s)print)rrrrrdump]s zMatchCounter.dumpcstfdd|DS)Nc3s|]}t|dVqdS)rN)r)r"m)rrrr#bsz1MatchCounter.matched_haystacks..)set)rrr)rrmatched_haystacksaszMatchCounter.matched_haystackscCs6g}x,||D] }|d|kr q|j|dqW|S)Nr)r')rrresultirrr matched_keysds  zMatchCounter.matched_keyscCstdd||DS)Ncss|]}|dVqdS)r Nr)r"r+rrrr#nsz/MatchCounter.matched_needles..)r,)rrrrrr!mszMatchCounter.matched_needlesFNcCs |r|n|j}t||jdS)N)r)keysrr )rreverseZlimit_tor1rrrrpszMatchCounter.sortedcstfdddS)Ncs|t|S)N)r )totalr)rrrusz$MatchCounter.total..r)r)rr)rrr3tszMatchCounter.total)FN)__name__ __module__ __qualname____doc__ staticmethodrr r%r(r*r-r0r!rr3rrrrr)s   rN) Z __future__rrr functoolsrrrdictrrrrrs