Valhalla Legends Archive

Programming => General Programming => Topic started by: iago on April 14, 2003, 12:15 PM

Title: [c++] Free Code! (Buffer/Hash table)
Post by: iago on April 14, 2003, 12:15 PM
These are a couple modules I wrote.  They're pretty easy to use, and they each come with a .cpp file to test them, but I'll give a quick description of each:
Buffer (http://www.valhallalegends.com/iago/Buffer.zip)
This is just a text buffer.  It allows you to add text/binary to a buffer and remove it using << and >> operators.  Supports string, char*, dword, word, byte, and other buffers.  << adds to the right, and >> removes from the left.  It also has a function that allows you to remove from the right, but it needs a pointer to where to put the data/size to remove, so it's more annoying to use.  

Also, it has a toString() function which will return a hexdump of the string.

The point of this is to eventually derive a PacketBuffer subclass, and a BNetPacketBuffer subclass from there, but I haven't started those yet.



HashTable (http://www.valhallalegends.com/iago/HashTable.zip)
This is a decent (not *good*) implementation of a hashtable.  By default, you insert a string into it with an associated string, and can lookup via that string.  In English, what I mean is you can do this:
addString("John", new HashData("LovesJoey")); // Keeping in mind that my name is neither John nor Joey
and later, you can call
findString("John");
and it will return HashData *"LovesJoey".

It uses a hashtable with a constant size of 1023 (can easily be changed), and a hash algorithm reversed from storm.dll (Thanks, arta!).  

The second parameter is a HashData class, but that can easily be substituted with a derived class of HashData to insert whatever type of data is needed into the list.  Gogo oop!


Anyway, if you have any question/comments/concerns/memory leaks/bugs, feel free to respond!

And if you feel the need to tell me I should learn to use templates, don't bother responding :-)

[edit: added c++ to title]