Skip to content
/ chap Public

Lightweight C implementation of hashmap for maps of arbitrary data size

License

Notifications You must be signed in to change notification settings

bradenhc/chap

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

chap

Lightweight C implementation of hashmap for maps of arbitrary data size

Compilation

make all

Eventually there will be an install in the make file that will place it in the appropriate system library and include directory.

Example Usage

See the header file to get detailed descriptions for all the functions in the chap library.

main.c

#include <chap.h>

int main(int argc, char const *argv[])
{
    // Create a new map
    chap_map_t *map = chap_map_new();

    // Put a key/value pair into the map
    chap_put(map, "key", "value");

    // Get a key/value pair from the map
    char *sval = chap_get(map, "key");

    // Get an integer value from the map
    chap_put(map, "number", "42");
    int ival;
    chap_get_int(map, "number", &ival);

    // Provide a default to insert into the map if the value is not found when
    // performing the get
    char *dval = chap_get_default(map, "dkey", "default");

    // Remove all entries from the map
    chap_clear(map);

    // Destroy the map to prevent memory leaks
    chap_map_destroy(map);

    return 0;
}
gcc -o out main.c -lchap

About

Lightweight C implementation of hashmap for maps of arbitrary data size

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published