[init]: init tensor repo one file header
This commit is contained in:
@@ -0,0 +1,2 @@
|
||||
**.swp
|
||||
**is_good*
|
||||
Symlink
+1
@@ -0,0 +1 @@
|
||||
../../onefileheader_test/y_test_h.h
|
||||
@@ -0,0 +1,56 @@
|
||||
# file list_t/Makefile
|
||||
CC=gcc
|
||||
ROOTPROJECTDIR:=$(realpath ..)
|
||||
TOOLDIR=$(ROOTPROJECTDIR)/ytools_t
|
||||
|
||||
INCLUDE_DIR=$(TOOLDIR)/include
|
||||
CFLAGS=-I$(INCLUDE_DIR) -I./src
|
||||
|
||||
#SRC_DIR=$(ROOT_DIR)/src
|
||||
#SRC=$(wildcard */*/*.c)
|
||||
#HEADS=$(OBJS:.o=.h)
|
||||
|
||||
LISTSRC=src/list_t/list_t.c
|
||||
LISTSRC_O=$(LISTSRC:.c=.o)
|
||||
|
||||
SETTSRC=src/set_theoric_t/set_theoric_t.c
|
||||
SETTSRC_O=$(SETTSRC:.c=.o)
|
||||
|
||||
|
||||
TOOLSRC_O=$(TOOLDIR)/src/tools_t/tools_t.o
|
||||
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||
#TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||
|
||||
SRC=$(wildcard **/**/*.c)
|
||||
OBJ=$(SRC:.c=.o) #$(TOOLSRC_O)
|
||||
|
||||
TOPTARGETS := all clean
|
||||
DEP=$(TOOLDIR)
|
||||
|
||||
$(TOPTARGETS): $(DEP)
|
||||
|
||||
all: $(LISTSRC_O)
|
||||
|
||||
|
||||
$(LISTSRC_O): $(LISTSRC) $(TOOLSRC_O)
|
||||
$(CC) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
#$(SETTSRC_O) : $(SETTSRC) $(TOOLSRC_O)
|
||||
# $(CC) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
$(DEP):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||
|
||||
#$(TOOLSRC_O): $(TOOLSRC)
|
||||
# $(CC) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
rm -f $(EXEC)
|
||||
|
||||
run: $(EXEC)
|
||||
$(EXEC) -h
|
||||
+438
@@ -0,0 +1,438 @@
|
||||
#ifndef __LIST_T_H__
|
||||
#define __LIST_T_H__
|
||||
|
||||
#include <omp.h>
|
||||
|
||||
//#include <pthread.h>
|
||||
|
||||
|
||||
#define TYPE_PTR void*
|
||||
|
||||
#define CREATE_HEADER_LIST(type)\
|
||||
struct list_##type {\
|
||||
type value;\
|
||||
size_t index;\
|
||||
struct list_##type *preview;\
|
||||
struct list_##type *next;\
|
||||
};\
|
||||
struct main_list_##type {\
|
||||
struct list_##type *begin_list;\
|
||||
struct list_##type *current_list;\
|
||||
size_t current_index;\
|
||||
struct list_##type *end_list;\
|
||||
size_t size;\
|
||||
};\
|
||||
struct main_list_##type *create_var_list_##type();\
|
||||
void push_back_list_##type(struct main_list_##type *var_list, type value);\
|
||||
void push_front_list_##type(struct main_list_##type *var_list, type value);\
|
||||
size_t move_current_to_index_list_##type(struct main_list_##type *var_list, size_t index, struct list_##type **list_in_index);\
|
||||
size_t move_current_to_begin_list_##type(struct main_list_##type *var_list);\
|
||||
size_t move_current_to_end_list_##type(struct main_list_##type *var_list);\
|
||||
size_t insert_into_list_##type(struct main_list_##type *var_list, size_t index, type value );\
|
||||
void remove_index_from_list_##type(struct main_list_##type *var_list, size_t index );\
|
||||
struct list_##type* pull_index_from_list_##type(struct main_list_##type *var_list, size_t index );\
|
||||
void free_all_var_list_##type(struct main_list_##type *var_list);\
|
||||
void remove_all_list_in_##type(struct main_list_##type *var_list);\
|
||||
void increment_list_##type(struct main_list_##type * var_list);\
|
||||
void decrement_list_##type(struct main_list_##type * var_list);\
|
||||
struct list_##type * search_first_occ_with_mov_from_curr_in_list_##type(struct main_list_##type *var_list, \
|
||||
type value, int (*funcCmp)(type, type), struct list_##type * (*incr_or_decr_mov)(struct list_##type *));\
|
||||
struct list_##type * search_first_occ_from_begin_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type));\
|
||||
struct list_##type * search_first_occ_from_end_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type));\
|
||||
struct list_##type * pull_end_from_list_##type(struct main_list_##type *var_list);\
|
||||
struct list_##type * pull_begin_from_list_##type(struct main_list_##type *var_list);\
|
||||
void append_list_##type(struct main_list_##type *var_list, struct list_##type *list);\
|
||||
struct list_##type * local_increment_list_##type(struct list_##type *list);\
|
||||
struct list_##type * local_decrement_list_##type(struct list_##type *list);\
|
||||
|
||||
|
||||
#if 0
|
||||
|
||||
GENERATE_LIST_ALL(TYPE_CHAR)
|
||||
GENERATE_LIST_ALL(TYPE_U_CHAR)
|
||||
GENERATE_LIST_ALL(TYPE_INT)
|
||||
GENERATE_LIST_ALL(TYPE_U_INT)
|
||||
GENERATE_LIST_ALL(TYPE_L_INT)
|
||||
GENERATE_LIST_ALL(TYPE_U_L_INT)
|
||||
GENERATE_LIST_ALL(TYPE_SIZE_T)
|
||||
GENERATE_LIST_ALL(TYPE_FLOAT)
|
||||
GENERATE_LIST_ALL(TYPE_DOUBLE)
|
||||
GENERATE_LIST_ALL(TYPE_L_DOUBLE)
|
||||
GENERATE_LIST_ALL(TYPE_STRING)
|
||||
|
||||
GENERATE_LIST_ALL(TYPE_PTR)
|
||||
|
||||
#endif
|
||||
|
||||
#define FOR_LIST_FORM_BEGIN(type, var_list)\
|
||||
for(move_current_to_begin_list_##type(var_list); var_list->current_list; increment_list_##type(var_list))
|
||||
|
||||
#define FOR_LIST_FORM_END(type, var_list)\
|
||||
for(move_current_to_end_list_##type(var_list); var_list->current_list; decrement_list_##type(var_list))
|
||||
|
||||
|
||||
#define IMPLEMENTATION_LIST(type)\
|
||||
\
|
||||
struct main_list_##type *create_var_list_##type(){\
|
||||
struct main_list_##type *ret_var_list = malloc(sizeof(struct main_list_##type));\
|
||||
ret_var_list->begin_list = NULL;\
|
||||
ret_var_list->end_list = NULL;\
|
||||
ret_var_list->current_list = NULL;\
|
||||
ret_var_list->current_index = 0;\
|
||||
ret_var_list->size = 0;\
|
||||
return ret_var_list;\
|
||||
}\
|
||||
void push_back_list_##type(struct main_list_##type *var_list, type value){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
list_to_add->value = value;\
|
||||
list_to_add->index = var_list->size;\
|
||||
list_to_add->preview = var_list->end_list;\
|
||||
list_to_add->next = NULL;\
|
||||
if(var_list->end_list){\
|
||||
(var_list->end_list)->next = list_to_add;\
|
||||
}else {\
|
||||
var_list->begin_list = list_to_add;\
|
||||
var_list->current_list= list_to_add;\
|
||||
var_list->current_index=0;\
|
||||
}\
|
||||
var_list->end_list = list_to_add;\
|
||||
++(var_list->size);\
|
||||
}\
|
||||
void push_front_list_##type(struct main_list_##type *var_list, type value){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
list_to_add->value = value;\
|
||||
list_to_add->preview = NULL;\
|
||||
list_to_add->next = var_list->begin_list;\
|
||||
if(var_list->begin_list){\
|
||||
(var_list->begin_list)->preview = list_to_add;\
|
||||
++(var_list->current_index);\
|
||||
}else {\
|
||||
var_list->end_list = list_to_add;\
|
||||
var_list->current_list= list_to_add;\
|
||||
var_list->current_index=0;\
|
||||
}\
|
||||
var_list->begin_list = list_to_add;\
|
||||
++(var_list->size);\
|
||||
size_t index=0;\
|
||||
while(list_to_add){\
|
||||
list_to_add->index = index++;\
|
||||
list_to_add = list_to_add->next;\
|
||||
}\
|
||||
}\
|
||||
size_t move_current_to_index_list_##type(struct main_list_##type *var_list, size_t index, struct list_##type **list_in_index){\
|
||||
if(var_list->current_list==NULL) {;\
|
||||
if(index <= var_list->size - 1 - index){\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
}else{\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
}\
|
||||
}\
|
||||
if(index == var_list->current_list->index){\
|
||||
if(list_in_index) *list_in_index = var_list->current_list;\
|
||||
return index;\
|
||||
}\
|
||||
if(var_list->begin_list == NULL){\
|
||||
if(list_in_index) *list_in_index=NULL;\
|
||||
return 0;\
|
||||
}\
|
||||
if(index >= var_list->size){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
var_list->current_index = var_list->size - 1;\
|
||||
if(list_in_index) *list_in_index = var_list->current_list;\
|
||||
return var_list->current_list->index /*size - 1*/;\
|
||||
}\
|
||||
/*if((var_list->current_list->index >= var_list->size) || !(var_list->current_list)){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
var_list->current_index = var_list->size - 1;\
|
||||
}*/\
|
||||
long from_current_index = var_list->current_list->index - index; \
|
||||
size_t abs_cur_diff = abs(from_current_index); \
|
||||
size_t array_diff_index[3] = {index, abs_cur_diff , var_list->size - 1 - index}; \
|
||||
size_t index_nearest = ARG_MIN_ARRAY_TYPE_SIZE_T(array_diff_index, 3);\
|
||||
if(index_nearest == 0){\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
for(size_t i=0; i<array_diff_index[0]; ++i) var_list->current_list = (var_list->current_list)->next; \
|
||||
}\
|
||||
else if(index_nearest == 2){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
for(size_t i=0; i < array_diff_index[2]; ++i) var_list->current_list = (var_list->current_list)->preview; \
|
||||
}else if(from_current_index >= 0) \
|
||||
for(size_t i=0; i < array_diff_index[1]; ++i) var_list->current_list = (var_list->current_list)->preview; \
|
||||
else \
|
||||
for(size_t i=0; i < array_diff_index[1]; ++i) var_list->current_list = (var_list->current_list)->next; \
|
||||
\
|
||||
var_list->current_index = index;\
|
||||
if(list_in_index) *list_in_index = var_list->current_list;\
|
||||
return index;\
|
||||
}\
|
||||
size_t move_current_to_begin_list_##type(struct main_list_##type *var_list){\
|
||||
if(var_list->begin_list == NULL){\
|
||||
return 0;\
|
||||
}\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
var_list->current_index = 0;\
|
||||
return 0;\
|
||||
}\
|
||||
size_t move_current_to_end_list_##type(struct main_list_##type *var_list){\
|
||||
if(var_list->end_list == NULL){\
|
||||
return 0;\
|
||||
}\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
var_list->current_index = var_list->size - 1;\
|
||||
return var_list->current_index;\
|
||||
}\
|
||||
size_t insert_into_list_##type(struct main_list_##type *var_list, size_t index, type value ){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
size_t ii=0;\
|
||||
list_to_add->value = value;\
|
||||
if(var_list->begin_list == NULL){\
|
||||
list_to_add->preview = NULL;\
|
||||
list_to_add->next = NULL;\
|
||||
var_list->begin_list = list_to_add;\
|
||||
var_list->end_list = list_to_add;\
|
||||
var_list->current_list = list_to_add;\
|
||||
var_list->current_index = 0;\
|
||||
\
|
||||
}else {\
|
||||
struct list_##type *current_list;\
|
||||
ii = move_current_to_index_list_##type(var_list, index, ¤t_list);\
|
||||
if(index > ii)\
|
||||
printf("%ld out of range, we put the value at %ld index of the list \n",index, ii);\
|
||||
if(current_list){\
|
||||
struct list_##type *prev_list = (current_list)->preview;\
|
||||
list_to_add->preview = prev_list;\
|
||||
list_to_add->next = current_list;\
|
||||
if(list_to_add->preview == NULL){\
|
||||
var_list->begin_list = list_to_add;\
|
||||
}else\
|
||||
prev_list->next = list_to_add;\
|
||||
if(list_to_add->next == NULL)\
|
||||
var_list->end_list = list_to_add;\
|
||||
(current_list)->preview = list_to_add;\
|
||||
var_list->current_list = list_to_add;\
|
||||
var_list->current_index = ii;\
|
||||
}\
|
||||
}\
|
||||
++(var_list->size);\
|
||||
size_t local_ii = ii;\
|
||||
while(list_to_add){\
|
||||
list_to_add->index = local_ii++;\
|
||||
list_to_add = list_to_add->next;\
|
||||
}\
|
||||
return ii;\
|
||||
}\
|
||||
void remove_index_from_list_##type(struct main_list_##type *var_list, size_t index ){\
|
||||
struct list_##type *current_list;\
|
||||
if( index == move_current_to_index_list_##type(var_list, index, ¤t_list)) {\
|
||||
struct list_##type * list_tmp_prev = (current_list)->preview;\
|
||||
struct list_##type * list_tmp_next = (current_list)->next;\
|
||||
if(list_tmp_prev){\
|
||||
list_tmp_prev->next = list_tmp_next;\
|
||||
if(list_tmp_next){\
|
||||
list_tmp_next->preview = list_tmp_prev;\
|
||||
var_list->current_list = list_tmp_next;\
|
||||
}\
|
||||
else {\
|
||||
var_list->end_list = list_tmp_prev;\
|
||||
var_list->current_list = list_tmp_prev;\
|
||||
}\
|
||||
}else{\
|
||||
var_list->begin_list = list_tmp_next;\
|
||||
if(list_tmp_next) {\
|
||||
list_tmp_next->preview = list_tmp_prev;\
|
||||
}\
|
||||
else{\
|
||||
var_list->end_list = NULL;\
|
||||
var_list->current_list = NULL;\
|
||||
}\
|
||||
}\
|
||||
free(current_list);\
|
||||
--(var_list->size);\
|
||||
while(list_tmp_next){\
|
||||
list_tmp_next->index = index++;\
|
||||
list_tmp_next=list_tmp_next->next;\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
struct list_##type * pull_index_from_list_##type(struct main_list_##type *var_list, size_t index ){\
|
||||
struct list_##type *current_list=NULL;\
|
||||
if( index == move_current_to_index_list_##type(var_list, index, ¤t_list)) {\
|
||||
struct list_##type * list_tmp_prev = (current_list)->preview;\
|
||||
struct list_##type * list_tmp_next = (current_list)->next;\
|
||||
if(list_tmp_prev){\
|
||||
list_tmp_prev->next = list_tmp_next;\
|
||||
if(list_tmp_next){\
|
||||
list_tmp_next->preview = list_tmp_prev;\
|
||||
var_list->current_list = list_tmp_next;\
|
||||
}\
|
||||
else {\
|
||||
var_list->end_list = list_tmp_prev;\
|
||||
var_list->current_list = list_tmp_prev;\
|
||||
}\
|
||||
}else{\
|
||||
var_list->begin_list = list_tmp_next;\
|
||||
if(list_tmp_next) {\
|
||||
list_tmp_next->preview = list_tmp_prev;\
|
||||
}\
|
||||
else{\
|
||||
var_list->end_list = NULL;\
|
||||
var_list->current_list = NULL;\
|
||||
}\
|
||||
}\
|
||||
--(var_list->size);\
|
||||
while(list_tmp_next){\
|
||||
list_tmp_next->index = index++;\
|
||||
list_tmp_next=list_tmp_next->next;\
|
||||
}\
|
||||
}\
|
||||
return current_list;\
|
||||
}\
|
||||
void remove_all_list_in_##type(struct main_list_##type *var_list){\
|
||||
struct list_##type *tmp = var_list->begin_list, *prec_tmp;\
|
||||
while(tmp){\
|
||||
prec_tmp = tmp;\
|
||||
tmp = tmp->next;\
|
||||
free(prec_tmp);\
|
||||
}\
|
||||
var_list->begin_list = NULL;\
|
||||
var_list->current_list = NULL;\
|
||||
var_list->end_list = NULL;\
|
||||
var_list->size = 0;\
|
||||
var_list->current_index = 0;\
|
||||
}\
|
||||
void free_all_var_list_##type(struct main_list_##type *var_list){\
|
||||
remove_all_list_in_##type(var_list);\
|
||||
free(var_list);\
|
||||
}\
|
||||
void increment_list_##type(struct main_list_##type * var_list){\
|
||||
var_list->current_list = (var_list->current_list)->next;\
|
||||
++(var_list->current_index);\
|
||||
}\
|
||||
void decrement_list_##type(struct main_list_##type * var_list){\
|
||||
var_list->current_list = (var_list->current_list)->preview;\
|
||||
--(var_list->current_index);\
|
||||
}\
|
||||
struct list_##type * local_increment_list_##type(struct list_##type *list){\
|
||||
if(list) return list->next;\
|
||||
return NULL;\
|
||||
}\
|
||||
struct list_##type * local_decrement_list_##type(struct list_##type *list){\
|
||||
if (list) return list->preview;\
|
||||
return NULL;\
|
||||
}\
|
||||
struct list_##type * search_first_occ_with_mov_from_curr_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type), struct list_##type * (*incr_or_decr_mov)(struct list_##type *)){\
|
||||
for(struct list_##type *list_cur = var_list->current_list; list_cur; list_cur = incr_or_decr_mov(list_cur)){\
|
||||
if(0 == funcCmp(value, list_cur->value)){\
|
||||
return list_cur;\
|
||||
}\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
struct list_##type * search_first_occ_from_begin_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type)){\
|
||||
/*printf("debug: cur_index change to 0");*/\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
return search_first_occ_with_mov_from_curr_in_list_##type(var_list, value, funcCmp, local_increment_list_##type);\
|
||||
}\
|
||||
struct list_##type * search_first_occ_from_end_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type)){\
|
||||
/*printf("debug: cur_index change to end");*/\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
return search_first_occ_with_mov_from_curr_in_list_##type(var_list, value, funcCmp, local_decrement_list_##type);\
|
||||
}\
|
||||
struct list_##type * pull_end_from_list_##type(struct main_list_##type *var_list){\
|
||||
struct list_##type *ret = var_list->end_list;\
|
||||
if(ret != NULL){\
|
||||
struct list_##type * prevL = ret->preview;\
|
||||
if(prevL != NULL){\
|
||||
prevL->next=NULL;\
|
||||
}else{\
|
||||
var_list->begin_list=NULL;\
|
||||
var_list->current_index = 0;\
|
||||
var_list->current_list=NULL;\
|
||||
}\
|
||||
var_list->end_list = prevL;\
|
||||
--(var_list->size);\
|
||||
ret->preview = NULL;\
|
||||
}\
|
||||
return ret;\
|
||||
}\
|
||||
struct list_##type * pull_begin_from_list_##type(struct main_list_##type *var_list){\
|
||||
struct list_##type *ret = var_list->begin_list;\
|
||||
if(ret != NULL){\
|
||||
struct list_##type * nextL = ret->next;\
|
||||
if(nextL != NULL){\
|
||||
nextL->preview=NULL;\
|
||||
}else{\
|
||||
var_list->end_list=NULL;\
|
||||
var_list->current_index = 0;\
|
||||
var_list->current_list=NULL;\
|
||||
}\
|
||||
var_list->begin_list = nextL;\
|
||||
--(var_list->size);\
|
||||
ret->next = NULL;\
|
||||
}\
|
||||
struct list_##type *tmp = var_list->begin_list;\
|
||||
while(tmp){ --(tmp->index); tmp=tmp->next;}\
|
||||
return ret;\
|
||||
}\
|
||||
void append_list_##type(struct main_list_##type *var_list, struct list_##type *list){\
|
||||
list->index = var_list->size;\
|
||||
if(var_list->end_list == NULL){\
|
||||
list->preview = NULL;\
|
||||
var_list->end_list = list;\
|
||||
var_list->begin_list = list;\
|
||||
var_list->current_list = list;\
|
||||
var_list->current_index = 0;\
|
||||
}else{\
|
||||
var_list->end_list->next = list;\
|
||||
list->preview = var_list->end_list;\
|
||||
var_list->end_list = list;\
|
||||
}\
|
||||
++(var_list->size);\
|
||||
}\
|
||||
|
||||
|
||||
#define GEN_HEAD_PTR_LIST(type)\
|
||||
void remove_all_ptr_type_list_##type(struct main_list_##type *var_list);\
|
||||
void purge_ptr_type_list_##type(struct main_list_##type *var_list);\
|
||||
void free_##type(type arg);\
|
||||
|
||||
|
||||
|
||||
#define GEN_FUNC_PTR_LIST_FREE(type)\
|
||||
void remove_all_ptr_type_list_##type(struct main_list_##type *var_list){\
|
||||
struct list_##type *tmp = var_list->begin_list, *prec_tmp;\
|
||||
while(tmp){\
|
||||
prec_tmp = tmp;\
|
||||
tmp = tmp->next;\
|
||||
free_##type(prec_tmp->value);\
|
||||
free(prec_tmp);\
|
||||
}\
|
||||
var_list->begin_list = NULL;\
|
||||
var_list->current_list = NULL;\
|
||||
var_list->end_list = NULL;\
|
||||
var_list->size = 0;\
|
||||
var_list->current_index = 0;\
|
||||
}\
|
||||
void purge_ptr_type_list_##type(struct main_list_##type *var_list){\
|
||||
remove_all_ptr_type_list_##type(var_list);\
|
||||
free(var_list);\
|
||||
}\
|
||||
\
|
||||
void free_##type(type arg)\
|
||||
|
||||
|
||||
#define LIST_T(type) \
|
||||
CREATE_HEADER_LIST(type)\
|
||||
IMPLEMENTATION_LIST(type)
|
||||
|
||||
#define LIST_PTR_T_FREE(type) \
|
||||
CREATE_HEADER_LIST(type)\
|
||||
IMPLEMENTATION_LIST(type)\
|
||||
GEN_HEAD_PTR_LIST(type)\
|
||||
GEN_FUNC_PTR_LIST_FREE(type)
|
||||
|
||||
|
||||
|
||||
|
||||
#endif /* __LIST_T_C__H */
|
||||
|
||||
Executable
+155
@@ -0,0 +1,155 @@
|
||||
|
||||
#include "list_t/list_t.h"
|
||||
|
||||
#if 0
|
||||
|
||||
#define GEN_LIST_ALL_L(type)\
|
||||
\
|
||||
struct main_list_##type *create_var_list_##type(){\
|
||||
struct main_list_##type *ret_var_list = malloc(sizeof(struct main_list_##type));\
|
||||
ret_var_list->begin_list = NULL;\
|
||||
ret_var_list->end_list = NULL;\
|
||||
ret_var_list->current_list = NULL;\
|
||||
ret_var_list->current_index = 0;\
|
||||
ret_var_list->size = 0;\
|
||||
return ret_var_list;\
|
||||
}\
|
||||
void push_back_list_##type(struct main_list_##type *var_list, type value){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
list_to_add->value = value;\
|
||||
list_to_add->preview = var_list->end_list;\
|
||||
list_to_add->next = NULL;\
|
||||
if(var_list->end_list){\
|
||||
(var_list->end_list)->next = list_to_add;\
|
||||
}else {\
|
||||
var_list->begin_list = list_to_add;\
|
||||
var_list->current_list= list_to_add;\
|
||||
}\
|
||||
var_list->end_list = list_to_add;\
|
||||
++(var_list->size);\
|
||||
}\
|
||||
void push_front_list_##type(struct main_list_##type *var_list, type value){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
list_to_add->value = value;\
|
||||
list_to_add->preview = NULL;\
|
||||
list_to_add->next = var_list->begin_list;\
|
||||
if(var_list->begin_list){\
|
||||
(var_list->begin_list)->preview = list_to_add;\
|
||||
++(var_list->current_index);\
|
||||
}else {\
|
||||
var_list->end_list = list_to_add;\
|
||||
var_list->current_list= list_to_add;\
|
||||
}\
|
||||
var_list->begin_list = list_to_add;\
|
||||
++(var_list->size);\
|
||||
}\
|
||||
size_t move_current_to_index_list_##type(struct main_list_##type *var_list, size_t index){\
|
||||
if(index == var_list->current_index) return index;\
|
||||
if(var_list->begin_list == NULL) return 0;\
|
||||
if(index >= var_list->size){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
var_list->current_index = var_list->size - 1;\
|
||||
return var_list->size - 1;\
|
||||
}\
|
||||
if((var_list->current_index >= var_list->size) || !(var_list->current_list)){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
var_list->current_index = var_list->size - 1;\
|
||||
}\
|
||||
long from_current_index = var_list->current_index - index; \
|
||||
size_t abs_cur_diff = abs(from_current_index); \
|
||||
size_t array_diff_index[3] = {index, abs_cur_diff , var_list->size - 1 - index}; \
|
||||
size_t index_nearest = ARG_MIN_ARRAY_TYPE_SIZE_T(array_diff_index, 3);\
|
||||
if(index_nearest == 0){\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
for(size_t i=0; i<array_diff_index[0]; ++i) var_list->current_list = (var_list->current_list)->next; \
|
||||
}\
|
||||
else if(index_nearest == 2){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
for(size_t i=0; i < array_diff_index[0]; ++i) var_list->current_list = (var_list->current_list)->preview; \
|
||||
}else if(from_current_index >= 0) \
|
||||
for(size_t i=0; i < array_diff_index[1]; ++i) var_list->current_list = (var_list->current_list)->preview; \
|
||||
else \
|
||||
for(size_t i=0; i < array_diff_index[1]; ++i) var_list->current_list = (var_list->current_list)->next; \
|
||||
\
|
||||
var_list->current_index = index;\
|
||||
return index;\
|
||||
}\
|
||||
void insert_into_list_##type(struct main_list_##type *var_list, size_t index, type value ){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
list_to_add->value = value;\
|
||||
if(var_list->begin_list == NULL){\
|
||||
list_to_add->preview = NULL;\
|
||||
list_to_add->next = NULL;\
|
||||
var_list->begin_list = list_to_add;\
|
||||
var_list->end_list = list_to_add;\
|
||||
var_list->current_list = list_to_add;\
|
||||
var_list->current_index = 0;\
|
||||
\
|
||||
}else {\
|
||||
size_t ii = move_current_to_index_list_##type(var_list, index);\
|
||||
if(index > ii)\
|
||||
printf("%ld out of range, we put the value at %ld index of the list \n",index, ii);\
|
||||
if(var_list->current_list){\
|
||||
list_to_add->preview = (var_list->current_list)->preview;\
|
||||
list_to_add->next = var_list->current_list;\
|
||||
if(list_to_add->preview)\
|
||||
(list_to_add->preview)->next = list_to_add;\
|
||||
else var_list->begin_list = list_to_add;\
|
||||
(var_list->current_list)->preview = list_to_add;\
|
||||
var_list->current_list = list_to_add;\
|
||||
}\
|
||||
}\
|
||||
++(var_list->size);\
|
||||
}\
|
||||
void remove_index_from_list_##type(struct main_list_##type *var_list, size_t index ){\
|
||||
if( index == move_current_to_index_list_##type(var_list, index)) {\
|
||||
struct list_##type * list_tmp_prev = (var_list->current_list)->preview;\
|
||||
struct list_##type * list_tmp_next = (var_list->current_list)->next;\
|
||||
if(list_tmp_prev){\
|
||||
list_tmp_prev->next = list_tmp_next;\
|
||||
if(list_tmp_next) list_tmp_next->preview = list_tmp_prev;\
|
||||
}\
|
||||
free(var_list->current_list);\
|
||||
var_list->current_list = list_tmp_next;\
|
||||
--(var_list->size);\
|
||||
\
|
||||
}\
|
||||
}\
|
||||
void free_all_var_list_##type(struct main_list_##type *var_list){\
|
||||
struct list_##type *tmp = var_list->begin_list;\
|
||||
while(tmp){\
|
||||
var_list->current_list = tmp;\
|
||||
tmp = tmp->next;\
|
||||
free(var_list->current_list);\
|
||||
}\
|
||||
free(var_list);\
|
||||
}\
|
||||
void increment_list_##type(struct main_list_##type * var_list){\
|
||||
var_list->current_list = (var_list->current_list)->next;\
|
||||
++(var_list->current_index);\
|
||||
}\
|
||||
void decrement_list_##type(struct main_list_##type * var_list){\
|
||||
var_list->current_list = (var_list->current_list)->preview;\
|
||||
--(var_list->current_index);\
|
||||
}\
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
GEN_LIST_ALL(TYPE_CHAR)
|
||||
GEN_LIST_ALL(TYPE_U_CHAR)
|
||||
GEN_LIST_ALL(TYPE_INT)
|
||||
GEN_LIST_ALL(TYPE_U_INT)
|
||||
GEN_LIST_ALL(TYPE_L_INT)
|
||||
GEN_LIST_ALL(TYPE_U_L_INT)
|
||||
GEN_LIST_ALL(TYPE_SIZE_T)
|
||||
GEN_LIST_ALL(TYPE_FLOAT)
|
||||
GEN_LIST_ALL(TYPE_DOUBLE)
|
||||
GEN_LIST_ALL(TYPE_L_DOUBLE)
|
||||
GEN_LIST_ALL(TYPE_STRING)
|
||||
|
||||
GEN_LIST_ALL(TYPE_PTR)
|
||||
|
||||
GEN_FUNC_PTR_LIST_FREE(TYPE_PTR){
|
||||
free(arg);
|
||||
}
|
||||
@@ -0,0 +1,478 @@
|
||||
#ifndef __LIST_T_C__H
|
||||
#define __LIST_T_C__H
|
||||
|
||||
#include <pthread.h>
|
||||
|
||||
#include "tools_t/tools_t.h"
|
||||
|
||||
#define TYPE_PTR void*
|
||||
|
||||
#define GENERATE_LIST_ALL(type)\
|
||||
struct list_##type {\
|
||||
type value;\
|
||||
size_t index;\
|
||||
struct list_##type *preview;\
|
||||
struct list_##type *next;\
|
||||
};\
|
||||
struct main_list_##type {\
|
||||
struct list_##type *begin_list;\
|
||||
struct list_##type *current_list;\
|
||||
size_t current_index;\
|
||||
struct list_##type *end_list;\
|
||||
size_t size;\
|
||||
pthread_mutex_t *mut_list;\
|
||||
};\
|
||||
struct main_list_##type *create_var_list_##type();\
|
||||
void push_back_list_##type(struct main_list_##type *var_list, type value);\
|
||||
void push_front_list_##type(struct main_list_##type *var_list, type value);\
|
||||
size_t move_current_to_index_list_##type(struct main_list_##type *var_list, size_t index, struct list_##type **list_in_index);\
|
||||
size_t move_current_to_begin_list_##type(struct main_list_##type *var_list);\
|
||||
size_t move_current_to_end_list_##type(struct main_list_##type *var_list);\
|
||||
size_t insert_into_list_##type(struct main_list_##type *var_list, size_t index, type value );\
|
||||
void remove_index_from_list_##type(struct main_list_##type *var_list, size_t index );\
|
||||
struct list_##type* pull_index_from_list_##type(struct main_list_##type *var_list, size_t index );\
|
||||
void free_all_var_list_##type(struct main_list_##type *var_list);\
|
||||
void remove_all_list_in_##type(struct main_list_##type *var_list);\
|
||||
void increment_list_##type(struct main_list_##type * var_list);\
|
||||
void decrement_list_##type(struct main_list_##type * var_list);\
|
||||
struct list_##type * search_first_occ_with_mov_from_curr_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type), struct list_##type * (*incr_or_decr_mov)(struct list_##type *));\
|
||||
struct list_##type * search_first_occ_from_begin_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type));\
|
||||
struct list_##type * search_first_occ_from_end_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type));\
|
||||
struct list_##type * pull_end_from_list_##type(struct main_list_##type *var_list);\
|
||||
struct list_##type * pull_begin_from_list_##type(struct main_list_##type *var_list);\
|
||||
void append_list_##type(struct main_list_##type *var_list, struct list_##type *list);\
|
||||
struct list_##type * local_increment_list_##type(struct list_##type *list);\
|
||||
struct list_##type * local_decrement_list_##type(struct list_##type *list);\
|
||||
|
||||
|
||||
GENERATE_LIST_ALL(TYPE_CHAR)
|
||||
GENERATE_LIST_ALL(TYPE_U_CHAR)
|
||||
GENERATE_LIST_ALL(TYPE_INT)
|
||||
GENERATE_LIST_ALL(TYPE_U_INT)
|
||||
GENERATE_LIST_ALL(TYPE_L_INT)
|
||||
GENERATE_LIST_ALL(TYPE_U_L_INT)
|
||||
GENERATE_LIST_ALL(TYPE_SIZE_T)
|
||||
GENERATE_LIST_ALL(TYPE_FLOAT)
|
||||
GENERATE_LIST_ALL(TYPE_DOUBLE)
|
||||
GENERATE_LIST_ALL(TYPE_L_DOUBLE)
|
||||
GENERATE_LIST_ALL(TYPE_STRING)
|
||||
|
||||
GENERATE_LIST_ALL(TYPE_PTR)
|
||||
|
||||
#define FOR_LIST_FORM_BEGIN(type, var_list)\
|
||||
for(move_current_to_begin_list_##type(var_list); var_list->current_list; increment_list_##type(var_list))
|
||||
|
||||
#define FOR_LIST_FORM_END(type, var_list)\
|
||||
for(move_current_to_end_list_##type(var_list); var_list->current_list; decrement_list_##type(var_list))
|
||||
|
||||
|
||||
#define GEN_LIST_ALL(type)\
|
||||
\
|
||||
struct main_list_##type *create_var_list_##type(){\
|
||||
struct main_list_##type *ret_var_list = malloc(sizeof(struct main_list_##type));\
|
||||
ret_var_list->begin_list = NULL;\
|
||||
ret_var_list->end_list = NULL;\
|
||||
ret_var_list->current_list = NULL;\
|
||||
ret_var_list->current_index = 0;\
|
||||
ret_var_list->size = 0;\
|
||||
ret_var_list->mut_list = malloc(sizeof(pthread_mutex_t));\
|
||||
pthread_mutex_init(ret_var_list->mut_list, NULL);\
|
||||
return ret_var_list;\
|
||||
}\
|
||||
void push_back_list_##type(struct main_list_##type *var_list, type value){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
list_to_add->value = value;\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
list_to_add->index = var_list->size;\
|
||||
list_to_add->preview = var_list->end_list;\
|
||||
list_to_add->next = NULL;\
|
||||
if(var_list->end_list){\
|
||||
(var_list->end_list)->next = list_to_add;\
|
||||
}else {\
|
||||
var_list->begin_list = list_to_add;\
|
||||
var_list->current_list= list_to_add;\
|
||||
var_list->current_index=0;\
|
||||
}\
|
||||
var_list->end_list = list_to_add;\
|
||||
++(var_list->size);\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
void push_front_list_##type(struct main_list_##type *var_list, type value){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
list_to_add->value = value;\
|
||||
list_to_add->preview = NULL;\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
list_to_add->next = var_list->begin_list;\
|
||||
if(var_list->begin_list){\
|
||||
(var_list->begin_list)->preview = list_to_add;\
|
||||
++(var_list->current_index);\
|
||||
}else {\
|
||||
var_list->end_list = list_to_add;\
|
||||
var_list->current_list= list_to_add;\
|
||||
var_list->current_index=0;\
|
||||
}\
|
||||
var_list->begin_list = list_to_add;\
|
||||
++(var_list->size);\
|
||||
size_t index=0;\
|
||||
while(list_to_add){\
|
||||
list_to_add->index = index++;\
|
||||
list_to_add = list_to_add->next;\
|
||||
}\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
size_t move_current_to_index_list_##type(struct main_list_##type *var_list, size_t index, struct list_##type **list_in_index){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
if(var_list->current_list==NULL) {;\
|
||||
if(index <= var_list->size - 1 - index){\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
}else{\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
}\
|
||||
}\
|
||||
if(index == var_list->current_list->index){\
|
||||
if(list_in_index) *list_in_index = var_list->current_list;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return index;\
|
||||
}\
|
||||
if(var_list->begin_list == NULL){\
|
||||
if(list_in_index) *list_in_index=NULL;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return 0;\
|
||||
}\
|
||||
if(index >= var_list->size){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
var_list->current_index = var_list->size - 1;\
|
||||
if(list_in_index) *list_in_index = var_list->current_list;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return var_list->current_list->index /*size - 1*/;\
|
||||
}\
|
||||
/*if((var_list->current_list->index >= var_list->size) || !(var_list->current_list)){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
var_list->current_index = var_list->size - 1;\
|
||||
}*/\
|
||||
long from_current_index = var_list->current_list->index - index; \
|
||||
size_t abs_cur_diff = abs(from_current_index); \
|
||||
size_t array_diff_index[3] = {index, abs_cur_diff , var_list->size - 1 - index}; \
|
||||
size_t index_nearest = ARG_MIN_ARRAY_TYPE_SIZE_T(array_diff_index, 3);\
|
||||
if(index_nearest == 0){\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
for(size_t i=0; i<array_diff_index[0]; ++i) var_list->current_list = (var_list->current_list)->next; \
|
||||
}\
|
||||
else if(index_nearest == 2){\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
for(size_t i=0; i < array_diff_index[2]; ++i) var_list->current_list = (var_list->current_list)->preview; \
|
||||
}else if(from_current_index >= 0) \
|
||||
for(size_t i=0; i < array_diff_index[1]; ++i) var_list->current_list = (var_list->current_list)->preview; \
|
||||
else \
|
||||
for(size_t i=0; i < array_diff_index[1]; ++i) var_list->current_list = (var_list->current_list)->next; \
|
||||
\
|
||||
var_list->current_index = index;\
|
||||
if(list_in_index) *list_in_index = var_list->current_list;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return index;\
|
||||
}\
|
||||
size_t move_current_to_begin_list_##type(struct main_list_##type *var_list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
if(var_list->begin_list == NULL){\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return 0;\
|
||||
}\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
var_list->current_index = 0;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return 0;\
|
||||
}\
|
||||
size_t move_current_to_end_list_##type(struct main_list_##type *var_list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
if(var_list->end_list == NULL){\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return 0;\
|
||||
}\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
var_list->current_index = var_list->size - 1;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return var_list->current_index;\
|
||||
}\
|
||||
size_t insert_into_list_##type(struct main_list_##type *var_list, size_t index, type value ){\
|
||||
struct list_##type * list_to_add = malloc(sizeof(struct list_##type));\
|
||||
size_t ii=0;\
|
||||
list_to_add->value = value;\
|
||||
if(var_list->begin_list == NULL){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
list_to_add->preview = NULL;\
|
||||
list_to_add->next = NULL;\
|
||||
var_list->begin_list = list_to_add;\
|
||||
var_list->end_list = list_to_add;\
|
||||
var_list->current_list = list_to_add;\
|
||||
var_list->current_index = 0;\
|
||||
\
|
||||
}else {\
|
||||
struct list_##type *current_list;\
|
||||
ii = move_current_to_index_list_##type(var_list, index, ¤t_list);\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
if(index > ii)\
|
||||
printf("%ld out of range, we put the value at %ld index of the list \n",index, ii);\
|
||||
if(current_list){\
|
||||
struct list_##type *prev_list = (current_list)->preview;\
|
||||
list_to_add->preview = prev_list;\
|
||||
list_to_add->next = current_list;\
|
||||
if(list_to_add->preview == NULL){\
|
||||
var_list->begin_list = list_to_add;\
|
||||
}else\
|
||||
prev_list->next = list_to_add;\
|
||||
if(list_to_add->next == NULL)\
|
||||
var_list->end_list = list_to_add;\
|
||||
(current_list)->preview = list_to_add;\
|
||||
var_list->current_list = list_to_add;\
|
||||
var_list->current_index = ii;\
|
||||
}\
|
||||
}\
|
||||
++(var_list->size);\
|
||||
size_t local_ii = ii;\
|
||||
while(list_to_add){\
|
||||
list_to_add->index = local_ii++;\
|
||||
list_to_add = list_to_add->next;\
|
||||
}\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return ii;\
|
||||
}\
|
||||
void remove_index_from_list_##type(struct main_list_##type *var_list, size_t index ){\
|
||||
struct list_##type *current_list;\
|
||||
if( index == move_current_to_index_list_##type(var_list, index, ¤t_list)) {\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
struct list_##type * list_tmp_prev = (current_list)->preview;\
|
||||
struct list_##type * list_tmp_next = (current_list)->next;\
|
||||
if(list_tmp_prev){\
|
||||
list_tmp_prev->next = list_tmp_next;\
|
||||
if(list_tmp_next){\
|
||||
list_tmp_next->preview = list_tmp_prev;\
|
||||
var_list->current_list = list_tmp_next;\
|
||||
}\
|
||||
else {\
|
||||
var_list->end_list = list_tmp_prev;\
|
||||
var_list->current_list = list_tmp_prev;\
|
||||
}\
|
||||
}else{\
|
||||
var_list->begin_list = list_tmp_next;\
|
||||
if(list_tmp_next) {\
|
||||
list_tmp_next->preview = list_tmp_prev;\
|
||||
}\
|
||||
else{\
|
||||
var_list->end_list = NULL;\
|
||||
var_list->current_list = NULL;\
|
||||
}\
|
||||
}\
|
||||
free(current_list);\
|
||||
--(var_list->size);\
|
||||
while(list_tmp_next){\
|
||||
list_tmp_next->index = index++;\
|
||||
list_tmp_next=list_tmp_next->next;\
|
||||
}\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
}\
|
||||
struct list_##type * pull_index_from_list_##type(struct main_list_##type *var_list, size_t index ){\
|
||||
struct list_##type *current_list=NULL;\
|
||||
if( index == move_current_to_index_list_##type(var_list, index, ¤t_list)) {\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
struct list_##type * list_tmp_prev = (current_list)->preview;\
|
||||
struct list_##type * list_tmp_next = (current_list)->next;\
|
||||
if(list_tmp_prev){\
|
||||
list_tmp_prev->next = list_tmp_next;\
|
||||
if(list_tmp_next){\
|
||||
list_tmp_next->preview = list_tmp_prev;\
|
||||
var_list->current_list = list_tmp_next;\
|
||||
}\
|
||||
else {\
|
||||
var_list->end_list = list_tmp_prev;\
|
||||
var_list->current_list = list_tmp_prev;\
|
||||
}\
|
||||
}else{\
|
||||
var_list->begin_list = list_tmp_next;\
|
||||
if(list_tmp_next) {\
|
||||
list_tmp_next->preview = list_tmp_prev;\
|
||||
}\
|
||||
else{\
|
||||
var_list->end_list = NULL;\
|
||||
var_list->current_list = NULL;\
|
||||
}\
|
||||
}\
|
||||
--(var_list->size);\
|
||||
while(list_tmp_next){\
|
||||
list_tmp_next->index = index++;\
|
||||
list_tmp_next=list_tmp_next->next;\
|
||||
}\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
return current_list;\
|
||||
}\
|
||||
void remove_all_list_in_##type(struct main_list_##type *var_list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
struct list_##type *tmp = var_list->begin_list, *prec_tmp;\
|
||||
while(tmp){\
|
||||
prec_tmp = tmp;\
|
||||
tmp = tmp->next;\
|
||||
free(prec_tmp);\
|
||||
}\
|
||||
var_list->begin_list = NULL;\
|
||||
var_list->current_list = NULL;\
|
||||
var_list->end_list = NULL;\
|
||||
var_list->size = 0;\
|
||||
var_list->current_index = 0;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
void free_all_var_list_##type(struct main_list_##type *var_list){\
|
||||
remove_all_list_in_##type(var_list);\
|
||||
pthread_mutex_destroy(var_list->mut_list);\
|
||||
free(var_list->mut_list);\
|
||||
free(var_list);\
|
||||
}\
|
||||
void increment_list_##type(struct main_list_##type * var_list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
var_list->current_list = (var_list->current_list)->next;\
|
||||
++(var_list->current_index);\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
void decrement_list_##type(struct main_list_##type * var_list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
var_list->current_list = (var_list->current_list)->preview;\
|
||||
--(var_list->current_index);\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
struct list_##type * local_increment_list_##type(struct list_##type *list){\
|
||||
if(list) return list->next;\
|
||||
return NULL;\
|
||||
}\
|
||||
struct list_##type * local_decrement_list_##type(struct list_##type *list){\
|
||||
if (list) return list->preview;\
|
||||
return NULL;\
|
||||
}\
|
||||
struct list_##type * search_first_occ_with_mov_from_curr_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type), struct list_##type * (*incr_or_decr_mov)(struct list_##type *)){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
for(struct list_##type *list_cur = var_list->current_list; list_cur; list_cur = incr_or_decr_mov(list_cur)){\
|
||||
if(0 == funcCmp(value, list_cur->value)){\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return list_cur;\
|
||||
}\
|
||||
}\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return NULL;\
|
||||
}\
|
||||
struct list_##type * search_first_occ_from_begin_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type)){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
/*printf("debug: cur_index change to 0");*/\
|
||||
var_list->current_list = var_list->begin_list;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return search_first_occ_with_mov_from_curr_in_list_##type(var_list, value, funcCmp, local_increment_list_##type);\
|
||||
}\
|
||||
struct list_##type * search_first_occ_from_end_in_list_##type(struct main_list_##type *var_list, type value, int (*funcCmp)(type, type)){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
/*printf("debug: cur_index change to end");*/\
|
||||
var_list->current_list = var_list->end_list;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return search_first_occ_with_mov_from_curr_in_list_##type(var_list, value, funcCmp, local_decrement_list_##type);\
|
||||
}\
|
||||
struct list_##type * pull_end_from_list_##type(struct main_list_##type *var_list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
struct list_##type *ret = var_list->end_list;\
|
||||
if(ret != NULL){\
|
||||
struct list_##type * prevL = ret->preview;\
|
||||
if(prevL != NULL){\
|
||||
prevL->next=NULL;\
|
||||
}else{\
|
||||
var_list->begin_list=NULL;\
|
||||
var_list->current_index = 0;\
|
||||
var_list->current_list=NULL;\
|
||||
}\
|
||||
var_list->end_list = prevL;\
|
||||
--(var_list->size);\
|
||||
ret->preview = NULL;\
|
||||
}\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return ret;\
|
||||
}\
|
||||
struct list_##type * pull_begin_from_list_##type(struct main_list_##type *var_list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
struct list_##type *ret = var_list->begin_list;\
|
||||
if(ret != NULL){\
|
||||
struct list_##type * nextL = ret->next;\
|
||||
if(nextL != NULL){\
|
||||
nextL->preview=NULL;\
|
||||
}else{\
|
||||
var_list->end_list=NULL;\
|
||||
var_list->current_index = 0;\
|
||||
var_list->current_list=NULL;\
|
||||
}\
|
||||
var_list->begin_list = nextL;\
|
||||
--(var_list->size);\
|
||||
ret->next = NULL;\
|
||||
}\
|
||||
struct list_##type *tmp = var_list->begin_list;\
|
||||
while(tmp){ --(tmp->index); tmp=tmp->next;}\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
return ret;\
|
||||
}\
|
||||
void append_list_##type(struct main_list_##type *var_list, struct list_##type *list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
list->index = var_list->size;\
|
||||
if(var_list->end_list == NULL){\
|
||||
list->preview = NULL;\
|
||||
var_list->end_list = list;\
|
||||
var_list->begin_list = list;\
|
||||
var_list->current_list = list;\
|
||||
var_list->current_index = 0;\
|
||||
}else{\
|
||||
var_list->end_list->next = list;\
|
||||
list->preview = var_list->end_list;\
|
||||
var_list->end_list = list;\
|
||||
}\
|
||||
++(var_list->size);\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
|
||||
|
||||
#define GEN_HEAD_PTR_LIST(type)\
|
||||
void remove_all_ptr_type_list_##type(struct main_list_##type *var_list);\
|
||||
void purge_ptr_type_list_##type(struct main_list_##type *var_list);\
|
||||
void free_##type(type arg);\
|
||||
|
||||
|
||||
|
||||
#define GEN_FUNC_PTR_LIST_FREE(type)\
|
||||
void remove_all_ptr_type_list_##type(struct main_list_##type *var_list){\
|
||||
pthread_mutex_lock(var_list->mut_list);\
|
||||
struct list_##type *tmp = var_list->begin_list, *prec_tmp;\
|
||||
while(tmp){\
|
||||
prec_tmp = tmp;\
|
||||
tmp = tmp->next;\
|
||||
free_##type(prec_tmp->value);\
|
||||
free(prec_tmp);\
|
||||
}\
|
||||
var_list->begin_list = NULL;\
|
||||
var_list->current_list = NULL;\
|
||||
var_list->end_list = NULL;\
|
||||
var_list->size = 0;\
|
||||
var_list->current_index = 0;\
|
||||
pthread_mutex_unlock(var_list->mut_list);\
|
||||
}\
|
||||
void purge_ptr_type_list_##type(struct main_list_##type *var_list){\
|
||||
remove_all_ptr_type_list_##type(var_list);\
|
||||
pthread_mutex_destroy(var_list->mut_list);\
|
||||
free(var_list->mut_list);\
|
||||
free(var_list);\
|
||||
}\
|
||||
\
|
||||
void free_##type(type arg)\
|
||||
|
||||
|
||||
GEN_HEAD_PTR_LIST(TYPE_PTR)
|
||||
|
||||
|
||||
#define LIST_T(type) \
|
||||
GENERATE_LIST_ALL(type)\
|
||||
GEN_LIST_ALL(type)
|
||||
|
||||
|
||||
|
||||
#endif /* __LIST_T_C__H */
|
||||
|
||||
Binary file not shown.
@@ -0,0 +1,60 @@
|
||||
# file list_t/test/Makefile
|
||||
|
||||
ROOTPROJECTDIR:=$(realpath ../..)
|
||||
|
||||
NAME_TEST=is_good
|
||||
CC=gcc
|
||||
ROOT_DIR=$(ROOTPROJECTDIR)/list_t
|
||||
YTESTDIR=$(ROOTPROJECTDIR)/ytest_t
|
||||
|
||||
INCLUDE_DIR=$(ROOT_DIR)/src
|
||||
CFLAGS=-I$(INCLUDE_DIR) -I$(YTESTDIR)/include_ytest/include
|
||||
LDFLAGS=-L$(YTESTDIR) -lytest
|
||||
|
||||
#SRC_DIR=$(ROOT_DIR)/src
|
||||
#SRC=$(wildcard */*/*.c)
|
||||
SRC=$(wildcard **/**/*.c)
|
||||
#HEADS=$(OBJS:.o=.h)
|
||||
TEST_DIR=$(ROOT_DIR)/test
|
||||
EXECSRC=$(NAME_TEST).c
|
||||
EXEC=launch_$(NAME_TEST)_m
|
||||
|
||||
LISTDIR=$(ROOT_DIR)
|
||||
|
||||
LISTSRC_O=$(LISTDIR)/src/list_t/list_t.o
|
||||
|
||||
TOPTARGETS := all clean
|
||||
|
||||
DEPS=$(LISTDIR) $(YTESTDIR)
|
||||
|
||||
$(TOPTARGETS): $(DEPS)
|
||||
|
||||
$(DEPS):
|
||||
$(MAKE) -C $@ $(MAKECMDGOALS)
|
||||
|
||||
|
||||
#LISTSRC_O=$(LISTSRC:.c=.o)
|
||||
#SETTSRC_O=$(PWD)/../src/set_theoric_t/set_theoric_t.o
|
||||
#SETTSRC_O=$(SETTSRC:.c=.o)
|
||||
#TOOLSRC=$(TOOLDIR)/src/tools_t/tools_t.c
|
||||
#TOOLSRC_O=$(TOOLSRC:.c=.o)
|
||||
|
||||
OBJ=$(SRC:.c=.o) $(LISTSRC_O)
|
||||
|
||||
LIB_YTEST=$(YTESTDIR)/libytest.so
|
||||
|
||||
all: $(EXEC) $(LIB_YTEST)
|
||||
|
||||
$(EXEC): $(EXECSRC) $(OBJ)
|
||||
$(CC) -o $@ $^ $(CFLAGS) $(LDFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
rm -f $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
rm -f $(EXEC)
|
||||
|
||||
run: $(EXEC)
|
||||
$(EXEC) -h
|
||||
Executable
+23
@@ -0,0 +1,23 @@
|
||||
#!/bin/bash
|
||||
|
||||
if [ "$#" -le 0 ] ; then
|
||||
echo "Usage: $0 is_good.c" >&2
|
||||
echo "for example to compile: is_good.c" >&2
|
||||
exit 1
|
||||
fi
|
||||
if [ "$#" -le 1 ] ; then
|
||||
echo "Usage: $0 $1" >&2
|
||||
echo " we can add more option for example '-D DEBUG=1' to have debug print, '-D HK' to have gtest like prompt, od '-g' to gbd" >&2
|
||||
echo "for example: $0 $1 \"-D DEBUG=1 -D HK -g\""
|
||||
fi
|
||||
|
||||
DIR_YTEST=$PWD/../../ytest_t
|
||||
SRC=../src
|
||||
|
||||
gcc -o launch_is_good_c $1 -L$DIR_YTEST $2 -lytest -I$DIR_YTEST/include_ytest/include $SRC/list_t/list_t.c -I$SRC
|
||||
#gcc -o launch_is_good_c $1 $2 -lytest -I../include_ytest src/list_t/list_t.o src/set_theoric_t/set_theoric_t.o -I./src
|
||||
|
||||
export LD_LIBRARY_PATH=$DIR_YTEST/:LD_LIBRARY_PATH
|
||||
|
||||
|
||||
#gcc $1 src/ftest/ftest.c src/fmock/fmock.c src/tools_t/tools_t.c src/bar_progress/bar_progress.c src/list_t/list_t.c src/set_theoric_t/set_theoric_t.c -I./include $2 -o launch_is_good_c -lpthread
|
||||
@@ -0,0 +1,271 @@
|
||||
#include "../linktest/y_test_h.h"
|
||||
|
||||
IMPLEMENTATION_FTEST()
|
||||
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// for sleep !
|
||||
#ifdef __linux__
|
||||
#include <unistd.h>
|
||||
#elif _WIN32
|
||||
#include <windows.h>
|
||||
#endif
|
||||
|
||||
#include "y_tensor_h.h"
|
||||
|
||||
IMPLEMENTATION_DIMENSION()
|
||||
|
||||
TEST(dimension0){
|
||||
|
||||
dimension *D = create_dim(5);
|
||||
|
||||
EXPECT_EQ(D->size,5);
|
||||
|
||||
free_dimension(D);
|
||||
}
|
||||
TEST(rank){
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
updateRankDim(D);
|
||||
EXPECT_EQ(D->rank, 180);
|
||||
|
||||
free_dimension(D);
|
||||
}
|
||||
TEST(SplitDim){
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
updateRankDim(D);
|
||||
printDebug_dimension(D," D root");
|
||||
|
||||
dimension *d_part1 = NULL,*d_part2=NULL;
|
||||
|
||||
split_dim_part(D, &d_part1, &d_part2, 1, 2);
|
||||
|
||||
printDebug_dimension(d_part1," part1 from Root");
|
||||
printDebug_dimension(d_part2," part2 from Root");
|
||||
|
||||
dimension *ad;
|
||||
|
||||
add_dimension(&ad,d_part1, d_part2);
|
||||
printDebug_dimension(D," D root");
|
||||
printDebug_dimension(ad," ad ");
|
||||
|
||||
|
||||
free_dimension(D);
|
||||
free_dimension(ad);
|
||||
free(d_part1);
|
||||
free(d_part2);
|
||||
}
|
||||
|
||||
TEST(SplitDim_2){
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
updateRankDim(D);
|
||||
printDebug_dimension(D," D root");
|
||||
|
||||
dimension *d_part1 = NULL,*d_part2=NULL;
|
||||
|
||||
split_dim_part(D, &d_part1, &d_part2, 3, 2);
|
||||
|
||||
printDebug_dimension(d_part1," part1 from Root");
|
||||
printDebug_dimension(d_part2," part2 from Root");
|
||||
|
||||
dimension *ad;
|
||||
|
||||
add_dimension(&ad,d_part1, d_part2);
|
||||
printDebug_dimension(D," D root");
|
||||
printDebug_dimension(ad," ad ");
|
||||
|
||||
|
||||
free_dimension(D);
|
||||
free_dimension(ad);
|
||||
free(d_part1);
|
||||
free(d_part2);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
TEST(SubDim){
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
dimension *d_head2 = sub_minus_dim_head(D,2);
|
||||
|
||||
|
||||
EXPECT_EQ(d_head2->rank, 2*3);
|
||||
|
||||
dimension *d_tail2 = sub_minus_dim_tail(D,2);
|
||||
EXPECT_EQ(d_tail2->rank, 5*6);
|
||||
|
||||
free_dimension(D);
|
||||
free(d_tail2);
|
||||
free(d_head2);
|
||||
}
|
||||
|
||||
TEST(SubDim){
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
|
||||
dimension *d_head2 = sub_minus_dim_head(D,2);
|
||||
|
||||
|
||||
EXPECT_EQ(d_head2->rank, 2*3);
|
||||
|
||||
dimension *d_tail2 = sub_minus_dim_tail(D,2);
|
||||
EXPECT_EQ(d_tail2->rank, 5*6);
|
||||
|
||||
free_dimension(D);
|
||||
free(d_tail2);
|
||||
free(d_head2);
|
||||
}
|
||||
|
||||
TEST(Coord_linear){
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
updateRankDim(D);
|
||||
|
||||
size_t line=255;
|
||||
size_t *coord = CoordFromLin(line,D);
|
||||
|
||||
for(size_t i=0; i<D->size; ++i){
|
||||
LOG("coo[%ld]=%ld\n",i,coord[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(line, LineFromCoord(coord, D));
|
||||
free_dimension(D);
|
||||
free(coord);
|
||||
}
|
||||
|
||||
TEST(signedCoord_linear){
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
updateRankDim(D);
|
||||
|
||||
long line=-255;
|
||||
long *coord = signedCoordFromLin(line,D);
|
||||
|
||||
for(size_t i=0; i<D->size; ++i){
|
||||
LOG("coo[%ld]=%ld\n",i,coord[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(line, signedLineFromCoord(coord, D));
|
||||
free_dimension(D);
|
||||
free(coord);
|
||||
}
|
||||
|
||||
TEST(signedCoord_linearSuccessif){
|
||||
dimension *D=create_dim(3);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=2;
|
||||
|
||||
updateRankDim(D);
|
||||
|
||||
for(long line=-4; line < 4; ++line){
|
||||
long *coord = signedCoordFromLin(line,D);
|
||||
|
||||
for(size_t i=0; i<D->size; ++i){
|
||||
LOG("coo[%ld]=%ld\n",i,coord[i]);
|
||||
}
|
||||
|
||||
EXPECT_EQ(line, signedLineFromCoord(coord, D));
|
||||
free(coord);
|
||||
}
|
||||
free_dimension(D);
|
||||
}
|
||||
|
||||
TEST(sprint_dim){
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
updateRankDim(D);
|
||||
|
||||
char *dimSTR =NULL;
|
||||
size_t nb=sprint_dimension(&dimSTR, D);
|
||||
|
||||
LOG(" nb char : %ld\n, dim print:\n%s\n",nb, dimSTR);
|
||||
|
||||
free_dimension(D);
|
||||
free(dimSTR);
|
||||
}
|
||||
|
||||
TEST(incrment_dim){
|
||||
littleEndian=false;
|
||||
dimension *D=create_dim(4);
|
||||
D->shape[0]=2;
|
||||
D->shape[1]=3;
|
||||
D->shape[2]=5;
|
||||
D->shape[3]=6;
|
||||
|
||||
updateRankDim(D);
|
||||
|
||||
char *dimSTR =NULL;
|
||||
size_t nb=sprint_dimension(&dimSTR, D);
|
||||
|
||||
LOG(" nb char : %ld\n, dim print:\n%s\n",nb, dimSTR);
|
||||
|
||||
increment_dim_var(D);
|
||||
|
||||
nb=sprint_dimension(&dimSTR, D);
|
||||
|
||||
LOG(" nb char : %ld\n, dim print increment:\n%s\n",nb, dimSTR);
|
||||
|
||||
free_dimension(D);
|
||||
free(dimSTR);
|
||||
}
|
||||
|
||||
|
||||
TEST(list_shape_in_dim){
|
||||
list_shape_in_dim *l_p=NULL;
|
||||
|
||||
for(size_t i=1;i<5; ++i){
|
||||
append_in_list_shape(&l_p, i);
|
||||
}
|
||||
|
||||
dimension *dim=create_dim_from_list_shape(l_p);
|
||||
|
||||
printDebug_dimension(dim, "from l_p");
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv){
|
||||
|
||||
|
||||
run_all_tests_args(argc, argv);
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,789 @@
|
||||
#ifndef __TOOLS_T_C_H__
|
||||
#define __TOOLS_T_C_H__
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <stdbool.h>
|
||||
#include <time.h>
|
||||
|
||||
#include <sys/ioctl.h>
|
||||
|
||||
|
||||
/* to define DEBUG in gcc cli do: gcc -D DEBUG=1 or 0 if need!*/
|
||||
#ifndef DEBUG
|
||||
#define DEBUG 0
|
||||
#endif
|
||||
|
||||
|
||||
/* F_OUT file (stream) to log*/
|
||||
#ifndef F_OUT
|
||||
#define F_OUT stdout
|
||||
#endif
|
||||
/* F_ERR file (stream) to log*/
|
||||
#ifndef F_ERR
|
||||
#define F_ERR stderr
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifndef SECOND
|
||||
#define SECOND 0
|
||||
#endif
|
||||
#ifndef NANOSECOND
|
||||
#define NANOSECOND 0
|
||||
#endif
|
||||
|
||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start);
|
||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start);
|
||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start);
|
||||
*/
|
||||
|
||||
#if 1
|
||||
|
||||
extern long int PRECISION_TYPE_FLOAT ;
|
||||
extern long int PRECISION_TYPE_DOUBLE ;
|
||||
extern long int PRECISION_TYPE_L_DOUBLE ;
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/*void get_cursor_position(int *col, int *rows);*/
|
||||
|
||||
#if DEBUG
|
||||
|
||||
#define debug_print(fmt, ...) \
|
||||
do { /*if (DEBUG)*/ fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||
|
||||
#define PRINT_DEBUG_(fmt, ...) \
|
||||
do { /*if (DEBUG)*/ fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__); } while (0)
|
||||
|
||||
#else
|
||||
#define debug_print(fmt, ...) {}
|
||||
|
||||
#define PRINT_DEBUG_(fmt, ...) {}
|
||||
|
||||
#endif
|
||||
|
||||
#define error_print(fmt, ...) \
|
||||
fprintf(stderr, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);
|
||||
|
||||
#define PRINT_ERROR(fmt, ...) \
|
||||
fprintf(F_ERR, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);
|
||||
|
||||
#define PRINT_LOC_T(fmt, ...) \
|
||||
fprintf(F_OUT, "%s:%d:%s(): " fmt, __FILE__, \
|
||||
__LINE__, __func__, __VA_ARGS__);
|
||||
|
||||
|
||||
|
||||
#define TYPE_CHAR char
|
||||
#define TYPE_U_CHAR unsigned char
|
||||
#define TYPE_INT int
|
||||
#define TYPE_U_INT unsigned int
|
||||
#define TYPE_L_INT long int
|
||||
#define TYPE_U_L_INT unsigned long int
|
||||
#define TYPE_SIZE_T size_t
|
||||
#define TYPE_FLOAT float
|
||||
#define TYPE_DOUBLE double
|
||||
#define TYPE_L_DOUBLE long double
|
||||
#define TYPE_STRING char*
|
||||
|
||||
#define FREE(x) { free((x)); (x) = NULL;}
|
||||
|
||||
#define FOREACH(array, size, function)\
|
||||
for(size_t _ind = 0; _ind < size; ++_ind) function(array[_ind]);
|
||||
|
||||
#define MIN(X, Y) (((Y) < (X)) ? (Y) : (X))
|
||||
#define MAX(X, Y) (((Y) > (X)) ? (Y) : (X))
|
||||
|
||||
#define GENERATE_ALL(type)\
|
||||
int COMPARE_N_##type(const void *,const void*);\
|
||||
void COPY_ARRAY_##type(type* dst, const type* src, size_t size);\
|
||||
type MAX_ARRAY_##type(const type *array, size_t size);\
|
||||
size_t ARG_MAX_ARRAY_##type(const type *array, size_t size);\
|
||||
type MIN_ARRAY_##type(const type *array, size_t size);\
|
||||
size_t ARG_MIN_ARRAY_##type(const type *array, size_t size);\
|
||||
TYPE_STRING type##_TO_STR(type var);\
|
||||
|
||||
|
||||
GENERATE_ALL(TYPE_CHAR)
|
||||
GENERATE_ALL(TYPE_U_CHAR)
|
||||
GENERATE_ALL(TYPE_INT)
|
||||
GENERATE_ALL(TYPE_U_INT)
|
||||
GENERATE_ALL(TYPE_L_INT)
|
||||
GENERATE_ALL(TYPE_U_L_INT)
|
||||
GENERATE_ALL(TYPE_SIZE_T)
|
||||
GENERATE_ALL(TYPE_FLOAT)
|
||||
GENERATE_ALL(TYPE_DOUBLE)
|
||||
GENERATE_ALL(TYPE_L_DOUBLE)
|
||||
GENERATE_ALL(TYPE_STRING)
|
||||
|
||||
/* strto_type */
|
||||
|
||||
int strto_TYPE_INT(char *str, char **endptr);
|
||||
unsigned int strto_TYPE_U_INT(char *str, char **endptr);
|
||||
long int strto_TYPE_L_INT(char *str, char **endptr);
|
||||
unsigned long int strto_TYPE_U_L_INT(char *str, char **endptr);
|
||||
size_t strto_TYPE_SIZE_T(char *str, char **endptr);
|
||||
float strto_TYPE_FLOAT(char *str, char **endptr);
|
||||
double strto_TYPE_DOUBLE(char *str, char **endptr);
|
||||
long double strto_TYPE_L_DOUBLE(char *str, char **endptr);
|
||||
|
||||
/*
|
||||
* time calucl
|
||||
*/
|
||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start);
|
||||
|
||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start);
|
||||
|
||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start);
|
||||
|
||||
|
||||
#endif /*__TOOLS_T_C_H__*/
|
||||
|
||||
|
||||
|
||||
#define IMPLEMENTATION_TOOLS()\
|
||||
\
|
||||
GEN_TO_STR_N(TYPE_CHAR,2,"%c")\
|
||||
GEN_TO_STR_N(TYPE_U_CHAR,2,"%c")\
|
||||
GEN_TO_STR_N(TYPE_INT,22,"%d")\
|
||||
GEN_TO_STR_N(TYPE_U_INT,22,"%u")\
|
||||
GEN_TO_STR_N(TYPE_L_INT,22,"%ld")\
|
||||
GEN_TO_STR_N(TYPE_U_L_INT,22,"%lu")\
|
||||
GEN_TO_STR_N(TYPE_SIZE_T,22,"%lu")\
|
||||
GEN_TO_STR_N(TYPE_FLOAT,128,"%.10f")\
|
||||
GEN_TO_STR_N(TYPE_DOUBLE,256,"%.30lf")\
|
||||
GEN_TO_STR_N(TYPE_L_DOUBLE,256,"%.30Lf")\
|
||||
\
|
||||
TYPE_STRING TYPE_STRING_TO_STR(TYPE_STRING var){\
|
||||
return var;\
|
||||
}\
|
||||
\
|
||||
\
|
||||
long int PRECISION_TYPE_CHAR = 1;\
|
||||
long int PRECISION_TYPE_U_CHAR = 1;\
|
||||
long int PRECISION_TYPE_INT = 1;\
|
||||
long int PRECISION_TYPE_U_INT = 1;\
|
||||
long int PRECISION_TYPE_L_INT = 1;\
|
||||
long int PRECISION_TYPE_U_L_INT = 1;\
|
||||
long int PRECISION_TYPE_SIZE_T = 1;\
|
||||
\
|
||||
long int PRECISION_TYPE_FLOAT = 100000000;\
|
||||
long int PRECISION_TYPE_DOUBLE = 100000000000;\
|
||||
long int PRECISION_TYPE_L_DOUBLE = 100000000000000;\
|
||||
\
|
||||
\
|
||||
\
|
||||
\
|
||||
int \
|
||||
COMPARE_N_TYPE_STRING(const void *a,const void* b)\
|
||||
{\
|
||||
char **aa=(char**)a;\
|
||||
char **bb=(char**)b;\
|
||||
PRINT_DEBUG_("a=%s, b=%s\n",*aa, *bb);\
|
||||
return strcmp(*aa,*bb);\
|
||||
}\
|
||||
\
|
||||
void COPY_ARRAY_TYPE_STRING(char** dst, const char** src, size_t size)\
|
||||
{\
|
||||
for(size_t i = 0; i < size; ++i) strcpy(dst[i],src[i]);\
|
||||
}\
|
||||
\
|
||||
\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_CHAR)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_U_CHAR)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_INT)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_U_INT)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_L_INT)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_U_L_INT)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_SIZE_T)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_FLOAT)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_DOUBLE)\
|
||||
GENERATE_FUNCTION_NUMERIC(TYPE_L_DOUBLE)\
|
||||
\
|
||||
GENERATE_FUNCTION_ALL(TYPE_CHAR)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_U_CHAR)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_INT)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_U_INT)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_L_INT)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_U_L_INT)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_SIZE_T)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_FLOAT)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_DOUBLE)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_L_DOUBLE)\
|
||||
GENERATE_FUNCTION_ALL(TYPE_STRING)\
|
||||
\
|
||||
/* strto_type */\
|
||||
\
|
||||
int strto_TYPE_INT(char *str, char **endptr){ \
|
||||
return (int)strtol(str,endptr,10);\
|
||||
}\
|
||||
unsigned int strto_TYPE_U_INT(char *str, char **endptr){ \
|
||||
return (unsigned int)strtoul(str,endptr,10);\
|
||||
}\
|
||||
long int strto_TYPE_L_INT(char *str, char **endptr){\
|
||||
return strtol(str,endptr,10);\
|
||||
}\
|
||||
unsigned long int strto_TYPE_U_L_INT(char *str, char **endptr){\
|
||||
return strtoul(str,endptr,10);\
|
||||
}\
|
||||
size_t strto_TYPE_SIZE_T(char *str, char **endptr){\
|
||||
return strtoul(str,endptr,10);\
|
||||
}\
|
||||
float strto_TYPE_FLOAT(char *str, char **endptr){\
|
||||
return strtof(str,endptr);\
|
||||
}\
|
||||
double strto_TYPE_DOUBLE(char *str, char **endptr){\
|
||||
return strtod(str,endptr);\
|
||||
}\
|
||||
long double strto_TYPE_L_DOUBLE(char *str, char **endptr){\
|
||||
return strtold(str,endptr);\
|
||||
}\
|
||||
\
|
||||
\
|
||||
/*\
|
||||
* time section\
|
||||
*/\
|
||||
\
|
||||
double diff_timespec_seconds(struct timespec time_stop, struct timespec time_start){\
|
||||
/*PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);*/\
|
||||
return (time_stop.tv_sec - time_start.tv_sec) + 1.0e-9 * (time_stop.tv_nsec - time_start.tv_nsec);\
|
||||
}\
|
||||
\
|
||||
double diff_timespec_milliseconds(struct timespec time_stop, struct timespec time_start){\
|
||||
/*PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);*/\
|
||||
return 1.0e3 * (time_stop.tv_sec - time_start.tv_sec) + 1.0e-6 * (time_stop.tv_nsec - time_start.tv_nsec);\
|
||||
}\
|
||||
\
|
||||
long diff_timespec_nanoseconds(struct timespec time_stop, struct timespec time_start){\
|
||||
/*PRINT_DEBUG_("\n\nstop.sec:%ld, start.sec:%ld, stop.nsec:%ld, start.nsec:%ld\n\n", time_stop.tv_sec , time_start.tv_sec, time_stop.tv_nsec , time_start.tv_nsec);*/\
|
||||
return 1.0e9 * (time_stop.tv_sec - time_start.tv_sec) + (time_stop.tv_nsec - time_start.tv_nsec);\
|
||||
}\
|
||||
\
|
||||
|
||||
|
||||
|
||||
#ifndef __DIMENSION_T_H__
|
||||
#define __DIMENSION_T_H__
|
||||
|
||||
#include "../list_t/list_t.h"
|
||||
|
||||
struct dimension{
|
||||
size_t rank;
|
||||
size_t *shape;
|
||||
size_t size;
|
||||
};
|
||||
|
||||
|
||||
|
||||
extern bool littleEndian;
|
||||
|
||||
bool isLessEqThan(long int a, long int b) ;
|
||||
bool isLessThan(long int a, long int b) ;
|
||||
bool isGreatEqThan(long int a, long int b) ;
|
||||
bool isGreatThan(long int a, long int b) ;
|
||||
long int incr(long int i) ;
|
||||
long int decr(long int i) ;
|
||||
|
||||
|
||||
typedef struct dimension dimension ;
|
||||
|
||||
dimension * create_dim(size_t size);
|
||||
dimension * create_reverse_dim(size_t size);
|
||||
dimension* init_dim(size_t *t, size_t sz);
|
||||
dimension* init_copy_dim(size_t *t, size_t sz);
|
||||
dimension* clone_dim(dimension *dim);
|
||||
void free_dimension(dimension *d);
|
||||
|
||||
bool is_equal_dim(dimension *d0, dimension *d1);
|
||||
|
||||
dimension* sub_minus_dim_head(dimension *t, size_t minusSubdim);
|
||||
dimension* sub_minus_dim_tail(dimension *t, size_t minusSubdim);
|
||||
dimension* sub_dim_head(dimension *t, size_t subdim);
|
||||
dimension* sub_dim_tail(dimension *t, size_t subdim);
|
||||
|
||||
dimension* sub_copy_minus_dim_head(dimension *t, size_t minusSubdim);
|
||||
dimension* sub_copy_minus_dim_tail(dimension *t, size_t minusSubdim);
|
||||
dimension* sub_copy_dim_head(dimension *t, size_t sub_copydim);
|
||||
dimension* sub_copy_dim_tail(dimension *t, size_t sub_copydim);
|
||||
|
||||
void split_dim_part(dimension *root, dimension **part_1, dimension **part_2, size_t pivotSplit, size_t rangeInPivot );
|
||||
|
||||
void add_copy_dimension(dimension **d, dimension *d0, dimension *d1);
|
||||
void min_copy_dimension(dimension **d, dimension *d0, dimension *d1);
|
||||
|
||||
void add_dimension(dimension **d, dimension *d0, dimension *d1);
|
||||
void min_dimension(dimension **d, dimension *d0, dimension *d1);
|
||||
|
||||
void printDebug_dimension(dimension *d, char *msg);
|
||||
size_t sprint_dimension(char **dimContent, dimension *d);
|
||||
|
||||
void updateRankDim(dimension *dim);
|
||||
|
||||
size_t LineFromCoord(size_t *coo, dimension *dim);
|
||||
size_t* CoordFromLin(size_t line, dimension *dim);
|
||||
void vCoordFromLin(size_t *ret, size_t line, dimension *dim );
|
||||
|
||||
long int signedLineFromCoord(long *coo, dimension *dim);
|
||||
long int* signedCoordFromLin(long line, dimension *dim);
|
||||
void signedvCoordFromLin(long *ret, long int line, dimension *dim );
|
||||
|
||||
|
||||
void increment_dim_var(dimension *d);
|
||||
void decrement_dim_var(dimension *d);
|
||||
|
||||
struct list_shape_in_dim{
|
||||
size_t index;
|
||||
size_t shape;
|
||||
struct list_shape_in_dim *next;
|
||||
};
|
||||
|
||||
typedef struct list_shape_in_dim list_shape_in_dim;
|
||||
|
||||
void append_in_list_shape(list_shape_in_dim **list_p, size_t shape);
|
||||
dimension * create_dim_from_list_shape( list_shape_in_dim *l_p);
|
||||
|
||||
dimension * create_binary_dim(size_t dimension_size);
|
||||
|
||||
void free_list_shape_in_dim(list_shape_in_dim *l_p);
|
||||
|
||||
CREATE_HEADER_LIST(dimension)
|
||||
|
||||
typedef dimension * ptr_DIMENSION;
|
||||
|
||||
CREATE_HEADER_LIST(ptr_DIMENSION)
|
||||
GEN_HEAD_PTR_LIST(ptr_DIMENSION)
|
||||
|
||||
/*int compare_dimension(dimension *d1, dimension *d2);*/
|
||||
|
||||
#endif /* __DIMENSION_T_H__*/
|
||||
|
||||
#ifndef min
|
||||
#define min(x,y) (((x)<(y))?(x):(y))
|
||||
#endif
|
||||
|
||||
#define IMPLEMENTATION_DIMENSION()\
|
||||
\
|
||||
bool littleEndian=true;\
|
||||
\
|
||||
bool isLessEqThan(long int a, long int b) { return a <= b; }\
|
||||
bool isLessThan(long int a, long int b) { return a < b; }\
|
||||
bool isGreatEqThan(long int a, long int b) { return a >= b; }\
|
||||
bool isGreatThan(long int a, long int b) { return a > b; }\
|
||||
long int incr(long int i) { return i + 1; }\
|
||||
long int decr(long int i) { return i - 1; }\
|
||||
\
|
||||
dimension* init_dim(size_t *t, size_t sz){\
|
||||
dimension *d = malloc(sizeof(dimension));\
|
||||
d->size=sz;\
|
||||
d->shape=t;\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
\
|
||||
dimension* init_copy_dim(size_t *t, size_t sz){\
|
||||
if (sz==0) return NULL;\
|
||||
dimension *d = malloc(sizeof(dimension));\
|
||||
d->shape=malloc(sz * sizeof(size_t));\
|
||||
d->size = sz;\
|
||||
for(size_t i=0; i<sz; ++i) d->shape[i]=t[i];\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
dimension *\
|
||||
create_dim(size_t sz){\
|
||||
if (sz==0) return NULL;\
|
||||
dimension *d = malloc(sizeof(dimension));\
|
||||
d->shape=malloc(sz * sizeof(size_t));\
|
||||
d->size = sz;\
|
||||
return d;\
|
||||
}\
|
||||
\
|
||||
dimension* clone_dim(dimension *dim){\
|
||||
return init_copy_dim(dim->shape,dim->size);\
|
||||
}\
|
||||
\
|
||||
dimension *\
|
||||
create_reverse_dim(size_t sz){\
|
||||
dimension *dim = create_dim(sz);\
|
||||
for(size_t i=0;i<sz;++i) dim->shape[i]=sz-1-i;\
|
||||
updateRankDim(dim);\
|
||||
return dim;\
|
||||
}\
|
||||
\
|
||||
void free_dimension(dimension *d){\
|
||||
if(d){\
|
||||
free(d->shape);\
|
||||
free(d);\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
bool is_equal_dim(dimension *d0, dimension *d1){\
|
||||
if(d0->size != d1->size) return false;\
|
||||
if(d0->rank != d1->rank) return false;\
|
||||
for(size_t i=0;i<d0->size; ++i)\
|
||||
if(d0->shape[i] != d1->shape[i]) return false;\
|
||||
\
|
||||
return true;\
|
||||
}\
|
||||
\
|
||||
dimension* sub_copy_minus_dim_head(dimension *root, size_t minusSubdim){\
|
||||
if(minusSubdim < (root->size)){\
|
||||
dimension *d = init_copy_dim(root->shape, (root->size)-minusSubdim);\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
\
|
||||
dimension* sub_copy_minus_dim_tail(dimension *root, size_t minusSubdim){\
|
||||
if(minusSubdim < (root->size)){\
|
||||
dimension *d = init_copy_dim((root->shape)+minusSubdim, (root->size)-minusSubdim);\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
\
|
||||
dimension* sub_copy_dim_head(dimension *root, size_t subdim){\
|
||||
if(subdim < (root->size)){\
|
||||
dimension *d = init_copy_dim(root->shape, subdim);\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
\
|
||||
dimension* sub_copy_dim_tail(dimension *root, size_t subdim){\
|
||||
if(subdim < (root->size)){\
|
||||
dimension *d = init_copy_dim((root->shape)+(root->size - subdim), subdim);\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
\
|
||||
void add_copy_dimension(dimension **d, dimension *d0, dimension *d1) {\
|
||||
(*d) = create_dim(d0->size + d1->size);\
|
||||
for (size_t i = 0; i < d0->size; i++) (*d)->shape[i] = d0->shape[i];\
|
||||
for (size_t i = 0; i < d1->size; i++) (*d)->shape[d0->size + i] = d1->shape[i];\
|
||||
updateRankDim(*d);\
|
||||
}\
|
||||
\
|
||||
void min_copy_dimension(dimension **d, dimension *d0, dimension *d1) {\
|
||||
size_t mindim = min(d0->size,d1->size) ;\
|
||||
(*d)=create_dim(mindim);\
|
||||
\
|
||||
for (size_t i = 0; i < mindim; i++) {\
|
||||
if (d0->shape[i] > d1->shape[i]) (*d)->shape[i] = d1->shape[i];\
|
||||
else (*d)->shape[i] = d0->shape[i];\
|
||||
}\
|
||||
updateRankDim(*d);\
|
||||
}\
|
||||
\
|
||||
\
|
||||
\
|
||||
\
|
||||
dimension* sub_minus_dim_head(dimension *root, size_t minusSubdim){\
|
||||
if(minusSubdim < (root->size)){\
|
||||
dimension *d = init_dim(root->shape, (root->size)-minusSubdim);\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
dimension* sub_minus_dim_tail(dimension *root, size_t minusSubdim){\
|
||||
if(minusSubdim < (root->size)){\
|
||||
dimension *d = init_dim((root->shape)+minusSubdim, (root->size)-minusSubdim);\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
dimension* sub_dim_head(dimension *root, size_t subdim){\
|
||||
if(subdim < (root->size)){\
|
||||
dimension *d = init_dim(root->shape, subdim);\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
dimension* sub_dim_tail(dimension *root, size_t subdim){\
|
||||
if(subdim < (root->size)){\
|
||||
dimension *d = init_dim((root->shape)+(root->size - subdim), subdim);\
|
||||
updateRankDim(d);\
|
||||
return d;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
\
|
||||
/*\
|
||||
void split_dim_part(dimension *root, dimension **part_1, dimension **part_2, size_t sz_nb_minus_part ) */\
|
||||
void split_dim_part(dimension *root, dimension **part_1, dimension **part_2, size_t pivotSplit, size_t rangeInPivot ) {\
|
||||
if(pivotSplit < root->size){\
|
||||
if(rangeInPivot < root->shape[pivotSplit]){\
|
||||
/*size_t sz_part1= (root->rank * sz_nb_minus_part)/(root->shape[(root->size)-1]);*/\
|
||||
/*printf("sz_part1 :%ld \n",sz_part1);*/\
|
||||
*part_1 = init_copy_dim(root->shape, root->size);\
|
||||
((*part_1)->shape[pivotSplit]) -= rangeInPivot;\
|
||||
updateRankDim(*part_1);\
|
||||
/*if(sz_nb_minus_part <2)\
|
||||
*part_2 = init_copy_dim((root->shape), root->size-1 );\
|
||||
else{*/\
|
||||
*part_2 = init_copy_dim((root->shape), root->size );\
|
||||
(*part_2)->shape[pivotSplit] = rangeInPivot ;\
|
||||
/*}*/\
|
||||
updateRankDim(*part_2);\
|
||||
}\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
void increment_dim_var(dimension *d){\
|
||||
if(littleEndian){\
|
||||
(d->shape[0])++;\
|
||||
}\
|
||||
else{\
|
||||
(d->shape[d->size - 1])++;\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
\
|
||||
void decrement_dim_var(dimension *d){\
|
||||
if(littleEndian){\
|
||||
(d->shape[0])--;\
|
||||
}\
|
||||
else{\
|
||||
(d->shape[d->size - 1])--;\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
void add_dimension(dimension **d, dimension *d0, dimension *d1) {\
|
||||
(*d) = create_dim(d0->size + d1->size);\
|
||||
for (size_t i = 0; i < d0->size; i++) (*d)->shape[i] = d0->shape[i];\
|
||||
for (size_t i = 0; i < d1->size; i++) (*d)->shape[d0->size + i] = d1->shape[i];\
|
||||
updateRankDim(*d);\
|
||||
}\
|
||||
\
|
||||
void min_dimension(dimension **d, dimension *d0, dimension *d1) {\
|
||||
if (d0->size > d1->size) {\
|
||||
*d = d1;\
|
||||
}\
|
||||
else if (d0->size < d1->size) {\
|
||||
*d = d0;\
|
||||
}\
|
||||
else { /* d0->size = d1->size*/\
|
||||
*d = d0;\
|
||||
for (size_t i = 0; i < d0->size; i++) {\
|
||||
if (d0->shape[i] > d1->shape[i]) (*d)->shape[i] = d1->shape[i];\
|
||||
}\
|
||||
}\
|
||||
updateRankDim(*d);\
|
||||
}\
|
||||
\
|
||||
void printDebug_dimension(dimension *d,char *msg){\
|
||||
\
|
||||
printf("<%p>(%s)->size = %ld | (%s)->rank = %ld \n[",d,msg,d->size,msg,d->rank);\
|
||||
for(size_t i=0; i<d->size; ++i)\
|
||||
printf(" %ld,", d->shape[i]);\
|
||||
printf("] \n");\
|
||||
/*printf("[%ld: %ld] |", i,d->shape[i]);*/\
|
||||
/* if(littleEndian)\
|
||||
printf("\nlittleEndian (true): the bigest index varies first, e.g: [x0,x1,x2,...,xn] xn is the bigest index\n");\
|
||||
else\
|
||||
printf("\nlittleEndian (false): the lowest index varies first, e.g: [x0,x1,x2,...,xn] x0 is the lowest index\n");\
|
||||
*/\
|
||||
}\
|
||||
\
|
||||
size_t sprint_dimension(char **dimContent, dimension *d){\
|
||||
if(*dimContent != NULL){\
|
||||
free(*dimContent);\
|
||||
*dimContent=NULL;\
|
||||
}\
|
||||
size_t nbch=6*d->size+40;\
|
||||
*dimContent = malloc(nbch);\
|
||||
/*printf("nbCh=%ld\n",nbch);*/\
|
||||
char *val=NULL;\
|
||||
size_t cur=0;\
|
||||
char *dimSzCh="dim->size";\
|
||||
for(size_t i=0; i<strlen(dimSzCh);++i)\
|
||||
(*dimContent)[cur++]=dimSzCh[i];\
|
||||
(*dimContent)[cur++]='=';\
|
||||
val=TYPE_SIZE_T_TO_STR(d->size);\
|
||||
for(size_t c=0;c<strlen(val);++c)\
|
||||
(*dimContent)[cur++]=val[c];\
|
||||
free(val); val = NULL;\
|
||||
(*dimContent)[cur++]=' ';\
|
||||
(*dimContent)[cur++]='/';\
|
||||
(*dimContent)[cur++]=' ';\
|
||||
char *dimRkCh="dim->rank";\
|
||||
for(size_t i=0; i<strlen(dimRkCh);++i)\
|
||||
(*dimContent)[cur++]=dimRkCh[i];\
|
||||
(*dimContent)[cur++]='=';\
|
||||
val=TYPE_SIZE_T_TO_STR(d->rank);\
|
||||
for(size_t c=0;c<strlen(val);++c)\
|
||||
(*dimContent)[cur++]=val[c];\
|
||||
free(val); val = NULL;\
|
||||
(*dimContent)[cur++]=' ';\
|
||||
(*dimContent)[cur++]='\n';\
|
||||
(*dimContent)[cur++]='[';\
|
||||
for(size_t i=0; i<d->size;++i){\
|
||||
(*dimContent)[cur++]=' ';\
|
||||
val=TYPE_SIZE_T_TO_STR(d->shape[i]);\
|
||||
for(size_t c=0;c<strlen(val);++c)\
|
||||
(*dimContent)[cur++]=val[c];\
|
||||
free(val); val = NULL;\
|
||||
(*dimContent)[cur++]=',';\
|
||||
\
|
||||
}\
|
||||
(*dimContent)[cur++]=']';\
|
||||
\
|
||||
(*dimContent)[cur++]='\n';\
|
||||
(*dimContent)[cur++]='\0';\
|
||||
\
|
||||
return cur;\
|
||||
}\
|
||||
\
|
||||
void updateRankDim(dimension *dim){\
|
||||
dim->rank=1;\
|
||||
for(size_t i=0; i<dim->size; ++i)\
|
||||
dim->rank *=dim->shape[i];\
|
||||
}\
|
||||
\
|
||||
/* signed */\
|
||||
long int signedLineFromCoord(long int *coo, dimension *dim){\
|
||||
long int begin = 0;\
|
||||
long int end = dim->size - 1;\
|
||||
long int (*iter)(long int); iter = &incr;\
|
||||
bool (*cond)(long int, long int); cond = &isLessEqThan;\
|
||||
\
|
||||
if (littleEndian) {\
|
||||
begin = dim->size - 1; end = 0;\
|
||||
iter = &decr; cond = &isGreatEqThan;\
|
||||
}\
|
||||
\
|
||||
long int pp = 1;\
|
||||
long int sm = 0;\
|
||||
for (long int i = begin; cond(i, end); i = iter(i)) {\
|
||||
sm += (coo[i] * pp);\
|
||||
pp *= dim->shape[i];\
|
||||
}\
|
||||
return sm;\
|
||||
\
|
||||
}\
|
||||
\
|
||||
void signedvCoordFromLin(long int *ret, long int line, dimension *dim ){\
|
||||
\
|
||||
long int begin = 0, end = dim->size - 1;\
|
||||
long int (*iter)(long int) = incr;\
|
||||
bool (*cond)(long int, long int) = isLessThan;\
|
||||
if (littleEndian == false) {\
|
||||
/*if (littleEndian) {*/\
|
||||
begin = dim->size - 1; end = 0;\
|
||||
iter = decr; cond = isGreatThan;\
|
||||
}\
|
||||
/*prlong intf("to coor begin = %d end = %d \n", begin, end);*/\
|
||||
\
|
||||
long int sm = line;\
|
||||
long int pp = dim->rank;\
|
||||
for (long int i = begin; cond(i, end); i = iter(i)) {\
|
||||
/*prlong intf(" i: %d ", i);*/\
|
||||
pp /= dim->shape[i];\
|
||||
ret[i] = sm / pp;\
|
||||
sm %= pp;\
|
||||
/*prlong intf("sm[%d] = %d , pp=%d ; ", i, sm, pp);*/\
|
||||
}\
|
||||
ret[end] = sm;\
|
||||
}\
|
||||
\
|
||||
long int* signedCoordFromLin(long int line, dimension *dim){\
|
||||
long int *ret;\
|
||||
ret=malloc(dim->size*sizeof(long int));\
|
||||
signedvCoordFromLin(ret,line,dim);\
|
||||
return ret;\
|
||||
}\
|
||||
\
|
||||
/* */\
|
||||
/* unsigned */\
|
||||
size_t LineFromCoord(size_t *coo, dimension *dim) {\
|
||||
return (long)signedLineFromCoord((long*)coo,dim);\
|
||||
}\
|
||||
\
|
||||
void vCoordFromLin(size_t *ret, size_t line, dimension *dim ){\
|
||||
signedvCoordFromLin((long*)ret, (long)line, dim);\
|
||||
}\
|
||||
\
|
||||
size_t* CoordFromLin(size_t line, dimension *dim){\
|
||||
return (size_t*)signedCoordFromLin((long)line, dim);\
|
||||
}\
|
||||
\
|
||||
\
|
||||
/* */\
|
||||
\
|
||||
void append_in_list_shape(list_shape_in_dim **list_p, size_t shape){\
|
||||
list_shape_in_dim *lis=malloc(sizeof(list_shape_in_dim));\
|
||||
lis->shape=shape;\
|
||||
lis->next=NULL;\
|
||||
if(*list_p == NULL){\
|
||||
lis->index=0;\
|
||||
*list_p = lis;\
|
||||
}\
|
||||
else{\
|
||||
list_shape_in_dim *tmp =*list_p;\
|
||||
while(tmp->next) tmp=tmp->next;\
|
||||
lis->index = tmp->index +1;\
|
||||
tmp->next=lis;\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
dimension * create_dim_from_list_shape( list_shape_in_dim *l_p){\
|
||||
\
|
||||
if(l_p){\
|
||||
list_shape_in_dim *tmp =l_p;\
|
||||
while(tmp->next) tmp=tmp->next;\
|
||||
dimension *dim=create_dim(tmp->index + 1);\
|
||||
(dim)->size = tmp->index + 1;\
|
||||
tmp=l_p;\
|
||||
while(tmp){\
|
||||
(dim)->shape[tmp->index]=tmp->shape;\
|
||||
tmp=tmp->next;\
|
||||
}\
|
||||
updateRankDim(dim);\
|
||||
return dim;\
|
||||
}\
|
||||
return NULL;\
|
||||
}\
|
||||
\
|
||||
dimension * create_binary_dim(size_t dimension_size){\
|
||||
dimension * dim = create_dim(dimension_size);\
|
||||
for(size_t i=0; i<dimension_size; ++i)\
|
||||
dim->shape[i]=2;\
|
||||
updateRankDim(dim);\
|
||||
return dim;\
|
||||
}\
|
||||
\
|
||||
\
|
||||
void free_list_shape_in_dim(list_shape_in_dim *l_p){\
|
||||
list_shape_in_dim *tmp=l_p, *ttmp;\
|
||||
while(tmp){\
|
||||
ttmp = tmp;\
|
||||
tmp = ttmp->next;\
|
||||
free(ttmp);\
|
||||
}\
|
||||
}\
|
||||
\
|
||||
IMPLEMENTATION_LIST(dimension)\
|
||||
\
|
||||
IMPLEMENTATION_LIST(ptr_DIMENSION)\
|
||||
GEN_FUNC_PTR_LIST_FREE(ptr_DIMENSION){\
|
||||
dimension *pdim=(dimension*)arg;\
|
||||
free_dimension(pdim);\
|
||||
/*free(pdim);*/\
|
||||
}\
|
||||
\
|
||||
|
||||
|
||||
Reference in New Issue
Block a user