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

From: Maxime Devos <[email-masked]>
Date: Thu, 30 Sep 2021 10:42:13 +0200

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.

Greetings,
Maxime.