\hypertarget{qsort_8c_source}{}\doxysection{qsort.\+c}
\label{qsort_8c_source}\index{libkern/qsort.c@{libkern/qsort.c}}
\mbox{\hyperlink{qsort_8c}{Go to the documentation of this file.}}
\begin{DoxyCode}{0}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00001}00001 \textcolor{comment}{/*-\/}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00002}00002 \textcolor{comment}{ * SPDX-\/License-\/Identifier: BSD-\/3-\/Clause}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00003}00003 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00004}00004 \textcolor{comment}{ * Copyright (c) 1992, 1993}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00005}00005 \textcolor{comment}{ *      The Regents of the University of California.  All rights reserved.}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00006}00006 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00007}00007 \textcolor{comment}{ * Redistribution and use in source and binary forms, with or without}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00008}00008 \textcolor{comment}{ * modification, are permitted provided that the following conditions}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00009}00009 \textcolor{comment}{ * are met:}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00010}00010 \textcolor{comment}{ * 1. Redistributions of source code must retain the above copyright}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00011}00011 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer.}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00012}00012 \textcolor{comment}{ * 2. Redistributions in binary form must reproduce the above copyright}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00013}00013 \textcolor{comment}{ *    notice, this list of conditions and the following disclaimer in the}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00014}00014 \textcolor{comment}{ *    documentation and/or other materials provided with the distribution.}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00015}00015 \textcolor{comment}{ * 3. Neither the name of the University nor the names of its contributors}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00016}00016 \textcolor{comment}{ *    may be used to endorse or promote products derived from this software}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00017}00017 \textcolor{comment}{ *    without specific prior written permission.}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00018}00018 \textcolor{comment}{ *}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00019}00019 \textcolor{comment}{ * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00020}00020 \textcolor{comment}{ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00021}00021 \textcolor{comment}{ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00022}00022 \textcolor{comment}{ * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00023}00023 \textcolor{comment}{ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00024}00024 \textcolor{comment}{ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00025}00025 \textcolor{comment}{ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00026}00026 \textcolor{comment}{ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00027}00027 \textcolor{comment}{ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00028}00028 \textcolor{comment}{ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00029}00029 \textcolor{comment}{ * SUCH DAMAGE.}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00030}00030 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00031}00031 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00032}00032 \textcolor{preprocessor}{\#include <sys/cdefs.h>}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00033}\mbox{\hyperlink{qsort_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{00033}} \mbox{\hyperlink{qsort_8c_a8c3ef283470a68cd30afe9b8a72cb60f}{\_\_FBSDID}}(\textcolor{stringliteral}{"{}\$FreeBSD\$"{}});}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00034}00034 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00035}00035 \textcolor{preprocessor}{\#include <sys/param.h>}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00036}00036 \textcolor{preprocessor}{\#include <sys/libkern.h>}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00037}00037 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00038}00038 \textcolor{preprocessor}{\#ifdef I\_AM\_QSORT\_R}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00039}00039 \textcolor{keyword}{typedef} \textcolor{keywordtype}{int}              \mbox{\hyperlink{qsort_8c_abd8540c0d653e4a1457e863923410bbc}{cmp\_t}}(\textcolor{keywordtype}{void} *, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00040}00040 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00041}\mbox{\hyperlink{qsort_8c_abd8540c0d653e4a1457e863923410bbc}{00041}} \textcolor{keyword}{typedef} \textcolor{keywordtype}{int}              \mbox{\hyperlink{qsort_8c_abd8540c0d653e4a1457e863923410bbc}{cmp\_t}}(\textcolor{keyword}{const} \textcolor{keywordtype}{void} *, \textcolor{keyword}{const} \textcolor{keywordtype}{void} *);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00042}00042 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00043}\mbox{\hyperlink{qsort_8c_a3203defea2c13dc0819dd5b5334f5145}{00043}} \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{char}      *\mbox{\hyperlink{qsort_8c_a3203defea2c13dc0819dd5b5334f5145}{med3}}(\textcolor{keywordtype}{char} *, \textcolor{keywordtype}{char} *, \textcolor{keywordtype}{char} *, \mbox{\hyperlink{qsort_8c_abd8540c0d653e4a1457e863923410bbc}{cmp\_t}} *, \textcolor{keywordtype}{void} *);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00044}00044 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void}       \mbox{\hyperlink{qsort_8c_ac54cbc0f2f2eac11e363d4a3829f14d8}{swapfunc}}(\textcolor{keywordtype}{char} *, \textcolor{keywordtype}{char} *, \textcolor{keywordtype}{size\_t}, \textcolor{keywordtype}{int}, \textcolor{keywordtype}{int});}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00045}00045 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00046}00046 \textcolor{comment}{/*}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00047}00047 \textcolor{comment}{ * Qsort routine from Bentley \& McIlroy's "{}Engineering a Sort Function"{}.}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00048}00048 \textcolor{comment}{ */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00049}\mbox{\hyperlink{qsort_8c_a94e98b172e7b50dde8c112d1617d446d}{00049}} \textcolor{preprocessor}{\#define swapcode(TYPE, parmi, parmj, n) \{               \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00050}00050 \textcolor{preprocessor}{        size\_t i = (n) / sizeof (TYPE);                 \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00051}00051 \textcolor{preprocessor}{        TYPE *pi = (TYPE *) (parmi);            \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00052}00052 \textcolor{preprocessor}{        TYPE *pj = (TYPE *) (parmj);            \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00053}00053 \textcolor{preprocessor}{        do \{                                            \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00054}00054 \textcolor{preprocessor}{                TYPE    t = *pi;                \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00055}00055 \textcolor{preprocessor}{                *pi++ = *pj;                            \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00056}00056 \textcolor{preprocessor}{                *pj++ = t;                              \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00057}00057 \textcolor{preprocessor}{        \} while (-\/-\/i > 0);                              \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00058}00058 \textcolor{preprocessor}{\}}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00059}00059 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00060}\mbox{\hyperlink{qsort_8c_a916654799a6c8ec8aefc106702a327fb}{00060}} \textcolor{preprocessor}{\#define SWAPINIT(TYPE, a, es) swaptype\_ \#\# TYPE =       \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00061}00061 \textcolor{preprocessor}{        ((char *)a -\/ (char *)0) \% sizeof(TYPE) ||       \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00062}00062 \textcolor{preprocessor}{        es \% sizeof(TYPE) ? 2 : es == sizeof(TYPE) ? 0 : 1;}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00063}00063 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00064}00064 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00065}\mbox{\hyperlink{qsort_8c_ac54cbc0f2f2eac11e363d4a3829f14d8}{00065}} \mbox{\hyperlink{qsort_8c_ac54cbc0f2f2eac11e363d4a3829f14d8}{swapfunc}}(\textcolor{keywordtype}{char} *a, \textcolor{keywordtype}{char} *b, \textcolor{keywordtype}{size\_t} n, \textcolor{keywordtype}{int} swaptype\_long, \textcolor{keywordtype}{int} swaptype\_int)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00066}00066 \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00067}00067         \textcolor{keywordflow}{if} (swaptype\_long <= 1)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00068}00068                 \mbox{\hyperlink{qsort_8c_a94e98b172e7b50dde8c112d1617d446d}{swapcode}}(\textcolor{keywordtype}{long}, a, b, n)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00069}00069         \textcolor{keywordflow}{else} \textcolor{keywordflow}{if} (swaptype\_int <= 1)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00070}00070                 \mbox{\hyperlink{qsort_8c_a94e98b172e7b50dde8c112d1617d446d}{swapcode}}(\textcolor{keywordtype}{int}, a, b, n)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00071}00071         \textcolor{keywordflow}{else}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00072}00072                 \mbox{\hyperlink{qsort_8c_a94e98b172e7b50dde8c112d1617d446d}{swapcode}}(\textcolor{keywordtype}{char}, a, b, n)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00073}00073 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00074}00074 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00075}\mbox{\hyperlink{qsort_8c_a3ca5ecd34b04d6a243c054ac3a57f68d}{00075}} \textcolor{preprocessor}{\#define swap(a, b)                                      \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00076}00076 \textcolor{preprocessor}{        if (swaptype\_long == 0) \{                       \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00077}00077 \textcolor{preprocessor}{                long t = *(long *)(a);                  \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00078}00078 \textcolor{preprocessor}{                *(long *)(a) = *(long *)(b);            \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00079}00079 \textcolor{preprocessor}{                *(long *)(b) = t;                       \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00080}00080 \textcolor{preprocessor}{        \} else if (swaptype\_int == 0) \{                 \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00081}00081 \textcolor{preprocessor}{                int t = *(int *)(a);                    \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00082}00082 \textcolor{preprocessor}{                *(int *)(a) = *(int *)(b);              \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00083}00083 \textcolor{preprocessor}{                *(int *)(b) = t;                        \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00084}00084 \textcolor{preprocessor}{        \} else                                          \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00085}00085 \textcolor{preprocessor}{                swapfunc(a, b, es, swaptype\_long, swaptype\_int)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00086}00086 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00087}\mbox{\hyperlink{qsort_8c_a584c607dc0b230ebfdde9a157887c6a9}{00087}} \textcolor{preprocessor}{\#define vecswap(a, b, n)                                \(\backslash\)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00088}00088 \textcolor{preprocessor}{        if ((n) > 0) swapfunc(a, b, n, swaptype\_long, swaptype\_int)}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00089}00089 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00090}00090 \textcolor{preprocessor}{\#ifdef I\_AM\_QSORT\_R}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00091}00091 \textcolor{preprocessor}{\#define CMP(t, x, y) (cmp((t), (x), (y)))}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00092}00092 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00093}\mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{00093}} \textcolor{preprocessor}{\#define CMP(t, x, y) (cmp((x), (y)))}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00094}00094 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00095}00095 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00096}00096 \textcolor{keyword}{static} \textcolor{keyword}{inline} \textcolor{keywordtype}{char} *}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00097}\mbox{\hyperlink{qsort_8c_ae430fd2582deae0fbd112817a59104f8}{00097}} \mbox{\hyperlink{qsort_8c_a3203defea2c13dc0819dd5b5334f5145}{med3}}(\textcolor{keywordtype}{char} *a, \textcolor{keywordtype}{char} *b, \textcolor{keywordtype}{char} *\mbox{\hyperlink{iconv__converter__if_8m_a4e1e0e72dd773439e333c84dd762a9c3}{c}}, \mbox{\hyperlink{qsort_8c_abd8540c0d653e4a1457e863923410bbc}{cmp\_t}} *cmp, \textcolor{keywordtype}{void} *\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00098}00098 \#ifndef \mbox{\hyperlink{qsort__r_8c_a0e42000b342ee27a26c63e4d933dcd3a}{I\_AM\_QSORT\_R}}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00099}00099 \_\_unused}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00100}00100 \#endif}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00101}00101 )}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00102}00102 \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00103}00103         \textcolor{keywordflow}{return} \mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, a, b) < 0 ?}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00104}00104                (\mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, b, \mbox{\hyperlink{iconv__converter__if_8m_a4e1e0e72dd773439e333c84dd762a9c3}{c}}) < 0 ? b : (\mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, a, \mbox{\hyperlink{iconv__converter__if_8m_a4e1e0e72dd773439e333c84dd762a9c3}{c}}) < 0 ? \mbox{\hyperlink{iconv__converter__if_8m_a4e1e0e72dd773439e333c84dd762a9c3}{c}} : a ))}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00105}00105               :(\mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, b, \mbox{\hyperlink{iconv__converter__if_8m_a4e1e0e72dd773439e333c84dd762a9c3}{c}}) > 0 ? b : (\mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, a, \mbox{\hyperlink{iconv__converter__if_8m_a4e1e0e72dd773439e333c84dd762a9c3}{c}}) < 0 ? a : \mbox{\hyperlink{iconv__converter__if_8m_a4e1e0e72dd773439e333c84dd762a9c3}{c}} ));}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00106}00106 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00107}00107 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00108}00108 \textcolor{preprocessor}{\#ifdef I\_AM\_QSORT\_R}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00109}00109 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00110}00110 qsort\_r(\textcolor{keywordtype}{void} *a, \textcolor{keywordtype}{size\_t} n, \textcolor{keywordtype}{size\_t} es, \textcolor{keywordtype}{void} *\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, \mbox{\hyperlink{qsort_8c_abd8540c0d653e4a1457e863923410bbc}{cmp\_t}} *cmp)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00111}00111 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00112}\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{00112}} \textcolor{preprocessor}{\#define thunk NULL}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00113}00113 \textcolor{keywordtype}{void}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00114}\mbox{\hyperlink{qsort_8c_a2e2d678f8229e5cc532206da89450741}{00114}} \mbox{\hyperlink{qsort_8c_a2e2d678f8229e5cc532206da89450741}{qsort}}(\textcolor{keywordtype}{void} *a, \textcolor{keywordtype}{size\_t} n, \textcolor{keywordtype}{size\_t} es, \mbox{\hyperlink{qsort_8c_abd8540c0d653e4a1457e863923410bbc}{cmp\_t}} *cmp)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00115}00115 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00116}00116 \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00117}00117         \textcolor{keywordtype}{char} *pa, *pb, *pc, *pd, *pl, *pm, *pn;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00118}00118         \textcolor{keywordtype}{size\_t} d1, d2;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00119}00119         \textcolor{keywordtype}{int} cmp\_result;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00120}00120         \textcolor{keywordtype}{int} swaptype\_long, swaptype\_int, swap\_cnt;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00121}00121 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00122}00122 loop:   \mbox{\hyperlink{qsort_8c_a916654799a6c8ec8aefc106702a327fb}{SWAPINIT}}(\textcolor{keywordtype}{long}, a, es);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00123}00123         \mbox{\hyperlink{qsort_8c_a916654799a6c8ec8aefc106702a327fb}{SWAPINIT}}(\textcolor{keywordtype}{int}, a, es);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00124}00124         swap\_cnt = 0;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00125}00125         \textcolor{keywordflow}{if} (n < 7) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00126}00126                 \textcolor{keywordflow}{for} (pm = (\textcolor{keywordtype}{char} *)a + es; pm < (\textcolor{keywordtype}{char} *)a + n * es; pm += es)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00127}00127                         \textcolor{keywordflow}{for} (pl = pm; }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00128}00128                              pl > (\textcolor{keywordtype}{char} *)a \&\& \mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, pl -\/ es, pl) > 0;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00129}00129                              pl -\/= es)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00130}00130                                 \mbox{\hyperlink{qsort_8c_a3ca5ecd34b04d6a243c054ac3a57f68d}{swap}}(pl, pl -\/ es);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00131}00131                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00132}00132         \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00133}00133         pm = (\textcolor{keywordtype}{char} *)a + (n / 2) * es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00134}00134         \textcolor{keywordflow}{if} (n > 7) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00135}00135                 pl = a;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00136}00136                 pn = (\textcolor{keywordtype}{char} *)a + (n -\/ 1) * es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00137}00137                 \textcolor{keywordflow}{if} (n > 40) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00138}00138                         \textcolor{keywordtype}{size\_t} d = (n / 8) * es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00139}00139 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00140}00140                         pl = \mbox{\hyperlink{qsort_8c_a3203defea2c13dc0819dd5b5334f5145}{med3}}(pl, pl + d, pl + 2 * d, cmp, \mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}});}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00141}00141                         pm = \mbox{\hyperlink{qsort_8c_a3203defea2c13dc0819dd5b5334f5145}{med3}}(pm -\/ d, pm, pm + d, cmp, \mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}});}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00142}00142                         pn = \mbox{\hyperlink{qsort_8c_a3203defea2c13dc0819dd5b5334f5145}{med3}}(pn -\/ 2 * d, pn -\/ d, pn, cmp, \mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}});}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00143}00143                 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00144}00144                 pm = \mbox{\hyperlink{qsort_8c_a3203defea2c13dc0819dd5b5334f5145}{med3}}(pl, pm, pn, cmp, \mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}});}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00145}00145         \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00146}00146         \mbox{\hyperlink{qsort_8c_a3ca5ecd34b04d6a243c054ac3a57f68d}{swap}}(a, pm);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00147}00147         pa = pb = (\textcolor{keywordtype}{char} *)a + es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00148}00148 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00149}00149         pc = pd = (\textcolor{keywordtype}{char} *)a + (n -\/ 1) * es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00150}00150         \textcolor{keywordflow}{for} (;;) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00151}00151                 \textcolor{keywordflow}{while} (pb <= pc \&\& (cmp\_result = \mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, pb, a)) <= 0) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00152}00152                         \textcolor{keywordflow}{if} (cmp\_result == 0) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00153}00153                                 swap\_cnt = 1;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00154}00154                                 \mbox{\hyperlink{qsort_8c_a3ca5ecd34b04d6a243c054ac3a57f68d}{swap}}(pa, pb);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00155}00155                                 pa += es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00156}00156                         \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00157}00157                         pb += es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00158}00158                 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00159}00159                 \textcolor{keywordflow}{while} (pb <= pc \&\& (cmp\_result = \mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, pc, a)) >= 0) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00160}00160                         \textcolor{keywordflow}{if} (cmp\_result == 0) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00161}00161                                 swap\_cnt = 1;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00162}00162                                 \mbox{\hyperlink{qsort_8c_a3ca5ecd34b04d6a243c054ac3a57f68d}{swap}}(pc, pd);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00163}00163                                 pd -\/= es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00164}00164                         \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00165}00165                         pc -\/= es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00166}00166                 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00167}00167                 \textcolor{keywordflow}{if} (pb > pc)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00168}00168                         \textcolor{keywordflow}{break};}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00169}00169                 \mbox{\hyperlink{qsort_8c_a3ca5ecd34b04d6a243c054ac3a57f68d}{swap}}(pb, pc);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00170}00170                 swap\_cnt = 1;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00171}00171                 pb += es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00172}00172                 pc -\/= es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00173}00173         \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00174}00174         \textcolor{keywordflow}{if} (swap\_cnt == 0) \{  \textcolor{comment}{/* Switch to insertion sort */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00175}00175                 \textcolor{keywordflow}{for} (pm = (\textcolor{keywordtype}{char} *)a + es; pm < (\textcolor{keywordtype}{char} *)a + n * es; pm += es)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00176}00176                         \textcolor{keywordflow}{for} (pl = pm; }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00177}00177                              pl > (\textcolor{keywordtype}{char} *)a \&\& \mbox{\hyperlink{qsort_8c_a6f285bba3edde515f2fe634df512cdbc}{CMP}}(\mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, pl -\/ es, pl) > 0;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00178}00178                              pl -\/= es)}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00179}00179                                 \mbox{\hyperlink{qsort_8c_a3ca5ecd34b04d6a243c054ac3a57f68d}{swap}}(pl, pl -\/ es);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00180}00180                 \textcolor{keywordflow}{return};}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00181}00181         \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00182}00182 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00183}00183         pn = (\textcolor{keywordtype}{char} *)a + n * es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00184}00184         d1 = MIN(pa -\/ (\textcolor{keywordtype}{char} *)a, pb -\/ pa);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00185}00185         \mbox{\hyperlink{qsort_8c_a584c607dc0b230ebfdde9a157887c6a9}{vecswap}}(a, pb -\/ d1, d1);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00186}00186         d1 = MIN(pd -\/ pc, pn -\/ pd -\/ es);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00187}00187         \mbox{\hyperlink{qsort_8c_a584c607dc0b230ebfdde9a157887c6a9}{vecswap}}(pb, pn -\/ d1, d1);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00188}00188 }
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00189}00189         d1 = pb -\/ pa;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00190}00190         d2 = pd -\/ pc;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00191}00191         \textcolor{keywordflow}{if} (d1 <= d2) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00192}00192                 \textcolor{comment}{/* Recurse on left partition, then iterate on right partition */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00193}00193                 \textcolor{keywordflow}{if} (d1 > es) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00194}00194 \textcolor{preprocessor}{\#ifdef I\_AM\_QSORT\_R}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00195}00195                         qsort\_r(a, d1 / es, es, \mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, cmp);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00196}00196 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00197}00197                         \mbox{\hyperlink{qsort_8c_a2e2d678f8229e5cc532206da89450741}{qsort}}(a, d1 / es, es, cmp);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00198}00198 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00199}00199                 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00200}00200                 \textcolor{keywordflow}{if} (d2 > es) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00201}00201                         \textcolor{comment}{/* Iterate rather than recurse to save stack space */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00202}00202                         \textcolor{comment}{/* qsort(pn -\/ d2, d2 / es, es, cmp); */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00203}00203                         a = pn -\/ d2;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00204}00204                         n = d2 / es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00205}00205                         \textcolor{keywordflow}{goto} loop;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00206}00206                 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00207}00207         \} \textcolor{keywordflow}{else} \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00208}00208                 \textcolor{comment}{/* Recurse on right partition, then iterate on left partition */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00209}00209                 \textcolor{keywordflow}{if} (d2 > es) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00210}00210 \textcolor{preprocessor}{\#ifdef I\_AM\_QSORT\_R}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00211}00211                         qsort\_r(pn -\/ d2, d2 / es, es, \mbox{\hyperlink{qsort_8c_a2b18d15414231a2d9b8f0918188039aa}{thunk}}, cmp);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00212}00212 \textcolor{preprocessor}{\#else}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00213}00213                         \mbox{\hyperlink{qsort_8c_a2e2d678f8229e5cc532206da89450741}{qsort}}(pn -\/ d2, d2 / es, es, cmp);}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00214}00214 \textcolor{preprocessor}{\#endif}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00215}00215                 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00216}00216                 \textcolor{keywordflow}{if} (d1 > es) \{}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00217}00217                         \textcolor{comment}{/* Iterate rather than recurse to save stack space */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00218}00218                         \textcolor{comment}{/* qsort(a, d1 / es, es, cmp); */}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00219}00219                         n = d1 / es;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00220}00220                         \textcolor{keywordflow}{goto} loop;}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00221}00221                 \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00222}00222         \}}
\DoxyCodeLine{\Hypertarget{qsort_8c_source_l00223}00223 \}}

\end{DoxyCode}
