GSHashmap DLL

Posted By: pegamode

GSHashmap DLL - 08/03/08 07:13

HI everybody,

here is the link to my GSHashmap DLL:

GSHashmap Vesrion 0.8

Feel free to use it ... you may list me in the credits :-)

Post your questions and tips for improvement here.

Best regards,
Pegamode
Posted By: Nowherebrain

Re: GSHashmap DLL - 08/07/08 11:52

you may want to put a description in there, I have no idea what this adds. Otherwise I am very curious.
Posted By: pegamode

Re: GSHashmap DLL - 08/10/08 16:28

Hi Nowherebrain,

the add function is declared in c++ as follows:

DLLFUNC void addToGSHashmap(char* key, var value)

So you can add everything to the hashmap that fits into a var.

I use it to store pointers to my struct objects into my hashmap, but
you could also store pointers to entities or whatever.

Hope this helps.

Best regards,
Pegamode
Posted By: Trooper119

Re: GSHashmap DLL - 08/12/08 17:47

Sorry bud, I'll admit I'm ignorant on this but I have no clue what this is about and I'm sure I'm not alone in this. You'll find your contributions will be long lived if you include the following so people have a clue if your contribution will be helpful to them:

-What is a hashmap?
-Why was this DLL made?
-How does this DLL fit that need?
-Features
-Screenshot/movie if applicable of application working, before and after the DLL is used.
-Step by step of how you implement the DLL into a foreign project.
-Any other points that might be interesting/useful.

If you give people an idea of what they are looking at people will use it and pass it on, otherwise it becomes just another lost contribution.
Posted By: Nowherebrain

Re: GSHashmap DLL - 08/12/08 23:54

Not to discredit you, but he is right..I have no idea how this would be useful or it's purpose/implementation. I'm not that bright though.
Posted By: pegamode

Re: GSHashmap DLL - 08/13/08 06:22

Sorry, my fault ...

I thought that a hashmap is well-known as it is a common and one of the most used container in nearly every programming language.

To keep it short:

A hashmap is used to store objects under a unique key in a container and get it back by its key.

For a detailed explanation follow that link:

http://en.wikipedia.org/wiki/Hash_table

As GS doesn't support hashmaps (only a simple type of arrays and some kind of linked lists by using structs), I wrote this dll.

And now a short example how to use my GSHashmap with Lite-C (C-Script should work as well):

Put the GSHashmap.dll into your plugins folder. Usually Lite-C opens DLLs on its own, so you do not have to load it in script. If you have to, just take a look in the GS manual.

Put the file GSHashmap.h into your working directory or whereever you have your header files and add the following line to your main.c:

#include "GSHashmap.h"

That's all you have to do to use the GSHashmap :-)

Now you can use the following functions:

function addToGSHashmap(key,value); // char* key, var value
is used to add a value (for example a pointer or whatever fits in a var)
under a given key into the hashmap:

addToGSHashmap(_chr("myplayer"), ((ENTITY*)player));

function getFromGSHashmap(key);
is used to get the stored values back from the hashmap:

ENTITY* player = (ENTITY*)getFromGSHashmap(_chr("myplayer"));

function clearGSHashmap();
clears all entries from the hashmap.

function removeFromGSHashmap(key);
removes the entry with the given key from the hashmap.

function isInGSHashmap(key); // returns 0 if false, 1 if true
used to check if the entry with the given key exists in the hashmap:

if (isInGSHashmap(_chr("myplayer")) == 1) {
// do something
}

function sizeOfGSHashmap();
returns the current number of entries in the hashmap

***********************************************************************

And here's a short snippet from my project how I use the GSHashmap to store pointers to struct objects filled with data read from a file:

var fhandle;

void filereader() {
fhandle = file_open_read("..\\database\\objects.data");
if (fhandle != 0) {
var tempPointer = 0;
str_cpy(delimit_str,";");
STRING* objName = "";
STRING* str = "";
while (file_str_read(fhandle,objName) != -1) {
USEABLE_OBJECT* tmpObj = (USEABLE_OBJECT*)malloc(sizeof(USEABLE_OBJECT));
file_str_read(fhandle,str);
((USEABLE_OBJECT*)tmpObj).displayName = str_create(str);
file_str_read(fhandle,str);
((USEABLE_OBJECT*)tmpObj).description = str_create(str);
addToGSHashmap(_chr(objName), ((USEABLE_OBJECT*)tmpObj));
file_str_read(fhandle,str);
}
}
file_close(fhandle);
}

***********************************************************************

Hope that helps.

If there are questions ... ask me :-)

Best regards,
Pegamode.
Posted By: Trooper119

