Subject: [bug#50878] [PATCH] union: Resolve collisions by stable-sort'ing them.

From: Ludovic Courtès <[email-masked]>
Date: Thu, 30 Sep 2021 16:00:32 +0200

Hi,

Maxime Devos <[email-masked]> skribis:

> Attila Lendvai schreef op do 30-09-2021 om 08:10 [+0000]:
>> > > -   (let* ((original-files (list->vector files))
>> > > -           (count (vector-length original-files))
>> > > -           (stripped-files (vector-map (lambda (_ el)
>> > > -                                         (strip-store-file-name el))
>> > > -                                       original-files))
>> > > -           (indices (vector-unfold values count)))
>> > > 
>> > > -   (stable-sort! indices
>> > > -                    (lambda (a b)
>> > > -                      (string> (vector-ref stripped-files a)
>> > > -                               (vector-ref stripped-files b))))
>> > > -   (vector-ref original-files (vector-ref indices 0))))
>> > 
>> > Instead of stable-sort!-ing the indices of a vector, what about stable-
>> > sort!-ing (map strip-store-file-name original-files) in more or less
>> > one go?
>> 
>> the hash also needs to be dropped from the path for sorting to be
>> useful, but the return value must be the full path, hence the
>> complexity with sorting the indices, pointing both to the full paths
>> and the cut parts.
>
> You can replace the 'less' argument of 'stable-sort'.
> Example sorting by the second character of a string:
>
> (sort '("za" "yb" "xc") (lambda (x y)
>                           (char>? (string-ref x 1)
>                                   (string-ref y 1)))))
>
> IIUC, you would need to replace char>? by string> and string-ref
> by strip-store-file-name.

Agreed.  I’d advice using this strategy rather than resorting to
SRFI-43; it should have the desired effect.

BTW, because TeX Live packages rely on ‘union-build’, this patch
triggers a lot of rebuilds, but we can try to squeeze it in the upcoming
‘core-updates-frozen’ rebuild.

Thanks,
Ludo’.