Raised This Month: $ Target: $400
 0% 

[solved] SortCustom2D with more than 3000values


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
noname\
Junior Member
Join Date: Jun 2007
Old 06-23-2007 , 05:06   [solved] SortCustom2D with more than 3000values
Reply With Quote #1

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
[...]
__________________

\\brainbread server with live ranking system and webstatistics

Last edited by noname\; 06-24-2007 at 00:08. Reason: problem solved
noname\ is offline
Sylwester
Veteran Member
Join Date: Oct 2006
Location: Poland
Old 06-23-2007 , 12:14   Re: SortCustom2D with more than 3000values
Reply With Quote #2

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.
__________________
Impossible is Nothing
Sylwester is offline
_Master_
Senior Member
Join Date: Dec 2006
Old 06-23-2007 , 12:22   Re: SortCustom2D with more than 3000values
Reply With Quote #3

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.

Last edited by _Master_; 06-23-2007 at 12:27.
_Master_ is offline
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 06-23-2007 , 22:41   Re: SortCustom2D with more than 3000values
Reply With Quote #4

Quote:
Originally Posted by _Master_ View Post
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.
__________________
fyren sucks

Last edited by sawce the snail; 06-23-2007 at 22:54.
sawce is offline
noname\
Junior Member
Join Date: Jun 2007
Old 06-23-2007 , 23:50   Re: SortCustom2D with more than 3000values
Reply With Quote #5

Quote:
Originally Posted by Sylwester View Post
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_ View Post
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 View Post
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 View Post
#pragma dynamic 32768
i will give it a try.
edit:works like a charm =)



Quote:
Originally Posted by sawce View Post
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!
__________________

\\brainbread server with live ranking system and webstatistics

Last edited by noname\; 06-24-2007 at 00:17. Reason: sawce ftw!
noname\ is offline
XxAvalanchexX
Veteran Member
Join Date: Oct 2004
Location: abort73.com
Old 06-23-2007 , 16:07   Re: SortCustom2D with more than 3000values
Reply With Quote #6

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.
__________________
No longer around. Thanks your support, everyone! As always:
THIS ONES FOR YOU
3000 PTS
XxAvalanchexX is offline
Old 06-23-2007, 17:15
commonbullet
This message has been deleted by commonbullet. Reason: zzz
sawce
The null pointer exception error and virtual machine bug
Join Date: Oct 2004
Old 06-23-2007 , 22:40   Re: SortCustom2D with more than 3000values
Reply With Quote #8

#pragma dynamic 32768
__________________
fyren sucks
sawce is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


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


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