bunkum

an old and silly c99 web server with some fun features
Log | Files | Refs | README

hashmap.h (891B)


      1 #ifndef HASHMAP_H
      2 #define HASHMAP_H
      3 
      4 #include <stddef.h>
      5 #include <stdbool.h>
      6 
      7 typedef struct hashmap_t {
      8     void* keys;
      9     void* vals;
     10     size_t k_sz;
     11     size_t v_sz;
     12     size_t len;
     13     size_t filled;
     14     bool vark;
     15 } hashmap_t;
     16 
     17 // Generates a new hashmap_t.
     18 hashmap_t hashmap_new(size_t ksize, size_t vsize);
     19 
     20 #define hashmap_init(t1, t2) hashmap_new(sizeof(t1), sizeof(t2))
     21 
     22 // Sets a key-value pair in the hashmap_t passed to it.
     23 // Returns 0x0 for success, 0x1 for failure.
     24 int hashmap_set(hashmap_t* h, void* k, void* v);
     25 
     26 // Returns address of value associated with key in hashmap if it exists,
     27 // otherwise returns 0x0 for no value or 0x1 for full table.
     28 void* hashmap_get(hashmap_t* h, void* k);
     29 
     30 // Deletes key in hashmap (but not value).
     31 int hashmap_del(hashmap_t* h, void* k);
     32 
     33 // Frees a hashmap.
     34 void hashmap_free(hashmap_t* h);
     35 
     36 void hashmap_dump(hashmap_t* h);
     37 
     38 #endif