Skip to content

CobbCoding1/hashmap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 2

  •  
  •