diff --git a/include/block/block.h b/include/block/block.h new file mode 100644 index 0000000..21e11a9 --- /dev/null +++ b/include/block/block.h @@ -0,0 +1,7 @@ +#ifndef block_h +#define block_h + +#include + + +#endif /* block_h */ diff --git a/include/block/block_expand.h b/include/block/block_expand.h new file mode 100644 index 0000000..5b33ca2 --- /dev/null +++ b/include/block/block_expand.h @@ -0,0 +1,5 @@ +#ifndef BLOCK_EXPAND_H +#define BLOCK_EXPAND_H + + +#endif /* block_expand_h */ diff --git a/include/block/block_type.h b/include/block/block_type.h new file mode 100644 index 0000000..074c4c2 --- /dev/null +++ b/include/block/block_type.h @@ -0,0 +1,22 @@ +#ifndef block_type_h +#define block_type_h + +#include +#ifdef id_enable +#include +#endif + +/* + *块的管理及操作的结构 + */ +typedef struct block{ + uint64_t size; + uint32_t carve; + void *data; +#ifdef id_enable + SID *s_id;//栈节点的ID +#endif +} SNode; + + +#endif /* block_type_h */ diff --git a/include/stack/stack.h b/include/stack/stack.h deleted file mode 100644 index 2274b40..0000000 --- a/include/stack/stack.h +++ /dev/null @@ -1,19 +0,0 @@ -#ifndef stack_h -#define stack_h - -#include - -extern Stack *initStack(void); -extern SNode *initSNode(void); - -extern int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value); - -extern SNode *popStack(Stack *p_stack); - -extern int pushStack(Stack *p_stack, SNode *p_snode); - -extern int releaseStack(Stack *p_stack); - -extern int releaseSNode(SNode *p_snode); - -#endif /* stack_h */ diff --git a/include/stack/stack_expand.h b/include/stack/stack_expand.h deleted file mode 100644 index e16279c..0000000 --- a/include/stack/stack_expand.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef STACK_EXPAND_H -#define STACK_EXPAND_H - -SNode *snodeWithInt(int); -SNode *snodeWithDouble(double); -SNode *snodeWithString(char *); -SNode *snodeWithPointer(void *); - -int getValueByIntForSNode(SNode *); -double getValueByDoubleForSNode(SNode *); -char *getValueByStringForSNode(SNode *); -void *getValueByPointerForSNode(SNode *); - -#endif /* stack_expand_h */ diff --git a/include/stack/stack_type.h b/include/stack/stack_type.h deleted file mode 100644 index 05f43f8..0000000 --- a/include/stack/stack_type.h +++ /dev/null @@ -1,31 +0,0 @@ -#ifndef stack_type_h -#define stack_type_h - -#ifdef id_enable -#include -#endif - -/* - *栈节点的管理及操作的结构 - */ -typedef struct stack_node{ - unsigned int type;//栈节点的类型 - void *value;//值指针 - struct stack_node *next;//下一个栈节点 -#ifdef id_enable - SID *s_id;//栈节点的ID -#endif -} SNode; - -/* - *栈的管理及操作的结构 - */ -typedef struct stack{ - unsigned long long length;//栈的长度 - SNode *top;//指向栈顶的栈节点 -#ifdef id_enable - SID *s_id;//栈的ID -#endif -} Stack; - -#endif /* stack_type_h */ diff --git a/src/block/block.c b/src/block/block.c new file mode 100644 index 0000000..91b351f --- /dev/null +++ b/src/block/block.c @@ -0,0 +1,2 @@ +#include + diff --git a/src/block/block_expand.c b/src/block/block_expand.c new file mode 100644 index 0000000..0284594 --- /dev/null +++ b/src/block/block_expand.c @@ -0,0 +1,2 @@ +#include +#include diff --git a/src/stack/stack.c b/src/stack/stack.c deleted file mode 100644 index ad66956..0000000 --- a/src/stack/stack.c +++ /dev/null @@ -1,74 +0,0 @@ -#include -#include - -Stack *initStack(void) { - Stack *p_stack = (Stack *)malloc(sizeof(Stack)); -#ifdef id_enable - p_stack->s_id = getS_id(STACK, 1); -#endif - p_stack->length = 0; - p_stack->top = NULL; - return p_stack; -} - -SNode *initSNode(void) { - SNode *p_snode = (SNode *)malloc(sizeof(SNode)); -#ifdef id_enable - p_snode->s_id = getS_id(STACK_NODE, 1); -#endif - p_snode->next = NULL; - p_snode->value = NULL; - return p_snode; -} - -SNode *popStack(Stack *p_stack) { - if (p_stack->top != NULL) { - SNode *p_snode = p_stack->top; - p_stack->top = p_snode->next; - p_snode->next = NULL; - p_stack->length -= 1; - return p_snode; - } - else return NULL; -} - -int pushStack(Stack *p_stack, SNode *p_snode) { - SNode *pn_snode = p_stack->top; - p_stack->top = p_snode; - p_snode->next = pn_snode; - p_stack->length -= 1; - return 0; -} - -int releaseStack(Stack *p_stack) { - SNode *p_sndoe = p_stack->top; - while (p_sndoe != NULL) { - SNode *pl_snode = p_sndoe; - p_sndoe = p_sndoe->next; - releaseSNode(pl_snode); - } -#ifdef id_enable - freeS_id(p_stack->s_id); -#endif - p_stack->top = NULL; - p_stack->length = 0; - free(p_stack); - return 0; -} - -int releaseSNode(SNode *p_snode) { -#ifdef id_enable - freeS_id(p_snode->s_id); -#endif - free(p_snode->value); - p_snode->value = NULL; - p_snode->type = VOID; - free(p_snode); - return 0; -} - -int initMallocValueForSNode(SNode *p_snode, unsigned int type, void *value) { - p_snode->type = type; - p_snode->value = value; - return 0; -} diff --git a/src/stack/stack_expand.c b/src/stack/stack_expand.c deleted file mode 100644 index 39287fd..0000000 --- a/src/stack/stack_expand.c +++ /dev/null @@ -1,62 +0,0 @@ -#include -#include -#include - -SNode *snodeWithInt(int temp) { - SNode *p_snode = initSNode(); - int *p_temp = (int *)malloc(sizeof(int)); - if(p_temp == NULL){ - return NULL; - } - *p_temp = temp; - initMallocValueForSNode(p_snode, INT, p_temp); - return p_snode; -} - -SNode *snodeWithDouble(double temp) { - SNode *p_snode = initSNode(); - double *p_temp = (double *)malloc(sizeof(double)); - if(p_temp == NULL){ - return NULL; - } - *p_temp = temp; - initMallocValueForSNode(p_snode, DOUBLE, p_temp); - return p_snode; -} - -SNode *snodeWithString(char *temp) { - SNode *p_snode = initSNode(); - char *p_temp = (char *)malloc(sizeof(char)*(strlen(temp) + 1)); - if(p_temp == NULL){ - return NULL; - } - strcpy(p_temp, temp); - initMallocValueForSNode(p_snode, STRING, p_temp); - return p_snode; -} - -SNode *snodeWithPointer(void *temp) { - SNode *p_snode = initSNode(); - initMallocValueForSNode(p_snode, POINTER, temp); - return p_snode; -} - -int getValueByIntForSNode(SNode *p_snode) { - if (p_snode->type == INT) return *(int *)p_snode->value; - else return -1; -} - -double getValueByDoubleForSNode(SNode *p_snode) { - if (p_snode->type == DOUBLE) return *(double *)p_snode->value; - else return -1; -} - -char *getValueByStringForSNode(SNode *p_snode) { - if (p_snode->type == STRING) return (char *)p_snode->value; - else return NULL; -} - -void *getValueByPointerForSNode(SNode *p_snode) { - if (p_snode->type == POINTER) return (void *)p_snode->value; - else return NULL; -}