diff --git a/src/SearchTree/SearchTree.c b/src/SearchTree/SearchTree.c index 8f86ab4..e7cfac6 100644 --- a/src/SearchTree/SearchTree.c +++ b/src/SearchTree/SearchTree.c @@ -45,11 +45,16 @@ indexes3 splitindex(uint8 i){ }; } -void ST_push(STNode* node_first, const char* key, Unitype value){ +void ST_push(STNode* node_first, char* key, Unitype value){ + string keyString={key, cptr_length(key)}; + ST_pushString(node_first, keyString, value); +} + +void ST_pushString(STNode* node_first, string key, Unitype value){ if (!node_first) throw(ERR_NULLPTR); STNode* node_last=node_first; - while(*key){ - indexes3 i3=splitindex((uint8)*key); + while(key.length--){ + indexes3 i3=splitindex((uint8)*key.ptr); if(!node_last->branches){ node_last->branches=(STNode****)malloc(8*sizeof(STNode***)); for(uint8 i=0;i<8;i++) @@ -68,16 +73,21 @@ void ST_push(STNode* node_first, const char* key, Unitype value){ if(!node_last->branches[i3.n32][i3.n4][i3.rem]) node_last->branches[i3.n32][i3.n4][i3.rem]=STNode_create(); node_last=node_last->branches[i3.n32][i3.n4][i3.rem]; - key++; + key.ptr++; } node_last->value=value; } -Unitype ST_pull(STNode* node_first, const char* key){ +Unitype ST_pull(STNode* node_first, char* key){ + string keyString={key, cptr_length(key)}; + return ST_pullString(node_first, keyString); +} + +Unitype ST_pullString(STNode* node_first, string key){ if (!node_first) throw(ERR_NULLPTR); STNode* node_last=node_first; - while (*key){ - indexes3 i3=splitindex((uint8)*key); + while (key.length--){ + indexes3 i3=splitindex((uint8)*key.ptr); if(!node_last->branches) return UniNull; STNode*** ptrn32=(STNode***)node_last->branches[i3.n32]; if(!ptrn32) return UniNull; @@ -85,7 +95,7 @@ Unitype ST_pull(STNode* node_first, const char* key){ if(!ptrn4) return UniNull; node_last=ptrn4[i3.rem]; if(!node_last) return UniNull; - key++; + key.ptr++; } return node_last->value; } diff --git a/src/SearchTree/SearchTree.h b/src/SearchTree/SearchTree.h index 4d83bb1..fc4eb8c 100644 --- a/src/SearchTree/SearchTree.h +++ b/src/SearchTree/SearchTree.h @@ -5,6 +5,7 @@ extern "C" { #endif #include "../base/base.h" +#include "../String/string.h" typedef struct SearchTreeNode{ struct SearchTreeNode**** branches; // *STNode[8][8][4] @@ -14,8 +15,10 @@ typedef struct SearchTreeNode{ STNode* STNode_create(); void STNode_free(STNode* node); -void ST_push(STNode* node, const char* key, Unitype value); -Unitype ST_pull(STNode* node, const char* key); +void ST_push(STNode* node, char* key, Unitype value); +void ST_pushString(STNode* node, string key, Unitype value); +Unitype ST_pull(STNode* node, char* key); +Unitype ST_pullString(STNode* node, string key); #if __cplusplus }