Added and Fixed.
This commit is contained in:
parent
30323b5d63
commit
a7b6538bac
7
include/block/block.h
Normal file
7
include/block/block.h
Normal file
@ -0,0 +1,7 @@
|
||||
#ifndef block_h
|
||||
#define block_h
|
||||
|
||||
#include <block/block_type.h>
|
||||
|
||||
|
||||
#endif /* block_h */
|
5
include/block/block_expand.h
Normal file
5
include/block/block_expand.h
Normal file
@ -0,0 +1,5 @@
|
||||
#ifndef BLOCK_EXPAND_H
|
||||
#define BLOCK_EXPAND_H
|
||||
|
||||
|
||||
#endif /* block_expand_h */
|
22
include/block/block_type.h
Normal file
22
include/block/block_type.h
Normal file
@ -0,0 +1,22 @@
|
||||
#ifndef block_type_h
|
||||
#define block_type_h
|
||||
|
||||
#include<type.h>
|
||||
#ifdef id_enable
|
||||
#include <id/id.h>
|
||||
#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 */
|
@ -1,19 +0,0 @@
|
||||
#ifndef stack_h
|
||||
#define stack_h
|
||||
|
||||
#include <stack/stack_type.h>
|
||||
|
||||
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 */
|
@ -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 */
|
@ -1,31 +0,0 @@
|
||||
#ifndef stack_type_h
|
||||
#define stack_type_h
|
||||
|
||||
#ifdef id_enable
|
||||
#include <id/id.h>
|
||||
#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 */
|
2
src/block/block.c
Normal file
2
src/block/block.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include <block/block.h>
|
||||
|
2
src/block/block_expand.c
Normal file
2
src/block/block_expand.c
Normal file
@ -0,0 +1,2 @@
|
||||
#include <block/block.h>
|
||||
#include <block/block_expand.h>
|
@ -1,74 +0,0 @@
|
||||
#include <type.h>
|
||||
#include <stack/stack.h>
|
||||
|
||||
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;
|
||||
}
|
@ -1,62 +0,0 @@
|
||||
#include <type.h>
|
||||
#include <stack/stack.h>
|
||||
#include <stack/stack_expand.h>
|
||||
|
||||
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;
|
||||
}
|
Loading…
Reference in New Issue
Block a user