From 80dcfa99fef3684d506ee8f96298563433b10e74 Mon Sep 17 00:00:00 2001 From: Fabrice Date: Tue, 10 Feb 2026 10:08:28 +0100 Subject: idk --- .gitmodules | 3 +++ Makefile | 8 ++++++-- hashmap | 1 + src/hashm.h | 47 +++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 57 insertions(+), 2 deletions(-) create mode 160000 hashmap create mode 100644 src/hashm.h diff --git a/.gitmodules b/.gitmodules index de4d60e..981d9ff 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,3 +1,6 @@ [submodule "mimalloc"] path = mimalloc url = https://github.com/microsoft/mimalloc.git +[submodule "hashmap"] + path = hashmap + url = https://github.com/tidwall/hashmap.c.git diff --git a/Makefile b/Makefile index 4fe542a..ec9ee02 100644 --- a/Makefile +++ b/Makefile @@ -28,7 +28,10 @@ MI_FLAGS = \ -DMI_XMALLOC=YES \ -DMI_OVERRIDE=YES -CSH_FLAGS += -I$(MI_INCLUDE) +HASHMAP_DIR = $(WORK_DIR)/hashmap +HASHMAP_SOURCE = $(HASHMAP_DIR)/hashmap.c + +CSH_FLAGS += -I$(MI_INCLUDE) -I$(HASHMAP_DIR) MI_GENERATOR = "Unix Makefiles" @@ -40,7 +43,8 @@ SOURCES = \ $(SRC_DIR)/xdg-shell.c \ $(SRC_DIR)/wlstate.c \ $(SRC_DIR)/vec.c \ - $(SRC_DIR)/events.c + $(SRC_DIR)/events.c \ + $(HASHMAP_SOURCE) OBJECTS := $(SOURCES:.cc=.o) OBJECTS := $(OBJECTS:.c=.o) diff --git a/hashmap b/hashmap new file mode 160000 index 0000000..5e475b4 --- /dev/null +++ b/hashmap @@ -0,0 +1 @@ +Subproject commit 5e475b4662622c51b8f375e7b2013e25f3c77b57 diff --git a/src/hashm.h b/src/hashm.h new file mode 100644 index 0000000..67bb3e0 --- /dev/null +++ b/src/hashm.h @@ -0,0 +1,47 @@ +#pragma once + +#include "hashmap.h" +#include "utils.h" +#include +#include + +#define WAYC_HASHMAP_SEED 0 +#define WAYC_HASHMAP_CAP 16 + +template struct hashmap_s { + struct hashmap *inner; +}; + +template +static inline i32 wayc_hashmap_hash(const void *item, uint64_t seed0, + uint64_t seed1) { + wayc_notnull(item); + return hashmap_xxhash3(item, sizeof(T), seed0, seed1); +} + +template +static inline bool wayc_hashmap_compare(const void *a, const void *b, + void *udata) { + (void)udata; + + wayc_notnull(a); + wayc_notnull(b); + return memcmp(a, b, sizeof(T)) == 0; +} + +template inline hashmap_s wayc_hashmap_init(void) { + struct hashmap *map = hashmap_new_with_allocator( + mi_malloc, mi_realloc, mi_free, sizeof(T), WAYC_HASHMAP_CAP, + WAYC_HASHMAP_SEED, WAYC_HASHMAP_SEED, wayc_hashmap_hash, + wayc_hashmap_compare, nullptr, nullptr); + + hashmap_s result; + result.inner = map; + + return result; +} + +template inline void wayc_hashmap_deinit(hashmap_s *map) { + hashmap_free(map->inner); + map->inner = nullptr; +} \ No newline at end of file -- cgit v1.2.3