Skip to content

Commit 968c8a7

Browse files
committed
added new addon functions for simpler working
1 parent c1c661c commit 968c8a7

73 files changed

Lines changed: 3699 additions & 2802 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

include/cerpec.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,13 @@
1212
# define CERPEC_CHUNK 256
1313
#elif CERPEC_CHUNK <= 0
1414
# error "Chunk size must be greater than zero."
15+
#elif (CERPEC_CHUNK & (CERPEC_CHUNK - 1))
16+
# error "Chunk size must be a power of 2."
17+
#endif
18+
19+
#ifdef NDEBUG
20+
# define NERROR
21+
# define NVALID
1522
#endif
1623

1724
#ifndef NVALID

include/dodac.h

Lines changed: 239 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,239 @@
1+
#ifndef DODAC_H
2+
#define DODAC_H
3+
4+
#include <stddef.h>
5+
#include <stdbool.h>
6+
7+
#ifndef DODAC_SEED
8+
# define DODAC_SEED 0x12345678
9+
#endif
10+
11+
#define CHAR_FORMAT "%c"
12+
#define UCHAR_FORMAT "%c"
13+
#define INT_FORMAT "%d "
14+
#define UINT_FORMAT "%u "
15+
#define FLOAT_FORMAT "%f "
16+
#define FLOAT_FORMAT "%f "
17+
#define DOUBLE_FORMAT "%lf "
18+
#define SIZE_FORMAT "%zu "
19+
#define STRING_FORMAT "%s "
20+
21+
void chardst(void * const element);
22+
23+
void * charcpy(void * const destination, void const * const source);
24+
25+
void * charsum(void * const sum, void const * const addent);
26+
27+
size_t charhshsame(void const * const element);
28+
29+
int charcmp(void const * const a, void const * const b);
30+
31+
int charrcmp(void const * const a, void const * const b);
32+
33+
bool charprint(void * const element, void * const format);
34+
35+
bool chartolower(void * const element, void * const null);
36+
37+
bool chartoupper(void * const element, void * const null);
38+
39+
void charqsort(void * const array, size_t const lenght, void * const null);
40+
41+
void charrqsort(void * const array, size_t const lenght, void * const null);
42+
43+
bool chareven(void const * const element, void * const null);
44+
45+
bool charodd(void const * const element, void * const null);
46+
47+
bool charalnum(void const * const element, void * const null);
48+
49+
bool charalpha(void const * const element, void * const null);
50+
51+
bool charcntrl(void const * const element, void * const null);
52+
53+
bool chardigit(void const * const element, void * const null);
54+
55+
bool charlower(void const * const element, void * const null);
56+
57+
bool charupper(void const * const element, void * const null);
58+
59+
bool charpunct(void const * const element, void * const null);
60+
61+
bool charspace(void const * const element, void * const null);
62+
63+
bool charxdigit(void const * const element, void * const null);
64+
65+
bool charprime(void const * const element, void * const null);
66+
67+
void uchardst(void * const element);
68+
69+
void * ucharcpy(void * const destination, void const * const source);
70+
71+
void * ucharsum(void * const sum, void const * const addent);
72+
73+
size_t ucharhshsame(void const * const element);
74+
75+
int ucharcmp(void const * const a, void const * const b);
76+
77+
int ucharrcmp(void const * const a, void const * const b);
78+
79+
bool ucharprint(void * const element, void * const format);
80+
81+
bool uchartolower(void * const element, void * const null);
82+
83+
bool uchartoupper(void * const element, void * const null);
84+
85+
void ucharqsort(void * const array, size_t const lenght, void * const null);
86+
87+
void ucharrqsort(void * const array, size_t const lenght, void * const null);
88+
89+
bool uchareven(void const * const element, void * const null);
90+
91+
bool ucharodd(void const * const element, void * const null);
92+
93+
bool ucharalnum(void const * const element, void * const null);
94+
95+
bool ucharalpha(void const * const element, void * const null);
96+
97+
bool ucharcntrl(void const * const element, void * const null);
98+
99+
bool uchardigit(void const * const element, void * const null);
100+
101+
bool ucharlower(void const * const element, void * const null);
102+
103+
bool ucharupper(void const * const element, void * const null);
104+
105+
bool ucharpunct(void const * const element, void * const null);
106+
107+
bool ucharspace(void const * const element, void * const null);
108+
109+
bool ucharxdigit(void const * const element, void * const null);
110+
111+
bool ucharprime(void const * const element, void * const null);
112+
113+
void intdst(void * const element);
114+
115+
void * intcpy(void * const destination, void const * const source);
116+
117+
void * intsum(void * const sum, void const * const addent);
118+
119+
size_t inthshsame(void const * const element);
120+
121+
size_t inthshmurmur(void const * const element);
122+
123+
int intcmp(void const * const a, void const * const b);
124+
125+
int intrcmp(void const * const a, void const * const b);
126+
127+
bool intprint(void * const element, void * const format);
128+
129+
bool intincrement(void * const element, void * const value);
130+
131+
bool intdecrement(void * const element, void * const value);
132+
133+
void intqsort(void * const array, size_t const lenght, void * const null);
134+
135+
void intrqsort(void * const array, size_t const lenght, void * const null);
136+
137+
bool inteven(void const * const element, void * const null);
138+
139+
bool intodd(void const * const element, void * const null);
140+
141+
bool intprime(void const * const element, void * const null);
142+
143+
void uintdst(void * const element);
144+
145+
void * uintcpy(void * const destination, void const * const source);
146+
147+
void * uintsum(void * const sum, void const * const addent);
148+
149+
size_t uinthshsame(void const * const element);
150+
151+
int uintcmp(void const * const a, void const * const b);
152+
153+
int uintrcmp(void const * const a, void const * const b);
154+
155+
bool uintprint(void * const element, void * const format);
156+
157+
void uintqsort(void * const array, size_t const lenght, void * const null);
158+
159+
void uintrqsort(void * const array, size_t const lenght, void * const null);
160+
161+
bool uinteven(void const * const element, void * const null);
162+
163+
bool uintodd(void const * const element, void * const null);
164+
165+
bool uintprime(void const * const element, void * const null);
166+
167+
void floatdst(void * const element);
168+
169+
void * floatcpy(void * const destination, void const * const source);
170+
171+
void * floatsum(void * const sum, void const * const addent);
172+
173+
size_t floathshsame(void const * const element);
174+
175+
int floatcmp(void const * const a, void const * const b);
176+
177+
int floatrcmp(void const * const a, void const * const b);
178+
179+
bool floatprint(void * const element, void * const format);
180+
181+
void floatqsort(void * const array, size_t const lenght, void * const null);
182+
183+
void floatrqsort(void * const array, size_t const lenght, void * const null);
184+
185+
void doubledst(void * const element);
186+
187+
void * doublecpy(void * const destination, void const * const source);
188+
189+
void * doublesum(void * const sum, void const * const addent);
190+
191+
size_t doublehshsame(void const * const element);
192+
193+
int doublecmp(void const * const a, void const * const b);
194+
195+
int doublercmp(void const * const a, void const * const b);
196+
197+
bool doubleprint(void * const element, void * const format);
198+
199+
void doubleqsort(void * const array, size_t const lenght, void * const null);
200+
201+
void doublerqsort(void * const array, size_t const lenght, void * const null);
202+
203+
void sizedst(void * const element);
204+
205+
void * sizecpy(void * const destination, void const * const source);
206+
207+
void * sizesum(void * const sum, void const * const addent);
208+
209+
size_t sizehshsame(void const * const element);
210+
211+
int sizecmp(void const * const a, void const * const b);
212+
213+
int sizercmp(void const * const a, void const * const b);
214+
215+
bool sizeprint(void * const element, void * const format);
216+
217+
void sizeqsort(void * const array, size_t const lenght, void * const null);
218+
219+
void sizerqsort(void * const array, size_t const lenght, void * const null);
220+
221+
bool sizeeven(void const * const element, void * const null);
222+
223+
bool sizeodd(void const * const element, void * const null);
224+
225+
bool sizeprime(void const * const element, void * const null);
226+
227+
size_t stringhshmurmur(void const * const element);
228+
229+
int stringcmp(void const * const a, void const * const b);
230+
231+
int stringrcmp(void const * const a, void const * const b);
232+
233+
bool stringprint(void * const element, void * const format);
234+
235+
void stringqsort(void * const array, size_t const lenght, void * const null);
236+
237+
void stringrqsort(void * const array, size_t const lenght, void * const null);
238+
239+
#endif // DODAC_H

include/graph/iam_graph.h

Lines changed: 20 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# define IAM_GRAPH_CHUNK CERPEC_CHUNK
88
#elif IAM_GRAPH_CHUNK <= 0
99
# error "Chunk size must be greater than zero."
10+
#elif (IAM_GRAPH_CHUNK & (IAM_GRAPH_CHUNK - 1))
11+
# error "Chunk size must be a power of 2."
1012
#endif
1113

1214
#define IAM_NIL ((size_t)(-1))
@@ -39,7 +41,7 @@ typedef struct infinite_matrix_graph_table {
3941
iam_cost_s const * data;
4042
size_t * previous;
4143
char * costs;
42-
} iam_list_s;
44+
} iam_table_s;
4345

4446
/// @brief Composes a structure via its parametric properties.
4547
/// @param size Size of cost.
@@ -99,12 +101,18 @@ bool is_empty_iam_graph(iam_graph_s const * const graph);
99101
/// @return 'true' if graph is complete, 'false' otherwise.
100102
bool is_complete_iam_graph(iam_graph_s const * const graph);
101103

102-
/// @brief A graph is connected if a path exists between every pair of vertices
104+
/// @brief A graph is connected if a path exists between every pair of vertices.
103105
/// @param graph Structure to check.
104106
/// @return 'true' if graph is connected, 'false' otherwise.
105107
/// @note The algorithm uses DFS to determine connectivity.
106108
bool is_connected_iam_graph(iam_graph_s const * const graph);
107109

