Sorting

What is available to do sorting in Matrix Brandy, is there a library for it? This must be a fairly common requirement so I'm hoping there's an off-the-shelf solution.

Comments

  • What is available to do sorting in Matrix Brandy?
    My reason for asking is that I'd like to port this program to Matrix Brandy (and possibly even to ARM BASIC V). It's entirely generic BBC BASIC code, except for the unavoidable need to sort the balls into reverse depth order (farthest first, nearest last) before plotting them. What's the solution?
  • What's the solution?
    I suppose I must conclude that there are no off-the-shelf solutions for sorting in Matrix Brandy at all. I find that very surprising; BBC BASIC for Windows, BBC BASIC for SDL 2.0 and my Console Mode editions all come with a sortlib library.
  • BigEd
    edited March 9
    Back in the day for this size of problem (actually any size) I would probably just code up a bubble sort. And then find out if that's good enough or not - it's only a few lines I think?

    Could sortlib be used? If it's not already in Basic, I imagine it could be.
  • [Richard Russell]
    edited March 9
    BigEd wrote: »
    Back in the day for this size of problem (actually any size) I would probably just code up a bubble sort.
    That would have been in assembler code, presumably, and unfortunately that's not an option in Brandy. My assumption is that an off-the-shelf sorting solution for Brandy would have to be coded in C and called using SYS, which is not trivial (especially given that SYS doesn't have the flexibility of CALL in the way parameters are passed)
    Could sortlib be used? If it's not already in Basic, I imagine it could be.
    That's also assembly language code, so the same issue arises of how to port it to a BASIC with no built-in assembler! I can't say I've ever understood why Matrix Brandy doesn't have an assembler (it would have to be a different assembler for each supported CPU type, of course, but that's what I do in BBC BASIC for SDL 2.0) but we're stuck with that.

    In a former life I would have considered trying to write a C sorting library for Matrix Brandy myself, but that boat has sailed. I'd naively assumed that it's such a crucial tool somebody would have already written it.
  • It seems that no solution for fast sorting in Matrix Brandy is available, or is likely to be in the near future. Here is the program which I was hoping to port (listing at YouTube), perhaps somebody might try adapting it to use a BASIC sort of some kind (preferably something a lot better than a Bubble Sort). Since Brandy is so fast there is a possibility it might still manage 60 fps.

  • I'm still on the lookout for a (fast) sorting solution for Matrix Brandy.

    Several BASICs have a built-in sort function (for example Liberty BASIC's SORT statement and PureBASIC's SortArray statement). BBC BASIC doesn't, largely (I assume) because using assembler code and the CALL statement is so straightforward, but of course that's not a solution for Matrix Brandy.

    Since it's such a common requirement, I would have expected an off-the-shelf solution to have been devised long ago to make it possible to port programs using an assembler-code sort to Brandy BASIC.
  • Hated_moron
    edited September 6
    I'm still on the lookout for a (fast) sorting solution for Matrix Brandy.
    Scrub that, the reason for wanting it no longer exists.