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

Print the content of a trie to the server for debug


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-22-2015 , 18:39   Print the content of a trie to the server for debug
Reply With Quote #1

Hi there!

This can turn out to be very useful when dealing with nested handles. It prints the content of a trie to the server console.

Code:
stock void DEBUG_PrintMapStructure(Handle nh_map, char[] ns_mapnametoshow, char[] ns_prefix) 
{ 
    if (nh_map == INVALID_HANDLE) 
    { 
        PrintToServer("%s Invalid map Handle: \"%s\" (0)", ns_prefix, ns_mapnametoshow); 
        return; 
    } 
         
    Handle nh_snapshot = CreateTrieSnapshot(nh_map); 
    int ni_size = TrieSnapshotLength(nh_snapshot); 
    PrintToServer("%s Analyzing Map: \"%s\"", ns_prefix, ns_mapnametoshow); 
    PrintToServer("%s Size of the Map: %i", ns_prefix, ni_size); 
    for (int ni_i = 0; ni_i < ni_size; ni_i++) 
    { 
        int ni_buffersize = TrieSnapshotKeyBufferSize(nh_snapshot, ni_i); 
        char[] ns_buffer = new char[ni_buffersize]; 
        GetTrieSnapshotKey(nh_snapshot, ni_i, ns_buffer, ni_buffersize); 
        int ni_value; 
        PrintToServer("%s     #%i. Key: %s | Value: %s", (GetTrieValue(nh_map, ns_buffer, ni_value) ? ni_value : "--probably an array or a string--")); 
    } 
    PrintToServer("%s Finished analyzing Map: \"%s\"", ns_prefix, ns_mapnametoshow); 
    CloseHandle(nh_snapshot); 
}
how I called it: DEBUG_PrintMapStructure(table, "DBTable", "[DBScanner.inc]");

the output
Code:
[DBScanner.inc] Analyzing Map: "DBTable"
[DBScanner.inc] Size of the Map: 6
[DBScanner.inc]     #1. Key: rows | Value: 3433
[DBScanner.inc]     #2. Key: DBTColumnsName | Value: 97124628
[DBScanner.inc]     #3. Key: name | Value: --probably an array or a string--
[DBScanner.inc]     #4. Key: column_count | Value: 12
[DBScanner.inc]     #5. Key: name__size_ | Value: 12
[DBScanner.inc]     #6. Key: DBTColumns | Value: 97059132
[DBScanner.inc] Finished analyzing Map: "DBTable"
And if for some reason the handle is 0

DEBUG_PrintMapStructure(0, "VOID TEST", "[DBScanner.inc]");

Code:
[DBScanner.inc] Invalid map Handle: "VOID TEST" (0)

Last edited by fakuivan; 12-29-2015 at 22:28. Reason: Thanks to Black-Rabbit
fakuivan is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 12-23-2015 , 00:29   Re: Print the content of a trie to the server for debug
Reply With Quote #2

So you gave us this snippet to make us all smile,
but all that I see is bad coding style!
There's spaghetti so much and the handle's not closed,
the idea may be great but this snippet is hosed!
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
Jakeey802
Senior Member
Join Date: Oct 2015
Old 12-23-2015 , 04:56   Re: Print the content of a trie to the server for debug
Reply With Quote #3

Quote:
Originally Posted by Dr. Greg House View Post
So you gave us this snippet to make us all smile,
but all that I see is bad coding style!
There's spaghetti so much and the handle's not closed,
the idea may be great but this snippet is hosed!

hahahahahahahahahhaha
Jakeey802 is offline
fakuivan
Senior Member
Join Date: Nov 2015
Old 12-24-2015 , 14:04   Re: Print the content of a trie to the server for debug
Reply With Quote #4

Fixed.
fakuivan 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 05:34.


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