Graphviz 13.0.0~dev.20250523.0001
Loading...
Searching...
No Matches
sort.h
Go to the documentation of this file.
1
9
10#pragma once
11
12#include <assert.h>
13#include <stdlib.h>
14
15static _Thread_local int (*gv_sort_compar)(const void *, const void *, void *);
16static _Thread_local void *gv_sort_arg;
17
18static inline int gv_sort_compar_wrapper(const void *a, const void *b) {
19 assert(gv_sort_compar != NULL && "no comparator set in gv_sort");
20 return gv_sort_compar(a, b, gv_sort_arg);
21}
22
24static inline void gv_sort(void *base, size_t nmemb, size_t size,
25 int (*compar)(const void *, const void *, void *),
26 void *arg) {
27 assert(gv_sort_compar == NULL && gv_sort_arg == NULL &&
28 "unsupported recursive call to gv_sort");
29
30 gv_sort_compar = compar;
31 gv_sort_arg = arg;
32
33 if (nmemb > 1) {
34 qsort(base, nmemb, size, gv_sort_compar_wrapper);
35 }
36
39}
node NULL
Definition grammar.y:163
static _Thread_local void * gv_sort_arg
Definition sort.h:16
static _Thread_local int(* gv_sort_compar)(const void *, const void *, void *)
Definition sort.h:15
static void gv_sort(void *base, size_t nmemb, size_t size, int(*compar)(const void *, const void *, void *), void *arg)
qsort with an extra state parameter, ala qsort_r
Definition sort.h:24
static int gv_sort_compar_wrapper(const void *a, const void *b)
Definition sort.h:18