[MERGE] walkdirs sort order

John Arbash Meinel john at arbash-meinel.com
Fri Jun 16 18:23:48 BST 2006


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Denys Duchier wrote:
> Robert Collins <robertc at robertcollins.net> writes:
> 
>> As a key, (dirname(path), path) works to pass my tests with an
>> additional test for the case you have exposed.
> 
> by definition of lexicographic order:
> 
> (D1, D1/n1) << (D2, D2/n2)  ==  (D1 < D2) | (D1=D2 & D1/n1<D2/n2)
> 
> by the same definition, we also have:
> 
> (D1, n1) << (D2, n2)  == (D1 < D2) | (D1=D2 & n1<n2)
> 
> which is equivalent to the earlier definition.  therefore, I suspect your key
> can be simplified to be (dirname(path), basename(path)).
> 
> Am I getting this wrong?
> 
> Cheers,
> 
> --Denys

I do believe you are correct. The downside is that it isn't actually
simplified :). The problem being now you have 2 function calls, instead
of just one.

Actually, what would be simpler is to use:


def path_prefix_key(path):
    """Generate a prefix-order path key for path.

    This can be used to sort paths in the same way that walkdirs does.
    """
    return os.path.split(path)

Both dirname() and basename() call 'split()' and then throw away the
other half of the result. So just call it directly. And use the full result.

John
=:->
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.2.2 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFEkukkJdeBCYSNAAMRAu2YAJ9iXQb3mqALc8yM8fftWS2gWntVrgCePF2V
RIB4c2dYYaAchVOToxBWOEw=
=eFR9
-----END PGP SIGNATURE-----




More information about the bazaar mailing list