Raised This Month: $51 Target: $400
 12% 

StringMap (trie) in StringMap - Performance?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 02-13-2016 , 11:18   StringMap (trie) in StringMap - Performance?
Reply With Quote #1

Hello,

I am currently writing a plugin which allows players to get ranked per stage/checkpoint (Timer), for example:

Player x has passed Stage 3 [Rank x/y]

Now, I need to store the data for that somehow.
I have thought about creating a structure like this:

StringMap a
key => level (e.g. stage 3)
value => StringMap b
StringMap b
key => auth
value => time

StringMap b would be sorted to easily find out the rank of a player. Now the question is, how much of a performance hit it would be to access data from the second StringMap.

Current code:

PHP Code:
// setting
StringMap b = new StringMap();
g_hTimes.SetValue("1"b);

// getting
g_hTimes.GetValue("1"b); 
Any help/information would be appreciated (also accepting suggestions for my data structure itself).
</span>
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 02-13-2016 , 12:01   Re: StringMap (trie) in StringMap - Performance?
Reply With Quote #2

a would be faster as an arraylist, and accessing b should always be very fast irrespective of size

Last edited by Miu; 02-13-2016 at 12:04.
Miu is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 02-16-2016 , 12:26   Re: StringMap (trie) in StringMap - Performance?
Reply With Quote #3

Well, I have switched around a bit, StringMap is a, ArrayList b now.
Now the question is, whether or not there is any way to improve this code:

I need to compare a new time to all existing times, to somehow calculate the rank a player gets (hitting the DB each time this happens is not a good idea).
Had some laggy moments, I expect the ExplodeString stuff to be slow:

PHP Code:
arraySize dataPerLevel.Length;
    
FormatEx(newRowsizeof(newRow), "%f;%s"timeauth);
    
    for(
int i 0arraySizei++)
    {
        
dataPerLevel.GetString(irowsizeof(row));
        
ExplodeString(row";"explode232);
        
float existingTime StringToFloat(explode[0]);
        
        if(
time existingTime || time == existingTime)
        {
           
rank i;
            
            
dataPerLevel.ShiftUp(i);
            
dataPerLevel.SetString(inewRow);
            
            break;
      }
      ... 
more checks

</span>
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 02-16-2016 , 13:16   Re: StringMap (trie) in StringMap - Performance?
Reply With Quote #4

What's wrong with querying the DB?
Miu is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 02-16-2016 , 14:29   Re: StringMap (trie) in StringMap - Performance?
Reply With Quote #5

That I don't want to do a full query on the table, just to update the ranks of one player.
Later on, the table will have up to 15-20k entries per map. Now if multiple people finish at once, that's gonna kill of the DB server (and cause some blocking problems).
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 02-17-2016 , 12:00   Re: StringMap (trie) in StringMap - Performance?
Reply With Quote #6

I am also wondering, is it possible to have string (or rather char[]) properties in methodmaps?
That's the closest I could get to a C struct, meaning I could scrap the ExplodeString nonsense entirely.
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
Miu
Veteran Member
Join Date: Nov 2013
Old 02-17-2016 , 12:53   Re: StringMap (trie) in StringMap - Performance?
Reply With Quote #7

Quote:
Originally Posted by pcmaster View Post
That I don't want to do a full query on the table, just to update the ranks of one player.
Later on, the table will have up to 15-20k entries per map. Now if multiple people finish at once, that's gonna kill of the DB server (and cause some blocking problems).
I would hope the software that is specifically designed to handle your data would be able to do trivial queries without dying

I think you want some kind of binary search tree if you insist on doing it yourself though

Quote:
Originally Posted by pcmaster View Post
I am also wondering, is it possible to have string (or rather char[]) properties in methodmaps?
That's the closest I could get to a C struct, meaning I could scrap the ExplodeString nonsense entirely.
Methodmaps don't change anything. o.o You could just have the time as a float in one arraylist and the auth in the other with the same index, or something like that.
Miu is offline
pcmaster
AlliedModders Donor
Join Date: Sep 2009
Old 02-21-2016 , 07:25   Re: StringMap (trie) in StringMap - Performance?
Reply With Quote #8

Yea, I think I will go with the second method, storing auths in a seperate list, then referencing to them with their index.
Methodmaps I thought would be like structs, holding the data directly, saving me from doing a (I think) quite expensive ExplodeString several thousand times.

The DB is an issue, as when two people complete a stage shortly after eachother (e.g. 1 sec apart), the refresh from player A may not have been finished before player B gets updated.
And as those callbacks are asynchronous, I am not sure how well SM's arraylist would handle concurrent access.

Thanks for your help anyways!
__________________
Stopped hosting servers as of November 2018, no longer active around here.
pcmaster is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 02-21-2016 , 08:45   Re: StringMap (trie) in StringMap - Performance?
Reply With Quote #9

Quote:
Originally Posted by pcmaster View Post
Methodmaps I thought would be like structs, holding the data directly.
There is a reason they use the custom term MethodMap rather than "class" or "struct".

Quote:
Originally Posted by pcmaster View Post
And as those callbacks are asynchronous, I am not sure how well SM's arraylist would handle concurrent access.
They're asynchronous, yes, but not multi-threaded - it's an event loop.
__________________
asherkin 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 16:59.


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