AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   TrieCreate -- what is it? How to use it. (https://forums.alliedmods.net/showthread.php?t=167721)

gamer99 09-19-2011 06:25

TrieCreate -- what is it? How to use it.
 
Hi All ,


I saw in one of ConnorMcLeod's plugin he is using TrieCreate.

Can somebody tell me what is it and how to use it :oops:?

I am just learning. So don't scold me.:oops:

Arkshine 09-19-2011 06:49

Re: TrieCreate -- what is it? How to use it.
 
It allows you to associate a key to something (integer, string or array), so a keytable.
And it's unlimited.

// Creating a trie
new handle = TrieCreate()

// Inserting a new key
TrieSetCell( handle, "gamer99", 1337 );
TrieSetCell( handle, "blabla", 123 );
...

// Checking if a key exists in the table
new bool:result = TrieKeyExists( handle, "gamer99" );

// Checking existing key/Retrieving its associated value
new value;
new bool:result = TrieGetCell( handle, "gamer99", value );

You get the idea.
To get more examples, simply look at the plugins. Many plugins use Trie. (Some default plugin too If I remember)

hleV 09-19-2011 06:51

Re: TrieCreate -- what is it? How to use it.
 
It can assign an unlimited amount of arrays/strings to values.
PHP Code:

new Trie:tAwesomenessLevel TrieCreate();

SetTrieCell(tAwesomenessLevel"hleV"1337);
SetTrieCell(tAwesomenessLevel"ConnorMcLeod", -1); 

For more functions check celltrie.inc.

gamer99 09-19-2011 06:52

Re: TrieCreate -- what is it? How to use it.
 
Thank you for your nice explanation.

I got the idea :).

abdul-rehman 09-19-2011 09:29

Re: TrieCreate -- what is it? How to use it.
 
As far as Exolent told me, Tries allows you to index arrays with strings instead of numbers
Heres a brief concept map:
Code:
// this is not real coding, it just gives you an idea of what tries do my_trie[ "gamer99" ] = 89 my_trie[ "Arkshine" ] = my_key // Tries also support strings my_trie[ "Arkshine" ] = "my string"

ConnorMcLeod 09-19-2011 11:44

Re: TrieCreate -- what is it? How to use it.
 
Quote:

Originally Posted by abdul-rehman (Post 1558734)
As far as Exolent told me, Tries allows you to index arrays with strings instead of numbers
Heres a brief concept map:
Code:
// this is not real coding, it just gives you an idea of what tries do my_trie[ "gamer99" ] = 89 my_trie[ "Arkshine" ] = my_key // Tries also support strings my_trie[ "Arkshine" ] = "my string"

Note that you have to know what the key data type is before you retrieve it.


All times are GMT -4. The time now is 19:33.

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