From 1f2e4e56bbce3c3632b99a7998bea4cbedcedb47 Mon Sep 17 00:00:00 2001 From: wjf-hs Date: Mon, 19 May 2025 10:30:38 +0800 Subject: [PATCH] =?UTF-8?q?=E5=85=88=E6=B7=BB=E5=8A=A0map=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E6=8E=A5=E5=8F=A3=EF=BC=8C=E8=80=83=E8=99=91=E4=BA=86?= =?UTF-8?q?=E4=B8=8B=E6=9A=82=E5=AE=9A=E9=9A=90=E5=B1=82=E5=BA=95=E5=B1=82?= =?UTF-8?q?=E7=BB=86=E8=8A=82=EF=BC=8C=E5=8F=82=E8=80=83C++=E7=9A=84?= =?UTF-8?q?=E5=91=BD=E5=90=8D=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- include/map.h | 58 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 include/map.h diff --git a/include/map.h b/include/map.h new file mode 100644 index 0000000..80d0cb0 --- /dev/null +++ b/include/map.h @@ -0,0 +1,58 @@ +/** + * @file map.h + * @author wenjf (Orig5826@163.com) + * @brief + * @version 0.1 + * @date 2025-05-19 + * + * @copyright Copyright (c) 2025 + * + */ +#ifndef _MAP_H_ +#define _MAP_H_ + +#include "unicstl_internal.h" +#include "tree.h" + +struct _map_node +{ + char* key; + void* value; +}; + +struct _map +{ + // -------------------- private -------------------- + tree_t tree; + + // -------------------- public -------------------- + // kernel + bool (*insert)(struct _tree* self, const char* key, void* value); + bool (*erase)(struct _tree* self, const char* key); + void* (*find)(struct _tree* self, const char* key); + + bool (*get)(struct _tree* self, const char* key, void* value); + bool (*set)(struct _tree* self, const char* key, void* value); + + // base + bool (*clear)(struct _tree* self); + bool (*empty)(struct _tree* self); + uint32_t(*size)(struct _tree* self); + + // iter + iterator_t(*iter)(struct _tree* self, enum _tree_order); + + // config + compare_fun_t compare; // !!! you have to implement this function + + // -------------------- debug -------------------- + void (*print_obj)(void* obj); +}; +typedef struct _map* map_t; + +map_t map_new(uint32_t obj_size); +map_t unordered_map_new(uint32_t obj_size); + +void map_free(map_t self); + +#endif