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

TrieSnapshots?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
gabuch2
AlliedModders Donor
Join Date: Mar 2011
Location: Chile
Old 08-19-2017 , 19:10   TrieSnapshots?
Reply With Quote #1

Hello

I've read in this forum that you could transfer Tries over to a new map, apparently it is done via TrieSnapshots.

I do not understand how can this be achieved, can someone post an example of how to do this?

Thanks in advance.
__________________
gabuch2 is offline
fysiks
Veteran Member
Join Date: Sep 2007
Location: Flatland, USA
Old 08-19-2017 , 23:43   Re: TrieSnapshots?
Reply With Quote #2

Where is this TrieSnapshots module of which you speak?
__________________
fysiks is offline
Arkshine
AMX Mod X Plugin Approver
Join Date: Oct 2005
Old 08-20-2017 , 04:48   Re: TrieSnapshots?
Reply With Quote #3

It's from the dev version.

You have actually two ways to iterate over a trie:

- Snapshot: A basic API which duplicates the whole set of keys (only) into a list. Any changes to the original list will not affect the snapshot. It's an expensive operation but can be stored.
- Iterator: A contrario, Iterators are designed to be short-lived and not stored, and creating them is very cheap. Reading data from an iterator is just as fast as reading directly from the map. Any changes are forbidden (except updating value of existing key).

Snapshot:
Code:
#include <amxmodx>   public plugin_init() {     new Trie:list = TrieCreate();     {         TrieSetString(list, "adventure", "time!");         TrieSetString(list, "butterflies", "bees");         TrieSetString(list, "egg", "egg");     }       new Snapshot:keys = TrieSnapshotCreate(list);     {         new const length = TrieSnapshotLength(keys);         new buffer[32];           for (new const i = 0; i < length; ++i)         {             TrieSnapshotGetKey(keys, i, buffer, charmax(buffer));             server_print("buffer = %s", buffer);         }     }     TrieSnapshotDestroy(keys); }

Iterator:

Code:
#include <amxmodx> public plugin_init() {     new Trie:list = TrieCreate();     {         TrieSetString(list, "adventure", "time!");         TrieSetString(list, "butterflies", "bees");         TrieSetString(list, "hello", "world!");     }     new TrieIter:iter = TrieIterCreate(list);     {         new key[32], key_length;         new value[32], value_length;         while (!TrieIterEnded(iter))         {             key_length = TrieIterGetKey(iter, key, charsmax(key));             TrieIterGetString(iter, value, charsmax(value), value_length);             server_print("%s (%d) -> %s (%d)", key, key_length, value, value_length);             // Should throw an error             // TrieSetString(t, "monkey", "island");             // TrieDeleteKey(t, "full");             // TrieClear(t);             TrieIterNext(iter);         }     }     TrieIterDestroy(iter);     TrieDestroy(list); }
__________________
Arkshine is offline
Reply


Thread Tools
Display Modes

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 10:28.


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