Raised This Month: $ Target: $400
 0% 

Recursive Tries.


  
 
 
Thread Tools Display Modes
Prev Previous Post   Next Post Next
Author Message
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 04-22-2014 , 11:54   Recursive Tries.
Reply With Quote #1

I present to you this include file with stocks for recursive tries(tries inside of tries inside of tries) that iteration Handle is auto updated when trie is(that's if you use the stocks).
Stocks:
PHP Code:
/*
 * This stock creates a new iteratable trie.
 * @keyNameSize            Size of keyNames array.
 * @forceNoChild        Should CheckForChildren skip it's check and just false.
 * @forceProtectFalse    Should we skip FreeChildren's leak protection.
 * @return                A handle to newly created iteratable trie, otherwise, it returns INVALID_HANDLE.
 */
stock Handle:CreateIterTrie(keyNameSizebool:forceNoChild falsebool:forceProtectFalse false);

/*
 * Inserts a value into an iteratable trie.
 * @trie        Trie to add to.
 * @entry        Keyname to store item as.
 * @item        Item to store.
 * @return        True on success, false otherwise.
 */
stock bool:InsertValueIntoTrie(Handle:trie, const String:entry[], any:item);

/*
 * Inserts a string into an iteratable trie.
 * @trie        Trie to add to.
 * @entry        Keyname to store item as.
 * @item        String to store.
 * @return        True on success, false otherwise.
 */
stock bool:InsertStringIntoTrie(Handle:trie, const String:entry[], const String:item[]);

/*
 * Inserts an array into an iteratable trie.
 * @trie        Trie to add to.
 * @entry        Keyname to store item as.
 * @item        Array to store.
 * @return        True on success, false otherwise.
 */
stock bool:InsertArrayIntoTrie(Handle:trie, const String:entry[], const any:item[]);

/*
 * Creates a new trie and inserts it into a parent trie.
 * Parent trie has to be iteratable.
 * @parent            Parent trie to store into.
 * @entry            Keyname to store as.
 * @return            Handle to new trie, INVALID_HANDLE if insertion failed.
 */
stock Handle:InsertNewTrie(Handle:parent, const String:entry[]);

/*
 * Creates a new iteratable trie and inserts it into a parent trie.
 * Parent trie has to be iteratable.
 * @parent                Parent trie to store into.
 * @entry                Keyname to store as.
 * @keyNameSize            Size of keyNames array.
 * @forceNoChild        Should CheckForChildren skip it's check and just false.
 * @forceProtectFalse    Should we skip FreeChildren's leak protection.
 * @return                Handle to new trie, INVALID_HANDLE if insertion failed or trie failed to be made.
 */
stock Handle:InsertNewIterTrie(Handle:parent, const String:entry[], keyNameSizebool:forceNoChild falsebool:forceProtectFalse false);

/*
 * This stock is for checking if a trie has children, an iteratable and non-iteratable trie can be passed.
 * Used mostly internally.
 * @trieCheck        The trie to check for children.
 * @return            True if it has children, false if otherwise.
 */
stock bool:CheckForChildren(Handle:trieCheck);

/*
 * This stock will fail if it was passed a non-iteratable trie, this is for recursivily freeing tries stored into it.
 * Note: Use this in an if statement with CheckForChildren()
 * Used mostly internally.
 * @trie                Trie to free children and itself as.
 * @keyNameLength        Max string size to be expected for keynames in ADT array.
 * @noreturn
 */
stock FreeChildren(Handle:triekeyNameLength);

/*
 * This starts recursive freeing starting with trie passed.
 * This also checks if passed trie can be recursed freed.
 * @trie                Trie to begin recursive freeing on.
 * @keyNameLength        Length of keyName strings.
 * @noreturn
 */
stock RecursiveFree(&Handle:triekeyNameLength); 
ChangeLog:
Quote:
1.0
  • Initial post
1.1
  • Fixed derp (Thx spumer)
1.2
  • Changed SetFailure to SetFailState (I had a SetFailure function in the code I made this for).
  • Removed unused parameters
  • Cleaned up code.
1.3
  • Made this into a full blown include file, changed thread name.
1.4
  • Fixed a derp.
1.4
  • Removed warning.
  • Fixed compile issue.
1.5
  • Added another stock
1.6
  • Renamed some stocks
  • Added 2 more stocks
  • Added some more parameters to some stocks.
Attached Files
File Type: inc recursivetries.inc (7.0 KB, 106 views)

Last edited by WildCard65; 08-25-2014 at 09:40.
WildCard65 is offline
 


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 18:34.


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