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

The advantages of a trie over an array for strings storage


Post New Thread Reply   
 
Thread Tools Display Modes
stupok
Veteran Member
Join Date: Feb 2006
Old 03-24-2009 , 19:07   Re: The advantages of a trie over an array for strings storage
Reply With Quote #11

I appreciate your attitude

Now I understand what I'm doing, but I don't have time to post my results from my latest test.

I'm searching the list of 14,000 steamids 1,000 times and finding that the cellTrie method is 4 to 5 orders of magnitude faster than the cellArray method. When searching the list only once, the profiler measures the cellTrie time as 0.000001. That's impressive!
__________________
stupok is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-24-2009 , 19:33   Re: The advantages of a trie over an array for strings storage
Reply With Quote #12

Quote:
Originally Posted by stupok View Post
I appreciate your attitude

Now I understand what I'm doing, but I don't have time to post my results from my latest test.

I'm searching the list of 14,000 steamids 1,000 times and finding that the cellTrie method is 4 to 5 orders of magnitude faster than the cellArray method. When searching the list only once, the profiler measures the cellTrie time as 0.000001. That's impressive!
For what i read in wikipedia, the performance of searching in a trie is O(length of the string) while iterating over all values of an array is O(number of strings it contains).

That means that, in this case, the longer the list the bigger the difference.

I tried with your list 10000 times and while the celltrie results were almost the same, with cellarray my windows halted.
__________________

Last edited by joaquimandrade; 03-24-2009 at 19:37.
joaquimandrade is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-25-2009 , 09:37   Re: The advantages of a trie over an array for strings storage
Reply With Quote #13

Honestly, I never knew what a trie was. I just assumed that it was a different word for array. This is very useful information and I plan on using tries in the future.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-25-2009 , 09:47   Re: The advantages of a trie over an array for strings storage
Reply With Quote #14

Quote:
Originally Posted by Exolent[jNr] View Post
Honestly, I never knew what a trie was. I just assumed that it was a different word for array. This is very useful information and I plan on using tries in the future.
That's normal. You probably started amxx programming without having prior knowledge in programming. I know that because i've studied it.
I recommend you to use tries in your "Advanced Bans".
__________________
joaquimandrade is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-25-2009 , 17:43   Re: The advantages of a trie over an array for strings storage
Reply With Quote #15

I started converting it into Tries, and it is so much less code instead of using Arrays.
However, there is one disadvantage: I can't view the keys for my amx_banlist command so I cannot list the banned players.
I would have to create Arrays inside that command, read the file to fill the Arrays, then print the ones that were specified.
Should I keep doing Tries and do what I said above, or keep it as Arrays?
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-25-2009 , 18:07   Re: The advantages of a trie over an array for strings storage
Reply With Quote #16

Quote:
Originally Posted by Exolent[jNr] View Post
I started converting it into Tries, and it is so much less code instead of using Arrays.
However, there is one disadvantage: I can't view the keys for my amx_banlist command so I cannot list the banned players.
I would have to create Arrays inside that command, read the file to fill the Arrays, then print the ones that were specified.
Should I keep doing Tries and do what I said above, or keep it as Arrays?
You are saying that:

For amx_banlist you need to list all the steam Ids?

If yes, use both. Fill both a trie and a an array with the steamIDs when you load the ban list. Then, to search use the trie, to iterate use the array. It will waste more memory but it will be much faster.
__________________
joaquimandrade is offline
Exolent[jNr]
Veteran Member
Join Date: Feb 2007
Location: Tennessee
Old 03-25-2009 , 18:09   Re: The advantages of a trie over an array for strings storage
Reply With Quote #17

Well, now that I got further into the plugin, I also need the list to save the bans and to check which ones are time to be unbanned.
So, you think I should have both? Because that seems unnecessary.
__________________
No private work or selling mods.
Quote:
Originally Posted by xPaw View Post
I love you exolent!
Exolent[jNr] is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-25-2009 , 18:18   Re: The advantages of a trie over an array for strings storage
Reply With Quote #18

Quote:
Originally Posted by Exolent[jNr] View Post
Well, now that I got further into the plugin, I also need the list to save the bans and to check which ones are time to be unbanned.
So, you think I should have both? Because that seems unnecessary.
Yes, try to see if you can get a way to use both. Then, to see the difference, profile both versions.

Edit:

You can make it like this:

PHP Code:
new Array:arrayBanList
new Trie:trieBanList

new arraySize

public plugin_init()
{
    
register_plugin(PLUGINVERSIONAUTHOR)
}

public 
plugin_cfg()
{
    
arrayBanList ArrayCreate(34)
    
trieBanList TrieCreate();
}

isBanned(steamID[])
{
    return 
TrieKeyExists(trieBanList,steamID);
}

addBanToList(steamID[])
{
    
ArrayPushString(arrayBanList,steamID)
    
TrieSetCell(trieBanList,steamID,arraySize++);
}

removeBanFromList(steamID[])
{
    new 
item
    TrieGetCell
(trieBanList,steamID,item)
    
ArrayDeleteItem(arrayBanList,item);
    
TrieDeleteKey(trieBanList,steamID)
    
arraySize--


__________________

Last edited by joaquimandrade; 03-25-2009 at 19:08.
joaquimandrade is offline
ot_207
Veteran Member
Join Date: Jan 2008
Location: Romania The Love Country
Old 03-29-2009 , 08:16   Re: The advantages of a trie over an array for strings storage
Reply With Quote #19

Interesting, this reminds me of collage. I will study these things soon, so I will have an advantage.
It's good to start with pawn when you want to become a programmer, cause you learn how to get used to with functions and programming.
GJ.
__________________
My approved plug-ins | Good for newbies! | Problems?

Back, will come around when I have time.
ot_207 is offline
joaquimandrade
Veteran Member
Join Date: Dec 2008
Location: Portugal
Old 03-29-2009 , 09:06   Re: The advantages of a trie over an array for strings storage
Reply With Quote #20

Let me add that "Advanced Bans (Real Time) by Exolent" know uses tries. I thought that Exolent would give up on using them (since they were giving some trouble to implement) but, not only he implemented them as, he made it very nicely.
__________________

Last edited by joaquimandrade; 03-29-2009 at 09:17.
joaquimandrade 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 15:15.


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