liba 0.1.15
An algorithm library based on C/C++
Loading...
Searching...
No Matches
a.h
Go to the documentation of this file.
1
6#ifndef LIBA_A_H
7#define LIBA_A_H
8
9#if defined(A_HAVE_H)
10#include A_HAVE_H
11#endif /* A_HAVE_H */
12
15#if !defined __has_attribute
16#define __has_attribute(x) 0
17#endif /* __has_attribute */
18#if !defined __has_builtin
19#define __has_builtin(x) 0
20#endif /* __has_builtin */
21#if !defined __has_feature
22#define __has_feature(x) 0
23#endif /* __has_feature */
24#if !defined __has_include
25#define __has_include(x) 0
26#endif /* __has_include */
27#if !defined __has_warning
28#define __has_warning(x) 0
29#endif /* __has_warning */
30#if !defined A_HAVE_INLINE
31#define A_HAVE_INLINE 1
32#elif A_HAVE_INLINE + 0 < 1
33#undef A_HAVE_INLINE
34#endif /* A_HAVE_INLINE */
35#if defined(__GNUC__) || \
36 defined(__clang__)
37#pragma GCC system_header
38#endif /* __GNUC__ */
39
40#if defined(__MINGW32__)
41#undef __USE_MINGW_ANSI_STDIO
42#define __USE_MINGW_ANSI_STDIO 1
43#endif /* __MINGW32__ */
44
45/* https://en.wikipedia.org/wiki/Microsoft_Visual_C++ */
46#if defined(_MSC_VER)
47#define A_PREREQ_MSVC(maj, min) (_MSC_VER >= (maj * 100 + min))
48#else /* !_MSC_VER */
49#define A_PREREQ_MSVC(maj, min) 0
50#endif /* _MSC_VER */
51
52/* https://gcc.gnu.org/onlinedocs/cpp/Common-Predefined-Macros.html */
53#if defined(__GNUC__) && defined(__GNUC_MINOR__)
54#define A_PREREQ_GNUC(maj, min) ((__GNUC__ << 16) + __GNUC_MINOR__ >= ((maj) << 16) + (min))
55#else /* !__GNUC__ */
56#define A_PREREQ_GNUC(maj, min) 0
57#endif /* __GNUC__ */
58
59/* https://clang.llvm.org/docs/LanguageExtensions.html */
60#if defined(__clang_major__) && defined(__clang_minor__)
61#define A_PREREQ_LLVM(maj, min) ((__clang_major__ << 16) + __clang_minor__ >= ((maj) << 16) + (min))
62#else /* !__clang__ */
63#define A_PREREQ_LLVM(maj, min) 0
64#endif /* __clang__ */
65
66#if !defined A_FUNC
67#if defined(_MSC_VER)
68#define A_FUNC __FUNCTION__
69#elif defined(__GNUC__)
70#define A_FUNC (__extension__ __PRETTY_FUNCTION__)
71#elif defined(__cplusplus) && (__cplusplus > 201100L) || \
72 defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L)
73#define A_FUNC __func__
74#else /* !__func__ */
75#define A_FUNC __FUNCTION__
76#endif /* __func__ */
77#endif /* A_FUNC */
78
79#if defined(__STDC_VERSION__) && (__STDC_VERSION__ > 199900L) || \
80 defined(__cplusplus) && (__cplusplus > 201100L) || A_PREREQ_MSVC(18, 0)
81
82#if !defined A_HAVE_LONG_LONG_TYPE
83#define A_HAVE_LONG_LONG_TYPE 1
84#endif /* A_HAVE_LONG_LONG_TYPE */
85
86#endif /* C > 199900 or C++ > 201100 */
87#if defined(A_HAVE_LONG_LONG_TYPE) && (A_HAVE_LONG_LONG_TYPE + 0 < 1)
88#undef A_HAVE_LONG_LONG_TYPE
89#endif /* A_HAVE_LONG_LONG_TYPE */
90
91#if defined(__cplusplus) && (__cplusplus > 201100L)
92
93#if !defined A_HAVE_NULLPTR
94#define A_HAVE_NULLPTR 1
95#endif /* A_HAVE_NULLPTR */
96
97#endif /* C++ > 201100 */
98#if defined(A_HAVE_NULLPTR) && (A_HAVE_NULLPTR + 0 < 1)
99#undef A_HAVE_NULLPTR
100#endif /* A_HAVE_NULLPTR */
101
102#if A_PREREQ_GNUC(2, 96) || __has_builtin(__builtin_expect)
103#define A_UNLIKELY(x) __builtin_expect(!!(x), 0)
104#define A_LIKELY(x) __builtin_expect(!!(x), 1)
105#else /* !likely */
106#define A_UNLIKELY(x) (!!(x))
107#define A_LIKELY(x) (!!(x))
108#endif /* likely */
109
110#if defined(_WIN32) || defined(__CYGWIN__)
111#define A_DECLSPEC(x) __declspec(x)
112#else /* !__declspec */
113#define A_DECLSPEC(x)
114#endif /* __declspec */
115
116#if defined(__GNUC__) || defined(__clang__)
117#define A_ATTRIBUTE(x) __attribute__(x)
118#else /* !__attribute__ */
119#define A_ATTRIBUTE(x)
120#endif /* __attribute__ */
121
122#if __has_builtin(__builtin_assume)
123#define A_ASSUME(x) __builtin_assume(x)
124#elif A_PREREQ_GNUC(13, 0)
125#define A_ASSUME(x) __attribute__((__assume__(x)))
126#elif defined(__GNUC__)
127#define A_ASSUME(x) \
128 do { \
129 if (!(x)) { __builtin_unreachable(); } \
130 } while (0)
131#elif defined(_MSC_VER)
132#define A_ASSUME(x) __assume(x)
133#else /* !assume */
134#define A_ASSUME(x) (void)0
135#endif /* assume */
136
137/* attribute nonnull */
138#if A_PREREQ_GNUC(3, 3) || __has_attribute(__nonnull__)
139#define A_NONULL(x) __attribute__((__nonnull__ x))
140#else /* !nonnull */
141#define A_NONULL(x)
142#endif /* nonnull */
143
144/* attribute format */
145#if A_PREREQ_GNUC(2, 4) || __has_attribute(__format__)
146#define A_FORMAT(_, a, b) __attribute__((__format__(_, a, b)))
147#else /* !format */
148#define A_FORMAT(_, a, b)
149#endif /* format */
150
151/* attribute fallthrough */
152#if A_PREREQ_GNUC(7, 0) || __has_attribute(__fallthrough__)
153#define A_FALLTHROUGH __attribute__((__fallthrough__))
154#else /* !fallthrough */
155#define A_FALLTHROUGH (void)0
156#endif /* fallthrough */
157
158/* attribute deprecated */
159#if A_PREREQ_GNUC(3, 2) || __has_attribute(__deprecated__)
160#define A_DEPRECATED __attribute__((__deprecated__))
161#elif defined(_WIN32) || defined(__CYGWIN__)
162#define A_DEPRECATED __declspec(deprecated)
163#else /* !deprecated */
164#define A_DEPRECATED
165#endif /* deprecated */
166
167/* attribute always inline */
168#if A_PREREQ_GNUC(3, 2) || __has_attribute(__always_inline__)
169#define A_INLINE __inline __attribute__((__always_inline__))
170#elif defined(_MSC_VER)
171#define A_INLINE __inline __forceinline
172#else /* !_MSC_VER */
173#define A_INLINE __inline
174#endif /* _MSC_VER */
175#if !defined A_INTERN
176#define A_INTERN static A_INLINE
177#endif /* A_INTERN */
178
179/* attribute visibility */
180#if defined(_WIN32) || defined(__CYGWIN__)
181#define A_EXPORT __declspec(dllexport)
182#define A_IMPORT __declspec(dllimport)
183#define A_HIDDEN
184#elif A_PREREQ_GNUC(4, 0) || __has_attribute(__visibility__)
185#define A_EXPORT __attribute__((__visibility__("default")))
186#define A_IMPORT __attribute__((__visibility__("default")))
187#define A_HIDDEN __attribute__((__visibility__("hidden")))
188#else /* !visibility */
189#define A_EXPORT
190#define A_IMPORT
191#define A_HIDDEN
192#endif /* visibility */
193#if defined(A_EXPORTS)
194#define A_PUBLIC A_EXPORT
195#elif defined(A_IMPORTS)
196#define A_PUBLIC A_IMPORT
197#else /* !A_PUBLIC */
198#define A_PUBLIC
199#endif /* A_PUBLIC */
200
201#if !defined A_EXTERN
202#define A_EXTERN A_PUBLIC extern
203#endif /* A_EXTERN */
204#if !defined __cplusplus
205#define A_EXTERN_C
206#define A_EXTERN_C_ENTER
207#define A_EXTERN_C_LEAVE
208#else /* !__cplusplus */
209#define A_EXTERN_C extern "C"
210#define A_EXTERN_C_ENTER extern "C" {
211#define A_EXTERN_C_LEAVE }
212#endif /* __cplusplus */
213
216/* byte order of little endian architecture */
217#if defined(__ORDER_LITTLE_ENDIAN__)
218#define A_ORDER_LITTLE __ORDER_LITTLE_ENDIAN__
219#else /* !__ORDER_LITTLE_ENDIAN__ */
220#define A_ORDER_LITTLE 1234
221#endif /* __ORDER_LITTLE_ENDIAN__ */
222/* byte order of big endian architecture */
223#if defined(__ORDER_BIG_ENDIAN__)
224#define A_ORDER_BIG __ORDER_BIG_ENDIAN__
225#else /* !__ORDER_BIG_ENDIAN__ */
226#define A_ORDER_BIG 4321
227#endif /* __ORDER_BIG_ENDIAN__ */
228/* byte order of architecture */
229#if !defined A_BYTE_ORDER
230#if defined(__BYTE_ORDER__)
231#define A_BYTE_ORDER __BYTE_ORDER__
232#endif /* __BYTE_ORDER__ */
233#endif /* A_BYTE_ORDER */
234
235/* size of void pointer */
236#if !defined A_SIZE_POINTER
237#if defined(__SIZEOF_POINTER__)
238#define A_SIZE_POINTER __SIZEOF_POINTER__
239#elif defined(_WIN64)
240#define A_SIZE_POINTER 8
241#elif defined(_WIN32)
242#define A_SIZE_POINTER 4
243#endif /* __SIZEOF_POINTER__ */
244#endif /* A_SIZE_POINTER */
245
246#include <stddef.h>
247#include <limits.h>
248#include <stdint.h>
249#include <float.h>
250
257#define A_BUILD_ASSERT(x) (void)(sizeof(char[1 - 2 * !(x)]))
258#define A_BUILD_BUG_ON(x) (void)(sizeof(char[1 - 2 * !!(x)]))
259
260#if defined(__cplusplus)
261#define a_cast_r(T, x) reinterpret_cast<T>(x)
262#define a_cast_d(T, x) dynamic_cast<T>(x)
263#define a_cast_s(T, x) static_cast<T>(x)
264#define a_cast_c(T, x) const_cast<T>(x)
265#else /* !__cplusplus */
266#define a_cast_r(T, x) ((T)(x))
267#define a_cast_d(T, x) ((T)(x))
268#define a_cast_s(T, x) ((T)(x))
269#define a_cast_c(T, x) ((T)(x))
270#endif /* __cplusplus */
271#define A_CAST_3(a, b, c) a##b##c
272#define A_CAST_2(a, b) a##b
273#define A_CAST_1(a) #a
274
275#if defined(__cplusplus) && defined(A_HAVE_NULLPTR)
276#define A_NULL nullptr
277#else /* !__cplusplus */
278#define A_NULL NULL
279#endif /* __cplusplus */
281#define a_void_c(_, x) a_cast_s(void, x)
282#define a_void_(_, x) a_cast_s(void _, x)
284#define a_void void
285
286#if defined(__cplusplus)
287#define A_TRUE true
288#define A_FALSE false
289#if !defined A_BOOL
290#define A_BOOL bool
291#endif /* A_BOOL */
292#else /* !__cplusplus */
293#define A_TRUE 1
294#define A_FALSE 0
295#if !defined A_BOOL
296#define A_BOOL _Bool
297#endif /* A_BOOL */
298#endif /* __cplusplus */
300#define a_bool_c(x) (!!(x))
302#define a_bool A_BOOL
303
304#define A_INT int
305#define A_INT_MIN INT_MIN
306#define A_INT_MAX INT_MAX
308#define a_int_c(x) a_cast_s(A_INT, x)
309#define a_int_(_, x) a_cast_s(A_INT _, x)
311#define a_int A_INT
312
313#define A_UINT unsigned int
314#define A_UINT_MAX UINT_MAX
316#define a_uint_c(x) a_cast_s(A_UINT, x)
317#define a_uint_(_, x) a_cast_s(A_UINT _, x)
319#define a_uint A_UINT
320
321#define A_SHRT short
322#define A_SHRT_MIN SHRT_MIN
323#define A_SHRT_MAX SHRT_MAX
325#define a_shrt_c(x) a_cast_s(A_SHRT, x)
326#define a_shrt_(_, x) a_cast_s(A_SHRT _, x)
328#define a_shrt A_SHRT
329
330#define A_USHRT unsigned short
331#define A_USHRT_MAX USHRT_MAX
333#define a_ushrt_c(x) a_cast_s(A_USHRT, x)
334#define a_ushrt_(_, x) a_cast_s(A_USHRT _, x)
336#define a_ushrt A_USHRT
337
338#define A_LONG long
339#define A_LONG_MIN LONG_MIN
340#define A_LONG_MAX LONG_MAX
342#define a_long_c(x) a_cast_s(A_LONG, x)
343#define a_long_(_, x) a_cast_s(A_LONG _, x)
345#define a_long A_LONG
346
347#define A_ULONG unsigned long
348#define A_ULONG_MAX ULONG_MAX
350#define a_ulong_c(x) a_cast_s(A_ULONG, x)
351#define a_ulong_(_, x) a_cast_s(A_ULONG _, x)
353#define a_ulong A_ULONG
354
355#if defined(A_HAVE_LONG_LONG_TYPE)
356
357#define A_LLONG long long
358#define A_LLONG_MIN LLONG_MIN
359#define A_LLONG_MAX LLONG_MAX
361#define a_llong_c(x) a_cast_s(A_LLONG, x)
362#define a_llong_(_, x) a_cast_s(A_LLONG _, x)
364#define a_llong A_LLONG
365
366#define A_ULLONG unsigned long long
367#define A_ULLONG_MAX ULLONG_MAX
369#define a_ullong_c(x) a_cast_s(A_ULLONG, x)
370#define a_ullong_(_, x) a_cast_s(A_ULLONG _, x)
372#define a_ullong A_ULLONG
373
374#endif /* A_HAVE_LONG_LONG_TYPE */
375
376#define A_BYTE unsigned char
377#define A_BYTE_MAX UCHAR_MAX
379#define a_byte_c(x) a_cast_s(A_BYTE, x)
380#define a_byte_(_, x) a_cast_s(A_BYTE _, x)
382#define a_byte A_BYTE
383
384#define A_C8 char
385#define A_C8_MIN CHAR_MIN
386#define A_C8_MAX CHAR_MAX
388#define a_c8_c(x) a_cast_s(A_C8, x)
389#define a_c8_(_, x) a_cast_s(A_C8 _, x)
391#define a_c8 A_C8
392
393#if !defined A_I8
394#define A_I8 int8_t
395#endif /* A_I8 */
396#if !defined A_I8_C && defined(INT8_C)
397#define A_I8_C(X) INT8_C(X)
398#endif /* A_I8_C */
399#if !defined A_I8_MIN && defined(INT8_MIN)
400#define A_I8_MIN INT8_MIN
401#endif /* A_I8_MIN */
402#if !defined A_I8_MAX && defined(INT8_MAX)
403#define A_I8_MAX INT8_MAX
404#endif /* A_I8_MAX */
406#define a_i8_c(x) a_cast_s(A_I8, x)
407#define a_i8_(_, x) a_cast_s(A_I8 _, x)
409#define a_i8 A_I8
410
411#if !defined A_U8
412#define A_U8 uint8_t
413#endif /* A_U8 */
414#if !defined A_U8_C && defined(UINT8_C)
415#define A_U8_C(X) UINT8_C(X)
416#endif /* A_U8_C */
417#if !defined A_U8_MAX && defined(UINT8_MAX)
418#define A_U8_MAX UINT8_MAX
419#endif /* A_U8_MAX */
421#define a_u8_c(x) a_cast_s(A_U8, x)
422#define a_u8_(_, x) a_cast_s(A_U8 _, x)
424#define a_u8 A_U8
425
426#if !defined A_I16
427#define A_I16 int16_t
428#endif /* A_I16 */
429#if !defined A_I16_C && defined(INT16_C)
430#define A_I16_C(X) INT16_C(X)
431#endif /* A_I16_C */
432#if !defined A_I16_MIN && defined(INT16_MIN)
433#define A_I16_MIN INT16_MIN
434#endif /* A_I16_MIN */
435#if !defined A_I16_MAX && defined(INT16_MAX)
436#define A_I16_MAX INT16_MAX
437#endif /* A_I16_MAX */
439#define a_i16_c(x) a_cast_s(A_I16, x)
440#define a_i16_(_, x) a_cast_s(A_I16 _, x)
442#define a_i16 A_I16
443
444#if !defined A_U16
445#define A_U16 uint16_t
446#endif /* A_U16 */
447#if !defined A_U16_C && defined(UINT16_C)
448#define A_U16_C(X) UINT16_C(X)
449#endif /* A_U16_C */
450#if !defined A_U16_MAX && defined(UINT16_MAX)
451#define A_U16_MAX UINT16_MAX
452#endif /* A_U16_MAX */
454#define a_u16_c(x) a_cast_s(A_U16, x)
455#define a_u16_(_, x) a_cast_s(A_U16 _, x)
457#define a_u16 A_U16
458
459#if !defined A_I32
460#define A_I32 int32_t
461#endif /* A_I32 */
462#if !defined A_I32_C && defined(INT32_C)
463#define A_I32_C(X) INT32_C(X)
464#endif /* A_I32_C */
465#if !defined A_I32_MIN && defined(INT32_MIN)
466#define A_I32_MIN INT32_MIN
467#endif /* A_I32_MIN */
468#if !defined A_I32_MAX && defined(INT32_MAX)
469#define A_I32_MAX INT32_MAX
470#endif /* A_I32_MAX */
472#define a_i32_c(x) a_cast_s(A_I32, x)
473#define a_i32_(_, x) a_cast_s(A_I32 _, x)
475#define a_i32 A_I32
476
477#if !defined A_U32
478#define A_U32 uint32_t
479#endif /* A_U32 */
480#if !defined A_U32_C && defined(UINT32_C)
481#define A_U32_C(X) UINT32_C(X)
482#endif /* A_U32_C */
483#if !defined A_U32_MAX && defined(UINT32_MAX)
484#define A_U32_MAX UINT32_MAX
485#endif /* A_U32_MAX */
487#define a_u32_c(x) a_cast_s(A_U32, x)
488#define a_u32_(_, x) a_cast_s(A_U32 _, x)
490#define a_u32 A_U32
491
492#if !defined A_I64
493#define A_I64 int64_t
494#endif /* A_I64 */
495#if !defined A_I64_C && defined(INT64_C)
496#define A_I64_C(X) INT64_C(X)
497#endif /* A_I64_C */
498#if !defined A_I64_MIN && defined(INT64_MIN)
499#define A_I64_MIN INT64_MIN
500#endif /* A_I64_MIN */
501#if !defined A_I64_MAX && defined(INT64_MAX)
502#define A_I64_MAX INT64_MAX
503#endif /* A_I64_MAX */
505#define a_i64_c(x) a_cast_s(A_I64, x)
506#define a_i64_(_, x) a_cast_s(A_I64 _, x)
508#define a_i64 A_I64
509
510#if !defined A_U64
511#define A_U64 uint64_t
512#endif /* A_U64 */
513#if !defined A_U64_C && defined(UINT64_C)
514#define A_U64_C(X) UINT64_C(X)
515#endif /* A_U64_C */
516#if !defined A_U64_MAX && defined(UINT64_MAX)
517#define A_U64_MAX UINT64_MAX
518#endif /* A_U64_MAX */
520#define a_u64_c(x) a_cast_s(A_U64, x)
521#define a_u64_(_, x) a_cast_s(A_U64 _, x)
523#define a_u64 A_U64
524
525#if !defined A_IMAX
526#define A_IMAX intmax_t
527#endif /* A_IMAX */
528#if !defined A_IMAX_C && defined(INTMAX_C)
529#define A_IMAX_C(X) INTMAX_C(X)
530#endif /* A_IMAX_C */
531#if !defined A_IMAX_MIN && defined(INTMAX_MIN)
532#define A_IMAX_MIN INTMAX_MIN
533#endif /* A_IMAX_MIN */
534#if !defined A_IMAX_MAX && defined(INTMAX_MAX)
535#define A_IMAX_MAX INTMAX_MAX
536#endif /* A_IMAX_MAX */
538#define a_imax_c(x) a_cast_s(A_IMAX, x)
539#define a_imax_(_, x) a_cast_s(A_IMAX _, x)
541#define a_imax A_IMAX
542
543#if !defined A_UMAX
544#define A_UMAX uintmax_t
545#endif /* A_UMAX */
546#if !defined A_UMAX_C && defined(UINTMAX_C)
547#define A_UMAX_C(X) UINTMAX_C(X)
548#endif /* A_UMAX_C */
549#if !defined A_UMAX_MAX && defined(UINTMAX_MAX)
550#define A_UMAX_MAX UINTMAX_MAX
551#endif /* A_UMAX_MAX */
553#define a_umax_c(x) a_cast_s(A_UMAX, x)
554#define a_umax_(_, x) a_cast_s(A_UMAX _, x)
556#define a_umax A_UMAX
557
558#if !defined A_IPTR
559#define A_IPTR intptr_t
560#endif /* A_IPTR */
561#if !defined A_IPTR_MIN && defined(INTPTR_MIN)
562#define A_IPTR_MIN INTPTR_MIN
563#endif /* A_IPTR_MIN */
564#if !defined A_IPTR_MAX && defined(INTPTR_MAX)
565#define A_IPTR_MAX INTPTR_MAX
566#endif /* A_IPTR_MAX */
568#define a_iptr_c(x) a_cast_s(A_IPTR, x)
569#define a_iptr_(_, x) a_cast_s(A_IPTR _, x)
571#define a_iptr A_IPTR
572
573#if !defined A_UPTR
574#define A_UPTR uintptr_t
575#endif /* A_UPTR */
576#if !defined A_UPTR_MAX && defined(UINTPTR_MAX)
577#define A_UPTR_MAX UINTPTR_MAX
578#endif /* A_UPTR_MAX */
580#define a_uptr_c(x) a_cast_s(A_UPTR, x)
581#define a_uptr_(_, x) a_cast_s(A_UPTR _, x)
583#define a_uptr A_UPTR
584
585#if !defined A_DIFF
586#define A_DIFF ptrdiff_t
587#endif /* A_DIFF */
588#if !defined A_DIFF_MIN && defined(PTRDIFF_MIN)
589#define A_DIFF_MIN PTRDIFF_MIN
590#endif /* A_DIFF_MIN */
591#if !defined A_DIFF_MAX && defined(PTRDIFF_MAX)
592#define A_DIFF_MAX PTRDIFF_MAX
593#endif /* A_DIFF_MAX */
595#define a_diff_c(x) a_cast_s(A_DIFF, x)
596#define a_diff_(_, x) a_cast_s(A_DIFF _, x)
598#define a_diff A_DIFF
599
600#if !defined A_SIZE
601#define A_SIZE size_t
602#endif /* A_SIZE */
603#if !defined A_SIZE_MAX && defined(SIZE_MAX)
604#define A_SIZE_MAX SIZE_MAX
605#endif /* A_SIZE_MAX */
607#define a_size_c(x) a_cast_s(A_SIZE, x)
608#define a_size_(_, x) a_cast_s(A_SIZE _, x)
610#define a_size A_SIZE
611
612#define A_F16_NNAN A_U16_C(0xFE00)
613#define A_F16_PNAN A_U16_C(0x7E00)
614#define A_F16_NINF A_U16_C(0xFC00)
615#define A_F16_PINF A_U16_C(0x7C00)
616
617#define A_F32 float
618#define A_F32_C(X) A_CAST_2(X, F)
619#define A_F32_F(F) A_CAST_2(F, f)
620#define A_F32_DIG FLT_DIG
621#define A_F32_EPSILON FLT_EPSILON
622#define A_F32_MANT_DIG FLT_MANT_DIG
623#define A_F32_MAX FLT_MAX
624#define A_F32_MAX_10_EXP FLT_MAX_10_EXP
625#define A_F32_MAX_EXP FLT_MAX_EXP
626#define A_F32_MIN FLT_MIN
627#define A_F32_MIN_10_EXP FLT_MIN_10_EXP
628#define A_F32_MIN_EXP FLT_MIN_EXP
629#define A_F32_INF a_cast_s(A_F32, A_F64_INF)
630#define A_F32_NAN (A_F32_C(0.0) * A_F32_INF)
631#define A_F32_NNAN A_U32_C(0xFFC00000)
632#define A_F32_PNAN A_U32_C(0x7FC00000)
633#define A_F32_NINF A_U32_C(0xFF800000)
634#define A_F32_PINF A_U32_C(0x7F800000)
636#define A_F32_PRI(F, C) "%" F C
638#define A_F32_SCN(F, C) "%" F C
640#define a_f32_c(x) a_cast_s(A_F32, x)
641#define a_f32_(_, x) a_cast_s(A_F32 _, x)
643#define a_f32 A_F32
644
645#define A_F64 double
646#define A_F64_C(X) X
647#define A_F64_F(F) F
648#define A_F64_DIG DBL_DIG
649#define A_F64_EPSILON DBL_EPSILON
650#define A_F64_MANT_DIG DBL_MANT_DIG
651#define A_F64_MAX DBL_MAX
652#define A_F64_MAX_10_EXP DBL_MAX_10_EXP
653#define A_F64_MAX_EXP DBL_MAX_EXP
654#define A_F64_MIN DBL_MIN
655#define A_F64_MIN_10_EXP DBL_MIN_10_EXP
656#define A_F64_MIN_EXP DBL_MIN_EXP
657#define A_F64_INF (DBL_MAX * DBL_MAX)
658#define A_F64_NAN (A_F64_C(0.0) * A_F64_INF)
659#define A_F64_NNAN A_U64_C(0xFFF8000000000000)
660#define A_F64_PNAN A_U64_C(0x7FF8000000000000)
661#define A_F64_NINF A_U64_C(0xFFF0000000000000)
662#define A_F64_PINF A_U64_C(0x7FF0000000000000)
664#define A_F64_PRI(F, C) "%" F "l" C
666#define A_F64_SCN(F, C) "%" F "l" C
668#define a_f64_c(x) a_cast_s(A_F64, x)
669#define a_f64_(_, x) a_cast_s(A_F64 _, x)
671#define a_f64 A_F64
672
679#if !defined A_FLOAT_TYPE
680#if !defined A_SIZE_FLOAT
681#define A_FLOAT_TYPE A_FLOAT_DOUBLE
682#else /* !A_SIZE_FLOAT */
683#define A_FLOAT_TYPE A_SIZE_FLOAT
684#endif /* A_SIZE_FLOAT */
685#endif /* A_FLOAT_TYPE */
686#define A_FLOAT_SINGLE 0x04
687#define A_FLOAT_DOUBLE 0x08
688#define A_FLOAT_EXTEND 0x10
689#if defined(A_FLOAT)
690#elif A_FLOAT_TYPE + 0 == A_FLOAT_SINGLE
691
693#define A_FLOAT float
694#define A_FLOAT_DIG FLT_DIG
695#define A_FLOAT_EPSILON FLT_EPSILON
696#define A_FLOAT_MANT_DIG FLT_MANT_DIG
697#define A_FLOAT_MAX FLT_MAX
698#define A_FLOAT_MAX_10_EXP FLT_MAX_10_EXP
699#define A_FLOAT_MAX_EXP FLT_MAX_EXP
700#define A_FLOAT_MIN FLT_MIN
701#define A_FLOAT_MIN_10_EXP FLT_MIN_10_EXP
702#define A_FLOAT_MIN_EXP FLT_MIN_EXP
703
707#define A_FLOAT_C(X) A_CAST_2(X, F)
711#define A_FLOAT_F(F) A_CAST_2(F, f)
712
714#define A_FLOAT_PRI(F, C) "%" F C
716#define A_FLOAT_SCN(F, C) "%" F C
717
718#elif A_FLOAT_TYPE + 0 == A_FLOAT_DOUBLE
719
721#define A_FLOAT double
722#define A_FLOAT_DIG DBL_DIG
723#define A_FLOAT_EPSILON DBL_EPSILON
724#define A_FLOAT_MANT_DIG DBL_MANT_DIG
725#define A_FLOAT_MAX DBL_MAX
726#define A_FLOAT_MAX_10_EXP DBL_MAX_10_EXP
727#define A_FLOAT_MAX_EXP DBL_MAX_EXP
728#define A_FLOAT_MIN DBL_MIN
729#define A_FLOAT_MIN_10_EXP DBL_MIN_10_EXP
730#define A_FLOAT_MIN_EXP DBL_MIN_EXP
731
735#define A_FLOAT_C(X) X
739#define A_FLOAT_F(F) F
740
742#define A_FLOAT_PRI(F, C) "%" F C
744#define A_FLOAT_SCN(F, C) "%" F "l" C
745
746#elif A_FLOAT_TYPE + 0 == A_FLOAT_EXTEND
747
749#define A_FLOAT long double
750#define A_FLOAT_DIG LDBL_DIG
751#define A_FLOAT_EPSILON LDBL_EPSILON
752#define A_FLOAT_MANT_DIG LDBL_MANT_DIG
753#define A_FLOAT_MAX LDBL_MAX
754#define A_FLOAT_MAX_10_EXP LDBL_MAX_10_EXP
755#define A_FLOAT_MAX_EXP LDBL_MAX_EXP
756#define A_FLOAT_MIN LDBL_MIN
757#define A_FLOAT_MIN_10_EXP LDBL_MIN_10_EXP
758#define A_FLOAT_MIN_EXP LDBL_MIN_EXP
759
763#define A_FLOAT_C(X) A_CAST_2(X, L)
767#define A_FLOAT_F(F) A_CAST_2(F, l)
768
770#define A_FLOAT_PRI(F, C) "%" F "L" C
772#define A_FLOAT_SCN(F, C) "%" F "L" C
773
774#else /* !A_FLOAT_TYPE */
775#error unsupported precision
776#endif /* A_FLOAT_TYPE */
777
778#define A_FLOAT_INF a_cast_s(A_FLOAT, A_F64_INF)
779#define A_FLOAT_NAN (A_FLOAT_C(0.0) * A_FLOAT_INF)
780
782#define a_float_c(x) a_cast_s(A_FLOAT, x)
783#define a_float_(_, x) a_cast_s(A_FLOAT _, x)
785#define a_float A_FLOAT
786
789typedef union a_cast
790{
791 a_c8 c;
792 a_int i;
793 a_uint u;
794 a_shrt ih;
795 a_ushrt uh;
796 a_long il;
797 a_ulong ul;
798#if defined(A_HAVE_LONG_LONG_TYPE)
799 a_llong ill;
800 a_ullong ull;
801#endif /* A_HAVE_LONG_LONG_TYPE */
802 a_i8 i8;
803 a_u8 u8;
804 a_i16 i16;
805 a_u16 u16;
806 a_i32 i32;
807 a_u32 u32;
808 a_i64 i64;
809 a_u64 u64;
810 a_f32 f32;
811 a_f64 f64;
812 a_imax imax;
813 a_umax umax;
814 a_iptr iptr;
815 a_uptr uptr;
816 a_diff diff;
817 a_size size;
818 void const *PTR;
819 void *ptr;
820 char const *STR;
821 char *str;
822#if defined(A_FLOAT_TYPE) && (A_FLOAT_TYPE + 0 < A_FLOAT_EXTEND)
823 a_float f;
824#endif /* A_FLOAT_TYPE */
825} a_cast;
826
830#define A_SQ(x) ((x) * (x))
831
835#define A_ABS(x) ((x) < 0 ? -(x) : (x))
839#define A_ABS_(f, g) ((f) < (g) ? (g) - (f) : (f) - (g))
840
844#define A_MIN(x, y) (((x) < (y)) ? (x) : (y))
845
849#define A_MAX(x, y) (((x) > (y)) ? (x) : (y))
850
854#define A_SGN(x) ((0 < (x)) - ((x) < 0))
858#define A_SGN_(f, g) (((f) > (g)) - ((f) < (g)))
859
863#define A_SAT(x, min, max) ((min) < (x) ? (x) < (max) ? (x) : (max) : (min))
864
869#define A_LEN(a) (sizeof(a) / sizeof(*(a)))
870
876#if defined(offsetof)
877#define a_offsetof(type, member) offsetof(type, member)
878#else /* !offsetof */
879#define a_offsetof(type, member) a_cast_r(a_size, &a_cast_r(type *, 0)->member)
880#endif /* offsetof */
881
888#define a_container_of(ptr, type, member) a_cast_r(type *, a_cast_r(a_uptr, ptr) - a_offsetof(type, member))
889
893#define a_size_down(a, n) (a_cast_s(a_size, n) & ~a_cast_s(a_size, (a) - 1))
894
898#define a_size_up(a, n) ((a_cast_s(a_size, n) + (a) - 1) & ~a_cast_s(a_size, (a) - 1))
899
903#define a_align_down(a, p) a_cast_r(void *, a_cast_r(a_uptr, p) & ~a_cast_s(a_uptr, (a) - 1))
904
908#define a_align_up(a, p) a_cast_r(void *, (a_cast_r(a_uptr, p) + (a) - 1) & ~a_cast_s(a_uptr, (a) - 1))
909
916#define a_forenum(I, i, n) for (I i = 0; i < (n); ++i)
917
924#define a_forenum_reverse(I, i, n) for (I i = (n); i-- > 0;)
925
934#define a_foreach(T, P, it, ptr, num) \
935 for (T P it = a_cast_s(T P, ptr), P it##_ = it + (num); it < it##_; ++it)
937#define a_forsafe(T, P, it, ptr, num) \
938 for (T P it = a_cast_s(T P, ptr), P it##_ = (num) ? it + (num) : it; it < it##_; ++it)
939
948#define a_foreach_reverse(T, P, it, ptr, num) \
949 for (T P it##_ = a_cast_s(T P, ptr) - 1, P it = it##_ + (num); it > it##_; --it)
951#define a_forsafe_reverse(T, P, it, ptr, num) \
952 for (T P it##_ = (num) ? a_cast_s(T P, ptr) - 1 : a_cast_s(T P, ptr), \
953 P it = (num) ? it##_ + (num) : it##_; \
954 it > it##_; --it)
955
964#define a_iterate(T, P, it, ptr, end) \
965 for (T P it = a_cast_s(T P, ptr), P it##_ = a_cast_s(T P, end); it < it##_; ++it)
966
975#define a_iterate_reverse(T, P, it, ptr, end) \
976 for (T P it = a_cast_s(T P, end) - 1, P it##_ = a_cast_s(T P, ptr) - 1; it > it##_; --it)
977
981enum
982{
985 A_INVALID
987
988#if defined(__cplusplus)
989extern "C" {
990#endif /* __cplusplus */
991#if defined(LIBA_A_C)
992#undef A_INTERN
993#define A_INTERN A_INLINE
994#endif /* LIBA_A_C */
995
1001#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1002A_EXTERN a_u8 a_u8_rev(a_u8 x);
1003#endif /* A_HAVE_INLINE */
1004#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1005A_INTERN a_u8 a_u8_rev(a_u8 x)
1006{
1007 x = a_cast_s(a_u8, (x >> 4) | (x << 4));
1008 x = a_cast_s(a_u8, ((x & 0xCC) >> 2) | ((x & 0x33) << 2));
1009 x = a_cast_s(a_u8, ((x & 0xAA) >> 1) | ((x & 0x55) << 1));
1010 return x;
1011}
1012#endif /* A_HAVE_INLINE */
1013
1019#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1021#endif /* A_HAVE_INLINE */
1022#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1023A_INTERN a_u16 a_u16_rev(a_u16 x)
1024{
1025 x = a_cast_s(a_u16, (x >> 8) | (x << 8));
1026 x = a_cast_s(a_u16, ((x & 0xF0F0) >> 4) | ((x & 0x0F0F) << 4));
1027 x = a_cast_s(a_u16, ((x & 0xCCCC) >> 2) | ((x & 0x3333) << 2));
1028 x = a_cast_s(a_u16, ((x & 0xAAAA) >> 1) | ((x & 0x5555) << 1));
1029 return x;
1030}
1031#endif /* A_HAVE_INLINE */
1032#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1033A_EXTERN A_NONULL((1)) a_u16 a_u16_getl(void const *b);
1034#endif /* A_HAVE_INLINE */
1035#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1036A_INTERN A_NONULL((1)) a_u16 a_u16_getl(void const *b)
1037{
1038 a_byte const *p = a_cast_s(a_byte const *, b);
1039 return a_cast_s(a_u16, (p[0] << 0) | (p[1] << 8));
1040}
1041#endif /* A_HAVE_INLINE */
1042#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1043A_EXTERN A_NONULL((1)) a_u16 a_u16_getb(void const *b);
1044#endif /* A_HAVE_INLINE */
1045#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1046A_INTERN A_NONULL((1)) a_u16 a_u16_getb(void const *b)
1047{
1048 a_byte const *p = a_cast_s(a_byte const *, b);
1049 return a_cast_s(a_u16, (p[1] << 0) | (p[0] << 8));
1050}
1051#endif /* A_HAVE_INLINE */
1052#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1053A_EXTERN A_NONULL((1)) void a_u16_setl(void *b, a_u16 x);
1054#endif /* A_HAVE_INLINE */
1055#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1056A_INTERN A_NONULL((1)) void a_u16_setl(void *b, a_u16 x)
1057{
1058 a_byte *p = a_cast_s(a_byte *, b);
1059 p[0] = a_cast_s(a_byte, x >> 0);
1060 p[1] = a_cast_s(a_byte, x >> 8);
1061}
1062#endif /* A_HAVE_INLINE */
1063#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1064A_EXTERN A_NONULL((1)) void a_u16_setb(void *b, a_u16 x);
1065#endif /* A_HAVE_INLINE */
1066#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1067A_INTERN A_NONULL((1)) void a_u16_setb(void *b, a_u16 x)
1068{
1069 a_byte *p = a_cast_s(a_byte *, b);
1070 p[0] = a_cast_s(a_byte, x >> 8);
1071 p[1] = a_cast_s(a_byte, x >> 0);
1072}
1073#endif /* A_HAVE_INLINE */
1074
1080#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1082#endif /* A_HAVE_INLINE */
1083#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1084A_INTERN a_u32 a_u32_rev(a_u32 x)
1085{
1086 x = (x >> 16) | (x << 16);
1087 x = ((x & 0xFF00FF00) >> 8) | ((x & 0x00FF00FF) << 8);
1088 x = ((x & 0xF0F0F0F0) >> 4) | ((x & 0x0F0F0F0F) << 4);
1089 x = ((x & 0xCCCCCCCC) >> 2) | ((x & 0x33333333) << 2);
1090 x = ((x & 0xAAAAAAAA) >> 1) | ((x & 0x55555555) << 1);
1091 return x;
1092}
1093#endif /* A_HAVE_INLINE */
1094#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1095A_EXTERN A_NONULL((1)) a_u32 a_u32_getl(void const *b);
1096#endif /* A_HAVE_INLINE */
1097#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1098A_INTERN A_NONULL((1)) a_u32 a_u32_getl(void const *b)
1099{
1100 a_byte const *p = a_cast_s(a_byte const *, b);
1101 return (a_cast_s(a_u32, p[0]) << 0x00) |
1102 (a_cast_s(a_u32, p[1]) << 0x08) |
1103 (a_cast_s(a_u32, p[2]) << 0x10) |
1104 (a_cast_s(a_u32, p[3]) << 0x18);
1105}
1106#endif /* A_HAVE_INLINE */
1107#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1108A_EXTERN A_NONULL((1)) a_u32 a_u32_getb(void const *b);
1109#endif /* A_HAVE_INLINE */
1110#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1111A_INTERN A_NONULL((1)) a_u32 a_u32_getb(void const *b)
1112{
1113 a_byte const *p = a_cast_s(a_byte const *, b);
1114 return (a_cast_s(a_u32, p[0]) << 0x18) |
1115 (a_cast_s(a_u32, p[1]) << 0x10) |
1116 (a_cast_s(a_u32, p[2]) << 0x08) |
1117 (a_cast_s(a_u32, p[3]) << 0x00);
1118}
1119#endif /* A_HAVE_INLINE */
1120#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1121A_EXTERN A_NONULL((1)) void a_u32_setl(void *b, a_u32 x);
1122#endif /* A_HAVE_INLINE */
1123#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1124A_INTERN A_NONULL((1)) void a_u32_setl(void *b, a_u32 x)
1125{
1126 a_byte *p = a_cast_s(a_byte *, b);
1127 p[0] = a_cast_s(a_byte, x >> 0x00);
1128 p[1] = a_cast_s(a_byte, x >> 0x08);
1129 p[2] = a_cast_s(a_byte, x >> 0x10);
1130 p[3] = a_cast_s(a_byte, x >> 0x18);
1131}
1132#endif /* A_HAVE_INLINE */
1133#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1134A_EXTERN A_NONULL((1)) void a_u32_setb(void *b, a_u32 x);
1135#endif /* A_HAVE_INLINE */
1136#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1137A_INTERN A_NONULL((1)) void a_u32_setb(void *b, a_u32 x)
1138{
1139 a_byte *p = a_cast_s(a_byte *, b);
1140 p[0] = a_cast_s(a_byte, x >> 0x18);
1141 p[1] = a_cast_s(a_byte, x >> 0x10);
1142 p[2] = a_cast_s(a_byte, x >> 0x08);
1143 p[3] = a_cast_s(a_byte, x >> 0x00);
1144}
1145#endif /* A_HAVE_INLINE */
1146
1152#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1154#endif /* A_HAVE_INLINE */
1155#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1156A_INTERN a_u64 a_u64_rev(a_u64 x)
1157{
1158 x = (x >> 32) | (x << 32);
1159 x = ((x & 0xFFFF0000FFFF0000) >> 0x10) | ((x & 0x0000FFFF0000FFFF) << 0x10);
1160 x = ((x & 0xFF00FF00FF00FF00) >> 0x08) | ((x & 0x00FF00FF00FF00FF) << 0x08);
1161 x = ((x & 0xF0F0F0F0F0F0F0F0) >> 0x04) | ((x & 0x0F0F0F0F0F0F0F0F) << 0x04);
1162 x = ((x & 0xCCCCCCCCCCCCCCCC) >> 0x02) | ((x & 0x3333333333333333) << 0x02);
1163 x = ((x & 0xAAAAAAAAAAAAAAAA) >> 0x01) | ((x & 0x5555555555555555) << 0x01);
1164 return x;
1165}
1166#endif /* A_HAVE_INLINE */
1167#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1168A_EXTERN A_NONULL((1)) a_u64 a_u64_getl(void const *b);
1169#endif /* A_HAVE_INLINE */
1170#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1171A_INTERN A_NONULL((1)) a_u64 a_u64_getl(void const *b)
1172{
1173 a_byte const *p = a_cast_s(a_byte const *, b);
1174 return (a_cast_s(a_u64, p[0]) << 0x00) |
1175 (a_cast_s(a_u64, p[1]) << 0x08) |
1176 (a_cast_s(a_u64, p[2]) << 0x10) |
1177 (a_cast_s(a_u64, p[3]) << 0x18) |
1178 (a_cast_s(a_u64, p[4]) << 0x20) |
1179 (a_cast_s(a_u64, p[5]) << 0x28) |
1180 (a_cast_s(a_u64, p[6]) << 0x30) |
1181 (a_cast_s(a_u64, p[7]) << 0x38);
1182}
1183#endif /* A_HAVE_INLINE */
1184#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1185A_EXTERN A_NONULL((1)) a_u64 a_u64_getb(void const *b);
1186#endif /* A_HAVE_INLINE */
1187#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1188A_INTERN A_NONULL((1)) a_u64 a_u64_getb(void const *b)
1189{
1190 a_byte const *p = a_cast_s(a_byte const *, b);
1191 return (a_cast_s(a_u64, p[0]) << 0x38) |
1192 (a_cast_s(a_u64, p[1]) << 0x30) |
1193 (a_cast_s(a_u64, p[2]) << 0x28) |
1194 (a_cast_s(a_u64, p[3]) << 0x20) |
1195 (a_cast_s(a_u64, p[4]) << 0x18) |
1196 (a_cast_s(a_u64, p[5]) << 0x10) |
1197 (a_cast_s(a_u64, p[6]) << 0x08) |
1198 (a_cast_s(a_u64, p[7]) << 0x00);
1199}
1200#endif /* A_HAVE_INLINE */
1201#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1202A_EXTERN A_NONULL((1)) void a_u64_setl(void *b, a_u64 x);
1203#endif /* A_HAVE_INLINE */
1204#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1205A_INTERN A_NONULL((1)) void a_u64_setl(void *b, a_u64 x)
1206{
1207 a_byte *p = a_cast_s(a_byte *, b);
1208 p[0] = a_cast_s(a_byte, x >> 0x00);
1209 p[1] = a_cast_s(a_byte, x >> 0x08);
1210 p[2] = a_cast_s(a_byte, x >> 0x10);
1211 p[3] = a_cast_s(a_byte, x >> 0x18);
1212 p[4] = a_cast_s(a_byte, x >> 0x20);
1213 p[5] = a_cast_s(a_byte, x >> 0x28);
1214 p[6] = a_cast_s(a_byte, x >> 0x30);
1215 p[7] = a_cast_s(a_byte, x >> 0x38);
1216}
1217#endif /* A_HAVE_INLINE */
1218#if !defined A_HAVE_INLINE || defined(LIBA_A_C)
1219A_EXTERN A_NONULL((1)) void a_u64_setb(void *b, a_u64 x);
1220#endif /* A_HAVE_INLINE */
1221#if defined(A_HAVE_INLINE) || defined(LIBA_A_C)
1222A_INTERN A_NONULL((1)) void a_u64_setb(void *b, a_u64 x)
1223{
1224 a_byte *p = a_cast_s(a_byte *, b);
1225 p[0] = a_cast_s(a_byte, x >> 0x38);
1226 p[1] = a_cast_s(a_byte, x >> 0x30);
1227 p[2] = a_cast_s(a_byte, x >> 0x28);
1228 p[3] = a_cast_s(a_byte, x >> 0x20);
1229 p[4] = a_cast_s(a_byte, x >> 0x18);
1230 p[5] = a_cast_s(a_byte, x >> 0x10);
1231 p[6] = a_cast_s(a_byte, x >> 0x08);
1232 p[7] = a_cast_s(a_byte, x >> 0x00);
1233}
1234#endif /* A_HAVE_INLINE */
1235
1243A_EXTERN A_NONULL((1, 2)) void *a_copy(void *__restrict dst, void const *__restrict src, a_size siz);
1244
1252A_EXTERN A_NONULL((1, 2)) void *a_move(void *dst, void const *src, a_size siz);
1253
1261A_EXTERN A_NONULL((1)) void *a_fill(void *ptr, a_size siz, int val);
1262
1269A_EXTERN A_NONULL((1)) void *a_zero(void *ptr, a_size siz);
1270
1277A_EXTERN A_NONULL((1, 2)) void a_swap(void *lhs, void *rhs, a_size siz);
1278
1285A_EXTERN a_u32 a_hash_bkdr(void const *str, a_u32 val);
1286
1294A_EXTERN a_u32 a_hash_bkdr_(void const *ptr, a_size siz, a_u32 val);
1295
1302A_EXTERN a_u32 a_hash_sdbm(void const *str, a_u32 val);
1303
1311A_EXTERN a_u32 a_hash_sdbm_(void const *ptr, a_size siz, a_u32 val);
1312
1319A_EXTERN void a_float_push_fore(a_float *p, a_size n, a_float x);
1326A_EXTERN void a_float_push_back(a_float *p, a_size n, a_float x);
1327
1335A_EXTERN void a_float_push_fore_(a_float *block_p, a_size block_n,
1336 a_float const *cache_p, a_size cache_n);
1337
1345A_EXTERN void a_float_push_back_(a_float *block_p, a_size block_n,
1346 a_float const *cache_p, a_size cache_n);
1347
1353A_EXTERN void a_float_roll_fore(a_float *p, a_size n);
1354
1360A_EXTERN void a_float_roll_back(a_float *p, a_size n);
1361
1369A_EXTERN void a_float_roll_fore_(a_float *block_p, a_size block_n,
1370 a_float *shift_p, a_size shift_n);
1371
1379A_EXTERN void a_float_roll_back_(a_float *block_p, a_size block_n,
1380 a_float *shift_p, a_size shift_n);
1381
1388A_EXTERN a_float a_float_mean(a_float const *p, a_size n);
1389
1396A_EXTERN a_float a_float_sum(a_float const *p, a_size n);
1397
1404A_EXTERN a_float a_float_sum1(a_float const *p, a_size n);
1405
1412A_EXTERN a_float a_float_sum2(a_float const *p, a_size n);
1413
1420A_EXTERN void *(*a_alloc)(void *addr, a_size size);
1421
1428A_EXTERN void *a_alloc_(void *addr, a_size size);
1429
1430#if defined(LIBA_A_C)
1431#undef A_INTERN
1432#define A_INTERN static A_INLINE
1433#endif /* LIBA_A_C */
1434#if defined(__cplusplus)
1435} /* extern "C" */
1436#endif /* __cplusplus */
1437
1439#define A_ALLOC(alloc, addr, size) void *alloc(void *addr, a_size size)
1440#define a_new(T, ptr, num) a_cast_s(T *, a_alloc(ptr, sizeof(T) * (num)))
1441#define a_die(ptr) a_alloc(ptr, 0)
1442
1445#endif /* a/a.h */
#define a_float
Definition a.h:785
uint8_t a_u8_rev(uint8_t x)
reverse the bits in an 8-bit unsigned integer
#define a_long
Definition a.h:345
#define a_size
Definition a.h:610
void * a_copy(void *__restrict dst, void const *__restrict src, size_t siz)
copy one buffer to another
#define a_i64
Definition a.h:508
void * a_zero(void *ptr, size_t siz)
fill a buffer with zero
uint32_t a_u32_rev(uint32_t x)
reverse the bits in a 32-bit unsigned integer
void a_float_push_fore(double *p, size_t n, double x)
push an element into the front of a float array
#define a_i8
Definition a.h:409
#define a_ulong
Definition a.h:353
#define a_u8
Definition a.h:424
#define a_shrt
Definition a.h:328
#define a_i32
Definition a.h:475
#define a_iptr
Definition a.h:571
void a_float_roll_back_(double *block_p, size_t block_n, double *shift_p, size_t shift_n)
roll backward the elements of a float array circularly
void a_swap(void *lhs, void *rhs, size_t siz)
swap two different memory blocks of the same size
void a_float_push_back_(double *block_p, size_t block_n, double const *cache_p, size_t cache_n)
push the elements into the end of a float array
double a_float_sum1(double const *p, size_t n)
calculate the absolute sum of a float array
#define a_diff
Definition a.h:598
double a_float_sum2(double const *p, size_t n)
calculate the sum of squares of a float array
#define a_c8
Definition a.h:391
uint16_t a_u16_rev(uint16_t x)
reverse the bits in a 16-bit unsigned integer
void a_float_roll_fore(double *p, size_t n)
roll forward the elements of a float array circularly
#define a_u16
Definition a.h:457
#define a_imax
Definition a.h:541
#define a_umax
Definition a.h:556
#define a_int
Definition a.h:311
#define a_i16
Definition a.h:442
#define a_u32
Definition a.h:490
void *(* a_alloc)(void *addr, size_t size)
allocation function pointer
Definition a.h:1420
uint32_t a_hash_bkdr(void const *str, uint32_t val)
a hash function whose prime number is 131
#define a_byte
Definition a.h:382
uint64_t a_u64_rev(uint64_t x)
reverse the bits in a 64-bit unsigned integer
#define a_u64
Definition a.h:523
void a_float_push_back(double *p, size_t n, double x)
push an element into the end of a float array
void * a_move(void *dst, void const *src, size_t siz)
move one buffer to another
void a_float_roll_back(double *p, size_t n)
roll backward the elements of a float array circularly
#define a_uptr
Definition a.h:583
#define a_f32
Definition a.h:643
void a_float_push_fore_(double *block_p, size_t block_n, double const *cache_p, size_t cache_n)
push the elements into the front of a float array
#define a_f64
Definition a.h:671
double a_float_mean(double const *p, size_t n)
calculate the mean of a float array
void * a_alloc_(void *addr, size_t size)
default allocation function
void * a_fill(void *ptr, size_t siz, int val)
fill a buffer with a character
void a_float_roll_fore_(double *block_p, size_t block_n, double *shift_p, size_t shift_n)
roll forward the elements of a float array circularly
uint32_t a_hash_bkdr_(void const *ptr, size_t siz, uint32_t val)
a hash function whose prime number is 131
uint32_t a_hash_sdbm_(void const *ptr, size_t siz, uint32_t val)
a hash function whose prime number is 65599
uint32_t a_hash_sdbm(void const *str, uint32_t val)
a hash function whose prime number is 65599
double a_float_sum(double const *p, size_t n)
calculate the sum of a float array
#define a_ushrt
Definition a.h:336
#define a_uint
Definition a.h:319
@ A_SUCCESS
Definition a.h:983
@ A_FAILURE
Definition a.h:984
@ A_INVALID
Definition a.h:985
Definition a.h:790