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

[STL] adt_* (travtrie, deque, queue, stack)


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-23-2008 , 01:51   [STL] adt_* (travtrie, deque, queue, stack)
Reply With Quote #1

A few useful stocks until official versions are added. These follow the same format as adt_array and adt_trie (even when I dislike it) just to maintain compatibility.

Deque:
Meets all deque requirements for speed, at the sacrifice of space
Space grows linearly, but quicker than it could
Worst case for space is queue (unfortunately)

Queue:
Based on deque (soon to be based on circular buffer)
Meets all queue requirements for speed

Stack:
Based on adt_array
Meets all stack requirements for speed

TravTrie:
Based on adt_trie and adt_array
Retrieve has no slow down
insert has O(1) slow down
delete has O(logn) or O(n) slow down
constant iteration provided through Plugin Iterator like mechanism
iteration occurs in O(n) unsorted, O(nlogn) sorted

TravTrie Tripups:
1. Getting the string key (not the value) will not increment the iterator
2. A function is provided to sort the travtrie if wanted

Note: These functions have been compile tested and moderately runtime tested, but not stress tested (except for queue and travtrie). Tell me if an error occurs.
Please tell me how if you like it!
Attached Files
File Type: inc adt_travtrie.inc (5.0 KB, 262 views)
File Type: inc adt_queue.inc (1.4 KB, 268 views)
File Type: inc adt_deque.inc (11.0 KB, 260 views)
File Type: inc adt_stack.inc (1.2 KB, 253 views)
__________________

Last edited by Twilight Suzuka; 03-23-2008 at 06:36. Reason: Enhanced
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
Nican
Veteran Member
Join Date: Jan 2006
Location: NY
Old 03-23-2008 , 11:58   Re: [STL] adt_* (travtrie, deque, queue, stack)
Reply With Quote #2

Good job.

Could you show some examples?
__________________
http://www.nican132.com
I require reputation!
Nican is offline
Send a message via ICQ to Nican Send a message via MSN to Nican
sfPlayer
Senior Member
Join Date: Dec 2007
Location: Germany
Old 03-23-2008 , 15:00   Re: [STL] adt_* (travtrie, deque, queue, stack)
Reply With Quote #3

(partial) adt_queue implementation based upon my C++ implementation

The SourceMod version is 150-200 times slower than the C++ one (benchmark: (push_back 2k, pop_front 1k, push_back 1k, pop_front 2k)*1k).
Attached Files
File Type: inc adt_queue.inc (3.9 KB, 239 views)

Last edited by sfPlayer; 03-23-2008 at 15:03.
sfPlayer is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-23-2008 , 23:46   Re: [STL] adt_* (travtrie, deque, queue, stack)
Reply With Quote #4

Got any comparisons of mine and yours? I assume yours will beat mine, but my circular buffer one should beat both.
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
sfPlayer
Senior Member
Join Date: Dec 2007
Location: Germany
Old 03-24-2008 , 11:10   Re: [STL] adt_* (travtrie, deque, queue, stack)
Reply With Quote #5

yours "crashes"
Code:
L 03/24/2008 - 16:08:24: [SM] Native "SetArrayCell" reported: Invalid index 4224 (count: 1280)
L 03/24/2008 - 16:08:24: [SM] Displaying call stack trace for plugin "adt_queue_test.smx":
L 03/24/2008 - 16:08:24: [SM]   [0]  Line 358, adt_deque.inc::PushBackDequeCell()
L 03/24/2008 - 16:08:24: [SM]   [1]  Line 18, adt_queue.inc::PushQueueCell()
The performance is primarily limited by the very poor performance of adt_array/datapacks as a replacement for object members / a struct on the heap

Last edited by sfPlayer; 03-24-2008 at 11:15.
sfPlayer is offline
sfPlayer
Senior Member
Join Date: Dec 2007
Location: Germany
Old 03-24-2008 , 11:12   Re: [STL] adt_* (travtrie, deque, queue, stack)
Reply With Quote #6

benchmark:

Code:
public OnPluginStart() {
    new Handle:queue = CreateQueue();
    new Float:startTime = GetEngineTime();
    for (new j=0; j<1000; j++) {
        for (new i=0; i<2000; i++) {
            PushQueueCell(queue, 123);
        }
        for (new i=0; i<1000; i++) {
            new test = FrontQueueCell(queue);
            if (test != 123) {
                PrintToServer("error at %d", GetQueueSize(queue));
                break;
            }
            PopQueue(queue);
        }
        for (new i=0; i<1000; i++) {
            PushQueueCell(queue, 123);
        }
        for (new i=0; i<2000; i++) {
            new test = FrontQueueCell(queue);
            if (test != 123) {
                PrintToServer("error at %d", GetQueueSize(queue));
                break;
            }
            PopQueue(queue);
        }
    }
    PrintToServer("queue test ok");
    PrintToServer("time: %fs", GetEngineTime()-startTime);
}
sfPlayer is offline
Twilight Suzuka
bad
Join Date: Jul 2004
Location: CS lab
Old 03-24-2008 , 20:03   Re: [STL] adt_* (travtrie, deque, queue, stack)
Reply With Quote #7

sweet googly moogly! Have to look into that.

The cost of the native overhead to just access the members in our fake structs is rather high. Wonder if I could pack the members somehow...
__________________
Twilight Suzuka is offline
Send a message via AIM to Twilight Suzuka Send a message via MSN to Twilight Suzuka
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 21:16.


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