mirror of
https://gitee.com/apaki/unicstl.git
synced 2025-07-03 23:56:54 +08:00
先添加map相关接口,考虑了下暂定隐层底层细节,参考C++的命名。
This commit is contained in:
parent
1081cda4fe
commit
1f2e4e56bb
58
include/map.h
Normal file
58
include/map.h
Normal file
@ -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
|
Loading…
Reference in New Issue
Block a user