开始设计
This commit is contained in:
@@ -0,0 +1,83 @@
|
||||
#ifndef INCLUDED_C_TREEMAP_H
|
||||
#define INCLUDED_C_TREEMAP_H
|
||||
|
||||
#ifndef INCLUDED_C_BASE_H
|
||||
#include <c_Base.h>
|
||||
#endif /*INCLUDED_C_BASE_H*/
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
// Link Color Definitions
|
||||
typedef enum {
|
||||
C_TM_BLACK = 0,
|
||||
C_TM_RED = 1
|
||||
} c_TMColor_t;
|
||||
|
||||
// TreeMap Inlined Node Layout Configuration
|
||||
typedef struct c_TMNode {
|
||||
struct c_TMNode* left;
|
||||
struct c_TMNode* right;
|
||||
c_TMColor_t color;
|
||||
// Payload layout: key block followed immediately by the value block in memory
|
||||
} c_TMNode_t;
|
||||
|
||||
// TreeMap Context Structure
|
||||
typedef struct {
|
||||
c_TMNode_t* root;
|
||||
c_size_t key_size;
|
||||
c_size_t val_size;
|
||||
c_size_t size;
|
||||
int (*compar)(const void*, const void*);
|
||||
} c_TreeMap_t;
|
||||
|
||||
typedef struct {
|
||||
c_TreeMap_t* map; // Non-const to allow operations on the backing collection
|
||||
c_TMNode_t** stack; // Dynamic lookup-vector tracking block
|
||||
long long stack_top; // Explicit tracking index pointer limits
|
||||
c_size_t max_depth; // Safety boundary memory cushion
|
||||
void* last_returned; // Pointer tracking the key returned by the most recent Next() call
|
||||
} c_TreeMapKeyIter_t;
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
// --- Internal Helper Accessors ---
|
||||
C_STATIC_FORCE_INLINE void* c_TreeMap_NodeKey(c_TMNode_t* node) {
|
||||
return (void*)((char*)node + sizeof(c_TMNode_t));
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE void* c_TreeMap_NodeVal(c_TMNode_t* node, c_size_t key_size) {
|
||||
return (void*)((char*)node + sizeof(c_TMNode_t) + key_size);
|
||||
}
|
||||
|
||||
C_STATIC_FORCE_INLINE c_bool_t c_TreeMap_IsRed(c_TMNode_t* node) {
|
||||
if (node == NULL) return C_FALSE;
|
||||
return node->color == C_TM_RED;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
c_err_t c_TreeMap_Init(c_TreeMap_t* map, c_size_t key_size, c_size_t val_size,
|
||||
int (*compar)(const void*, const void*));
|
||||
void c_TreeMap_Destroy(c_TreeMap_t* map);
|
||||
|
||||
c_bool_t c_TreeMap_Contains(const c_TreeMap_t* map, const void* key);
|
||||
void* c_TreeMap_Get(const c_TreeMap_t* map, const void* key);
|
||||
c_err_t c_TreeMap_Put(c_TreeMap_t* map, const void* key, const void* val);
|
||||
c_err_t c_TreeMap_Remove(c_TreeMap_t* map, const void* key);
|
||||
|
||||
/* ------------------------------------------------------------------------------------------------------------------ */
|
||||
/* */
|
||||
|
||||
c_err_t c_TreeMapKeyIter_Init(c_TreeMapKeyIter_t* iter, const c_TreeMap_t* map);
|
||||
void c_TreeMapKeyIter_Destroy(c_TreeMapKeyIter_t* iter);
|
||||
c_bool_t c_TreeMapKeyIter_HasNext(const c_TreeMapKeyIter_t* iter);
|
||||
void* c_TreeMapKeyIter_Get(c_TreeMapKeyIter_t* iter);
|
||||
void* c_TreeMapKeyIter_Next(c_TreeMapKeyIter_t* iter);
|
||||
c_err_t c_TreeMapKeyIter_Remove(c_TreeMapKeyIter_t* iter);
|
||||
|
||||
|
||||
#endif /*INCLUDED_C_TREEMAP_H*/
|
||||
Reference in New Issue
Block a user