Added generic hashmaps and 2 examples using them

This commit is contained in:
cannoli-fruit 2026-07-11 14:58:42 -04:00
commit 0b34fb93a6
3 changed files with 164 additions and 0 deletions

25
examples/hm_basic.c Normal file
View file

@ -0,0 +1,25 @@
#include <stdio.h>
#define LAZY_IMPL
#include "../lazy.h"
void printHmIdx(void *hm, int k) {
typedef Lz_HM(int,int) HM;
HM map = *(HM*)hm;
if (lz_hm_exists(map,k)) {
printf("hm[%d] = %d\n", k, lz_hm_get(map,k));
} else {
printf("hm[%d] = <N/A>\n", k);
}
}
int main() {
Lz_HM(int, int) hm;
lz_hm_init(hm);
lz_hm_add(hm, 1, 2);
lz_hm_add(hm, 2, 4);
printf("Hello World!\n");
printHmIdx(&hm, 1);
printHmIdx(&hm, 3);
}