Added and Fixed.

This commit is contained in:
Saturneic 2019-01-06 18:44:11 +08:00
parent 08f2d523c8
commit 940087e820
11 changed files with 224 additions and 46 deletions

View File

@ -11,12 +11,20 @@
/*
*,,if_sid指示是否为新链表分配ID号
*: ,NULL.*/
#ifdef id_enable
extern List *initList(_Bool if_sid);
#else
extern List *initList(void);
#endif
/*
*,,if_sid指示是否为新节点分配ID号
*: ,NULL.*/
#ifdef id_enable
extern Node *initNode(_Bool if_sid);
#else
extern Node *initNode(void);
#endif
/*库中内部调用函数,旨在为新节点的储存值获取内存,并将相应的储存值储存在获取到的内存中,并指明储存值的类型.*/
extern int initMallocValueForNode(Node *,unsigned int,const void *);

View File

@ -1,4 +1,4 @@
#ifndef list_expand_h
#ifndef list_expand_h
#define list_expand_h
#include <list/list_type.h>
@ -12,7 +12,7 @@
/*
*, 使
*if_sid指示函数是否为节点获取ID
*: ,NULL.*/
*: ,NULL.*/
extern Node *nodeWithInt(int, _Bool if_sid);
/*
@ -30,23 +30,23 @@ extern Node *nodeWithULLInt(unsigned long long, _Bool if_sid);
/*
*, 使
*if_sid指示函数是否为节点获取ID
*: ,NULL.*/
*: ,NULL.*/
extern Node *nodeWithDouble(double, _Bool if_sid);
/*
*, 使
*if_sid指示函数是否为节点获取ID
*: ,NULL.*/
*: ,NULL.*/
extern Node *nodeWithString(const char *, _Bool if_sid);
/*
*, 使
*if_sid指示函数是否为节点获取ID
*: ,NULL.*/
*: ,NULL.*/
extern Node *nodeWithPointer(const void *, _Bool if_sid);
/************************************************
*: ,
* 使
@ -55,33 +55,33 @@ extern Node *nodeWithPointer(const void *, _Bool if_sid);
/*
*
*: ,NULL.*/
*: ,NULL.*/
extern Node *nodeWithComplex(void);
/*
*
*: type指明所输入值的类型,value为指向所输入值的内存空间的指针
*: 0,-1.*/
*: 0,-1.*/
extern int addValueForComplex(Node *, int type, void *value);
/*
*
*: 0,-1.*/
*: 0,-1.*/
extern int addIntForComplex(Node *, int);
/*
*
*: 0,-1.*/
*: 0,-1.*/
extern int addDoubleForComplex(Node *, double);
/*
*
*: 0,-1.*/
*: 0,-1.*/
extern int addStringForComplex(Node *, char *);
/*
*
*: 0,-1.*/
*: 0,-1.*/
extern int addPointerForComplex(Node *, void *);
@ -99,7 +99,7 @@ extern int updateValueWithIntForNode(Node *,int);
/*
*
*: 0,-1.*/
extern int updateValueWithULLIntForNode(Node *, unsigned long long);
extern int updateValueWithULLIntForNode(Node *, uint64_t);
/*
*
@ -114,7 +114,7 @@ extern int updateValueWithStringForNode(Node *,char *);
/*
*
*: 0,-1.*/
extern int updateValueWithPointerForNode(Node *,void *);
extern int updateValueWithPointerForNode(Node *,void *);
@ -125,23 +125,23 @@ extern int updateValueWithPointerForNode(Node *,void *);
/*
*,
*: ,NULL.*/
*: ,NULL.*/
List *mply_findByIntForNode(List*, int);
/*
*,
*: ,NULL.*/
*: ,NULL.*/
List *mply_findByDoubleForNode(List*, double);
/*
*,
*: ,NULL.*/
*: ,NULL.*/
List *mply_findByStringForNode(List*, char *);
/*
*,
*: ,NULL.*/
List *mply_findByPointerForNode(List*, void *);
*: ,NULL.*/
List *mply_findByPointerForNode(List*, void *);
@ -157,7 +157,7 @@ List *mply_findByPointerForNode(List*, void *);
*: p_func为一个函数指针, (type)/(value)/(args),
,,,,
expand_resources为一个链表,
*: ,,NULL.*/
*: ,,NULL.*/
extern List *listThrough(List *p_list, List *(*p_func)(unsigned int type, void *value, List *args), List *expand_resources);
/*
@ -186,7 +186,7 @@ unsigned long long getInfoForListThrough(List *expand_resources, int type);
/*
*
*/
unsigned long long calListMemory(List *);
uint64_t calListMemory(List *);
@ -197,7 +197,7 @@ unsigned long long calListMemory(List *);
/*
**/
extern unsigned long long len(List *p_list);
extern uint64_t len(List *p_list);
/*
*
@ -283,5 +283,5 @@ extern Node *findByStringForNode(List *, char *);
*.
*: ,NULL.*/
extern Node *findByPointerForNode(List *, void *);
#endif
#endif

