xlab / handysort

Alphanumeric string sorting algorithm implementation in Go
MIT License
24 stars 3 forks source link

All Good Except For One #5

Open johnrs opened 9 years ago

johnrs commented 9 years ago

It looks like end-of-string is sorting after numbers, rather than before. []string{"", "1", "a", "a1"] ==> [1 a1 a]

xlab commented 9 years ago

:stuck_out_tongue_winking_eye::gun:

xlab commented 9 years ago

Consider using https://github.com/fvbommel/util/tree/master/sortorder though :)

johnrs commented 9 years ago

I’m sorry to have so much bad news. J

John

John Souvestre - New Orleans LA

From: Maxim Kupriianov [mailto:notifications@github.com] Sent: 2015 April 21, Tue 14:14 To: xlab/handysort Cc: JohnRS Subject: Re: [handysort] All Good Except For One (#5)

:stuck_out_tongue_winking_eye: https://assets-cdn.github.com/images/icons/emoji/unicode/1f61c.png :gun: https://assets-cdn.github.com/images/icons/emoji/unicode/1f52b.png

— Reply to this email directly or view it on GitHub https://github.com/xlab/handysort/issues/5#issuecomment-94910038 . https://github.com/notifications/beacon/AFaoap5Fr2wrT-8MGBExShGTpWIrxJtEks5oBpjcgaJpZM4EFYgs.gif

johnrs commented 9 years ago

Unfortunately, something else is wrong now.

[]string{"#", "1"} è [# 1]

Everything else looks good. Including {"a#", "a1"} which sorts correctly as [a1 a#].

John

John Souvestre - New Orleans LA

From: Maxim Kupriianov [mailto:notifications@github.com] Sent: 2015 April 21, Tue 14:22 To: xlab/handysort Cc: JohnRS Subject: Re: [handysort] All Good Except For One (#5)

Closed #5 https://github.com/xlab/handysort/issues/5 via https://github.com/xlab/handysort/commit/fb3537ed64a14615a020f0fe8dc08424233d491f fb3537e.

— Reply to this email directly or view it on GitHub https://github.com/xlab/handysort/issues/5#event-286545322 . https://github.com/notifications/beacon/AFaoaoQsWZuTgpPNyfyVQ4UGA5IXRyqyks5oBprEgaJpZM4EFYgs.gif

johnrs commented 9 years ago

Yes, it is nice. I have given him a few minor improvements. I’m working to add handling all of the Unicode 0 digits to it now, but it slows it down.

John

John Souvestre - New Orleans LA

From: Maxim Kupriianov [mailto:notifications@github.com] Sent: 2015 April 21, Tue 14:23 To: xlab/handysort Cc: JohnRS Subject: Re: [handysort] All Good Except For One (#5)

Consider using https://github.com/fvbommel/util/tree/master/sortorder though :)

— Reply to this email directly or view it on GitHub https://github.com/xlab/handysort/issues/5#issuecomment-94911710 . https://github.com/notifications/beacon/AFaoakcscebFdnrXyjoYBiVV15mNMKQOks5oBpr6gaJpZM4EFYgs.gif

xlab commented 9 years ago

I wonder why OS X does that sort

So I'm expecting # < 1 but then it's not clear why a1 > a#.

johnrs commented 9 years ago

Probably because it’s easy to do, since that is how the characters are ordered. But in a natural sort the idea is that “numbers are different”. So it doesn’t make much sense that a number would sort between two non-number characters.

A better visual example would be a “space” character instead of the “#”. The way it sorts now: [ 1 ]. The number is sorting between two non-numbers. What I think it should be: [1 ].

Imagine filenames, some with space separators and others with underscore separators. Shouldn’t they sort adjacently, without numbers between them?

Given this, should numbers sort before or after non-numbers? Either way seems OK to me, but every implementation I’ve looked at has them first.

John

John Souvestre - New Orleans LA