EnglishGermanFrenchRussianItalianSpanish
Log inRegister
 
[LIB] Array/Matrix Sorts
Post new topic Reply to topic
View previous topic :: View next topic
Author Message
s9ilent





Joined: 29 Jun 2005
Posts: 2009 on topic
Location: Galactic Sector ZZ9-Plural Z alpha +10 GMT
Thank you for registering your game
PostPosted: Sun, 25. Jan 09, 05:23    Post subject: [LIB] Array/Matrix Sorts Reply with quote Print

After a fair bit of trial and error

array_sorts.zip
Array Sorts

array_sorts.zip


4 Script files
All sorts are numerical!!! (as opposed to X3's string based one...why?!)

  • lib.array.insertsort -Your basic insertion sort, is stable, single array
  • lib.array.quicksort -Basic quick sort, is not stable, single array, is better then insertion sort if you can pick a better pivot (apparently?)
  • lib.array.quicksort.recursive -DONT CALL THIS ONE!!! call the other one
  • lib.array.insertsort.matrix -Insertion sort, is stable, does a matrix, max sort by 2 columns (optional sort up, sort down)

Notes on the matrix sort.
Leave col2 blank to sort by just col1
Garbage in Garbage out. It returns null if your matrix is not correctly sized (all columns are equal in size)
Array[C][R], Column, Row (C-> R, Alphabetical order). Don't get them confused!!!
-Alternatively, think like this: An array is a single column, an array of an array, is a whole lot of columns, ie. a row of columns. Thus, as you go DOWN a row, your going down the Inner array, so array[][down here]. So the second one is the row.
-Or just look at excel, it uses Column Row too (A1, B3, etc)

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Cycrow
Moderator (Script&Mod)
Moderator (Script&Mod)



Joined: 15 Nov 2004
Posts: 20473 on topic
Location: London
Thank you for registering your game
PostPosted: Mon, 1. Jun 09, 02:02    Post subject: Reply with quote Print

just wandering how come you created a script to sort arrays when there is already a built in command to do it ?

especially as the built in one uses qsort, and can handle any type of arrays including numbers and strings


_________________
My Scripts | MY X3TC Scripts | X3 Plugin Manager | Custom Gui
Back to top
View user's profile Send private message Visit poster's website MSN Messenger
s9ilent





Joined: 29 Jun 2005
Posts: 2009 on topic
Location: Galactic Sector ZZ9-Plural Z alpha +10 GMT
Thank you for registering your game
PostPosted: Mon, 1. Jun 09, 03:04    Post subject: Reply with quote Print

Smile

I wanted a matrix sort, but X3 only has an array sort (and yes, you can sort an array by another array, but I wanted to do it to like a 10x wide matrix, so I figured it might not be the most efficient way to do the sort 10x)

Plus, I just wanted to see if I could do it.

Tbh, I was going to use it for my SFM script (comparing wares) but in the end, I decided rather then physically sorting the matrix (which was messy... and CPU intensive), I would just search for the highest value (as I really only needed the highest, and that highest would rarely fail other checks, so there was really no need for this any more)

But hey, I made it, so I figured, I'd put it up here.


But this script isn't really efficient so I don't recommend people use it (unless they are sorting large matrices)



(Oh and also, I don't know how to do a quick sort Sad Well... I'm sure I could.. it'd just be hell messy in the SE)
(Oh yeh.. and to actually answer your question, I needed to build an array sort, in order to build the matrix sort)

Another though occurs to me... Cycrow, any chance you can request a matrix quick sort command in the S.E for the next patch or w/e
(Preferably with a setup like this one/..symtec's/yours? from X3R, 4 params, two for sort by which columns, and two for sort increasing/decreasing, and on failure return the original input -where failure occurs when the input is not a matrix other wise it does its best to
sort stuff, or... maybe null, I don't know, what ever)



As a side note thou, I think I did do a test on them and my sort is like infinitely slower (like 20s compared to <2s) (But I don't remember if it was a matrix/array sort)

Back to top
View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic Reply to topic
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum
Control Panel
Login Data
The time now is Thu, 14. Dec 17, 02:32

All times are GMT + 2 Hours


Board Security

Copyright © EGOSOFT 1989-2017
Powered by phpBB © 2001, 2005 phpBB Group
Template created by Avatar & BurnIt!
Debug: page generation = 0.07256 seconds, sql queries = 17