Raised This Month: $32 Target: $400
 8% 

[TUT] Tries


Post New Thread Reply   
 
Thread Tools Display Modes
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 12-07-2012 , 17:44   Re: [TUT] Tries
Reply With Quote #11

As I understand, you want something like this,

PHP Code:
public CallThis( )
{
    
// Call this on plugin_init or plugin_cfg
    
    // Your SQL Stuff goes here
    
    
new szAuthID32 ]
    
    while( 
SQL_MoreResultsQuery ) )
    {
        
SQL_ReadResultQuery0szAuthIDcharsmaxszAuthID ) )
        
        
TrieSetCellg_YourTrieszAuthID)
        
        
SQL_NextRowQuery )
    }
}

public 
client_putinserverid )
{
    new 
szAuthID32 ]; get_user_authididszAuthIDcharsmaxszAuthID ) )
    
    if( 
TrieKeyExistsg_YourTrieszAuthID ) )
    {
        
// Your Steam ID exists in the trie / database    
    
}

If not, give more information.

Last edited by guipatinador; 12-07-2012 at 17:45.
guipatinador is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 12-07-2012 , 20:29   Re: [TUT] Tries
Reply With Quote #12

Quote:
Originally Posted by Mucx View Post
Good tutorial, was searching a way to save data.

Can i set multiple key's to TrieSetString, if yes, then how?
For example i have Name and Steam in my table.
Idea is when Name or Steam is valid then plugin takes action, gives the rest data that is taken from mysql.
No, you cannot have two keys that point to the same data (literally). Use only SteamID, there is no good reason to use anything else.
__________________

Last edited by fysiks; 12-07-2012 at 20:30.
fysiks is offline
Mucx
Member
Join Date: Mar 2011
Location: Estonia
Old 12-08-2012 , 04:14   Re: [TUT] Tries
Reply With Quote #13

Quote:
Originally Posted by guipatinador View Post
As I understand, you want something like this,

PHP Code:
public CallThis( )
{
    
// Call this on plugin_init or plugin_cfg
    
    // Your SQL Stuff goes here
    
    
new szAuthID32 ]
    
    while( 
SQL_MoreResultsQuery ) )
    {
        
SQL_ReadResultQuery0szAuthIDcharsmaxszAuthID ) )
        
        
TrieSetCellg_YourTrieszAuthID)
        
        
SQL_NextRowQuery )
    }
}

public 
client_putinserverid )
{
    new 
szAuthID32 ]; get_user_authididszAuthIDcharsmaxszAuthID ) )
    
    if( 
TrieKeyExistsg_YourTrieszAuthID ) )
    {
        
// Your Steam ID exists in the trie / database    
    
}

If not, give more information.
Would something like this work in client_putinserver( id ) part.

PHP Code:
public CallThis( ) {
    
// Call this on plugin_init or plugin_cfg
    
    // Your SQL Stuff goes here
    
new szAuthID32 ], szName32 ], szSomeThing32 },

while( 
SQL_MoreResultsQuery ) ) {
    
SQL_ReadResultQuery0szAuthIDcharsmaxszAuthID ) )
    
SQL_ReadResultQuery1szNamecharsmaxszName ) )
    
SQL_ReadResultQuery0szSomeThingcharsmaxszSomeThing ) )
    
    
TrieSetCellg_YourTrieszAuthID)
    
TrieSetCellg_YourTrieszName)
    
TrieSetCellg_YourTrieszSomeThing)
    
    
SQL_NextRowQuery )
}
}

public 
client_putinserverid ) {
new 
szAuthID32 ]; get_user_authididszAuthIDcharsmaxszAuthID ) )
new 
szName32 ]; get_user_authididszNamecharsmaxszName ) )

if( 
TrieKeyExistsg_YourTrieszAuthID ) || TrieKeyExistsg_YourTrieszName ) ) {
    
// Use szSomeThing 
}

Quote:
Originally Posted by fysiks View Post
No, you cannot have two keys that point to the same data (literally). Use only SteamID, there is no good reason to use anything else.
Well there is a reason for me. Some via name, some steamid or both.

Last edited by Mucx; 12-08-2012 at 04:14.
Mucx is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 12-08-2012 , 05:02   Re: [TUT] Tries
Reply With Quote #14

How many columns have your table?
I will assume the table have 2 columns, one for the player name or Steam ID, and other for the data.
PHP Code:
public CallThis( )
{
    
// Call this on plugin_init or plugin_cfg
    // Your SQL Stuff goes here
    
    
new szIdentification32 // For Steam ID or Name
    
new szSomeThing32 ]
    
    while( 
SQL_MoreResultsQuery ) )
    {
        
SQL_ReadResultQuery0szIdentificationcharsmaxszIdentification ) ) // first column of the table
        
SQL_ReadResultQuery1szSomeThingcharsmaxszSomeThing ) ) // second column
        
        
TrieSetStringg_YourTrieszIdentificationszSomeThing )
        
        
SQL_NextRowQuery )
    }
}

public 
client_putinserverid )
{
    new 
szAuthID32 ]; get_user_authididszAuthIDcharsmaxszAuthID ) )
    new 
szName32 ]; get_user_nameidszNamecharsmaxszName ) )
    
    if( 
TrieKeyExistsg_YourTrieszAuthID ) || TrieKeyExistsg_YourTrieszName ) )
    {
        
// Steam ID or Name exists in the trie / database 
        // You can use the szSomeThing for what you want
        // Just an example...
        
        
new szSomeThing32 ]
        
        if( 
TrieGetStringg_YourTrieszAuthIDszSomeThingcharsmaxszSomeThing ) ) )
        {
            
client_print0print_chat"Steam ID = %s | Data = %s"szAuthIDszSomeThing )
        }
        
        if( 
TrieGetStringg_YourTrieszNameszSomeThingcharsmaxszSomeThing ) ) )
        {
            
client_print0print_chat"Name = %s | Data = %s"szNameszSomeThing )
        }
    }


Last edited by guipatinador; 12-08-2012 at 06:12.
guipatinador is offline
Mucx
Member
Join Date: Mar 2011
Location: Estonia
Old 12-08-2012 , 05:19   Re: [TUT] Tries
Reply With Quote #15

I have Name, Steam, Password, Flags columns in my table.
I'm tryng to create a bit custom admin plugin for my needs.
Mucx is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 12-08-2012 , 05:41   Re: [TUT] Tries
Reply With Quote #16

You need something like this,

PHP Code:
public CallThis( )
{
    
// Call this on plugin_init or plugin_cfg
    // Your SQL Stuff goes here
    
    
new szName32 ], szAuthID32 ], szPassword32 ], szFlags32 ]
    new 
FormattedData64 ]
    
    while( 
SQL_MoreResultsQuery ) )
    {
        
SQL_ReadResultQuery0szNamecharsmaxszName ) )
        
SQL_ReadResultQuery1szAuthIDcharsmaxszAuthID ) )
        
SQL_ReadResultQuery2szPasswordcharsmaxszPassword ) )
        
SQL_ReadResultQuery3szFlagscharsmaxszFlags ) )
        
        
formatexFormattedDatacharsmaxFormattedData ), "%s#%s"szPasswordszFlags )
        
        
TrieSetStringg_TrieWithNamesszNameFormattedData )
        
TrieSetStringg_TrieWithAuthIDsszAuthIDFormattedData )
        
        
SQL_NextRowQuery )
    }
}

public 
client_putinserverid )
{
    new 
szName32 ]; get_user_nameidszNamecharsmaxszName ) )
    new 
szAuthID32 ]; get_user_authididszAuthIDcharsmaxszAuthID ) )
    
    if( !( 
TrieKeyExistsg_TrieWithNamesszName ) || TrieKeyExistsg_TrieWithAuthIDsszAuthID ) ) )
        return 
PLUGIN_CONTINUE
    
    
new szData64 ]
    new 
szPassword32 ]
    new 
szFlags32 ]
    
    if( 
TrieGetStringg_TrieWithNamesszNameszDatacharsmaxszData ) ) )
    {
        
replace_allszDatacharsmaxszData ), "#"" " )
        
parseszDataszPasswordcharsmaxszPassword ), szFlagscharsmaxszFlags ) )
        
        new 
szPW32 ]; get_user_infoid"password"szPWcharsmaxszPW ) )
        
        if( 
equalszPWszPassword ) )
        {
            
set_user_flagsidszFlags )
        }
        
    }
    
    if( 
TrieGetStringg_TrieWithAuthIDsszAuthIDszDatacharsmaxszData ) ) )
    {
        
replace_allszDatacharsmaxszData ), "#"" " )
        
parseszDataszPasswordcharsmaxszPassword ), szFlagscharsmaxszFlags ) )
        
        
set_user_flagsidszFlags )
    }
    
    return 
PLUGIN_CONTINUE

That password can't contain spaces or #

Last edited by guipatinador; 12-08-2012 at 05:57.
guipatinador is offline
Mucx
Member
Join Date: Mar 2011
Location: Estonia
Old 12-08-2012 , 05:45   Re: [TUT] Tries
Reply With Quote #17

Thank you. If i get the time then i will try and post feedback.
Mucx is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 12-27-2012 , 10:44   Re: [TUT] Tries
Reply With Quote #18

I've made a benchmark with Tries and Arrays.

The plugin...
1 - writes to a file with random Steam IDs (STEAM_0:0:XXXXXXXX)
2 - saves the Steam IDs to an Trie and an Array
3 - loops through the Trie / Array and search for this Steam ID -> STEAM_0:0:12345678
4 - uses this timer http://forums.alliedmods.net/showthread.php?t=67752







X axis is the number of Steam IDs
Y axis is the time in seconds
Attached Files
File Type: zip benchmark.zip (96.6 KB, 130 views)

Last edited by guipatinador; 12-27-2012 at 10:49.
guipatinador is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 12-27-2012 , 10:53   Re: [TUT] Tries
Reply With Quote #19

Why would you make a [speed] comparaison between tries and arrays ? I don't understand how it's useful, both are used for different purposes. It's just irrelevant. All you need to know are both are dynamic, slow on insertion, fast on getting item, and that's all. Also, it's about a Trie tutorial here.
__________________
Arkshine is offline
guipatinador
SourceMod Donner Party
Join Date: Oct 2009
Location: Poortugal
Old 12-27-2012 , 11:03   Re: [TUT] Tries
Reply With Quote #20

I did it because I wanted to know the behavior of Tries with a lot of keys. I have found that between 1000 and 10000 it becomes slower (don't know why). The Array benchmark is just for curiosity.
I'm not telling that Tries are better, of course it depends on the situation.

Last edited by guipatinador; 12-27-2012 at 11:05.
guipatinador 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:57.


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