Browse Source

MT#56493 move GTree helpers to auxlib

Change-Id: Ia3135d9f2c370d9c18d7249506256241339df9d1
pull/1611/head
Richard Fuchs 3 years ago
parent
commit
cd185fd168
4 changed files with 60 additions and 62 deletions
  1. +0
    -18
      daemon/aux.c
  2. +0
    -44
      include/aux.h
  3. +18
    -0
      lib/auxlib.c
  4. +42
    -0
      lib/auxlib.h

+ 0
- 18
daemon/aux.c View File

@ -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;
}

+ 0
- 44
include/aux.h View File

@ -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) {


+ 18
- 0
lib/auxlib.c View File

@ -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);


+ 42
- 0
lib/auxlib.h View File

@ -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


Loading…
Cancel
Save