Disclaimer

The content of this blog is my personal opinion only. Although I am an employee - currently of Nvidia, in the past of other companies such as Iagination Technologies, MIPS, Intellectual Ventures, Intel, AMD, Motorola, and Gould - I reveal this only so that the reader may account for any possible bias I may have towards my employer's products. The statements I make here in no way represent my employer's position, nor am I authorized to speak on behalf of my employer. In fact, this posting may not even represent my personal opinion, since occasionally I play devil's advocate.

See http://docs.google.com/View?id=dcxddbtr_23cg5thdfj for photo credits.

Monday, September 16, 2013

Partially explicit sorting

A pattern I run into a lot: partially explicit sorting.

E.g. a regular linear sort - alphabetical, breadth or depth first, etc. - is okay for the "leftovers", but I have an explicit priority ordering of things I want to see at the head of the list.

More advanced, what I did for automatically deducing a print order in the Cp/PL wikified manual / specifications:


  • Create a manual table of contents
  • Attach unlinked items to where first linked to, alphabetically ordered.  
Have also played around with topological sorting, modified by the desored explicit ordering.


ISO: nice Perl / foobar language iioms to do this common pattern.


11 comments:

Andy Glew said...

A common trick is to use special characters to control the sort order.

Unfortunately, for Gmail this is warped, because the sort order for labels on a desktop PC on windows s different from the sort order on Android.

I created labels of the form "! test", "# test", ...

Android sort order:

!#$%'*+,:;<>?[\]_` F ~

Windows Chrome sort order:

_,;:!?.'[]@*\&#%`+<=>~$01a


Consistency, thy name is not Google!

Andy Glew said...

Ascii sort order:

!"#$%&`()*+'-./0...9:;<=>?@A...Z[\]^_`

Andy Glew said...

EBCDIC sort order

.<(+|&!$*); -/|,%_>?`:#@'="a..r~s..z^[]{A-I}J-R\S-Z0-9

So: Windows Chrome sort order is NOT EBCDIC (which seemed possible).

Andy Glew said...

I wonder if Chrome sorts

a) in UTF (but ASCII suborder???)

b) according to the

...

Whatever.


Nevertheless, it sucks that the sort order is different. Which makes it hard to use punctuation marks to control the order of labels.

Andy Glew said...

http://www.liamdelahunty.com/tips/gmail_label_sorting.php

Interestingly, the sort order he observed is different from what I observed - ~tilde comes high n the ordre, not late.

Andy Glew said...

http://rongou.blogspot.ca/2008/01/gmail-label-sort-order.html

Andy Glew said...

http://lifehacker.com/5187531/customize-your-gmail-labels-with-unicode-characters

"I used the Wikipedia list of Unicode characters for reference:

The sort order is the handy bit to keep in mind. I picked ✦ (U+2726) for individuals because it's just a little above ❤ (U+2764)."

Andy Glew said...

http://www.epicmedia.com/blog/2011/01/gmail-label-fun/

Andy Glew said...

Grrr.... this inconsistency, combined with the Android Gmail app's use of a flat list of labels, is compelling me , against my will, to use the Android Email (IMAP) app.

I would rather have one app on each platform. But, now, I have to use different apps for different purposes:

PC Gmail in Chrome ... usual. (Should it be?)

Thunderbird via IMAP to Gmail - slow, but allows sorting.

Android Gmail app - nice UI, swipe to archive. But labelling sucks.

Android Email app - like IMAP overall, doesn't really understand Gmail labels. But at least can show them hierarchically.



Andy Glew said...

I wrote a quick hack perl script, NOT to find maximal embedded orders, and NOT to find all possible orders - but just to test some orders that look nice for this kluge of using symbols to sort:



perl ./sort-order.pl
OK: !09az as expected
OK: !~ as expected *but* ~ is not ordered with letters or numbers
FAIL: !~az as expected ~ is not ordered with letters or numbers
FAIL: !az~ as expected ~ is not ordered with letters or numbers
FAIL: !~09 as expected ~ is not ordered with letters or numbers
FAIL: !09~ as expected ~ is not ordered with letters or numbers
FAIL: _! as expected _ and ! are not ordered consistently
OK: !$ as expected
OK: !$09az as expected $ is nicely ordered with ! numbers and letters
FAIL: !$@09az as expected ... but disallows using @ (which I like for contexts)
FAIL: !@$09az as expected ... and in general $ filters out many possibilities
OK: !09az as expected
OK: !$09az as expected
OK: !#$09az as expected this may be maximal involving $ <===
OK: !'*+|09az as expected alternatives to $ and @ <===
OK: !#%+|09az as expected alternatives to $ and @ <===
FAIL: !@09az as expected but @ filters out numbers it is after numbers in Android, before numbers in Chrome
FAIL: !09@az as expected but @ filters out numbers it is after numbers in Android, before numbers in Chrome
OK: !@az as expected if you are willing not to have labels begining 0-9
OK: !?@\`az as expected <===
OK: !.@\`az as expected <===



Grr.... stop wasting time on this crap!!!!!

Andy Glew said...

Outlook folder sorting


- dash
-- dash dash
+ initial dashes - special handling "- word" is sorted like an initial blank
' single quote
" double quote
# hash
$ dollar
% percent
& ampersand
( lparen
) rparen
* asterisk
, comma
. dot
/ slash
: colon
; semicolon
? question mark
@ at
[ lbracket
\ backslash
] rbracket
^ caret
_ underscore
` backtick
{ lbrace
| pipe
} rbrace
~ tilde
+ plus
< lt
= equals
> gt
0
9
a
-a
--a
see special handling of leading dashes
a space (elided’)
-b
X
special handling of space
X X
X X
X.X
X#X
XX
X< X
X.X
X-X
XXX
z




special Outlook sorting
+ spaces
+ leading space is elided./ thereafter space matters
+ and space precedes all others, except eos comes first

X X
X X
X.X
X#X
XX
X< X
X.X
X-X
XXX
+ leading dashes
+ leading dashes seem to be
+ skipped for initial sorting - i,.e. sort according to character after the dash
+ but then used as a final sort
+ e.g. as if they were moved to the end of the string, perhaps??