C Everything
This is a C repository containing a curated set of generic data structures and algorithm.
common.c
Go to the documentation of this file.
1 
5 #include "common.h"
6 
7 
15 void init_data_params(t_dparams *prms, e_data_types data_type)
16 {
17  switch(data_type)
18  {
19  case eINT8:
20  //char list;
21  prms->cmpr = compare_char;
22  prms->swap = swap_char;
23  prms->cmpr_idx = compare_idx_char;
24  prms->swap_idx = swap_idx_char;
25  prms->copy_idx = copy_idx_char;
26  prms->get_idx = get_idx_char;
27  prms->print_data = print_char;
28  prms->free = FREE_MEM;
29  break;
30  case eINT32:
31  //int list;
32  prms->cmpr = compare_int;
33  prms->swap = swap_int;
34  prms->cmpr_idx = compare_idx_int;
35  prms->swap_idx = swap_idx_int;
36  prms->copy_idx = copy_idx_int;
37  prms->get_idx = get_idx_int;
38  prms->print_data = print_int;
39  prms->free = FREE_MEM;
40  break;
41  case eFLOAT:
42  //float list;
43  prms->cmpr = compare_float;
44  prms->swap = swap_float;
46  prms->swap_idx = swap_idx_float;
47  prms->copy_idx = copy_idx_float;
48  prms->get_idx = get_idx_float;
49  prms->print_data = print_float;
50  prms->free = FREE_MEM;
51  break;
52  case eSTRING:
53  //string list;
54  prms->cmpr = compare_string;
55  prms->swap = swap_string;
56  prms->print_data = print_str;
57  prms->free = FREE_MEM;
58  break;
59 #if 0
60  case eGEN:
61  //gen list;
62  prms->cmpr = compare_gen;
63  prms->swap = swap_gen;
64  break;
65 #endif
66  }
67 }
68 
75 void dummy_free(void *mem_addr, char *file, int line)
76 {
77 
78 }
void init_data_params(t_dparams *prms, e_data_types data_type)
Called to initalize data params for default data types Else for custom data types the data params str...
Definition: common.c:15
void dummy_free(void *mem_addr, char *file, int line)
Dummy free function Else for custom data types the data params structure is to be defined by user
Definition: common.c:75
Top level include containg common headers.
t_gen get_idx_int(t_gen, int)
void swap_idx_char(t_gen, int, int)
void copy_idx_int(t_gen, int, t_gen)
e_cmpr compare_idx_char(t_gen, int, int)
void print_int(t_gen)
e_cmpr compare_string(t_gen, t_gen)
Definition: generic_def.c:26
void copy_idx_char(t_gen, int, t_gen)
e_cmpr compare_gen(t_gen, t_gen)
Definition: generic_def.c:13
e_cmpr compare_int(t_gen, t_gen)
void print_float(t_gen)
e_cmpr compare_char(t_gen, t_gen)
Below routines defined as reference for basic datatypes.
t_gen get_idx_float(t_gen, int)
void swap_int(t_gen, t_gen)
void print_char(t_gen)
void swap_gen(t_gen, t_gen)
void swap_char(t_gen, t_gen)
e_cmpr compare_float(t_gen, t_gen)
void copy_idx_float(t_gen, int, t_gen)
t_gen get_idx_char(t_gen, int)
void swap_idx_int(t_gen, int, int)
void swap_string(t_gen, t_gen)
void swap_float(t_gen, t_gen)
e_cmpr compare_idx_int(t_gen, int, int)
e_cmpr compare_idx_float(t_gen, int, int)
void swap_idx_float(t_gen, int, int)
void print_str(t_gen)
Definition: generic_def.c:63
#define FREE_MEM
data params struct defn
Definition: common.h:18
f_cmpr cmpr
Routine used for comparing two given elems of said type.
Definition: common.h:23
f_get_idx get_idx
Routine used for getting elem in given array index.
Definition: common.h:32
f_swap swap
Routine used for swaping two elemnts of goven data.
Definition: common.h:25
f_swp_idx swap_idx
Routine used for swapring elems in given array indicies.
Definition: common.h:29
f_free free
Routine used for freeing elements of said data.
Definition: common.h:26
f_cpy_idx copy_idx
Routine used for copying elems in given array indicies.
Definition: common.h:30
f_print print_data
Routine used for printing elem data.
Definition: common.h:33
f_cmp_idx cmpr_idx
Routine used for comparing elems in given array indicies.
Definition: common.h:28
enum data_types e_data_types
Enum to create data structure of the following type.
@ eFLOAT
Definition: typedefs.h:26
@ eSTRING
Definition: typedefs.h:28
@ eINT32
Definition: typedefs.h:24
@ eGEN
Definition: typedefs.h:29
@ eINT8
Definition: typedefs.h:20