View File

@ -4,11 +4,11 @@
#include <list/list_expand.h>
/************************************************
*
*,
************************************************/
/****
*ID相关
*ID模块相关
*/
/*直接获取一个以整型值初始化的节点不带ID的缩略*/
@ -30,7 +30,7 @@
#define lnp(x) nodeWithPointer(x,0)
/****
*ID相关
*ID模块的相关
*/
/*直接获取一个以整型值初始化的带ID节点的缩略*/

View File

@ -7,10 +7,10 @@
@param p_list
@return
*/
unsigned long long calListMemory(List * p_list){
uint64_t calListMemory(List * p_list){
Node *p_node = p_list->head;
unsigned long long nodes_size = 0LL;
unsigned long long list_size = sizeof(p_list);
uint64_t nodes_size = 0LL;
uint64_t list_size = sizeof(p_list);
while(p_node != NULL){
nodes_size += sizeof(p_node);
p_node = p_node->next;

View File

@ -3,10 +3,18 @@
#include <list/list_expand.h>
#include <list/list_expand_1.h>
List *listThrough(List *p_list, List *(*p_func)(unsigned int, void *, List *), List *expand_resources) {
/**
-1退1
@param p_list
@param p_func
@return
*/
List *listThrough(List *p_list, List *(*p_func)(uint32_t, void *, List *), List *expand_resources) {
Node *p_node = p_list->head;
List *m_rtnlst = NULL;
unsigned long long index = 0;
uint64_t index = 0;
insertInTail(expand_resources, nodeWithULLInt(index, 0));
insertInTail(expand_resources, nodeWithULLInt(p_list->length, 0));
while (p_node != NULL) {

View File

@ -2,6 +2,14 @@
#include <list/list.h>
#include <list/list_expand.h>
/**
使
@param m_int
@param if_sid id
@return
*/
Node *nodeWithInt(int m_int, _Bool if_sid) {
Node *p_node;
int *p_int = (int *)malloc(sizeof(int));
@ -14,21 +22,37 @@ Node *nodeWithInt(int m_int, _Bool if_sid) {
return p_node;
}
Node *nodeWithUInt(unsigned int m_uint, _Bool if_sid){
/**
使
@param m_uint
@param if_sid id
@return
*/
Node *nodeWithUInt(uint32_t m_uint, _Bool if_sid){
Node *p_node;
unsigned int *pu_int = (unsigned int *)malloc(sizeof(unsigned int));
unsigned int *pu_int = (uint32_t *)malloc(sizeof(uint32_t));
if(pu_int == NULL){
return NULL;
}
*pu_int = m_uint;
p_node = initNode(if_sid);
initMallocValueForNode(p_node, INT, (void *)pu_int);
initMallocValueForNode(p_node, UINT, (void *)pu_int);
return p_node;
}
Node *nodeWithULLInt(unsigned long long m_ullint, _Bool if_sid) {
/**
使8
@param m_ullint
@param if_sid id
@return
*/
Node *nodeWithULLInt(uint64_t m_ullint, _Bool if_sid) {
Node *p_node;
unsigned long long *p_ullint = (unsigned long long *)malloc(sizeof(unsigned long long));
unsigned long long *p_ullint = (uint64_t *)malloc(sizeof(uint64_t));
if(p_ullint == NULL){
return NULL;
}
@ -38,6 +62,14 @@ Node *nodeWithULLInt(unsigned long long m_ullint, _Bool if_sid) {
return p_node;
}
/**
使
@param m_double
@param if_sid id
@return
*/
Node *nodeWithDouble(double m_double, _Bool if_sid) {
Node *p_node;
double *p_double = (double *)malloc(sizeof(double));
@ -50,6 +82,14 @@ Node *nodeWithDouble(double m_double, _Bool if_sid) {
return p_node;
}
/**
使
@param m_string
@param if_sid id
@return
*/
Node *nodeWithString(const char *m_string, _Bool if_sid) {
Node *p_node;
char *p_string = (char *)malloc(sizeof(char)*(strlen(m_string) + 1));
@ -62,6 +102,14 @@ Node *nodeWithString(const char *m_string, _Bool if_sid) {
return p_node;
}
/**
使
@param m_pointer
@param if_sid id
@return
*/
Node *nodeWithPointer(const void *m_pointer, _Bool if_sid) {
Node *p_node = initNode(if_sid);
initMallocValueForNode(p_node, POINTER, m_pointer);

View File

@ -2,6 +2,14 @@
#include <list/list.h>
#include <list/list_expand.h>
/**
@param p_node
@param value
@return 0
*/
int updateValueWithIntForNode(Node *p_node,int value){
int *p_value = (int *)malloc(sizeof(int));
if(p_value == NULL){
@ -13,8 +21,16 @@ int updateValueWithIntForNode(Node *p_node,int value){
return 0;
}
int updateValueWithULLIntForNode(Node *p_node, unsigned long long value){
unsigned long long *p_value = (unsigned long long *)malloc(sizeof(unsigned long long));
/**
8
@param p_node
@param value
@return 0
*/
int updateValueWithULLIntForNode(Node *p_node, uint64_t value){
uint64_t *p_value = (uint64_t *)malloc(sizeof(uint64_t));
if(p_value == NULL){
return -1;
}
@ -24,6 +40,14 @@ int updateValueWithULLIntForNode(Node *p_node, unsigned long long value){
return 0;
}
/**
@param p_node
@param value
@return 0
*/
int updateValueWithDoubleForNode(Node *p_node, double value){
double *p_value = (double *)malloc(sizeof(double));
if(p_value == NULL){
@ -35,6 +59,14 @@ int updateValueWithDoubleForNode(Node *p_node, double value){
return 0;
}
/**
@param p_node
@param string
@return 0
*/
int updateValueWithStringForNode(Node *p_node, char *string){
char *p_value = (char *)malloc(sizeof(strlen(string)) + 1);
if(p_value == NULL){
@ -46,6 +78,14 @@ int updateValueWithStringForNode(Node *p_node, char *string){
return 0;
}
/**
@param p_node
@param pointer
@return 0
*/
int updateValueWithPointerForNode(Node *p_node, void *pointer){
free(p_node->value);
p_node->value = pointer;

View File

@ -1,7 +1,16 @@
#include <type.h>
#include <list/list.h>
//如果ID模块可能启用则编译以下代码
#ifdef id_enable
/**
ID查找链表中符合条件的第一个节点
@param p_list
@param s_id ID值
@return NULL
*/
Node *findByIdForNode(List *p_list, SID * s_id) {
Node *ph_node = p_list->head;
Node *pt_node = p_list->tail;
@ -29,7 +38,16 @@ Node *findByIdForNode(List *p_list, SID * s_id) {
}
#endif
Node *findByValue(List *p_list, unsigned int type, const void *value) {
/**
@param p_list
@param type
@param value
@return NULL
*/
Node *findByValue(List *p_list, uint type, const void *value) {
Node *p_node = p_list->head;
while (p_node != NULL) {
if (p_node->type != type) {
@ -64,6 +82,14 @@ Node *findByValue(List *p_list, unsigned int type, const void *value) {
return NULL;
}
/**
@param p_list
@param type
@param value
@return
*/
List *mply_findByValue(List *p_list, unsigned int type, const void *value) {
List *f_list = initList(0);
Node *p_node = p_list->head;

View File

@ -1,10 +1,23 @@
#include <type.h>
#include <list/list.h>
unsigned long long len(List *p_list) {
/**
@param p_list
@return
*/
uint64_t len(List *p_list) {
return p_list->length;
}
/**
@param p_list
@return 10
*/
int isListEmpty(List *p_list) {
if (p_list->head == NULL || p_list->tail == NULL)// If its head or tail is NULL,it would be thought as empty.
return 1; // But we should ensure that both of them are NULL when we

View File

@ -1,12 +1,25 @@
#include <type.h>
#include <list/list.h>
Node *initNode(_Bool if_sid) {
/**
@param if_sid ID
@return
*/
#ifdef id_enable
Node *initNode(_Bool if_sid)
#else
Node *initNode(void)
#endif
{
Node *p_node = (Node *)malloc(sizeof(Node));
if(p_node == NULL){
return NULL;
}
Node *prec_node = NULL;
//如果ID模块可能启用则编译以下代码
#ifdef id_enable
if (if_sid)p_node->s_id = getS_id(LIST_NODE, 1);
else p_node->s_id = NULL;
@ -15,6 +28,7 @@ Node *initNode(_Bool if_sid) {
p_node->last = NULL;
p_node->type = VOID;
p_node->f_number = 0;
// 链表内存安全模式相关操作
if (if_safeModeForNode) {
if_safeModeForNode = 0;
prec_node = initNode(0);
@ -25,12 +39,24 @@ Node *initNode(_Bool if_sid) {
return p_node;
}
List *initList(_Bool if_sid) {
/**
@param if_sid ID
@return
*/
#ifdef id_enable
List *initList(_Bool if_sid)
#else
List *initList(void)
#endif
{
Node *p_node = NULL;
List *p_list = (List *)malloc(sizeof(List));
if(p_list == NULL){
return NULL;
}
//如果ID模块可能启用则编译以下代码
#ifdef id_enable
if(if_sid) p_list->s_id = getS_id(LIST, 1);
else p_list->s_id = NULL;
@ -39,6 +65,7 @@ List *initList(_Bool if_sid) {
p_list->tail = NULL;
p_list->length = 0;
p_list->p_lq = NULL;
// 如果简单链表模式启用则编译以下代码
#ifdef list_simple_h
p_list->s_head = NULL;
#endif
@ -52,6 +79,14 @@ List *initList(_Bool if_sid) {
return p_list;
}
/**
@param p_node
@param type
@param p_value
@return 0
*/
inline int initMallocValueForNode(Node *p_node, unsigned int type, const void *p_value) {
p_node->type = type;
p_node->value = (void *)p_value;

View File

@ -9,10 +9,10 @@
*: .
*: type指明相关值的类型;value为指向储存相关值的内存的指针.
*: 0,-1.*/
static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node));
static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node *f_node, Node *s_node));
/**
@param p_list
@param begin
@ -20,7 +20,7 @@ static int sortList(List *p_list, unsigned long long begin, unsigned long long e
@param func
@return 0
*/
static int sortList(List *p_list, unsigned long long begin, unsigned long long end, int(*func)(Node *f_node, Node *s_node)){
static int sortList(List *p_list, uint64_t begin, uint64_t end, int(*func)(Node *f_node, Node *s_node)){
unsigned long long target_index = begin;
register Node *t_node = findByIndexForNode(p_list, target_index);
register Node *i_node = NULL, *j_node = NULL;