diff --git a/daemon/aux.c b/daemon/aux.c index 88e68025d..85fa9ed1d 100644 --- a/daemon/aux.c +++ b/daemon/aux.c @@ -303,21 +303,3 @@ void thread_create_detach_prio(void (*f)(void *), void *d, const char *scheduler if (thread_create(thread_detach_func, dt, 1, NULL, name)) abort(); } - -int g_tree_find_first_cmp(void *k, void *v, void *d) { - void **p = d; - GEqualFunc f = p[1]; - if (!f || f(v, p[0])) { - p[2] = v; - return TRUE; - } - return FALSE; -} -int g_tree_find_all_cmp(void *k, void *v, void *d) { - void **p = d; - GEqualFunc f = p[1]; - GQueue *q = p[2]; - if (!f || f(v, p[0])) - g_queue_push_tail(q, v); - return FALSE; -} diff --git a/include/aux.h b/include/aux.h index 0dffb50f6..37cff0341 100644 --- a/include/aux.h +++ b/include/aux.h @@ -161,50 +161,6 @@ INLINE void g_queue_append(GQueue *dst, const GQueue *src) { } -/* GTREE */ - -int g_tree_find_first_cmp(void *, void *, void *); -int g_tree_find_all_cmp(void *, void *, void *); -INLINE void *g_tree_find_first(GTree *t, GEqualFunc f, void *data) { - void *p[3]; - p[0] = data; - p[1] = f; - p[2] = NULL; - g_tree_foreach(t, g_tree_find_first_cmp, p); - return p[2]; -} -INLINE void g_tree_find_all(GQueue *out, GTree *t, GEqualFunc f, void *data) { - void *p[3]; - p[0] = data; - p[1] = f; - p[2] = out; - g_tree_foreach(t, g_tree_find_all_cmp, p); -} -INLINE void g_tree_get_values(GQueue *out, GTree *t) { - g_tree_find_all(out, t, NULL, NULL); -} -INLINE void g_tree_find_remove_all(GQueue *out, GTree *t) { - GList *l; - g_queue_init(out); - g_tree_find_all(out, t, NULL, NULL); - for (l = out->head; l; l = l->next) - g_tree_remove(t, l->data); -} -INLINE void g_tree_insert_coll(GTree *t, gpointer key, gpointer val, void (*cb)(gpointer, gpointer)) { - gpointer old = g_tree_lookup(t, key); - if (old) - cb(old, val); - g_tree_insert(t, key, val); -} -INLINE void g_tree_add_all(GTree *t, GQueue *q, void (*cb)(gpointer, gpointer)) { - GList *l; - for (l = q->head; l; l = l->next) - g_tree_insert_coll(t, l->data, l->data, cb); - g_queue_clear(q); -} - - - /* GHASHTABLE */ INLINE GQueue *g_hash_table_lookup_queue_new(GHashTable *ht, void *key, GDestroyNotify free_func) { diff --git a/lib/auxlib.c b/lib/auxlib.c index 083bb8227..b63c3ff78 100644 --- a/lib/auxlib.c +++ b/lib/auxlib.c @@ -414,6 +414,24 @@ void free_gvbuf(char ***p) { g_strfreev(*p); } +int g_tree_find_first_cmp(void *k, void *v, void *d) { + void **p = d; + GEqualFunc f = p[1]; + if (!f || f(v, p[0])) { + p[2] = v; + return TRUE; + } + return FALSE; +} +int g_tree_find_all_cmp(void *k, void *v, void *d) { + void **p = d; + GEqualFunc f = p[1]; + GQueue *q = p[2]; + if (!f || f(v, p[0])) + g_queue_push_tail(q, v); + return FALSE; +} + int num_cpu_cores(int minval) { #ifdef _SC_NPROCESSORS_ONLN int ret = sysconf(_SC_NPROCESSORS_ONLN); diff --git a/lib/auxlib.h b/lib/auxlib.h index 568e1ef8b..f96cb665d 100644 --- a/lib/auxlib.h +++ b/lib/auxlib.h @@ -326,6 +326,48 @@ INLINE void __g_hash_table_destroy(GHashTable **s) { g_hash_table_destroy(*s); } + +int g_tree_find_first_cmp(void *, void *, void *); +int g_tree_find_all_cmp(void *, void *, void *); +INLINE void *g_tree_find_first(GTree *t, GEqualFunc f, void *data) { + void *p[3]; + p[0] = data; + p[1] = f; + p[2] = NULL; + g_tree_foreach(t, g_tree_find_first_cmp, p); + return p[2]; +} +INLINE void g_tree_find_all(GQueue *out, GTree *t, GEqualFunc f, void *data) { + void *p[3]; + p[0] = data; + p[1] = f; + p[2] = out; + g_tree_foreach(t, g_tree_find_all_cmp, p); +} +INLINE void g_tree_get_values(GQueue *out, GTree *t) { + g_tree_find_all(out, t, NULL, NULL); +} +INLINE void g_tree_find_remove_all(GQueue *out, GTree *t) { + GList *l; + g_queue_init(out); + g_tree_find_all(out, t, NULL, NULL); + for (l = out->head; l; l = l->next) + g_tree_remove(t, l->data); +} +INLINE void g_tree_insert_coll(GTree *t, gpointer key, gpointer val, void (*cb)(gpointer, gpointer)) { + gpointer old = g_tree_lookup(t, key); + if (old) + cb(old, val); + g_tree_insert(t, key, val); +} +INLINE void g_tree_add_all(GTree *t, GQueue *q, void (*cb)(gpointer, gpointer)) { + GList *l; + for (l = q->head; l; l = l->next) + g_tree_insert_coll(t, l->data, l->data, cb); + g_queue_clear(q); +} + + #if !GLIB_CHECK_VERSION(2,68,0) # define __g_memdup(a,b) g_memdup(a,b) #else