-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patharr.h
667 lines (564 loc) · 24.9 KB
/
arr.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
#ifndef ZAKAROUF__ZTYPES_TYPES__ARR_H
#define ZAKAROUF__ZTYPES_TYPES__ARR_H
/**@file arr.h
* @brief Type Generic Dynamic Arrays
*
* Type Generic Dynamic Arrays using C-macros,
* this file provides all the required definations and functions to use it.
*/
#include "prep/args.h"
#include "prep/nm/cond.h"
#include "std/primitives.h"
#include "std/mem.h"
#include "typeof.h"
#define Z__CONFIG__ARR__GROWTH_FACTOR__NUM 8
#define Z__CONFIG__ARR__SHRINK_FACTOR__NUM 8
/* Known Type-safe arrays */
//-------------------- Fixed-size Array ---------------------//
/**
* @def z__ArrFx(T, N)
* @brief Create A stact allocated Fixed sized array.
*
* @param T Type
* @param N Length
*/
#define z__ArrFx(T, N) z__typeof(T [N])
/*-------------------- Dynamic Array ---------------------*/
/**
* @def z__Arr(T)
* @brief Define an Anonymous struct type of unit-type \a T.
*
* @param T Type of the units.
*/
#define z__Arr(...)\
struct \
{ \
__VA_ARGS__ *data; \
z__u32 len; \
z__u32 lenUsed; \
}
/**
*/
#define z__Arr_getLen(arr) (arr).len
#define z__Arr_getUsed(arr) (arr).lenUsed
#define z__Arr_getData(arr) (arr).data
#define z__Arr_getUnitSize(arr) sizeof(*(arr).data)
#define z__Arr_getSize(arr) (z__Arr_getUnitSize(arr) * z__Arr_getLen(arr))
#define z__Arr_getSizeUsed(arr) (z__Arr_getUnitSize(arr) * z__Arr_getUsed(arr))
#define z__Arr_getVal(arr, index) (arr).data[index]
#define z__Arr_getTop(arr) (arr).data[(arr).lenUsed-1]
#define z__Arr_getTopEmpty(arr) (arr).data[(arr).lenUsed]
// Signed
typedef z__Arr(z__i8) z__i8Arr;
typedef z__Arr(z__i16) z__i16Arr;
typedef z__Arr(z__i32) z__i32Arr;
typedef z__Arr(z__i64) z__i64Arr;
// Unsigned
typedef z__Arr(z__u8) z__u8Arr;
typedef z__Arr(z__u16) z__u16Arr;
typedef z__Arr(z__u32) z__u32Arr;
typedef z__Arr(z__u64) z__u64Arr;
// Floats
typedef z__Arr(z__f32) z__f32Arr;
typedef z__Arr(z__f64) z__f64Arr;
// Bytes
typedef z__Arr(z__byte) z__byteArr;
// Size
typedef z__Arr(z__size) z__sizeArr;
// Boolean
typedef z__Arr(z__bool) z__boolArr;
// Void *
typedef z__Arr(z__ptr) z__ptrArr;
typedef z__Arr(void) z__voidArr;
/**
* @def z__Arr_new(arr, size)
* @brief Initializes array by allocting memory and setting up the size.
*
* @param arr Array
* @param sz Initial length of the array.
*/
#define z__Arr_new(arr, sz)\
{ \
(arr)->data = z__MALLOC(sizeof(*(arr)->data)*sz); \
(arr)->len = sz; \
(arr)->lenUsed = 0; \
}
/**
* @def z__Arr_delete(arr)
* @brief Deletes the array and frees memory.
*
* @param arr Array
*/
#define z__Arr_delete(arr)\
{ \
(arr)->len = 0; \
(arr)->lenUsed = 0; \
z__FREE((arr)->data); \
}
/**
* @def z__Arr_init(arr_T, ...)
* @brief Initialize an array, and return it as rvalue.
*
* @param arr_T Either Array Type or lvalue whose type-array will be returned.
* @param ... List of arrguments that will be copied into the initialize array.
*/
#define z__Arr_init(arr_T, ...)\
({ \
z__typeof(arr_T) temp_arr; \
z__Arr_new(&temp_arr, zpp__Args_Count(__VA_ARGS__)); \
z__typeof(temp_arr.data) itr = temp_arr.data; \
z__typeof(itr) testa = (z__typeof(*testa)[]){__VA_ARGS__}; \
memcpy(itr, testa, sizeof(*itr) * zpp__Args_Count(__VA_ARGS__));\
temp_arr.lenUsed = temp_arr.len; \
temp_arr; \
})
/**
* @def z__Arr_newFromPtr(arr, src, srclen)
* @brief Initialize array, copy pointer data from \a src to arr data.
*
* @param arr Array
* @param src Pointer to the data to make copy from.
* @param srclen Number of units inside \a src.
*/
#define z__Arr_newFromPtr(arr, src, srclen)\
{ \
z__Arr_new(arr, srclen); \
z__typeof((arr)->data) src_in = src; \
memcpy((arr)->data, src_in, sizeof(*src_in) * srclen); \
(arr)->lenUsed = srclen; \
}
/**
* @def z__Arr_initFromPtr(arrT, src, srclen)
* @brief Initializes the array, copys the pointer src, return the array as rvalue.
*
* @param arrT Either the Array Type or the Array var \a lvalue.
* @param src Pointer
* @param srclen Length of the pointer data
*/
#define z__Arr_initFromPtr(arrT, src, srclen)\
({ \
arr_T z__Arr_initFromPtr__var__temp_arr; \
z__Arr_newFromPtr(&z__Arr_initFromPtr__var__temp_arr, src, srclen); \
z__Arr_initFromPtr__var__temp_arr; \
})
/**
* @def z__Arr_newExtractFrom_StructArrPtr(arr, s_ptr, member, len)
* @brief Initialize the array, with a pointer to struct array's member.
*
* @param arr Array
* @param s_ptr Struct array pointer
* @param member The struct member to fish out
* @param len Length of the \a s_ptr.
*/
#define z__Arr_newExtractFrom_StructArrPtr(arr, s_ptr, member, len)\
{ \
z__Arr_new(arr, len); \
z__ptr src_in = &(s_ptr)->member; \
\
for(z__size i = 0; i < len; i++){ \
z__Arr_push_nocheckMC(arr, src_in); \
src_in += sizeof(*s_ptr); \
} \
}
/**
* @def z__Arr_newCopy(arr, arr_src)
* @brief Create a new Array that is a copy of \a arr_src
*
* @param arr The Array
* @param arr_src The Source Array
*/
#define z__Arr_newCopy(arr, arr_src)\
{ \
z__Arr_new(arr, (arr_src).len); \
z__typeof((arr)->data) src_in = (arr_src).data; \
memcpy((arr)->data, src_in, sizeof(*src_in) * (arr_src).len); \
(arr)->lenUsed = (arr_src).lenUsed; \
}
/**
* @def z__Arr_clone(arr)
* @brief Returns an copy of the any Array.
*
* @param arr The Source Array
* @return Copy of the array
*/
#define z__Arr_clone(arr)\
({ \
z__typeof(arr) temp_arr; \
z__Arr_new(&temp_arr, arr.len); \
memcpy(temp_arr.data, arr.data, sizeof(*arr.data) * arr.len); \
temp_arr.lenUsed = arr.lenUsed; \
temp_arr; \
})
/**
* Create an array from a pointer slice, copies it, return it to lhs.
*/
#define z__Arr_cloneFromPtr(arr_T, src, srclen)\
({ \
arr_T temp_arr; \
z__Arr_newFromPtr(&temp_arr, src, srclen); \
temp_arr; \
})
/**
* Copies an array into another already initiazed array, replaces the values
*/
#define z__Arr_copy(dest_arr, arr)\
{\
if((dest_arr)->len <= (arr).lenUsed) {\
(dest_arr)->data = z__REALLOC_SAFE((dest_arr)->data, (arr).lenUsed * sizeof(*(arr).data)); \
(dest_arr)->len = (arr).lenUsed; \
} \
memcpy((dest_arr)->data, (arr).data, (arr).lenUsed * sizeof(*(arr).data)); \
(dest_arr)->lenUsed = (arr).lenUsed; \
}
/**
* Resize an array, reallocate space if newSize is greater than total capacity
*/
#define z__Arr_resize(arr, newSize)\
{ \
if ((arr)->lenUsed > newSize) { \
(arr)->lenUsed = newSize; \
} \
(arr)->data = z__REALLOC_SAFE((arr)->data, newSize * sizeof(*(arr)->data)); \
(arr)->len = newSize; \
}
/**
* Resizes array capacity to its used length.
*/
#define z__Arr_resize_pack(arr)\
{ \
(arr)->data = z__REALLOC_SAFE((arr)->data, (arr)->lenUsed * sizeof(*(arr)->data)); \
(arr)->len = (arr)->lenUsed; \
}
/**
* Expands the total capacity of the array
*/
#define z__Arr_expand(arr, by)\
{ \
(arr)->len += by; \
(arr)->data = z__REALLOC_SAFE((arr)->data, sizeof(*(arr)->data) * ((arr)->len));\
}
/**
* Expands the total capacity of the array, set all the bits to 0
*/
#define z__Arr_expand_set0(arr, by)\
{ \
z__Arr_expand(arr, by); \
memset( \
&(arr)->data[(arr)->lenUsed] \
, 0 \
, sizeof(*(arr)->data) * ((arr)->len - (arr)->lenUsed));\
}
/**
* Expand if lenof(arr) >= capacityof(arr)
*/
#define z__Arr_expand_if_reached_limit(arr)\
{\
if ((arr)->lenUsed >= (arr)->len) \
{ \
(arr)->len *= 2; \
(arr)->data = z__REALLOC_SAFE((arr)->data, sizeof(*(arr)->data)* ((arr)->len) ); \
} \
}
/**
* Expand of passed number `by` added to used length is greater than the capacity
*/
#define z__Arr_expand_ifneeded(arr, by)\
{\
if(((arr)->lenUsed + by) > (arr)->len) {\
z__Arr_expand(arr, by);\
}\
}
/**
* Push a value no check on capacity.
*/
#define z__Arr_push_nocheck(arr, ...)\
{ \
(arr)->data[(arr)->lenUsed] = __VA_ARGS__; \
(arr)->lenUsed += 1; \
}
/**
* Push data stream value no check on capacity.
*/
#define z__Arr_pushStream_nocheck(arr, data_ptr, data_len) \
{ \
memcpy((arr)->data + (arr)->lenUsed \
, data_ptr \
, data_len * sizeof(*data_ptr)); \
(arr)->lenUsed += data_len; \
}
/**
* Push a value, using memcpy
*/
#define z__Arr_pushMC_nocheck(arr, ...)\
{ \
memcpy(&(arr)->data[(arr)->lenUsed], (__VA_ARGS__), sizeof(*(arr)->data)); \
(arr)->lenUsed += 1; \
}
/**
* Increments the length and use constructor.
*/
#define z__Arr_push_cons_nocheck(arr, cons, ...)\
{ \
(arr)->lenUsed += 1; \
cons(&z__Arr_getTop((*arr)) ,##__VA_ARGS__); \
}
/**
* Push a value to array
*/
#define z__Arr_push(arr, ...)\
{ \
z__Arr_expand_if_reached_limit(arr) \
z__Arr_push_nocheck(arr, __VA_ARGS__); \
}
/**
* Push stream of data, multiple entry
*/
#define z__Arr_pushStream(arr, data_ptr, data_len) \
{ \
z__Arr_expand_ifneeded(arr, data_len); \
z__Arr_pushStream_nocheck(arr, data_ptr, data_len); \
}
/**
* Push a value to array, use memcpy to copy value
*/
#define z__Arr_pushMC(arr, ...)\
{ \
z__Arr_expand_if_reached_limit(arr); \
z__Arr_pushMC_nocheck(arr, __VA_ARGS__); \
}
/**
* Just Increments the length.
*/
#define z__Arr_pushInc(arr)\
{ \
z__Arr_expand_if_reached_limit(arr); \
(arr)->lenUsed += 1; \
}
/**
* Just Increments the length, multiple indices
*/
#define z__Arr_pushIncBy(arr, by)\
{ \
z__Arr_expand_ifneeded(arr, by);\
(arr)->lenUsed += by; \
}
#define z__Arr_push_cons(arr, cons, ...)\
{ \
z__Arr_pushInc(arr); \
z__Arr_push_cons_nocheck(arr, cons ,##__VA_ARGS__)\
}
#define z__Arr_pop_nocheck(arr)\
{ \
(arr)->lenUsed -= 1; \
}
#define z__Arr_pop(arr)\
{ \
(arr)->lenUsed -= 1; \
if (((arr)->len - (arr)->lenUsed) > Z__CONFIG__ARR__SHRINK_FACTOR__NUM) { \
z__Arr_resize(arr, (arr)->len - Z__CONFIG__ARR__SHRINK_FACTOR__NUM); \
} \
}
#define z__Arr_pop_getval(arr, v)\
{ \
*(v) = z__Arr_getTop((*arr)); \
z__Arr_pop(arr); \
}
#define z__Arr_join(dest, from)\
{ \
z__i32 totalLength = (dest)->lenUsed*sizeof(*(dest)->data) + from.lenUsed*sizeof(*from.data); \
if (totalLength > (dest)->len){ \
z__Arr_resize(dest, totalLength+1) \
} \
memcpy(&(dest)->data[(dest)->lenUsed], from.data, from.lenUsed * sizeof(*(dest)->data)); \
}
/**
*/
#define z__Arr_cmpdata(arr, _ptr_data, size)(\
(zpp__ter__if((sizeof(*(arr).data) * (arr).lenUsed) < (size)) -1\
zpp__ter__elif((sizeof(*(arr).data) * (arr).lenUsed) > (size)) 1\
zpp__ter__else(memcmp((arr).data, _ptr_data, (size)))))
#define z__Arr_cmp(arr1, arr2)\
z__Arr_cmpdata(arr1, (arr2).data, sizeof(*(arr2).data) * (arr2).lenUsed)
/**
* Returns True if equal
*/
#define z__Arr_isdataequal(arr1, arr2)\
( \
zpp__ter__if((arr1).lenUsed * sizeof(*(arr1).data) \
!= (arr2).lenUsed * sizeof(*(arr2).data)) ( \
false \
) zpp__ter__else ( \
!memcmp((arr1).data, (arr2).data, (arr1).lenUsed) \
) \
)
/**
* Create a newly allocated array from a slice of another array
*/
#define z__Arr_newSlice(...) zpp__Args_Overload(z__PRIV__Arr_newSlice_, __VA_ARGS__)
/**
* Create an Array slice
*/
#define z__Arr_slice(...) zpp__Args_Overload(z__PRIV__Arr_slice_, __VA_ARGS__)
/**
* Create an array slice in reverse
*/
#define z__Arr_sliceR(...) zpp__Args_Overload(z__PRIV__Arr_sliceR_, __VA_ARGS__)
/* foreach loop variant for Arr
* Example: z__Arr_foreach(i, arr){
* printf("%d\n", *i);
* }
* z__Arr_foreach(i, arr, reverse, 4, 0, 1) {
* printf("%d\n", *i);
* }
* FOR OLDER VERSIONS
* NOTE: OLDER VERSIONS ARE DEPRICATED
*/
#define z__Arr_foreach(iterator, arr, ...) z__PRIV__Arr_foreach(iterator, arr, ##__VA_ARGS__)
/**
*
*/
#define z__Arr_map(iterator, arr, options, expr)\
z__Arr_foreach(iterator, arr, zpp__UNPAREN(options)) { expr ; }
/**
* Map a function into elements of a array
*/
#define z__Arr_mapfn(arr, fn, ...)\
z__Arr_map(_i, arr, (__VA_ARGS__), fn(_i))
//z__Arr_foreach(_i, arr ,##__VA_ARGS__) { fn(i); }
/**
* Maps number array
*/
#define z__Arr_mapnum(...)\
zpp__Args_Overload(z__PRIV__Arr_mapnum_, __VA_ARGS__)
/**
* Shift elements towards right
*/
#define z__Arr_shift_right_nocheck(arr, n, ...)\
z__PRIV__Arr_shift_right_nocheck(arr, n, ##__VA_ARGS__)
/**
* Shift elements towards left
*/
#define z__Arr_shift_left_nocheck(arr, n, ...)\
z__PRIV__Arr_shift_left_nocheck(arr, n, ##__VA_ARGS__)
/**
* PRIVs
*/
/**
*/
#define z__PRIV__Arr_newSlice_5(dest, arr, from, upto, step)\
{\
z__size _from = from \
, _upto = upto \
, _step = step \
, _j = 0; \
z__Arr_new(dest, ((_upto - _from)/_step) +1);\
for(;_from < _upto; _from += _step){ \
(dest)->data[_j] = (arr).data[_from]; \
_j += 1; \
} \
(dest)->lenUsed = _j; \
}
#define z__PRIV__Arr_newSlice_4(dest, arr, from, upto)\
{\
z__size _len = upto - from; \
z__size _from = from; \
z__Arr_new(dest, _len); \
z__typeof((arr).data) _data = (dest)->data; \
memcpy(_data, &(arr).data[_from], sizeof(*_data) * _len);\
(dest)->lenUsed = _len; \
}
#define z__PRIV__Arr_newSlice_3(dest, arr, from) z__PRIV__Arr_newSlice_4(dest, arr, from, (arr).lenUsed-1)
#define z__PRIV__Arr_newSlice_2(dest, arr) z__Arr_newCopy(dest, arr)
#define z__PRIV__Arr_newSlice_1(arr) z__Arr_clone(arr)
/**
*/
#define z__PRIV__Arr_slice_5(arr, dest, from, upto, step)\
{ \
if ((arr).lenUsed > (dest)->len) { \
z__Arr_resize(dest, (arr).lenUsed); \
} \
int j = 0, i = from; \
for (; i < upto; i += step, j++) { \
(dest)->data[j] = (arr).data[i]; \
} \
(dest)->lenUsed = (j)+1; \
}
#define z__PRIV__Arr_slice_4(arr, dest, from, upto)\
{\
if ((arr).lenUsed > (dest)->len) { \
z__Arr_resize(dest, (arr).lenUsed); \
} \
int z__Arr_slice__var__from = from < 0?0:from; \
int z__Arr_slice__var__upto = upto > (arr).lenUsed? (arr).lenUsed : upto; \
\
memcpy((dest)->data, (arr).data[z__Arr_slice__var__from], (z__Arr_slice__var__upto - z__Arr_slice__var__from) * sizeof(*(arr).data))\
(dest)->lenUsed = z__Arr_slice__var__upto - z__Arr_slice__var__from;\
}
//#define z__Arr_slice_4(arr, dest, from, upto) z__Arr_slice_5(arr, dest, from, upto, 1)
#define z__PRIV__Arr_slice_3(arr, dest, from) z__PRIV__Arr_slice_4(arr, dest, from, (arr).lenUsed-1)
#define z__PRIV__Arr_slice_2(arr, dest) z__PRIV__Arr_slice_3(arr, dest, 0)
/**
*/
#define z__PRIV__Arr_sliceR_5(arr, dest, from, upto, step)\
{ \
if ((arr).lenUsed > (dest)->len) { \
z__Arr_resize(dest, (arr).lenUsed); \
} \
int j = 0, i = (arr).lenUsed-from, _upto = (((arr).lenUsed-from > 0)?(arr).lenUsed-from:0); \
for (; i > _upto; i -= step, j++) { \
(dest)->data[j] = (arr).data[i]; \
} \
(dest)->lenUsed = (j)+1; \
}
#define z__PRIV__Arr_sliceR_4(arr, dest, from, upto) z__PRIV__Arr_sliceR_5(arr, dest, from, upto, 1)
#define z__PRIV__Arr_sliceR_3(arr, dest, from) z__PRIV__Arr_sliceR_4(arr, dest, from, (arr).lenUsed)
#define z__PRIV__Arr_sliceR_2(arr, dest) z__PRIV__Arr_sliceR_4(arr, dest, 0, (arr).lenUsed)
/**
*/
#define z__PRIV__Arr_mapnum_4(arr, mapValStep, mapValFrom, operator) \
{ \
z__typeof(*(arr)->data)z__Arr_map__TMP_DATA = mapValFrom; \
for(int i = 0; i < (arr)->len; i++, z__Arr_map__TMP_DATA operator##= mapValStep){ \
(arr)->data[i] = z__Arr_map__TMP_DATA; \
}; \
(arr)->lenUsed = (arr)->len; \
}
#define z__PRIV__Arr_mapnum_3(arr, mapValStep, mapValFrom) z__PRIV__Arr_mapnum_4(arr, mapValStep, mapValFrom, +)
#define z__PRIV__Arr_mapnum_2(arr, mapValStep) z__PRIV__Arr_mapnum_4(arr, mapValStep, 0, +)
#define z__PRIV__Arr_mapnum_1(arr) { memset((arr)->data, 0, (arr)->len * sizeof(*(arr)->data)); }
/**
*/
#define z__PRIV__Arr_foreach_6(iterator, arr, comp, from, upto, step) \
for(z__typeof((arr).data) iterator = (arr).data + from \
;iterator zpp__CAT(z__PRIV__Arr_foreach__compas_, comp) (arr).data + upto\
;iterator zpp__CAT(z__PRIV__Arr_foreach__compas_step_, comp) step)
#define z__PRIV__Arr_foreach__compas_normal <
#define z__PRIV__Arr_foreach__compas_reverse >=
#define z__PRIV__Arr_foreach__compas_step_normal +=
#define z__PRIV__Arr_foreach__compas_step_reverse -=
#define z__PRIV__Arr_foreach__compas_def_from_normal(arr) 0
#define z__PRIV__Arr_foreach__compas_def_from_reverse(arr) (arr).lenUsed-1
#define z__PRIV__Arr_foreach__compas_def_upto_normal(arr) (arr).lenUsed
#define z__PRIV__Arr_foreach__compas_def_upto_reverse(arr) 0
#define z__PRIV__Arr_foreach_5(item, arr, c, from, upto) z__PRIV__Arr_foreach_6(item, arr, c, from, upto, 1)
#define z__PRIV__Arr_foreach_4(item, arr, c, from)\
z__PRIV__Arr_foreach_5(item, arr, c, from, zpp__CAT(z__PRIV__Arr_foreach__compas_def_upto_, c)(arr))
#define z__PRIV__Arr_foreach_3(item, arr, c)\
z__PRIV__Arr_foreach_4(item, arr, c, zpp__CAT(z__PRIV__Arr_foreach__compas_def_from_, c)(arr))
#define z__PRIV__Arr_foreach_2(item, arr) z__PRIV__Arr_foreach_3(item, arr, normal)
#define z__PRIV__Arr_foreach(...) zpp__Args_Overload(z__PRIV__Arr_foreach_, __VA_ARGS__)
/**
*/
#define z__PRIV__Arr_shift_right_nocheck_4(arr, n, index, len)\
z__mem_shift_right((arr)->data, sizeof(*(arr)->data), len, index, n)
#define z__PRIV__Arr_shift_right_nocheck_3(arr, n, index) z__PRIV__Arr_shift_right_nocheck_4(arr, n, index, (arr)->lenUsed - (index + n))
#define z__PRIV__Arr_shift_right_nocheck_2(arr, n) z__PRIV__Arr_shift_right_nocheck_3(arr, n, 0)
#define z__PRIV__Arr_shift_right_nocheck(...) zpp__Args_Overload(z__PRIV__Arr_shift_right_nocheck_, __VA_ARGS__)
/**
*/
#define z__PRIV__Arr_shift_left_nocheck_4(arr, n, index, len)\
z__mem_shift_left((arr)->data, sizeof(*(arr)->data), len, index, n)
#define z__PRIV__Arr_shift_left_nocheck_3(arr, n, index)z__PRIV__Arr_shift_left_nocheck_4(arr, n, index, (arr)->lenUsed - index)
#define z__PRIV__Arr_shift_left_nocheck_2(arr, n) z__PRIV__Arr_shift_left_nocheck_3(arr, n, n)
#define z__PRIV__Arr_shift_left_nocheck(...) zpp__Args_Overload(z__PRIV__Arr_shift_left_nocheck_, __VA_ARGS__)
#endif