August 7th, 2009

SHCIDS_CANONICALONLY is the moral equivalent in the shell namespace of the Unicode ordinal comparison

One of the flags you can pass to the IShellFolder::CompareIDs method is SHCIDS_CANONICALONLY. This flag means that the method should determine whether the two pointers refer to the same underlying object, and if they do not, then it should determine which one should come first by whatever mechanism it wants. It doesn’t matter which one is declared as coming before the other one, as long as it is consistent. I like to think of this as the moral equivalent of the Unicode ordinal comparison. In both cases, you use the comparison if you have two items that you wish to keep in sorted order, but you don’t care what the ordering rules are, as long as they are consistent. In fact, all you care about is consistency, and you’re perfectly happy to sacrifice readability for speed. The resulting sorted list won’t be displayed to the user; all you’re going to use it for is locating the item later.

You can think of this as the moral equivalent of the NTFS file name sorting algorithm. In both cases, the items are sorted not so that the user can find them, but so that the program can find them.

Topics
Code

Author

Raymond has been involved in the evolution of Windows for more than 30 years. In 2003, he began a Web site known as The Old New Thing which has grown in popularity far beyond his wildest imagination, a development which still gives him the heebie-jeebies. The Web site spawned a book, coincidentally also titled The Old New Thing (Addison Wesley 2007). He occasionally appears on the Windows Dev Docs Twitter account to tell stories which convey no useful information.

0 comments

Discussion are closed.