aocc23

Advent of Code 2023
git clone git://www.tkruger.se/aocc23.git
Log | Files | Refs | README

dict.h (624B)


      1 #ifndef DICT_H
      2 #define DICT_H
      3 
      4 #include "stack_sd.h"
      5 
      6 #define DICT_DEFAULT_SIZE 255
      7 #define DICT_DEFAULT_STACK_SIZE 2
      8 #define STACK_PTR_EMPTY_POP (NULL)
      9 #define DICT_LOOKUP_NOT_FOUND (STACK_SD_LOOKUP_NOT_FOUND) // == -1
     10 
     11 typedef struct {
     12   size_t nmemb;
     13   size_t alloc;
     14 
     15   void **data;
     16 } stack_ptr;
     17 
     18 typedef struct {
     19   size_t nelts;
     20   size_t nalloc;
     21 
     22   stack_sd *keys;
     23   stack_ptr *values;
     24 } dict_t;
     25 
     26 void dict_init_size(dict_t *d, const size_t alloc);
     27 void dict_init(dict_t *d);
     28 void dict_clear(dict_t *d);
     29 void *dict_lookup(dict_t *d, sd k);
     30 void dict_insert(dict_t *t, sd k, void *v);
     31 void print_dict(dict_t *d);
     32 
     33 #endif