Author | Message | Time |
---|---|---|
H0CKEY | How would one go about adding a effiecient queue system to a vb or c++ bot. If you could I would like examples of what would make a good queue system or examples of a good queue system that exists. Thanks for your time | February 2, 2004, 1:24 AM |
Newby | Use an array and a timer. That's about as general as I can get since you didn't specify C++ or VB. You said both. :P | February 2, 2004, 2:21 AM |
H0CKEY | vb Would do Fine. ^^ | February 2, 2004, 2:31 AM |
DarkMinion | February 2, 2004, 1:41 PM | |
K | For C++ I use a std::priority_queue<BnMsg> with a comparison object that gives certain commands (/ban, /kick) higher priority so that they are executed first. [code] #include <string> #include <queue> struct BnMsg { public: std::string Text; BnMsg(); BnMsg(const BnMsg& b); BnMsg(const std::string& s); BnMsg(const char* c); BnMsg& operator=(const std::string& s); BnMsg& operator=(const BnMsg& b); BnMsg& operator=(const char* c); ~BnMsg(); friend bool operator<(const BnMsg& a, const BnMsg& b); private: int GetPriority() const { // check if Text is a certain command, simple chat, or what... }; }; class ChatBot : public kBinaryBot { public: std::priority_queue<BnMsg> queue; // etc; }; [/code] Edit: I did this from memory -- I may have implemented the comparison wrong. Edit2: I did. I fixed it. | February 2, 2004, 7:02 PM |
Kp | [quote author=K link=board=17;threadid=5044;start=0#msg42307 date=1075748541] For C++ I use a std::priority_queue<BnMsg> with a comparison object that gives certain commands (/ban, /kick) higher priority so that they are executed first.[/quote] From the look of your code, you reanalyze the priority of the messages every time you compare them. While this works, it seems a bit wasteful when you could just keep an unsigned or enum member in the class that specifies the priority. Assign the enum a value from the GetPriority function when you create the class, then just query the enum's value when you need to sequence the messages. It'll save you from recomparing against all the other text strings at run time. Not a big optimization since it's not likely you'll often have lots of messages, but it's a fairly simple change. :) | February 3, 2004, 1:29 AM |
K | [quote author=Kp link=board=17;threadid=5044;start=0#msg42385 date=1075771772] [quote author=K link=board=17;threadid=5044;start=0#msg42307 date=1075748541] For C++ I use a std::priority_queue<BnMsg> with a comparison object that gives certain commands (/ban, /kick) higher priority so that they are executed first.[/quote] From the look of your code, you reanalyze the priority of the messages every time you compare them. While this works, it seems a bit wasteful when you could just keep an unsigned or enum member in the class that specifies the priority. Assign the enum a value from the GetPriority function when you create the class, then just query the enum's value when you need to sequence the messages. It'll save you from recomparing against all the other text strings at run time. Not a big optimization since it's not likely you'll often have lots of messages, but it's a fairly simple change. :) [/quote] I realized that after I posted. Since this is just an example, the under-the-hood implementation is up to whoever wants to use it. Your point is a valid one, though -- If I were actually using this code I would make the std:::string Text variable a private member, and only recalculate priority when the assignment operator is used to assign a different string to it. | February 3, 2004, 1:53 AM |