AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   [solved] SortCustom2D with more than 3000values (https://forums.alliedmods.net/showthread.php?t=56882)

noname\ 06-23-2007 05:06

[solved] SortCustom2D with more than 3000values
 
problem solved by sawce by adding #pragma dynamic 32768


i have used this script before, and it works fine. but now there is a stack error.
if i change the array_size to 3000 it will be executed.
Code:
SortCustom2D(sort,countn,"stats_custom_compare");/*countn=~4000*//*wont work*/ SortCustom2D(sort,3000,"stats_custom_compare");/*works*/


is there any way to fix it?


part of the script:
Code:
#include <amxmodx> #include <amxmisc> public bbrank_topx() {     static sortn[5000][2]     new lines[256], countn, hashidlvls[32], xppntlvls[32]     new configsdirs[256], playerslvls[256]     get_configsdir(configsdirs,255)     format(playerslvls,255,"players.lvl")     new playerslvlfp=fopen(playerslvls,"r")     if(playerslvlfp)     {         while(fgets(playerslvlfp,lines,255))         {             parse(lines,hashidlvls,31,xppntlvls,31)             if(!equal(xppntlvls,""))             {                 sortn[countn][0] = str_to_num(hashidlvls)                 sortn[countn][1] = str_to_num(xppntlvls)                 countn++             }         }         fseek(playerslvlfp,0,0)     }     SortCustom2D(sortn,countn,"stats_custom_compare");     /*[...]*/     return PLUGIN_CONTINUE } // our custom sorting function (check second dimension for score) public stats_custom_compare(elem1[],elem2[]) {     if(elem1[1] > elem2[1]) return -1;     else if(elem1[1] < elem2[1]) return 1;     return 0; }


players.lvl (~4000lines)
Code:

1177353836
18244 0.000000
45408503 0.000000
85855008 9669010.000000
184481526 111581.671875
131327360 59691.257812
190911329 31731.560547
162650882 2714077.000000
[...]


Sylwester 06-23-2007 12:14

Re: SortCustom2D with more than 3000values
 
SortCustom2D is using QuickSort algorithm. I dont know what version does it use exactly but some of them can run your system out of stack space even if you have just several thousands elements in your array, as it is massively recursive sort. To prevent this error there are implementations of QuickSort that use iteration with stack instead of recursion, but you would have to write it yourself or ask someone to make it for you.

_Master_ 06-23-2007 12:22

Re: SortCustom2D with more than 3000values
 
Let me see if I get this right... you have a 4000+ array and you want to sort it... in PAWN... in a thread with a time-limited execution... under HL ?!?
I'm not the biggest fan of SQL but in your case it's the ONLY solution.

EDIT: @Sylwester: Regrdless of the algorithm, the overhead is too much.
Even if the SortCustom2D works with ~3000 entries, it does not mean it's the right way to do this.

XxAvalanchexX 06-23-2007 16:07

Re: SortCustom2D with more than 3000values
 
That code looks familiar!!

To solve using huge arrays, I just decided to sort the entries as they came in. Check the source of the latest version of GunGame.

sawce 06-23-2007 22:40

Re: SortCustom2D with more than 3000values
 
#pragma dynamic 32768

sawce 06-23-2007 22:41

Re: SortCustom2D with more than 3000values
 
Quote:

Originally Posted by _Master_ (Post 493726)
Let me see if I get this right... you have a 4000+ array and you want to sort it... in PAWN... in a thread with a time-limited execution... under HL ?!?
I'm not the biggest fan of SQL but in your case it's the ONLY solution.

EDIT: @Sylwester: Regrdless of the algorithm, the overhead is too much.
Even if the SortCustom2D works with ~3000 entries, it does not mean it's the right way to do this.


Not everyone has access to an SQL server, and, so long as it is done someplace like mapload, that's not _that_ bad. Obviously SQL would be ideal, but it's not the end of the world.

@noname\: Can you provide me with the entire script + full database file to test something? You can send via PM if you don't want it to be public.

noname\ 06-23-2007 23:50

Re: SortCustom2D with more than 3000values
 
Quote:

Originally Posted by Sylwester (Post 493721)
SortCustom2D is using QuickSort algorithm. I dont know what version does it use exactly but some of them can run your system out of stack space even if you have just several thousands elements in your array, as it is massively recursive sort. To prevent this error there are implementations of QuickSort that use iteration with stack instead of recursion, but you would have to write it yourself or ask someone to make it for you.

like XxAvalanchexX one? by executing SortCustom2D each x-arrays?



Quote:

Originally Posted by _Master_ (Post 493726)
Let me see if I get this right... you have a 4000+ array and you want to sort it... in PAWN... in a thread with a time-limited execution... under HL ?!?
I'm not the biggest fan of SQL but in your case it's the ONLY solution.

EDIT: @Sylwester: Regrdless of the algorithm, the overhead is too much.
Even if the SortCustom2D works with ~3000 entries, it does not mean it's the right way to do this.

already thought of a mysql port but i was to lazy because it works pretty fine, till now.



Quote:

Originally Posted by XxAvalanchexX (Post 493790)
That code looks familiar!!

To solve using huge arrays, I just decided to sort the entries as they came in. Check the source of the latest version of GunGame.

well i found it at the scripting forums. ;)
your code looks really awesome! (btw: thanks for your great brainbread stock files) but i also want to show up three ranks above/below a users rank. [example]
so your code is not the best for me. i will take a look on your gungame_sql and do the mysql port. ;p



Quote:

Originally Posted by sawce (Post 493918)
#pragma dynamic 32768

i will give it a try.
edit:works like a charm =)



Quote:

Originally Posted by sawce (Post 493919)
Not everyone has access to an SQL server, and, so long as it is done someplace like mapload, that's not _that_ bad. Obviously SQL would be ideal, but it's not the end of the world.

@noname\: Can you provide me with the entire script + full database file to test something? You can send via PM if you don't want it to be public.

i have got a mysqld running. and it it is executed by user. ;/
sure. check your pm's.





thanks for your help!


All times are GMT -4. The time now is 21:34.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.