Skip to content

Instantly share code, notes, and snippets.

@pervognsen
Last active February 17, 2019 05:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pervognsen/696cdc33af2075aa2dcf69152985a09f to your computer and use it in GitHub Desktop.
Save pervognsen/696cdc33af2075aa2dcf69152985a09f to your computer and use it in GitHub Desktop.
func test_dynamic_arrays() {
a: int*;
apush(a, 42);
apush(a, 36);
len := alen(a);
cap := acap(a);
for (i := 0; i < alen(a); i++) {
printf("a[%d] = %d\n", i, a[i]);
}
asetcap(a, 1);
apush(a, 82);
for (i := 0; i < alen(a); i++) {
printf("a[%d] = %d\n", i, a[i]);
}
apop(a);
for (i := 0; i < alen(a); i++) {
printf("a[%d] = %d\n", i, a[i]);
}
b: int*;
apush(b, 1);
apush(b, 2);
acat(a, b);
afree(b);
acatn(a, a + 1, 2);
for (i := 0; i < alen(a); i++) {
printf("a[%d] = %d\n", i, a[i]);
}
adel(a, 1);
adeln(a, 2, 10);
for (i := 0; i < alen(a); i++) {
printf("a[%d] = %d\n", i, a[i]);
}
afree(a);
}
func test_aprintf() {
a: char*;
aprintf(a, "Hello");
aprintf(a, ", world! %d", 42);
len := alen(a);
printf("%s\n", a);
}
func test_index_arrays() {
a: int*;
kadd(a, 42);
kadd(a, 36);
for (i := 0; i < klen(a); i++) {
printf("%d\n", a[i]);
}
kdel(a, 42);
printf("%llu %llu %llu\n", kget(a, 42), kget(a, 36), kget(a, 123));
m: {char, int}*;
hput(m, 'x', 42);
hput(m, 'p', 36);
for (i := 0; i < hlen(m); i++) {
printf("[%d] %c => %d\n", i, m[i][0], m[i][1]);
}
hdel(m, 'x');
j := hget(m, 'p');
printf("[%llu] %c => %d\n", j, m[j][0], m[j][1]);
hput(m, 'm', 38);
hdel(m, 'p');
for (i := 0; i < hlen(m); i++) {
printf("[%d] %c => %d\n", i, m[i][0], m[i][1]);
}
}
// =>
#line 924
void test1_test_dynamic_arrays(void) {
int (*a) = {0};
apush(int, a, 42);
apush(int, a, 36);
ullong len = std_alen(a);
ullong cap = std_acap(a);
for (int i = 0; (i) < (std_alen(a)); (i)++) {
printf("a[%d] = %d\n", i, a[i]);
}
asetcap(a, 1);
apush(int, a, 82);
for (int i = 0; (i) < (std_alen(a)); (i)++) {
printf("a[%d] = %d\n", i, a[i]);
}
std_apop(a);
for (int i = 0; (i) < (std_alen(a)); (i)++) {
printf("a[%d] = %d\n", i, a[i]);
}
int (*b) = {0};
apush(int, b, 1);
apush(int, b, 2);
acat(a, b);
std_afree(b);
acatn(a, (a) + (1), 2);
for (int i = 0; (i) < (std_alen(a)); (i)++) {
printf("a[%d] = %d\n", i, a[i]);
}
adel(a, 1);
adeln(a, 2, 10);
for (int i = 0; (i) < (std_alen(a)); (i)++) {
printf("a[%d] = %d\n", i, a[i]);
}
std_afree(a);
}
#line 916
void test1_test_aprintf(void) {
char (*a) = {0};
aprintf(a, "Hello");
aprintf(a, ", world! %d", 42);
ullong len = std_alen(a);
printf("%s\n", a);
}
#line 959
void test1_test_index_arrays(void) {
int (*a) = {0};
kadd(int, a, 42);
kadd(int, a, 36);
for (int i = 0; (i) < (std_klen(a)); (i)++) {
printf("%d\n", a[i]);
}
kdel(int, a, 42);
printf("%llu %llu %llu\n", kget(int, a, 42), kget(int, a, 36), kget(int, a, 123));
#line 969
tuple0 (*m) = {0};
hput(tuple0, _0, m, 'x', 42);
hput(tuple0, _0, m, 'p', 36);
for (int i = 0; (i) < (std_hlen(m)); (i)++) {
printf("[%d] %c => %d\n", i, m[i]._0, m[i]._1);
}
hdel(char, m, 'x');
ullong j = hget(char, m, 'p');
printf("[%llu] %c => %d\n", j, m[j]._0, m[j]._1);
hput(tuple0, _0, m, 'm', 38);
hdel(char, m, 'p');
for (int i = 0; (i) < (std_hlen(m)); (i)++) {
printf("[%d] %c => %d\n", i, m[i]._0, m[i]._1);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment