5 #if defined(A_HAVE_MIMALLOC_H)
6 #include <mimalloc-override.h>
7 #endif /* A_HAVE_MIMALLOC_H */
9 void *a_copy(void *__restrict dst
, void const *__restrict src
, a_size siz
) { return memcpy(dst
, src
, siz
); }
11 void *a_move(void *dst
, void const *src
, a_size siz
) { return memmove(dst
, src
, siz
); }
13 void *a_fill(void *ptr
, a_size siz
, int val
) { return memset(ptr
, val
, siz
); }
15 void *a_zero(void *ptr
, a_size siz
) { return memset(ptr
, 0, siz
); }
17 void a_swap(void *lhs_
, void *rhs_
, a_size siz
)
19 a_byte
*lhs
= (a_byte
*)lhs_
;
20 a_byte
*rhs
= (a_byte
*)rhs_
;
21 for (a_byte byte
; siz
; --siz
, ++lhs
, ++rhs
)
29 a_u32
a_hash_bkdr(void const *str_
, a_u32 val
)
31 a_byte
const *str
= (a_byte
const *)str_
;
36 val
= val
* 131 + *str
;
42 a_u32
a_hash_bkdr_(void const *ptr_
, a_size siz
, a_u32 val
)
44 a_byte
const *ptr
= (a_byte
const *)ptr_
;
45 for (; siz
; --siz
, ++ptr
)
47 val
= val
* 131 + *ptr
;
52 a_u32
a_hash_sdbm(void const *str_
, a_u32 val
)
54 a_byte
const *str
= (a_byte
const *)str_
;
59 val
= val
* 65599 + *str
;
65 a_u32
a_hash_sdbm_(void const *ptr_
, a_size siz
, a_u32 val
)
67 a_byte
const *ptr
= (a_byte
const *)ptr_
;
68 for (; siz
; --siz
, ++ptr
)
70 val
= val
* 65599 + *ptr
;
75 void a_float_push(a_float
*block_p
, a_size block_n
,
76 a_float
const *cache_p
, a_size cache_n
)
78 a_size
const n
= A_MIN(cache_n
, block_n
);
79 for (a_size t
= block_n
, s
= block_n
- n
; s
;)
81 block_p
[--t
] = block_p
[--s
];
83 for (a_size i
= 0; i
!= n
; ++i
)
85 block_p
[i
] = cache_p
[i
];
89 void a_float_roll(a_float
*block_p
, a_size block_n
,
90 a_float
*shift_p
, a_size shift_n
)
92 a_size
const shift
= shift_n
% block_n
;
93 a_size
const start
= block_n
- shift
;
94 for (a_size t
= 0, s
= start
; t
!= shift
;)
96 shift_p
[t
++] = block_p
[s
++];
98 for (a_size t
= block_n
, s
= start
; s
;)
100 block_p
[--t
] = block_p
[--s
];
102 for (a_size i
= 0; i
!= shift
; ++i
)
104 block_p
[i
] = shift_p
[i
];
108 a_float
a_float_mean(a_float
const *p
, a_size n
)
113 a_float
const inv
= 1 / (a_float
)n
;
114 for (; n
; --n
, ++p
) { res
+= *p
* inv
; }
119 a_float
a_float_sum(a_float
const *p
, a_size n
)
122 for (; n
; --n
, ++p
) { res
+= *p
; }
126 a_float
a_float_sumsq(a_float
const *p
, a_size n
)
129 for (; n
; --n
, ++p
) { res
+= A_SQ(*p
); }
133 a_float
a_float_sumabs(a_float
const *p
, a_size n
)
136 for (; n
; --n
, ++p
) { res
+= A_ABS(*p
); }
140 A_ALLOC((*a_alloc
), addr
, size
) = a_alloc_
;
141 A_ALLOC(a_alloc_
, addr
, size
)
147 return realloc(addr
, size
);