czardas

Why sort alpha-numeric?

19 posts in this topic

#1 ·  Posted (edited)

Beyond the fact that mixed data types exist, and some have the desire to keep everything tidy; when do you really need to do an alpha-numeric sort? Isn't using one sorting method adequate in most situations? I know it's intended to be dual purpose, but that's not an answer to my question.

Edited by czardas

Share this post


Link to post
Share on other sites



You would use an alphanumeric sort when you want things sorted alphanumerically. Numbers sorted in ascending/descending order and then text sorted alphabetically. Lexicographical order would be if you want your strings/numbers sorted in ASCII order, 100 would come before 5 and after 10, and this isn't what most people would want them to be sorted to.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

What is this related to, as I am not understanding the question?

Wouldn't alphanumeric be the sensible default anyway, in most cases.

Perhaps a real world example would make things clearer.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#4 ·  Posted (edited)

4 hours ago, BrewManNH said:

You would use an alphanumeric sort when you want things sorted alphanumerically. Numbers sorted in ascending/descending order and then text sorted alphabetically. Lexicographical order would be if you want your strings/numbers sorted in ASCII order, 100 would come before 5 and after 10, and this isn't what most people would want them to be sorted to.

When do you want things sorted alpha-numerically and why? You are just saying people have the desire to have things sorted this way. I want a real reason: not some fad or fancy.

2 hours ago, TheSaint said:

Perhaps a real world example would make things clearer.

It is related to functional sorting algorithms. You give a real world example of where alpha-numeric sort is useful, because I can't think of one. plz

Edited by czardas

Share this post


Link to post
Share on other sites
3 minutes ago, czardas said:

You give a real world example of where it is useful, because I can't think of one. plz

Well, you haven't given me any parameters ... so no context.

However, in a generic way, what about band names. They can be comprised of the three main states (mixed, alpha, numeric) and they belong to the same group - band names.

So how would you sort them, if not alphanumerically?

It is useful to have a specific order, if just for look up purposes.


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#6 ·  Posted (edited)

Any context or parameters you choose. I would sort band names alphabetically (lexicographically) because they are names. There might be a really big band in the mix, but magnitude has no bearing on the name.

Edited by czardas

Share this post


Link to post
Share on other sites

So you have given it the parameter of names ... string in effect.

A string however, as you know, can be comprised of alphabetical characters as well as numerical ones.

So a band named 100 doesn't fall inside alphabetical.

Where would they be sorted to?

Would there be a conversion to the alphabetical text of "one hundred" and so sort under the alpha character 'o'


AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#8 ·  Posted (edited)

Well it's probably simplest to take the easiest path and use StringCompare() to test equality: lexicographically placing numbers before letters. However as you say, this is not the only possible way to arrange such a mixed group.

BTW, you mentioned band names: not me. I said any context. Band names do not constitute justification for an alpha-numeric sorting algorithm because numeric band names have nothing to do with a band's magnitude. To me, numeric sorting applies to magnitude and not to the position of characters within some code page.

I am of the opinion that alpha-numeric sorting is nothing more than a dual purpose algorithm with no real world application beyond this fact. Please prove me wrong if you can. I'm writing a sorting function and it already has 2, or possibly 3, algorithms: alphabetical, numeric and string length.

Edited by czardas

Share this post


Link to post
Share on other sites

#9 ·  Posted (edited)


Taken from - https://en.wikipedia.org/wiki/Lexicographical_order

Quote

A lexicographical ordering may not coincide with conventional alphabetical ordering. For example, the numerical order of Unicode codepoints does not always correspond to traditional alphabetic orderings of the characters, which vary from language to language. So the lexicographic ordering induced by codepoint value sorts strings in an unambiguous canonical order, but it does not necessarily "alphabetize" them in the conventional sense.

Perhaps that helps?

Me, I continue to struggle with the notion, that numbers can be alphabetical in their numeric state. It seems like an oxymoron to me.

To me, the numbers should be ignored or placed at start or end, without sorting ... for the sorting would require being numerical, not alphabetical.

Edited by TheSaint
1 person likes this

AutoIt.4.Life Clubrooms - Life is like a Donut (secret key)

Make sure brain is in gear before opening mouth!
Remember, what is not said, can be just as important as what is said.

Spoiler

What is the Secret Key? Life is like a Donut

If I put effort into communication, I expect you to read properly & fully, or just not comment.
Ignoring those who try to divert conversation with irrelevancies.
If I'm intent on insulting you or being rude, I will be obvious, not ambiguous about it.
I'm only big and bad, to those who have an over-active imagination.

I may have the Artistic Liesense ;) to disagree with you. TheSaint's Toolbox (be advised many downloads are not working due to ISP screwup with my storage)

userbar.png

Share this post


Link to post
Share on other sites

#10 ·  Posted (edited)

Good, I think we are getting somewhere now. The two sorting methods are incompatible. Numeric sorting should not necessarily care about data type, and alphabetic sorting applied to a mixture of alpha-numeric characters should ignore numeric magnitude. Keeping the algorithms separate avoids having to make some dubious decisions.

