#include "c.h"
Go to the source code of this file.
Defines | |
#define | swapcode(TYPE, parmi, parmj, n) |
#define | SWAPINIT(a, es) |
#define | swap(a, b) |
#define | vecswap(a, b, n) if ((n) > 0) swapfunc((a), (b), (size_t)(n), swaptype) |
Functions | |
static char * | med3 (char *a, char *b, char *c, int(*cmp)(const void *, const void *)) |
static void | swapfunc (char *, char *, size_t, int) |
void | pg_qsort (void *a, size_t n, size_t es, int(*cmp)(const void *, const void *)) |
int | pg_qsort_strcmp (const void *a, const void *b) |
#define swap | ( | a, | ||
b | ||||
) |
if (swaptype == 0) { \ long t = *(long *)(void *)(a); \ *(long *)(void *)(a) = *(long *)(void *)(b); \ *(long *)(void *)(b) = t; \ } else \ swapfunc(a, b, es, swaptype)
Definition at line 84 of file qsort.c.
Referenced by lo_hton64(), lo_ntoh64(), pg_lltoa(), pg_ltoa(), pg_qsort(), pq_getmsgfloat4(), pq_getmsgfloat8(), pq_sendfloat4(), and pq_sendfloat8().
#define swapcode | ( | TYPE, | ||
parmi, | ||||
parmj, | ||||
n | ||||
) |
do { \ size_t i = (n) / sizeof (TYPE); \ TYPE *pi = (TYPE *)(void *)(parmi); \ TYPE *pj = (TYPE *)(void *)(parmj); \ do { \ TYPE t = *pi; \ *pi++ = *pj; \ *pj++ = t; \ } while (--i > 0); \ } while (0)
Definition at line 60 of file qsort.c.
Referenced by swapfunc().
#define SWAPINIT | ( | a, | ||
es | ||||
) |
swaptype = ((char *)(a) - (char *)0) % sizeof(long) || \ (es) % sizeof(long) ? 2 : (es) == sizeof(long)? 0 : 1;
Definition at line 72 of file qsort.c.
Referenced by pg_qsort().
#define vecswap | ( | a, | ||
b, | ||||
n | ||||
) | if ((n) > 0) swapfunc((a), (b), (size_t)(n), swaptype) |
Definition at line 92 of file qsort.c.
Referenced by pg_qsort().
static char * med3 | ( | char * | a, | |
char * | b, | |||
char * | c, | |||
int(*)(const void *, const void *) | cmp | |||
) | [static] |
void pg_qsort | ( | void * | a, | |
size_t | n, | |||
size_t | es, | |||
int(*)(const void *, const void *) | cmp | |||
) |
Definition at line 103 of file qsort.c.
References cmp(), med3(), Min, qsort, swap, SWAPINIT, and vecswap.
Referenced by DropRelFileNodesAllBuffers().
{ char *pa, *pb, *pc, *pd, *pl, *pm, *pn; int d, r, swaptype, presorted; loop:SWAPINIT(a, es); if (n < 7) { for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) for (pl = pm; pl > (char *) a && cmp(pl - es, pl) > 0; pl -= es) swap(pl, pl - es); return; } presorted = 1; for (pm = (char *) a + es; pm < (char *) a + n * es; pm += es) { if (cmp(pm - es, pm) > 0) { presorted = 0; break; } } if (presorted) return; pm = (char *) a + (n / 2) * es; if (n > 7) { pl = (char *) a; pn = (char *) a + (n - 1) * es; if (n > 40) { d = (n / 8) * es; pl = med3(pl, pl + d, pl + 2 * d, cmp); pm = med3(pm - d, pm, pm + d, cmp); pn = med3(pn - 2 * d, pn - d, pn, cmp); } pm = med3(pl, pm, pn, cmp); } swap(a, pm); pa = pb = (char *) a + es; pc = pd = (char *) a + (n - 1) * es; for (;;) { while (pb <= pc && (r = cmp(pb, a)) <= 0) { if (r == 0) { swap(pa, pb); pa += es; } pb += es; } while (pb <= pc && (r = cmp(pc, a)) >= 0) { if (r == 0) { swap(pc, pd); pd -= es; } pc -= es; } if (pb > pc) break; swap(pb, pc); pb += es; pc -= es; } pn = (char *) a + n * es; r = Min(pa - (char *) a, pb - pa); vecswap(a, pb - r, r); r = Min(pd - pc, pn - pd - es); vecswap(pb, pn - r, r); if ((r = pb - pa) > es) qsort(a, r / es, es, cmp); if ((r = pd - pc) > es) { /* Iterate rather than recurse to save stack space */ a = pn - r; n = r / es; goto loop; } /* qsort(pn - r, r / es, es, cmp);*/ }
int pg_qsort_strcmp | ( | const void * | a, | |
const void * | b | |||
) |
Definition at line 201 of file qsort.c.
Referenced by BuildEventTriggerCache(), filter_event_trigger(), readstoplist(), and searchstoplist().
{ return strcmp(*(char *const *) a, *(char *const *) b); }