Raised This Month: $ Target: $400
 0% 

[INC] CellTravTrie


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
Hawk552
AMX Mod X Moderator
Join Date: Aug 2005
Old 07-24-2008 , 08:28   [INC] CellTravTrie
Reply With Quote #1

This is a set of stocks me and Twilight_Suzuka (but mostly her) wrote in order to reproduce the functionality of ArrayX using core AMXX functions. It requires CellTrie (included in AMXX 1.8.0 r3711) and CellArray (included in AMXX 1.8.0).

Here is an example plugin that I used to test it:

Code:
 #include <amxmodx> #include <amxmisc> #include <celltravtrie> public plugin_init() {     register_plugin("TravTrie Test","1.0","Hawk552")         new TravTrie:CurTrie = TravTrieCreate(),Temp,Results[4]     server_print("TravTrie: %d",CurTrie)         TravTrieSetCellEx(CurTrie,0,99)     Results[0] = TravTrieGetCellEx(CurTrie,0,Temp)         TravTrieSetCellEx(CurTrie,1,3)     TravTrieSetStringEx(CurTrie,2,"ham")         new Cell,String[33],Non     Results[1] = TravTrieGetCellEx(CurTrie,1,Cell)     Results[2] = TravTrieGetStringEx(CurTrie,2,String,32)     Results[3] = TravTrieGetCellEx(CurTrie,31,Non)     server_print("Cell: %d / Temp: %d / String: %s / Non: %d / Results: %d %d %d %d",Cell,Temp,String,Non,Results[0],Results[1],Results[2],Results[3])         new travTrieIter:Iter = GetTravTrieIterator(CurTrie),Value     while(MoreTravTrie(Iter))     {         ReadTravTrieCell(Iter,Value)         server_print("Value: %d",Value)     }     DestroyTravTrieIterator(Iter)         TravTrieNth(CurTrie,1,String,32)     TravTrieGetCell(CurTrie,String,Cell)         server_print("Nth: %d",Cell) }

A couple of notes:
  • This isn't a perfect replacement for ArrayX. It's designed to act as a keytable (it's a trie, after all) and the stocks I added to allow you to pass a cell as the key are much slower than the ArrayX equivalents.
  • TrieSetArray and TrieGetArray are broken and, as such, the stocks added basically mirror the functionality of TrieSetString/TrieGetString.
Some things you should know about tries:
  • Insertion (adding data) is relatively slow, but retrieving it is extremely fast.
  • I've had problems using this as a heterogeneous container (i.e. containing more than one data type in a single trie), so you should avoid it.
Have fun.
Attached Files
File Type: inc celltravtrie.inc (9.1 KB, 1085 views)
__________________

Last edited by Hawk552; 08-16-2009 at 19:53.
Hawk552 is offline
Send a message via AIM to Hawk552
 



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 13:39.


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