Edit : Sorting strings numerically has some excellent benefits. Firstly, the main benefit is that you don't (necessarily) have to corrupt data (formatting) by converting strings to numbers prior to sorting; and secondly, numeric size can be totally unlimited (well beyond the maximum, non-infinite, double). Theoretically, numeric strings can become as large as ~10^2147483646 in AutoIt. Although I don't intend to test these bounds, suffice it to say that it's pretty humongous.

Edited by czardas

Share this post


Link to post
Share on other sites

#11 ·  Posted (edited)

Here are the options I currently have planned for my function. I intend to use a binary flag with the following possible values. It seems unnecessary to include an alphanumeric sorting algorithm as well. I can't think of any application for it.

0 - alphabetical / lexical [applies to all items including numbers]
1 - descending [applies to sorted items]
2 - numeric [applies to numbers and decimal strings only ==> overrides flag 0]
4 - string length [applies to all items ==> overrides flags 0 & 2]

Any comments?

Edited by czardas

Share this post


Link to post
Share on other sites

Here is a real world example of why you'd want to sort alphanumerically, You have a list of addresses, houses numbered 1 through 1000, you want to drop off deliveries to each house, and you mark each one off as you drop it off. Would you want to search past 100 to find house #2, then go back and search past 200 to get to house #3? You'd want them in numerical order because that is how the real world is sorted.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#13 ·  Posted (edited)

Hmm, _ArraySort() currently can't do that. There is no such thing as a half-number/half-string data type. You need to add zero padding, or something to that effect. I appreciate you having a think about it, that was a clever answer :) even though I rejected it. 

Edited by czardas

Share this post


Link to post
Share on other sites

Currently can't do what?

Look at _VersionCompare which uses both a lexicographical and an alphanumeric comparison of version strings depending on the contents of the version string.


If I posted any code, assume that code was written using the latest release version unless stated otherwise. Also, if it doesn't work on XP I can't help with that because I don't have access to XP, and I'm not going to.
Give a programmer the correct code and he can do his work for a day. Teach a programmer to debug and he can do his work for a lifetime - by Chirag Gude
How to ask questions the smart way!

I hereby grant any person the right to use any code I post, that I am the original author of, on the autoitscript.com forums, unless I've specifically stated otherwise in the code or the thread post. If you do use my code all I ask, as a courtesy, is to make note of where you got it from.

Back up and restore Windows user files _Array.au3 - Modified array functions that include support for 2D arrays.  -  ColorChooser - An add-on for SciTE that pops up a color dialog so you can select and paste a color code into a script.  -  Customizable Splashscreen GUI w/Progress Bar - Create a custom "splash screen" GUI with a progress bar and custom label.  -  _FileGetProperty - Retrieve the properties of a file  -  SciTE Toolbar - A toolbar demo for use with the SciTE editor  -  GUIRegisterMsg demo - Demo script to show how to use the Windows messages to interact with controls and your GUI.  -   Latin Square password generator

Share this post


Link to post
Share on other sites

#15 ·  Posted (edited)

That's a very specific function. How do I know whether my half-string/half-number is a file version (delimited string), an English date (delimited string), a house number followed by a street name. _ArraySort() cannot currently do these things which you mention. It seems we mean two different things by alphanumeric sorting. I mean a dual purpose sorting algorithm which behaves in the same way as, or in a similar way to, _ArraySort() in Array.au3.

There are a zillion possible specific circumstances where sorting involves complex pre-processing. Should I include all words pertaining to magnitude of some type or other (eg September, nautical mile) within all languages, past or present? It's not really practical to have a sorting algorithm which is longer than the Britannica and takes weeks to run all checks.

Edited by czardas

Share this post


Link to post
Share on other sites

The so-called "natural sort" is pretty useful in many contexts.


This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.
Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe here
RegExp tutorial: enough to get started
PCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta.

SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.
SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.
An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.
SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)
A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!
SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt)

Share this post


Link to post
Share on other sites

Thanks, I'll look at that. I am not sure if I should include string length, because it's probably less useful. I have been playing around with it, but progress is slow - multiple projects on the go at the same time. :sweating:

Share this post


Link to post
Share on other sites

Natural sort looks to be a bit of a monster routine CPU eater. I see how it can be useful. :)

Share this post


Link to post
Share on other sites

#19 ·  Posted (edited)

I decided to include alphanumeric sort because people are used to it and I didn't want to raise too many eyebrows. I decided to exclude natural sort (for now at least), because I think it's only useful for badly designed systems, or those which have no clear design at all. I like the idea, but I intend focus my attention on highly organized data: numbers or strings preferably in separate containers. It's faster and cleaner, but less useful if you have strange mixed alphanumeric formatting which slows everything down. I feel that having so many numeric data types is complicated enough already.

You can find the results in ArrayWorkshop. This sort function turned out to be one of the more challenging functions I have written.

Edited by czardas

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now