SDL_qsort.c 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569
  1. /*
  2. Simple DirectMedia Layer
  3. Copyright (C) 1997-2023 Sam Lantinga <slouken@libsdl.org>
  4. This software is provided 'as-is', without any express or implied
  5. warranty. In no event will the authors be held liable for any damages
  6. arising from the use of this software.
  7. Permission is granted to anyone to use this software for any purpose,
  8. including commercial applications, and to alter it and redistribute it
  9. freely, subject to the following restrictions:
  10. 1. The origin of this software must not be misrepresented; you must not
  11. claim that you wrote the original software. If you use this software
  12. in a product, an acknowledgment in the product documentation would be
  13. appreciated but is not required.
  14. 2. Altered source versions must be plainly marked as such, and must not be
  15. misrepresented as being the original software.
  16. 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #if defined(__clang_analyzer__) && !defined(SDL_DISABLE_ANALYZE_MACROS)
  19. #define SDL_DISABLE_ANALYZE_MACROS 1
  20. #endif
  21. #include "../SDL_internal.h"
  22. #include "SDL_stdinc.h"
  23. #if defined(HAVE_QSORT)
  24. void SDL_qsort(void *base, size_t nmemb, size_t size, int (*compare) (const void *, const void *))
  25. {
  26. qsort(base, nmemb, size, compare);
  27. }
  28. #else
  29. #ifdef assert
  30. #undef assert
  31. #endif
  32. #define assert SDL_assert
  33. #ifdef malloc
  34. #undef malloc
  35. #endif
  36. #define malloc SDL_malloc
  37. #ifdef free
  38. #undef free
  39. #endif
  40. #define free SDL_free
  41. #ifdef memcpy
  42. #undef memcpy
  43. #endif
  44. #define memcpy SDL_memcpy
  45. #ifdef memmove
  46. #undef memmove
  47. #endif
  48. #define memmove SDL_memmove
  49. #ifdef qsortG
  50. #undef qsortG
  51. #endif
  52. #define qsortG SDL_qsort
  53. /*
  54. This code came from Gareth McCaughan, under the zlib license.
  55. Specifically this: https://www.mccaughan.org.uk/software/qsort.c-1.15
  56. Everything below this comment until the HAVE_QSORT #endif was from Gareth
  57. (any minor changes will be noted inline).
  58. Thank you to Gareth for relicensing this code under the zlib license for our
  59. benefit!
  60. --ryan.
  61. */
  62. /* This is a drop-in replacement for the C library's |qsort()| routine.
  63. *
  64. * It is intended for use where you know or suspect that your
  65. * platform's qsort is bad. If that isn't the case, then you
  66. * should probably use the qsort your system gives you in preference
  67. * to mine -- it will likely have been tested and tuned better.
  68. *
  69. * Features:
  70. * - Median-of-three pivoting (and more)
  71. * - Truncation and final polishing by a single insertion sort
  72. * - Early truncation when no swaps needed in pivoting step
  73. * - Explicit recursion, guaranteed not to overflow
  74. * - A few little wrinkles stolen from the GNU |qsort()|.
  75. * (For the avoidance of doubt, no code was stolen, only
  76. * broad ideas.)
  77. * - separate code for non-aligned / aligned / word-size objects
  78. *
  79. * Earlier releases of this code used an idiosyncratic licence
  80. * I wrote myself, because I'm an idiot. The code is now released
  81. * under the "zlib/libpng licence"; you will find the actual
  82. * terms in the next comment. I request (but do not require)
  83. * that if you make any changes beyond the name of the exported
  84. * routine and reasonable tweaks to the TRUNC_* and
  85. * PIVOT_THRESHOLD values, you modify the _ID string so as
  86. * to make it clear that you have changed the code.
  87. *
  88. * If you find problems with this code, or find ways of
  89. * making it significantly faster, please let me know!
  90. * My e-mail address, valid as of early 2016 and for the
  91. * foreseeable future, is
  92. * gareth.mccaughan@pobox.com
  93. * Thanks!
  94. *
  95. * Gareth McCaughan
  96. */
  97. /* Copyright (c) 1998-2016 Gareth McCaughan
  98. *
  99. * This software is provided 'as-is', without any express or implied
  100. * warranty. In no event will the authors be held liable for any
  101. * damages arising from the use of this software.
  102. *
  103. * Permission is granted to anyone to use this software for any purpose,
  104. * including commercial applications, and to alter it and redistribute it
  105. * freely, subject to the following restrictions:
  106. *
  107. * 1. The origin of this software must not be misrepresented;
  108. * you must not claim that you wrote the original software.
  109. * If you use this software in a product, an acknowledgment
  110. * in the product documentation would be appreciated but
  111. * is not required.
  112. *
  113. * 2. Altered source versions must be plainly marked as such,
  114. * and must not be misrepresented as being the original software.
  115. *
  116. * 3. This notice may not be removed or altered from any source
  117. * distribution.
  118. */
  119. /* Revision history since release:
  120. * 1998-03-19 v1.12 First release I have any records of.
  121. * 2007-09-02 v1.13 Fix bug kindly reported by Dan Bodoh
  122. * (premature termination of recursion).
  123. * Add a few clarifying comments.
  124. * Minor improvements to debug output.
  125. * 2016-02-21 v1.14 Replace licence with 2-clause BSD,
  126. * and clarify a couple of things in
  127. * comments. No code changes.
  128. * 2016-03-10 v1.15 Fix bug kindly reported by Ryan Gordon
  129. * (pre-insertion-sort messed up).
  130. * Disable DEBUG_QSORT by default.
  131. * Tweak comments very slightly.
  132. */
  133. /* BEGIN SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
  134. #if 0
  135. #include <assert.h>
  136. #include <stdlib.h>
  137. #include <string.h>
  138. #undef DEBUG_QSORT
  139. static char _ID[]="<qsort.c gjm 1.15 2016-03-10>";
  140. #endif
  141. /* END SDL CHANGE ... commented this out with an #if 0 block. --ryan. */
  142. /* How many bytes are there per word? (Must be a power of 2,
  143. * and must in fact equal sizeof(int).)
  144. */
  145. #define WORD_BYTES sizeof(int)
  146. /* How big does our stack need to be? Answer: one entry per
  147. * bit in a |size_t|.
  148. */
  149. #define STACK_SIZE (8*sizeof(size_t))
  150. /* Different situations have slightly different requirements,
  151. * and we make life epsilon easier by using different truncation
  152. * points for the three different cases.
  153. * So far, I have tuned TRUNC_words and guessed that the same
  154. * value might work well for the other two cases. Of course
  155. * what works well on my machine might work badly on yours.
  156. */
  157. #define TRUNC_nonaligned 12
  158. #define TRUNC_aligned 12
  159. #define TRUNC_words 12*WORD_BYTES /* nb different meaning */
  160. /* We use a simple pivoting algorithm for shortish sub-arrays
  161. * and a more complicated one for larger ones. The threshold
  162. * is PIVOT_THRESHOLD.
  163. */
  164. #define PIVOT_THRESHOLD 40
  165. typedef struct { char * first; char * last; } stack_entry;
  166. #define pushLeft {stack[stacktop].first=ffirst;stack[stacktop++].last=last;}
  167. #define pushRight {stack[stacktop].first=first;stack[stacktop++].last=llast;}
  168. #define doLeft {first=ffirst;llast=last;continue;}
  169. #define doRight {ffirst=first;last=llast;continue;}
  170. #define pop {if (--stacktop<0) break;\
  171. first=ffirst=stack[stacktop].first;\
  172. last=llast=stack[stacktop].last;\
  173. continue;}
  174. /* Some comments on the implementation.
  175. * 1. When we finish partitioning the array into "low"
  176. * and "high", we forget entirely about short subarrays,
  177. * because they'll be done later by insertion sort.
  178. * Doing lots of little insertion sorts might be a win
  179. * on large datasets for locality-of-reference reasons,
  180. * but it makes the code much nastier and increases
  181. * bookkeeping overhead.
  182. * 2. We always save the shorter and get to work on the
  183. * longer. This guarantees that every time we push
  184. * an item onto the stack its size is <= 1/2 of that
  185. * of its parent; so the stack can't need more than
  186. * log_2(max-array-size) entries.
  187. * 3. We choose a pivot by looking at the first, last
  188. * and middle elements. We arrange them into order
  189. * because it's easy to do that in conjunction with
  190. * choosing the pivot, and it makes things a little
  191. * easier in the partitioning step. Anyway, the pivot
  192. * is the middle of these three. It's still possible
  193. * to construct datasets where the algorithm takes
  194. * time of order n^2, but it simply never happens in
  195. * practice.
  196. * 3' Newsflash: On further investigation I find that
  197. * it's easy to construct datasets where median-of-3
  198. * simply isn't good enough. So on large-ish subarrays
  199. * we do a more sophisticated pivoting: we take three
  200. * sets of 3 elements, find their medians, and then
  201. * take the median of those.
  202. * 4. We copy the pivot element to a separate place
  203. * because that way we can always do our comparisons
  204. * directly against a pointer to that separate place,
  205. * and don't have to wonder "did we move the pivot
  206. * element?". This makes the inner loop better.
  207. * 5. It's possible to make the pivoting even more
  208. * reliable by looking at more candidates when n
  209. * is larger. (Taking this to its logical conclusion
  210. * results in a variant of quicksort that doesn't
  211. * have that n^2 worst case.) However, the overhead
  212. * from the extra bookkeeping means that it's just
  213. * not worth while.
  214. * 6. This is pretty clean and portable code. Here are
  215. * all the potential portability pitfalls and problems
  216. * I know of:
  217. * - In one place (the insertion sort) I construct
  218. * a pointer that points just past the end of the
  219. * supplied array, and assume that (a) it won't
  220. * compare equal to any pointer within the array,
  221. * and (b) it will compare equal to a pointer
  222. * obtained by stepping off the end of the array.
  223. * These might fail on some segmented architectures.
  224. * - I assume that there are 8 bits in a |char| when
  225. * computing the size of stack needed. This would
  226. * fail on machines with 9-bit or 16-bit bytes.
  227. * - I assume that if |((int)base&(sizeof(int)-1))==0|
  228. * and |(size&(sizeof(int)-1))==0| then it's safe to
  229. * get at array elements via |int*|s, and that if
  230. * actually |size==sizeof(int)| as well then it's
  231. * safe to treat the elements as |int|s. This might
  232. * fail on systems that convert pointers to integers
  233. * in non-standard ways.
  234. * - I assume that |8*sizeof(size_t)<=INT_MAX|. This
  235. * would be false on a machine with 8-bit |char|s,
  236. * 16-bit |int|s and 4096-bit |size_t|s. :-)
  237. */
  238. /* The recursion logic is the same in each case.
  239. * We keep chopping up until we reach subarrays of size
  240. * strictly less than Trunc; we leave these unsorted. */
  241. #define Recurse(Trunc) \
  242. { size_t l=last-ffirst,r=llast-first; \
  243. if (l<Trunc) { \
  244. if (r>=Trunc) doRight \
  245. else pop \
  246. } \
  247. else if (l<=r) { pushLeft; doRight } \
  248. else if (r>=Trunc) { pushRight; doLeft }\
  249. else doLeft \
  250. }
  251. /* and so is the pivoting logic (note: last is inclusive): */
  252. #define Pivot(swapper,sz) \
  253. if ((size_t)(last-first)>PIVOT_THRESHOLD*sz) mid=pivot_big(first,mid,last,sz,compare);\
  254. else { \
  255. if (compare(first,mid)<0) { \
  256. if (compare(mid,last)>0) { \
  257. swapper(mid,last); \
  258. if (compare(first,mid)>0) swapper(first,mid);\
  259. } \
  260. } \
  261. else { \
  262. if (compare(mid,last)>0) swapper(first,last)\
  263. else { \
  264. swapper(first,mid); \
  265. if (compare(mid,last)>0) swapper(mid,last);\
  266. } \
  267. } \
  268. first+=sz; last-=sz; \
  269. }
  270. #ifdef DEBUG_QSORT
  271. #include <stdio.h>
  272. #endif
  273. /* and so is the partitioning logic: */
  274. #define Partition(swapper,sz) { \
  275. do { \
  276. while (compare(first,pivot)<0) first+=sz; \
  277. while (compare(pivot,last)<0) last-=sz; \
  278. if (first<last) { \
  279. swapper(first,last); \
  280. first+=sz; last-=sz; } \
  281. else if (first==last) { first+=sz; last-=sz; break; }\
  282. } while (first<=last); \
  283. }
  284. /* and so is the pre-insertion-sort operation of putting
  285. * the smallest element into place as a sentinel.
  286. * Doing this makes the inner loop nicer. I got this
  287. * idea from the GNU implementation of qsort().
  288. * We find the smallest element from the first |nmemb|,
  289. * or the first |limit|, whichever is smaller;
  290. * therefore we must have ensured that the globally smallest
  291. * element is in the first |limit| (because our
  292. * quicksort recursion bottoms out only once we
  293. * reach subarrays smaller than |limit|).
  294. */
  295. #define PreInsertion(swapper,limit,sz) \
  296. first=base; \
  297. last=first + ((nmemb>limit ? limit : nmemb)-1)*sz;\
  298. while (last!=base) { \
  299. if (compare(first,last)>0) first=last; \
  300. last-=sz; } \
  301. if (first!=base) swapper(first,(char*)base);
  302. /* and so is the insertion sort, in the first two cases: */
  303. #define Insertion(swapper) \
  304. last=((char*)base)+nmemb*size; \
  305. for (first=((char*)base)+size;first!=last;first+=size) { \
  306. char *test; \
  307. /* Find the right place for |first|. \
  308. * My apologies for var reuse. */ \
  309. for (test=first-size;compare(test,first)>0;test-=size) ; \
  310. test+=size; \
  311. if (test!=first) { \
  312. /* Shift everything in [test,first) \
  313. * up by one, and place |first| \
  314. * where |test| is. */ \
  315. memcpy(pivot,first,size); \
  316. memmove(test+size,test,first-test); \
  317. memcpy(test,pivot,size); \
  318. } \
  319. }
  320. #define SWAP_nonaligned(a,b) { \
  321. register char *aa=(a),*bb=(b); \
  322. register size_t sz=size; \
  323. do { register char t=*aa; *aa++=*bb; *bb++=t; } while (--sz); }
  324. #define SWAP_aligned(a,b) { \
  325. register int *aa=(int*)(a),*bb=(int*)(b); \
  326. register size_t sz=size; \
  327. do { register int t=*aa;*aa++=*bb; *bb++=t; } while (sz-=WORD_BYTES); }
  328. #define SWAP_words(a,b) { \
  329. register int t=*((int*)a); *((int*)a)=*((int*)b); *((int*)b)=t; }
  330. /* ---------------------------------------------------------------------- */
  331. static char * pivot_big(char *first, char *mid, char *last, size_t size,
  332. int compare(const void *, const void *)) {
  333. size_t d=(((last-first)/size)>>3)*size;
  334. #ifdef DEBUG_QSORT
  335. fprintf(stderr, "pivot_big: first=%p last=%p size=%lu n=%lu\n", first, (unsigned long)last, size, (unsigned long)((last-first+1)/size));
  336. #endif
  337. char *m1,*m2,*m3;
  338. { char *a=first, *b=first+d, *c=first+2*d;
  339. #ifdef DEBUG_QSORT
  340. fprintf(stderr,"< %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c);
  341. #endif
  342. m1 = compare(a,b)<0 ?
  343. (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
  344. : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
  345. }
  346. { char *a=mid-d, *b=mid, *c=mid+d;
  347. #ifdef DEBUG_QSORT
  348. fprintf(stderr,". %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c);
  349. #endif
  350. m2 = compare(a,b)<0 ?
  351. (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
  352. : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
  353. }
  354. { char *a=last-2*d, *b=last-d, *c=last;
  355. #ifdef DEBUG_QSORT
  356. fprintf(stderr,"> %d %d %d @ %p %p %p\n",*(int*)a,*(int*)b,*(int*)c, a,b,c);
  357. #endif
  358. m3 = compare(a,b)<0 ?
  359. (compare(b,c)<0 ? b : (compare(a,c)<0 ? c : a))
  360. : (compare(a,c)<0 ? a : (compare(b,c)<0 ? c : b));
  361. }
  362. #ifdef DEBUG_QSORT
  363. fprintf(stderr,"-> %d %d %d @ %p %p %p\n",*(int*)m1,*(int*)m2,*(int*)m3, m1,m2,m3);
  364. #endif
  365. return compare(m1,m2)<0 ?
  366. (compare(m2,m3)<0 ? m2 : (compare(m1,m3)<0 ? m3 : m1))
  367. : (compare(m1,m3)<0 ? m1 : (compare(m2,m3)<0 ? m3 : m2));
  368. }
  369. /* ---------------------------------------------------------------------- */
  370. static void qsort_nonaligned(void *base, size_t nmemb, size_t size,
  371. int (*compare)(const void *, const void *)) {
  372. stack_entry stack[STACK_SIZE];
  373. int stacktop=0;
  374. char *first,*last;
  375. char *pivot=malloc(size);
  376. size_t trunc=TRUNC_nonaligned*size;
  377. assert(pivot != NULL);
  378. first=(char*)base; last=first+(nmemb-1)*size;
  379. if ((size_t)(last-first)>=trunc) {
  380. char *ffirst=first, *llast=last;
  381. while (1) {
  382. /* Select pivot */
  383. { char * mid=first+size*((last-first)/size >> 1);
  384. Pivot(SWAP_nonaligned,size);
  385. memcpy(pivot,mid,size);
  386. }
  387. /* Partition. */
  388. Partition(SWAP_nonaligned,size);
  389. /* Prepare to recurse/iterate. */
  390. Recurse(trunc)
  391. }
  392. }
  393. PreInsertion(SWAP_nonaligned,TRUNC_nonaligned,size);
  394. Insertion(SWAP_nonaligned);
  395. free(pivot);
  396. }
  397. static void qsort_aligned(void *base, size_t nmemb, size_t size,
  398. int (*compare)(const void *, const void *)) {
  399. stack_entry stack[STACK_SIZE];
  400. int stacktop=0;
  401. char *first,*last;
  402. char *pivot=malloc(size);
  403. size_t trunc=TRUNC_aligned*size;
  404. assert(pivot != NULL);
  405. first=(char*)base; last=first+(nmemb-1)*size;
  406. if ((size_t)(last-first)>=trunc) {
  407. char *ffirst=first,*llast=last;
  408. while (1) {
  409. /* Select pivot */
  410. { char * mid=first+size*((last-first)/size >> 1);
  411. Pivot(SWAP_aligned,size);
  412. memcpy(pivot,mid,size);
  413. }
  414. /* Partition. */
  415. Partition(SWAP_aligned,size);
  416. /* Prepare to recurse/iterate. */
  417. Recurse(trunc)
  418. }
  419. }
  420. PreInsertion(SWAP_aligned,TRUNC_aligned,size);
  421. Insertion(SWAP_aligned);
  422. free(pivot);
  423. }
  424. static void qsort_words(void *base, size_t nmemb,
  425. int (*compare)(const void *, const void *)) {
  426. stack_entry stack[STACK_SIZE];
  427. int stacktop=0;
  428. char *first,*last;
  429. char *pivot=malloc(WORD_BYTES);
  430. assert(pivot != NULL);
  431. first=(char*)base; last=first+(nmemb-1)*WORD_BYTES;
  432. if (last-first>=TRUNC_words) {
  433. char *ffirst=first, *llast=last;
  434. while (1) {
  435. #ifdef DEBUG_QSORT
  436. fprintf(stderr,"Doing %d:%d: ",
  437. (first-(char*)base)/WORD_BYTES,
  438. (last-(char*)base)/WORD_BYTES);
  439. #endif
  440. /* Select pivot */
  441. { char * mid=first+WORD_BYTES*((last-first) / (2*WORD_BYTES));
  442. Pivot(SWAP_words,WORD_BYTES);
  443. *(int*)pivot=*(int*)mid;
  444. #ifdef DEBUG_QSORT
  445. fprintf(stderr,"pivot = %p = #%lu = %d\n", mid, (unsigned long)(((int*)mid)-((int*)base)), *(int*)mid);
  446. #endif
  447. }
  448. /* Partition. */
  449. Partition(SWAP_words,WORD_BYTES);
  450. #ifdef DEBUG_QSORT
  451. fprintf(stderr, "after partitioning first=#%lu last=#%lu\n", (first-(char*)base)/4lu, (last-(char*)base)/4lu);
  452. #endif
  453. /* Prepare to recurse/iterate. */
  454. Recurse(TRUNC_words)
  455. }
  456. }
  457. PreInsertion(SWAP_words,TRUNC_words/WORD_BYTES,WORD_BYTES);
  458. /* Now do insertion sort. */
  459. last=((char*)base)+nmemb*WORD_BYTES;
  460. for (first=((char*)base)+WORD_BYTES;first!=last;first+=WORD_BYTES) {
  461. /* Find the right place for |first|. My apologies for var reuse */
  462. int *pl=(int*)(first-WORD_BYTES),*pr=(int*)first;
  463. *(int*)pivot=*(int*)first;
  464. for (;compare(pl,pivot)>0;pr=pl,--pl) {
  465. *pr=*pl; }
  466. if (pr!=(int*)first) *pr=*(int*)pivot;
  467. }
  468. free(pivot);
  469. }
  470. /* ---------------------------------------------------------------------- */
  471. extern void qsortG(void *base, size_t nmemb, size_t size,
  472. int (*compare)(const void *, const void *)) {
  473. if (nmemb<=1) return;
  474. if (((size_t)base|size)&(WORD_BYTES-1))
  475. qsort_nonaligned(base,nmemb,size,compare);
  476. else if (size!=WORD_BYTES)
  477. qsort_aligned(base,nmemb,size,compare);
  478. else
  479. qsort_words(base,nmemb,compare);
  480. }
  481. #endif /* HAVE_QSORT */
  482. void *SDL_bsearch(const void *key, const void *base, size_t nmemb, size_t size, int (*compare)(const void *, const void *))
  483. {
  484. #if defined(HAVE_BSEARCH)
  485. return bsearch(key, base, nmemb, size, compare);
  486. #else
  487. /* SDL's replacement: Taken from the Public Domain C Library (PDCLib):
  488. Permission is granted to use, modify, and / or redistribute at will.
  489. */
  490. const void *pivot;
  491. size_t corr;
  492. int rc;
  493. while (nmemb) {
  494. /* algorithm needs -1 correction if remaining elements are an even number. */
  495. corr = nmemb % 2;
  496. nmemb /= 2;
  497. pivot = (const char *)base + (nmemb * size);
  498. rc = compare(key, pivot);
  499. if (rc > 0) {
  500. base = (const char *)pivot + size;
  501. /* applying correction */
  502. nmemb -= (1 - corr);
  503. } else if (rc == 0) {
  504. return (void *)pivot;
  505. }
  506. }
  507. return NULL;
  508. #endif /* HAVE_BSEARCH */
  509. }
  510. /* vi: set ts=4 sw=4 expandtab: */