9#ifndef satoko__watch_list_h
10#define satoko__watch_list_h
40#define watch_list_foreach(vec, watch, lit) \
41 for (watch = watch_list_array(vec_wl_at(vec, lit)); \
42 watch < watch_list_array(vec_wl_at(vec, lit)) + watch_list_size(vec_wl_at(vec, lit)); \
45#define watch_list_foreach_bin(vec, watch, lit) \
46 for (watch = watch_list_array(vec_wl_at(vec, lit)); \
47 watch < watch_list_array(vec_wl_at(vec, lit)) + vec_wl_at(vec, lit)->n_bin; \
52static inline void watch_list_free(
struct watch_list *wl)
58static inline unsigned watch_list_size(
struct watch_list *wl)
63static inline void watch_list_shrink(
struct watch_list *wl,
unsigned size)
69static inline void watch_list_grow(
struct watch_list *wl)
71 unsigned new_size = (wl->
cap < 4) ? 4 : (wl->
cap / 2) * 3;
74 if (watchers == NULL) {
75 printf(
"Failed to realloc memory from %.1f MB to %.1f "
77 1.0 * wl->
cap / (1 << 20),
78 1.0 * new_size / (1 << 20));
86static inline void watch_list_push(
struct watch_list *wl,
struct watcher w,
unsigned is_bin)
105static inline void watch_list_remove(
struct watch_list *wl,
unsigned cref,
unsigned is_bin)
107 struct watcher *watchers = watch_list_array(wl);
110 for (i = 0; watchers[i].
cref !=
cref; i++);
111 assert(i < watch_list_size(wl));
116 for (i = wl->
n_bin; watchers[i].cref !=
cref; i++);
117 assert(i < watch_list_size(wl));
140static inline vec_wl_t *vec_wl_alloc(
unsigned cap)
154static inline void vec_wl_free(
vec_wl_t *vec_wl)
157 for (i = 0; i < vec_wl->
cap; i++)
163static inline void vec_wl_clean(
vec_wl_t *vec_wl)
166 for (i = 0; i < vec_wl->
size; i++) {
173static inline void vec_wl_push(
vec_wl_t *vec_wl)
175 if (vec_wl->
size == vec_wl->
cap) {
177 (vec_wl->
cap < 4) ? vec_wl->
cap * 2 : (vec_wl->cap / 2) * 3;
184 printf(
"failed to realloc memory from %.1f mb to %.1f "
186 1.0 * vec_wl->
cap / (1 << 20),
187 1.0 * new_size / (1 << 20));
190 vec_wl->
cap = new_size;
#define ABC_NAMESPACE_HEADER_END
#define ABC_NAMESPACE_HEADER_START
NAMESPACES ///.
#define stk_swap(type, a, b)
#define satoko_calloc(type, n_elements)
#define satoko_realloc(type, ptr, n_elements)
#define satoko_alloc(type, n_elements)
struct watch_list * watch_lists
struct watcher * watchers
struct vec_wl_t_ vec_wl_t