Re: GSHashmap DLL - 08/13/08 17:39

Excellent, exactly what I was talking about, and more. I don't know if you can still edit your first post, but I would change it with what you've just written if you can.

Actually I've worked with Hash Maps before, I just never knew what they were called when I used them lol. I appreciate the explanation and the contribution, good stuff.
Posted By: pegamode

Re: GSHashmap DLL - 08/13/08 20:16

Hi Trooper,

I can't edit the first post, but I copied the explanation into a textfile and put it into the rar-File on the server, so there's at least some more info shipped with the dll and header files.

As soon as I find the time I'll write a complete documentation and a short working demo.

I'm currently working on a real StringTokenizer-DLL for a better handling than
what GS supports (90% finished) ...

Regards,
Pegamode.
Posted By: Espér

Re: GSHashmap DLL - 09/02/08 14:00

isn´t there a way to do it as easy as in RGSS...

here an example: http://www.rmxp.de/scientia/index.php/Hash#Hash

??
Posted By: pegamode

Re: GSHashmap DLL - 11/01/08 14:15

Hi everybody,

I've added some more functions to GSHashmap.

Now in version 1.0 it is possible to use as many hashmaps as you like, instead of just one ... and it's fully backwards compatible.

You can download the new version here:

GSHashmap Version 1.0

Find more instructions in the rar-File.

Best regards,
Pegamode.
Posted By: BigM

Re: GSHashmap DLL - 06/06/10 20:46

Hello all,

Users of the latest lite-C free version (at least version 7.84) may have noticed that GSHashmap.dll fails to load. The most obvious symptom is the "Empty prototype called in ..." run-time error. This happens because support for engine plugins has been removed from the free version (it seems it should have never been there in the first place; read more here). This change also seems to break automagic function loading from DLLs. The way to load such functions is now by prototyping and defining PRAGMA_API (read the manual).

I rewrote GSHashmap.h (with feedback from pegamode; thanks!) to be compliant with the newer lite-C free. I use the API macro, which is equivalent to the #define PRAGMA_API statement but more readable.
Code:
/***************************************************************************************

Header for GSHashmap DLL

Version 1.0 - by Pegamode - 2008-11-01

modified 06-06-2010 by BigM to use the API macro, for compatibility with lite-C free

****************************************************************************************/

#ifndef GSHashmap_header
#define GSHashmap_header

	var createDynamicGSHashmap();
	void destroyDynamicGSHashmap(var);
	void addToDynamicGSHashmap(var, char*, var);
	var getFromDynamicGSHashmap(var, char*);
	void clearDynamicGSHashmap(var);
	void removeFromDynamicGSHashmap(var, char*);
	var isInDynamicGSHashmap(var, char*);
	var sizeOfDynamicGSHashmap(var);
	var sizeInBytesOfDynamicGSHashmap(var);
	void addToGSHashmap(char* key, var value);
	var getFromGSHashmap(char* key);
	void clearGSHashmap();
	void removeFromGSHashmap(char* key);
	var isInGSHashmap(char* key);
	var sizeOfGSHashmap();
	var sizeInBytesOfGSHashmap();

	API(createDynamicGSHashmap, GSHashmap)
	API(destroyDynamicGSHashmap, GSHashmap)
	API(addToDynamicGSHashmap, GSHashmap)
	API(getFromDynamicGSHashmap, GSHashmap)
	API(clearDynamicGSHashmap, GSHashmap)
	API(removeFromDynamicGSHashmap, GSHashmap)
	API(isInDynamicGSHashmap, GSHashmap)
	API(sizeOfDynamicGSHashmap, GSHashmap)
	API(sizeInBytesOfDynamicGSHashmap, GSHashmap)
	API(addToGSHashmap, GSHashmap)
	API(getFromGSHashmap, GSHashmap)
	API(clearGSHashmap, GSHashmap)
	API(removeFromGSHashmap, GSHashmap)
	API(isInGSHashmap, GSHashmap)
	API(sizeOfGSHashmap, GSHashmap)
	API(sizeInBytesOfGSHashmap, GSHashmap)
	
#endif


I did only minor testing and cannot guarantee all functions will work with lite-C free. The essential functions createDynamicGSHashmap, addToDynamicGSHashmap, getFromDynamicGSHashmap and isInDynamicGSHashmap seem to be ok.

Hope this helps the lite-C free community!

Cheers
Posted By: EpsiloN

Re: GSHashmap DLL - 12/22/10 20:39

Any chance someone will make this work on A6 too? tongue We might be small , but it still counts as a community :}
© 2024 lite-C Forums