CobbCoding1 / hashmap

A hashmap implementation, in C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Hashmap

Simple hashmap implementation in C

Key has to be a string, but the value can be any pointer.

Init map

Map *map = malloc(sizeof(Map));
init_map(map); // initializes with NULL values

Place in map

if(put_in_map(map, "key", "value") != 0) {
    // error: could not place in map
}

int value = 12;
if(put_in_map(map, "key", &value) != 0) {
    // error: could not place in map
}

Get from map

int *value = get_from_map(map, "key");
if(value == NULL) {
    // error: could not find in map
}
printf("%d\n", *value);

Remove from map

if(remove_from_map(map, "key") != 0){
    // error: could not remove from map
}

Print map

PRINT_MAP(map //name of map, "%s" //printf symbol for value, (char*) //value data type);

Delete and free map

delete_and_free_map(map);

About

A hashmap implementation, in C

License:MIT License


Languages

Language:C 99.2%Language:Shell 0.8%