mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 03:27:39 +00:00
7c83f4abc8
- wcsstr() is now linearly complex - strstr16() is now linearly complex - strstr() is now vectorized on aarch64 (10x) - strstr() now uses KMP on pathological cases - memmem() is now vectorized on aarch64 (10x) - memmem() now uses KMP on pathological cases - Disable shared_ptr::owner_before until fixed - Make iswlower(), iswupper() consistent with glibc - Remove figure space from iswspace() implementation - Include line and paragraph separator in iswcntrl() - Use Musl wcwidth(), iswalpha(), iswpunct(), towlower(), towupper()
20 lines
397 B
C
20 lines
397 B
C
#include <stdlib.h>
|
|
|
|
void *bsearch(const void *key, const void *base, size_t nel, size_t width, int (*cmp)(const void *, const void *))
|
|
{
|
|
void *try;
|
|
int sign;
|
|
while (nel > 0) {
|
|
try = (char *)base + width*(nel/2);
|
|
sign = cmp(key, try);
|
|
if (sign < 0) {
|
|
nel /= 2;
|
|
} else if (sign > 0) {
|
|
base = (char *)try + width;
|
|
nel -= nel/2+1;
|
|
} else {
|
|
return try;
|
|
}
|
|
}
|
|
return NULL;
|
|
}
|