110+
/// @brief A graph is a tree if it's connected and contains no cycles.
111+
/// @param graph Structure to check.
112+
/// @return 'true' if graph is a tree, 'false' otherwise.
113+
/// @note The algorithm uses DFS to determine tree-ness.
114+
bool is_tree_iam_graph(iam_graph_s const * const graph);
115+
108116
/// @brief Inserts a single vertex element into the structure.
109117
/// @param graph Structure to insert into.
110118
/// @param vertex Element buffer to insert.
@@ -168,23 +176,23 @@ size_t degree_iam_graph(iam_graph_s const * const graph, size_t const index);
168176
/// @param start Starting vertex index.
169177
/// @param end Last vertex index, or 'IAM_NIL' if all vertex shortest path.
170178
/// @return Breadth first search lookup table with subgraph from start node to all other nodes.
171-
iam_list_s bfs_iam_graph(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start, size_t const end);
179+
iam_table_s bfs_iam_graph(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start, size_t const end);
172180

173181
/// @brief Traverses the vertices of the specified structure using depth first search.
174182
/// @param graph Structure to traverse.
175183
/// @param cost Cost structure that defines the distance properties in table.
176184
/// @param start Starting vertex index.
177185
/// @param end Last vertex index, or 'IAM_NIL' if all vertex paths.
178186
/// @return Depth first search lookup table with subgraph from start node to all other nodes.
179-
iam_list_s dfs_iam_graph(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start, size_t const end);
187+
iam_table_s dfs_iam_graph(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start, size_t const end);
180188

181189
/// @brief Generate a Dijkstra lookup array table with nodes' edge sums and previous indexes.
182190
/// @param graph Structure to generate from.
183191
/// @param start Starting vertex index.
184192
/// @param end Last vertex index, or 'IAM_NIL' if all vertex shortest path.
185193
/// @param cost Cost structure that defines the distance properties in table.
186194
/// @return Dijkstra lookup table with subgraph of shortest paths from start node to all other nodes.
187-
iam_list_s dijkstra_iam_graph(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start, size_t const end);
195+
iam_table_s dijkstra_iam_graph(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start, size_t const end);
188196

189197
/// @brief Generate an A* lookup array table with nodes' edges and previous indexes.
190198
/// @param graph Structure to generate from.
@@ -193,14 +201,14 @@ iam_list_s dijkstra_iam_graph(iam_graph_s const * const graph, iam_cost_s const
193201
/// @param cost Cost structure that defines the distance properties in table.
194202
/// @param heuristic Function pointer to calculate heuristic cost based on two vectices.
195203
/// @return A* lookup table with subgraph of shortest paths from start to end node.
196-
iam_list_s a_star_iam_graph(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start, size_t const end, operate_fn const heuristic);
204+
iam_table_s a_star_iam_graph(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start, size_t const end, operate_fn const heuristic);
197205

198206
/// @brief Generate a Prim lookup array table with nodes' edges and previous indexes.
199207
/// @param graph Structure to generate from.
200208
/// @param start Starting vertex index.
201209
/// @param cost Cost structure that defines the distance properties in table.
202210
/// @return Prim lookup table with subgraph of minimum spanning tree from start node to all other nodes.
203-
iam_list_s prim_iam_list(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start);
211+
iam_table_s prim_iam_list(iam_graph_s const * const graph, iam_cost_s const * const cost, size_t const start);
204212

205213
/// @brief Generate a Kruskal lookup array table with nodes' ranks and previous indexes.
206214
/// @param graph Structure to generate from.
@@ -209,11 +217,11 @@ iam_list_s prim_iam_list(iam_graph_s const * const graph, iam_cost_s const * con
209217
/// @param arguments Arguments for sorting function.
210218
/// @param increment Function pointer to increment rank cost by one.
211219
/// @return Kruskal lookup table with subgraph of minimum spanning tree from start node to all other nodes.
212-
iam_list_s kruskal_iam_list(iam_graph_s const * const graph, iam_cost_s const * const cost, process_fn const sort, void * const arguments, set_fn const increment);
220+
iam_table_s kruskal_iam_list(iam_graph_s const * const graph, iam_cost_s const * const cost, process_fn const sort, void * const arguments, set_fn const increment);
213221

214222
/// @brief Destroys a structure, and its elements and makes it unusable.
215223
/// @param table Structure to destroy.
216-
void destroy_iam_list(iam_list_s * const table);
224+
void destroy_iam_list(iam_table_s * const table);
217225

218226
/// @brief Creates a subgraph copy of specified graph based on its table.
219227
/// @param table Structure to reference.
@@ -222,7 +230,7 @@ void destroy_iam_list(iam_list_s * const table);
222230
/// @return Matrix graph structure.
223231
/// @note The algorithm should be used for minimum spanning tree implementations like Prim and Kruskal,
224232
/// but one can also generate trees from path finding implementations.
225-
iam_graph_s subgraph_iam_list(iam_list_s const * const table, copy_fn const copy_vertex, copy_fn const copy_edge);
233+
iam_graph_s subgraph_iam_list(iam_table_s const * const table, copy_fn const copy_vertex, copy_fn const copy_edge);
226234

227235
/// @brief Iterates over each vertex element in structure starting from the beginning.
228236
/// @param graph Structure to iterate.
@@ -247,7 +255,7 @@ void each_edge_iam_graph(iam_graph_s const * const graph, handle_fn const handle
247255
/// @param table Structure to iterate.
248256
/// @param handle Operate function pointer to operate on each vertex.
249257
/// @param arguments Arguments for operate function pointer.
250-
void each_cost_iam_list(iam_list_s const * const table, handle_fn const handle, void * const arguments);
258+
void each_cost_iam_list(iam_table_s const * const table, handle_fn const handle, void * const arguments);
251259

252260
/// @brief Traverses the costs paths of the specified structure using a generated table.
253261
/// @param table Structure to traverse.
@@ -257,6 +265,6 @@ void each_cost_iam_list(iam_list_s const * const table, handle_fn const handle,
257265
/// @return 'true' if path exists, 'false' otherwise.
258266
/// @note The algorithm shoul be used with shortest path find implementations, i.e. Dijkstra and A*,
259267
/// to traverse the path from 'end' vertex to the start one, but one can also traverse MSP tables with it.
260-
bool each_path_iam_list(iam_list_s const * const table, size_t const end, handle_fn const handle, void * const arguments);
268+
bool each_path_iam_list(iam_table_s const * const table, size_t const end, handle_fn const handle, void * const arguments);
261269

262270
#endif // IAM_GRAPH_H

include/list/icircular_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# define ICIRCULAR_LIST_CHUNK CERPEC_CHUNK
88
#elif ICIRCULAR_LIST_CHUNK <= 0
99
# error "Chunk size must be greater than zero."
10+
#elif (ICIRCULAR_LIST_CHUNK & (ICIRCULAR_LIST_CHUNK - 1))
11+
# error "Chunk size must be a power of 2."
1012
#endif
1113

1214
/// @brief Infinite circular list data structure.

include/list/idouble_list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
# define IDOUBLE_LIST_CHUNK CERPEC_CHUNK
88
#elif IDOUBLE_LIST_CHUNK <= 0
99
# error "Chunk size must be greater than zero."
10+
#elif (IDOUBLE_LIST_CHUNK & (IDOUBLE_LIST_CHUNK - 1))
11+
# error "Chunk size must be a power of 2."
1012
#endif
1113

1214
#define IDL_NODE 2

0 commit comments

Comments
 (0)