mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-06-27 14:58:30 +00:00
Pay off more technical debt
This makes breaking changes to add underscores to many non-standard function names provided by the c library. MODE=tiny is now tinier and we now use smaller locks that are better for tiny apps in this mode. Some headers have been renamed to be in the same folder as the build package, so it'll be easier to know which build dependency is needed. Certain old misguided interfaces have been removed. Intel intrinsics headers are now listed in libc/isystem (but not in the amalgamation) to help further improve open source compatibility. Header complexity has also been reduced. Lastly, more shell scripts are now available.
This commit is contained in:
parent
b69f3d2488
commit
6f7d0cb1c3
960 changed files with 4072 additions and 4873 deletions
|
@ -19,8 +19,8 @@
|
|||
#include "libc/log/libfatal.internal.h"
|
||||
#include "libc/mem/arena.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/stdio/append.internal.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/stdio/append.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/hyperion.h"
|
||||
|
|
|
@ -1,110 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/intrin/bits.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/str/str.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(comparator, testByteCompare) {
|
||||
char *b1 = malloc(1);
|
||||
char *b2 = malloc(1);
|
||||
/* sign doesn't matter */
|
||||
EXPECT_EQ(cmpsb(memcpy(b1, "a", 1), memcpy(b2, "a", 1)), 0);
|
||||
EXPECT_LT(cmpsb(memcpy(b1, "a", 1), memcpy(b2, "z", 1)), 0);
|
||||
EXPECT_GT(cmpsb(memcpy(b1, "z", 1), memcpy(b2, "a", 1)), 0);
|
||||
EXPECT_EQ(cmpub(memcpy(b1, "a", 1), memcpy(b2, "a", 1)), 0);
|
||||
EXPECT_LT(cmpub(memcpy(b1, "a", 1), memcpy(b2, "z", 1)), 0);
|
||||
EXPECT_GT(cmpub(memcpy(b1, "z", 1), memcpy(b2, "a", 1)), 0);
|
||||
/* sign matters */
|
||||
EXPECT_EQ(cmpsb(memcpy(b1, "\xf0", 1), memcpy(b2, "\xf0", 1)), 0);
|
||||
EXPECT_LT(cmpsb(memcpy(b1, "\xf0", 1), memcpy(b2, "\x10", 1)), 0);
|
||||
EXPECT_GT(cmpsb(memcpy(b1, "\x10", 1), memcpy(b2, "\xf0", 1)), 0);
|
||||
EXPECT_EQ(cmpub(memcpy(b1, "\xf0", 1), memcpy(b2, "\xf0", 1)), 0);
|
||||
EXPECT_GT(cmpub(memcpy(b1, "\xf0", 1), memcpy(b2, "\x10", 1)), 0);
|
||||
EXPECT_LT(cmpub(memcpy(b1, "\x10", 1), memcpy(b2, "\xf0", 1)), 0);
|
||||
/* two's complement bane */
|
||||
EXPECT_GT(cmpsb(memcpy(b1, "\x7f", 1), memcpy(b2, "\x80", 1)), 0);
|
||||
EXPECT_LT(cmpub(memcpy(b1, "\x7f", 1), memcpy(b2, "\x80", 1)), 0);
|
||||
free(b2);
|
||||
free(b1);
|
||||
}
|
||||
|
||||
TEST(comparator, testWordCompare) {
|
||||
char *b1 = malloc(2);
|
||||
char *b2 = malloc(2);
|
||||
EXPECT_EQ(cmpsw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x80", 2)), 0);
|
||||
EXPECT_GT(cmpsw(memcpy(b1, "\x00\x7f", 2), memcpy(b2, "\x00\x80", 2)), 0);
|
||||
EXPECT_LT(cmpsw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x7f", 2)), 0);
|
||||
EXPECT_EQ(cmpuw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x80", 2)), 0);
|
||||
EXPECT_LT(cmpuw(memcpy(b1, "\x00\x7f", 2), memcpy(b2, "\x00\x80", 2)), 0);
|
||||
EXPECT_GT(cmpuw(memcpy(b1, "\x00\x80", 2), memcpy(b2, "\x00\x7f", 2)), 0);
|
||||
free(b2);
|
||||
free(b1);
|
||||
}
|
||||
|
||||
TEST(comparator, testDoublewordCompare) {
|
||||
char *b1 = malloc(4);
|
||||
char *b2 = malloc(4);
|
||||
EXPECT_EQ(cmpsl(memcpy(b1, "\x00\x00\x00\x80", 4),
|
||||
memcpy(b2, "\x00\x00\x00\x80", 4)),
|
||||
0);
|
||||
EXPECT_GT(cmpsl(memcpy(b1, "\x00\x00\x00\x7f", 4),
|
||||
memcpy(b2, "\x00\x00\x00\x80", 4)),
|
||||
0);
|
||||
EXPECT_LT(cmpsl(memcpy(b1, "\x00\x00\x00\x80", 4),
|
||||
memcpy(b2, "\x00\x00\x00\x7f", 4)),
|
||||
0);
|
||||
EXPECT_EQ(cmpul(memcpy(b1, "\x00\x00\x00\x80", 4),
|
||||
memcpy(b2, "\x00\x00\x00\x80", 4)),
|
||||
0);
|
||||
EXPECT_LT(cmpul(memcpy(b1, "\x00\x00\x00\x7f", 4),
|
||||
memcpy(b2, "\x00\x00\x00\x80", 4)),
|
||||
0);
|
||||
EXPECT_GT(cmpul(memcpy(b1, "\x00\x00\x00\x80", 4),
|
||||
memcpy(b2, "\x00\x00\x00\x7f", 4)),
|
||||
0);
|
||||
free(b2);
|
||||
free(b1);
|
||||
}
|
||||
|
||||
TEST(comparator, testQuadwordCompare) {
|
||||
char *b1 = malloc(8);
|
||||
char *b2 = malloc(8);
|
||||
EXPECT_EQ(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8),
|
||||
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)),
|
||||
0);
|
||||
EXPECT_GT(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8),
|
||||
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)),
|
||||
0);
|
||||
EXPECT_LT(cmpsq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8),
|
||||
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8)),
|
||||
0);
|
||||
EXPECT_EQ(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8),
|
||||
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)),
|
||||
0);
|
||||
EXPECT_LT(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8),
|
||||
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x80", 8)),
|
||||
0);
|
||||
EXPECT_GT(cmpuq(memcpy(b1, "\x00\x00\x00\x00\x00\x00\x00\x80", 8),
|
||||
memcpy(b2, "\x00\x00\x00\x00\x00\x00\x00\x7f", 8)),
|
||||
0);
|
||||
free(b2);
|
||||
free(b1);
|
||||
}
|
|
@ -23,7 +23,7 @@
|
|||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
#include "libc/str/str.h"
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include "libc/intrin/safemacros.internal.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/runtime/memtrack.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
|
|
|
@ -19,9 +19,8 @@
|
|||
#include "libc/intrin/bits.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/nexgen32e/bsr.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/runtime/runtime.h"
|
||||
#include "libc/stdio/rand.h"
|
||||
#include "libc/stdio/stdio.h"
|
||||
|
@ -29,6 +28,14 @@
|
|||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
int CompareInt(const void *a, const void *b) {
|
||||
const int *x = a;
|
||||
const int *y = b;
|
||||
if (*x < *y) return -1;
|
||||
if (*x > *y) return +1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int CompareLong(const void *a, const void *b) {
|
||||
const long *x = a;
|
||||
const long *y = b;
|
||||
|
@ -46,7 +53,7 @@ TEST(qsort, test) {
|
|||
{99, 'f'}, {782, 'i'}};
|
||||
int32_t(*M)[2] = malloc(sizeof(A));
|
||||
memcpy(M, B, sizeof(A));
|
||||
qsort(M, ARRAYLEN(A), sizeof(*M), cmpsl);
|
||||
qsort(M, ARRAYLEN(A), sizeof(*M), CompareInt);
|
||||
EXPECT_EQ(0, memcmp(M, B, sizeof(B)));
|
||||
free(M);
|
||||
}
|
||||
|
@ -54,9 +61,9 @@ TEST(qsort, test) {
|
|||
TEST(qsort, equivalence_random) {
|
||||
size_t i;
|
||||
size_t n = 1000;
|
||||
long *a = gc(malloc(n * sizeof(long)));
|
||||
long *b = gc(malloc(n * sizeof(long)));
|
||||
long *c = gc(malloc(n * sizeof(long)));
|
||||
long *a = _gc(malloc(n * sizeof(long)));
|
||||
long *b = _gc(malloc(n * sizeof(long)));
|
||||
long *c = _gc(malloc(n * sizeof(long)));
|
||||
for (i = 0; i < n; ++i) a[i] = lemur64();
|
||||
memcpy(b, a, n * sizeof(long));
|
||||
memcpy(c, a, n * sizeof(long));
|
||||
|
@ -70,16 +77,16 @@ TEST(qsort, equivalence_random) {
|
|||
smoothsort(c, n, sizeof(long), CompareLong);
|
||||
ASSERT_EQ(0, memcmp(b, c, n * sizeof(long)));
|
||||
memcpy(c, a, n * sizeof(long));
|
||||
longsort(c, n);
|
||||
_longsort(c, n);
|
||||
ASSERT_EQ(0, memcmp(b, c, n * sizeof(long)));
|
||||
}
|
||||
|
||||
TEST(qsort, equivalence_reverse) {
|
||||
size_t i;
|
||||
size_t n = 1000;
|
||||
long *a = gc(malloc(n * sizeof(long)));
|
||||
long *b = gc(malloc(n * sizeof(long)));
|
||||
long *c = gc(malloc(n * sizeof(long)));
|
||||
long *a = _gc(malloc(n * sizeof(long)));
|
||||
long *b = _gc(malloc(n * sizeof(long)));
|
||||
long *c = _gc(malloc(n * sizeof(long)));
|
||||
for (i = 0; i < n; ++i) a[n - i - 1] = i;
|
||||
memcpy(b, a, n * sizeof(long));
|
||||
memcpy(c, a, n * sizeof(long));
|
||||
|
@ -93,15 +100,15 @@ TEST(qsort, equivalence_reverse) {
|
|||
smoothsort(c, n, sizeof(long), CompareLong);
|
||||
ASSERT_EQ(0, memcmp(b, c, n * sizeof(long)));
|
||||
memcpy(c, a, n * sizeof(long));
|
||||
longsort(c, n);
|
||||
_longsort(c, n);
|
||||
ASSERT_EQ(0, memcmp(b, c, n * sizeof(long)));
|
||||
}
|
||||
|
||||
BENCH(qsort, bench) {
|
||||
size_t i;
|
||||
size_t n = 1000;
|
||||
long *p1 = gc(malloc(n * sizeof(long)));
|
||||
long *p2 = gc(malloc(n * sizeof(long)));
|
||||
long *p1 = _gc(malloc(n * sizeof(long)));
|
||||
long *p2 = _gc(malloc(n * sizeof(long)));
|
||||
|
||||
printf("\n");
|
||||
for (i = 0; i < n; ++i) p1[i] = i + ((lemur64() % 3) - 1);
|
||||
|
@ -113,8 +120,8 @@ BENCH(qsort, bench) {
|
|||
mergesort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("smoothsort nearly", memcpy(p2, p1, n * sizeof(long)),
|
||||
smoothsort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("longsort nearly", memcpy(p2, p1, n * sizeof(long)),
|
||||
longsort(p2, n));
|
||||
EZBENCH2("_longsort nearly", memcpy(p2, p1, n * sizeof(long)),
|
||||
_longsort(p2, n));
|
||||
|
||||
printf("\n");
|
||||
for (i = 0; i < n; ++i) p1[i] = n - i;
|
||||
|
@ -126,8 +133,8 @@ BENCH(qsort, bench) {
|
|||
mergesort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("smoothsort reverse", memcpy(p2, p1, n * sizeof(long)),
|
||||
smoothsort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("longsort reverse", memcpy(p2, p1, n * sizeof(long)),
|
||||
longsort(p2, n));
|
||||
EZBENCH2("_longsort reverse", memcpy(p2, p1, n * sizeof(long)),
|
||||
_longsort(p2, n));
|
||||
|
||||
printf("\n");
|
||||
rngset(p1, n * sizeof(long), 0, 0);
|
||||
|
@ -139,8 +146,8 @@ BENCH(qsort, bench) {
|
|||
mergesort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("smoothsort random", memcpy(p2, p1, n * sizeof(long)),
|
||||
smoothsort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("longsort random", memcpy(p2, p1, n * sizeof(long)),
|
||||
longsort(p2, n));
|
||||
EZBENCH2("_longsort random", memcpy(p2, p1, n * sizeof(long)),
|
||||
_longsort(p2, n));
|
||||
|
||||
printf("\n");
|
||||
for (i = 0; i < n / 2; ++i) {
|
||||
|
@ -155,5 +162,5 @@ BENCH(qsort, bench) {
|
|||
mergesort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("smoothsort 2n", memcpy(p2, p1, n * sizeof(long)),
|
||||
smoothsort(p2, n, sizeof(long), CompareLong));
|
||||
EZBENCH2("longsort 2n", memcpy(p2, p1, n * sizeof(long)), longsort(p2, n));
|
||||
EZBENCH2("_longsort 2n", memcpy(p2, p1, n * sizeof(long)), _longsort(p2, n));
|
||||
}
|
||||
|
|
|
@ -17,7 +17,7 @@
|
|||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/mem.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/mem/gc.internal.h"
|
||||
#include "libc/testlib/ezbench.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
|
|
|
@ -16,26 +16,26 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/errno.h"
|
||||
#include "libc/runtime/gc.internal.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/mem/gc.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
TEST(replacestr, demo) {
|
||||
TEST(_replacestr, demo) {
|
||||
EXPECT_STREQ("hello friends",
|
||||
gc(replacestr("hello world", "world", "friends")));
|
||||
EXPECT_STREQ("bbbbbbbb", gc(replacestr("aaaa", "a", "bb")));
|
||||
_gc(_replacestr("hello world", "world", "friends")));
|
||||
EXPECT_STREQ("bbbbbbbb", _gc(_replacestr("aaaa", "a", "bb")));
|
||||
}
|
||||
|
||||
TEST(replacestr, emptyString) {
|
||||
EXPECT_STREQ("", gc(replacestr("", "x", "y")));
|
||||
TEST(_replacestr, emptyString) {
|
||||
EXPECT_STREQ("", _gc(_replacestr("", "x", "y")));
|
||||
}
|
||||
|
||||
TEST(replacestr, emptyNeedle) {
|
||||
EXPECT_EQ(NULL, gc(replacestr("a", "", "a")));
|
||||
TEST(_replacestr, emptyNeedle) {
|
||||
EXPECT_EQ(NULL, _gc(_replacestr("a", "", "a")));
|
||||
EXPECT_EQ(EINVAL, errno);
|
||||
}
|
||||
|
||||
TEST(replacestr, needleInReplacement_doesntExplode) {
|
||||
EXPECT_STREQ("xxxxxxx", gc(replacestr("x", "x", "xxxxxxx")));
|
||||
TEST(_replacestr, needleInReplacement_doesntExplode) {
|
||||
EXPECT_STREQ("xxxxxxx", _gc(_replacestr("x", "x", "xxxxxxx")));
|
||||
}
|
||||
|
|
|
@ -1,37 +0,0 @@
|
|||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||
│ │
|
||||
│ Permission to use, copy, modify, and/or distribute this software for │
|
||||
│ any purpose with or without fee is hereby granted, provided that the │
|
||||
│ above copyright notice and this permission notice appear in all copies. │
|
||||
│ │
|
||||
│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │
|
||||
│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │
|
||||
│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │
|
||||
│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │
|
||||
│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │
|
||||
│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │
|
||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
|
||||
TEST(REPLACESTR, demo) {
|
||||
EXPECT_STREQ(S("hello friends"),
|
||||
REPLACESTR(S("hello world"), S("world"), S("friends")));
|
||||
EXPECT_STREQ(S("bbbbbbbb"), REPLACESTR(S("aaaa"), S("a"), S("bb")));
|
||||
}
|
||||
|
||||
TEST(REPLACESTR, emptyString) {
|
||||
EXPECT_STREQ(S(""), REPLACESTR(S(""), S("x"), S("y")));
|
||||
}
|
||||
|
||||
TEST(REPLACESTR, emptyNeedle) {
|
||||
EXPECT_EQ(NULL, REPLACESTR(S("a"), S(""), S("a")));
|
||||
EXPECT_EQ(EINVAL, errno);
|
||||
}
|
||||
|
||||
TEST(REPLACESTR, needleInReplacement_doesntExplode) {
|
||||
EXPECT_STREQ(S("xxxxxxx"), REPLACESTR(S("x"), S("x"), S("xxxxxxx")));
|
||||
}
|
|
@ -16,8 +16,8 @@
|
|||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/macros.internal.h"
|
||||
#include "libc/mem/alg.h"
|
||||
#include "libc/testlib/testlib.h"
|
||||
|
||||
STATIC_YOINK("realloc");
|
||||
|
@ -27,7 +27,7 @@ TEST(tarjan, empty_doesNothing) {
|
|||
int edges[][2] = {{0, 0}};
|
||||
int vertex_count = 0;
|
||||
int edge_count = 0;
|
||||
tarjan(vertex_count, (void *)edges, edge_count, sorted_vertices, NULL, NULL);
|
||||
_tarjan(vertex_count, (void *)edges, edge_count, sorted_vertices, NULL, NULL);
|
||||
ASSERT_EQ(-1, sorted_vertices[0]);
|
||||
}
|
||||
|
||||
|
@ -53,8 +53,8 @@ TEST(tarjan, topologicalSort_noCycles) {
|
|||
A
|
||||
*/
|
||||
int sorted[4], components[4], componentcount;
|
||||
ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
|
||||
sorted, components, &componentcount));
|
||||
ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
|
||||
sorted, components, &componentcount));
|
||||
EXPECT_EQ(C, sorted[0]);
|
||||
EXPECT_EQ(D, sorted[1]);
|
||||
EXPECT_EQ(B, sorted[2]);
|
||||
|
@ -76,8 +76,8 @@ TEST(tarjan, testOneBigCycle_isDetected_weDontCareAboutOrderInsideTheCycle) {
|
|||
{C /* depends on → */, D /* which must come before C */},
|
||||
{D /* depends on → */, A /* which must come before D */}};
|
||||
int sorted[4], components[4], componentcount;
|
||||
ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
|
||||
sorted, components, &componentcount));
|
||||
ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
|
||||
sorted, components, &componentcount));
|
||||
ASSERT_EQ(1, componentcount);
|
||||
EXPECT_EQ(4, components[0]);
|
||||
}
|
||||
|
@ -110,8 +110,8 @@ TEST(tarjan, testHeaders) {
|
|||
int sorted[ARRAYLEN(vertices)];
|
||||
int components[ARRAYLEN(vertices)];
|
||||
int componentcount;
|
||||
ASSERT_EQ(0, tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
|
||||
sorted, components, &componentcount));
|
||||
ASSERT_EQ(0, _tarjan(ARRAYLEN(vertices), (void *)edges, ARRAYLEN(edges),
|
||||
sorted, components, &componentcount));
|
||||
ASSERT_EQ(ARRAYLEN(vertices), componentcount);
|
||||
EXPECT_STREQ("libc/dce.h", vertices[sorted[0]]);
|
||||
EXPECT_STREQ("libc/integral.h", vertices[sorted[1]]);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue