mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-02-07 15:03:34 +00:00
This change changes qsort() to use the same code as NetBSD and MacOS because it goes 6x faster than Musl's SmoothSort function. Smoothsort can still be used if you need something that's provenly linearithmic. This change also improves GNU Make performance on whole by 7 percent! netbsd nearly l: 70,196c 22,673ns m: 68,428c 22,102ns musl nearly l: 53,844c 17,391ns m: 58,726c 18,968ns unixv6 nearly l: 65,885c 21,280ns m: 63,082c 20,375ns netbsd reverse l: 120,290c 38,853ns m: 122,619c 39,605ns musl reverse l: 801,826c 258,985ns m: 794,689c 256,680ns unixv6 reverse l: 58,977c 19,049ns m: 59,764c 19,303ns netbsd random l: 146,745c 47,398ns m: 145,782c 47,087ns musl random l: 855,804c 276,420ns m: 850,912c 274,840ns unixv6 random l: 214,325c 69,226ns m: 213,906c 69,090ns netbsd 2n l: 77,299c 24,967ns m: 76,773c 24,797ns musl 2n l: 818,012c 264,213ns m: 818,282c 264,301ns unixv6 2n l: 3,967,009c 1,281,322ns m: 3,941,792c 1,273,177ns https://justine.lol/dox/sort.pdf
50 lines
2 KiB
C
50 lines
2 KiB
C
#ifndef COSMOPOLITAN_LIBC_ALG_ALG_H_
|
|
#define COSMOPOLITAN_LIBC_ALG_ALG_H_
|
|
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
|
COSMOPOLITAN_C_START_
|
|
|
|
void *bsearch(const void *, const void *, size_t, size_t,
|
|
int (*)(const void *, const void *))
|
|
paramsnonnull() dontthrow nosideeffect;
|
|
void *bsearch_r(const void *, const void *, size_t, size_t,
|
|
int (*)(const void *, const void *, void *), void *)
|
|
paramsnonnull((1, 2, 5)) dontthrow nosideeffect;
|
|
void djbsort(int32_t *, size_t);
|
|
void qsort(void *, size_t, size_t, int (*)(const void *, const void *))
|
|
paramsnonnull();
|
|
void qsort_r(void *, size_t, size_t,
|
|
int (*)(const void *, const void *, void *), void *)
|
|
paramsnonnull((1, 4));
|
|
void smoothsort(void *, size_t, size_t, int (*)(const void *, const void *));
|
|
void smoothsort_r(void *, size_t, size_t,
|
|
int (*)(const void *, const void *, void *), void *);
|
|
int tarjan(int, const int (*)[2], int, int[], int[], int *)
|
|
paramsnonnull((2, 4)) nocallback dontthrow;
|
|
|
|
#define __algalloc returnspointerwithnoaliases dontthrow nocallback dontdiscard
|
|
|
|
char *replacestr(const char *, const char *, const char *)
|
|
paramsnonnull() __algalloc;
|
|
char16_t *replacestr16(const char16_t *, const char16_t *, const char16_t *)
|
|
paramsnonnull() __algalloc;
|
|
wchar_t *replacewcs(const wchar_t *, const wchar_t *, const wchar_t *)
|
|
paramsnonnull() __algalloc;
|
|
|
|
char *concatstr(const char *, ...) nullterminated() paramsnonnull() __algalloc;
|
|
char16_t *concatstr16(const char16_t *, ...) nullterminated()
|
|
paramsnonnull() __algalloc;
|
|
wchar_t *concatwcs(const wchar_t *, ...) nullterminated()
|
|
paramsnonnull() __algalloc;
|
|
|
|
int cmpsb(const void *, const void *);
|
|
int cmpub(const void *, const void *);
|
|
int cmpsw(const void *, const void *);
|
|
int cmpuw(const void *, const void *);
|
|
int cmpsl(const void *, const void *);
|
|
int cmpul(const void *, const void *);
|
|
int cmpsq(const void *, const void *);
|
|
int cmpuq(const void *, const void *);
|
|
|
|
COSMOPOLITAN_C_END_
|
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
|
#endif /* COSMOPOLITAN_LIBC_ALG_ALG_H_ */
|