GARTHWILSON wrote:
I think I would need a little more explanation to catch on; but you will be interested in the "Dictionary hashing" topic at viewtopic.php?f=9&t=555 . I should have quoted that thread as I had read it before posting and I think I left my original post somewhat incomplete and should elaborate a little more.
I am an 8-bit programmer but prefer the 65c02 over the 6502. And love programming ways to make use of Auxiliary memory. A very fast sort routine with similar results to the ultimate fastest sort routine is preferred if the code is quite a bit smaller. Such as my insertion sort over a hashing algorithm sort.
I tend to shy away from hashing as I still struggle to follow the code, and if I can't follow the code easily, then I also struggle to find other uses for it. Plus I tend to find hashing algorithms a little larger than I would like to use on a computer with limited memory. If I am reading Hashing right, it would require a bit of math to calculate what group a word should be in.
My version of the insertion sort can handle all the basic needs required for Forth. Finding words, adding words and forgetting a range of words as well as single words, and is not only quite a bit faster than a link list, but does not even require a link to other words. All words would be stored in Auxiliary memory along with its CodeFieldAddress (CFA) of the location in main memory for the description of that word.
I intentionally left out the twists as I didn't want to go into too much detail as they are not needed in Forth. A couple of the things added to the insertion routine was the ability to sort numbers in numerical order that are a part of a string. Most sorts will sort strings with numbers like this: Test1, Test11, Test111, Test2, Test 22, Test3 ... etc. My version will return: Test1, Test2, Test3, Test11, Test22, Test111 ... etc
The other twist I added, was the ability to return the previous word, if a word is not found. Can't begin to tell how powerful this was in programming a disassembler.
And a couple of last things it does is keep an original word order as well as a sorted list, and it can sort ascending as well as descending order. I don't think I have come across any other sort that can accomplish everything listed.
That wasn't supposed to look like bragging. I just wanted to mention what all could be done with this insertion sort that I find a little hard to do with other sorts. The bragging part is still yet to come.
Not counting the little bit of overhead to access Auxiliary memory, the actual sort routine and all its twists worked out to less than 512 bytes. 499 to be exact.
Sorry if I seem to be a little excited to find another use for my twisted version of a insertion sort. I use it in pretty much in everything from disk catalogs to databases to disassemblers, and now Forth. Although it may not be the fastest out there, it certainly is one of the most diverse compared to other sorts and at such a small memory footprint.