XINU
Functions | Variables
qsort.c File Reference

Go to the source code of this file.

Functions

static void qs1 (char *, char *)
 
static void qsexc (char *, char *)
 
void qsort (char *a, unsigned n, int es, int(*fc)(char *, char *))
 
static void qstexc (char *, char *, char *)
 

Variables

static int(* qscmp )(char *, char *)
 
static int qses
 

Function Documentation

◆ qs1()

static void qs1 ( char *  a,
char *  l 
)
static

Definition at line 29 of file qsort.c.

References qscmp, qses, qsexc(), qstexc(), and start.

Referenced by qsort().

33 {
34  register char *i, *j;
35  register int es;
36  char *lp, *hp;
37  int c;
38  unsigned n;
39 
40  es = qses;
41 
42  start:
43  if ((n = l - a) <= es)
44  {
45  return;
46  }
47  n = es * (n / (2 * es));
48  hp = lp = a + n;
49  i = a;
50  j = l - es;
51  for (;;)
52  {
53  if (i < lp)
54  {
55  if ((c = (*qscmp) (i, lp)) == 0)
56  {
57  qsexc(i, lp -= es);
58  continue;
59  }
60  if (c < 0)
61  {
62  i += es;
63  continue;
64  }
65  }
66 
67  loop:
68  if (j > hp)
69  {
70  if ((c = (*qscmp) (hp, j)) == 0)
71  {
72  qsexc(hp += es, j);
73  goto loop;
74  }
75  if (c > 0)
76  {
77  if (i == lp)
78  {
79  qstexc(i, hp += es, j);
80  i = lp += es;
81  goto loop;
82  }
83  qsexc(i, j);
84  j -= es;
85  i += es;
86  continue;
87  }
88  j -= es;
89  goto loop;
90  }
91 
92  if (i == lp)
93  {
94  if (lp - a >= l - hp)
95  {
96  qs1(hp + es, l);
97  l = lp;
98  }
99  else
100  {
101  qs1(a, lp);
102  a = hp + es;
103  }
104  goto start;
105  }
106 
107  qstexc(j, lp -= es, i);
108  j = hp -= es;
109  }
110 }
static void qs1(char *, char *)
Definition: qsort.c:29
static void qsexc(char *, char *)
Definition: qsort.c:116
static int qses
Definition: qsort.c:4
static int(* qscmp)(char *, char *)
Definition: qsort.c:3
uint32 start
static void qstexc(char *, char *, char *)
Definition: qsort.c:140
Here is the call graph for this function:
Here is the caller graph for this function:

◆ qsexc()

static void qsexc ( char *  i,
char *  j 
)
static

Definition at line 116 of file qsort.c.

References qses.

Referenced by qs1().

120 {
121  register char *ri, *rj, c;
122  int n;
123 
124  n = qses;
125  ri = i;
126  rj = j;
127  do
128  {
129  c = *ri;
130  *ri++ = *rj;
131  *rj++ = c;
132  }
133  while (--n);
134 }
static int qses
Definition: qsort.c:4
Here is the caller graph for this function:

◆ qsort()

void qsort ( char *  a,
unsigned  n,
int  es,
int(*)(char *, char *)  fc 
)

Definition at line 13 of file qsort.c.

References qs1(), qscmp, and qses.

19 {
20  qscmp = fc;
21  qses = es;
22  qs1(a, a + n * es);
23 }
static void qs1(char *, char *)
Definition: qsort.c:29
static int qses
Definition: qsort.c:4
static int(* qscmp)(char *, char *)
Definition: qsort.c:3
Here is the call graph for this function:

◆ qstexc()

static void qstexc ( char *  i,
char *  j,
char *  k 
)
static

Definition at line 140 of file qsort.c.

References qses.

Referenced by qs1().

145 {
146  register char *ri, *rj, *rk;
147  int c;
148  int n;
149 
150  n = qses;
151  ri = i;
152  rj = j;
153  rk = k;
154  do
155  {
156  c = *ri;
157  *ri++ = *rk;
158  *rk++ = *rj;
159  *rj++ = c;
160  }
161  while (--n);
162 }
static int qses
Definition: qsort.c:4
Here is the caller graph for this function:

Variable Documentation

◆ qscmp

int(* qscmp) (char *, char *)
static

Definition at line 3 of file qsort.c.

Referenced by qs1(), and qsort().

◆ qses

int qses
static

Definition at line 4 of file qsort.c.

Referenced by qs1(), qsexc(), qsort(), and qstexc().