MCPcopy Create free account
hub / github.com/NetHack/NetHack / qsort

Function qsort

sys/vms/oldcrtl.c:174–206  ·  view source on GitHub ↗
(base, count, size, compare)

Source from the content-addressed store, hash-verified

172extern void free();
173
174void
175qsort(base, count, size, compare)
176char *base;
177int count;
178REG int size;
179int (*compare)();
180{
181 REG int i, cmp;
182 REG char *next, *prev, *tmp = 0;
183 char wrk_buf[512];
184
185 /* just use a shuffle sort (tradeoff between efficiency & simplicity) */
186 /* [Optimal if already sorted; worst case when initially reversed.] */
187 for (next = base, i = 1; i < count; i++) {
188 prev = next, next += size; /* increment front pointer */
189 if ((cmp = (*compare)(next, prev)) < 0) {
190 /* found element out of order; move other(s) up then re-insert it
191 */
192 if (!tmp)
193 tmp = size > (int) (sizeof wrk_buf) ? malloc(size) : wrk_buf;
194 memcpy(tmp, next, size); /* save smaller element */
195 while (cmp < 0) {
196 memcpy(prev + size, prev, size); /* move larger elem. up */
197 prev -= size; /* decrement back pointer */
198 cmp = (prev >= base ? (*compare)(tmp, prev) : 0);
199 }
200 memcpy(prev + size, tmp, size); /* restore small element */
201 }
202 }
203 if (tmp != 0 && tmp != wrk_buf)
204 free(tmp);
205 return;
206}
207#endif /*!SUPPRESS_QSORT*/
208
209#endif /*VERYOLD_VMS*/

Callers 15

disco_output_sortedFunction · 0.85
doclassdiscoFunction · 0.85
notice_all_monsFunction · 0.85
dump_weightsFunction · 0.85
sortlootFunction · 0.85
list_migrating_monsFunction · 0.85
get_saved_gamesFunction · 0.85
init_mongen_orderFunction · 0.85
sortspellsFunction · 0.85
sort_roomsFunction · 0.85
condoptFunction · 0.85
cond_menuFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected