exebook / hashdict.c

This is my REALLY FAST implementation of a hash table in C, in 150 lines of code.
43 stars 6 forks source link

Any HASHDICT_VALUE_TYPE #3

Open senyai opened 3 years ago

senyai commented 3 years ago

Hi!

The documentations says the value type is defined as int in the header file, you can redefine it to the required type, which could be char or void* or anything you need., but https://github.com/exebook/hashdict.c/blob/d821398128ecbc964c381849603ec5bd4a0d7bbf/hashdict.c#L26 assigns -1 to that value and you can't assing -1 to a void *, don't you?

exebook commented 2 years ago

@senyai I think -1 will work for void* because I do not think that could possibly be a valid pointer in either 32 or 64 bit addressing systems, but you're right something have to be done about this magic number, maybe we could introduce a constant.

forcegk commented 10 months ago

I support this feature request, as it will not work for types like structs (kinda weird as you should use a pointer) but for UNIONS there is some problems, as you need to access a "field" (or interpretation of data). Maybe something in the lines of

#define HASHDICT_DEFAULT_ASSIGNMENT_OPERATION node->value.f64 = 0.

Thank you for the great work!