Skip to content

bitwise operators and sorts

Forums Forums SIMPOL Programming bitwise operators and sorts

Viewing 5 posts - 1 through 5 (of 5 total)
  • Author
    Posts
  • #3524
    JD Kromkowski
    Participant

    having fallen into a rabbit hole regarding sorting and calculating logs, some questions.

    1. I see AND, OR, XOR but do we have COMPLEMENT (~), LEFT SHIFT (<<), RIGHT SHIFT (>>)?

    2. Sorting: I am not confident in determining which sorts are the best for which circumstances. Under what conditions, does putting an array into a volatable and using its built in indexing, make sense? There are just too many sorting functions, but obviously indexes on tables are doing the job very efficiently and correctly.

    3. I found some situations where I wasn’t altogether confident in the results of the sorts (when I was writing a median function apart from agg functions in report) – it would be nice if you would expose the code for the report libs (reportlib.sml and quickreportlib.sml)

    #3525
    Michael
    Keymaster

    Hi John,

    1. We don’t have the left shift, right shift, or complement operators. Having said that, they could easily be added as functions to mathlib.sml. Please note that a proper implementation might require additional parameters to decide whether they should optionally truncate at a certain bit size, since in SIMPOL they will never overflow.

    2. I would be very surprised if using a volatable for sorting is the fastest method. Generally I wouls stick with an implementation of quicksortrit(). It uses QuickSort for sections greater than 20 and then for those sections switches to insertion sort. It is probably the fastest sort I am aware of currently. Please be aware that all of the sorting algorithms that do not use sbme or ppcs tables, will not sort accented characters correctly. At some point I will see about exposing the comparison algorithm used by the database engines (this resides in sbsort32.dll) so that correct comparisons that support upper and lower case, accented characters, etc. can be done in SIMPOL code. Adding that level of support in pure SIMPOL would probably result in a significantly slower sort in general, even if the feature were not required.

    3. We are currently not ready/willing to expose the source code for those at this time.

    Ciao, Neil

    • This reply was modified 6 years, 9 months ago by Michael.
    #3527
    JD Kromkowski
    Participant

    Thanks for the response. Obviously, left shift, right shift, or complement operators are not a burning functional requirement. On the other hand, it is probably something that would make SIMPOL a more robust and attractive language in the future.

    As to function quicksortrit(array a, integer base, integer count)

    1. Could you clarify to what “base” and “count” are supposed to refer?

    I find myself just using quicksortrit(myarray, 0, myarray.count()) but what else could you use and why?

    2. The function alters myarray so that the first element is myarray[1] not myarray[0]. Is it supposed to work that way?

    #3528
    JD Kromkowski
    Participant
    #3530
    Michael
    Keymaster

    1. Could you clarify to what “base” and “count” are supposed to refer?

    I find myself just using quicksortrit(myarray, 0, myarray.count()) but what else could you use and why?

    This is a recursive function, so it calls itself. You should always call it with the base of the array that you want sorted, and the total number of elements it should be sorting. QuickSort is a divide and conquer type of sort, so it breaks itself into chunks and calls itself to sort those chunks by passing in different values for base and count.

    Arrays in SIMPOL start at 1, not 0, so the count won’t work properly if the starting position is 0.

    Ciao, Neil

Viewing 5 posts - 1 through 5 (of 5 total)
  • You must be logged in to reply to this topic.