Made some tests to go through
This commit is contained in:
2
alisp.h
2
alisp.h
@@ -73,7 +73,7 @@ void vec_init(vec_t *, u64);
|
|||||||
void vec_free(vec_t *);
|
void vec_free(vec_t *);
|
||||||
void *vec_data(vec_t *);
|
void *vec_data(vec_t *);
|
||||||
void vec_ensure_free(vec_t *, u64);
|
void vec_ensure_free(vec_t *, u64);
|
||||||
void vec_append(vec_t *, void *, u64);
|
void vec_append(vec_t *, const void *const, u64);
|
||||||
void vec_clone(vec_t *, vec_t *);
|
void vec_clone(vec_t *, vec_t *);
|
||||||
|
|
||||||
/// Symbol table
|
/// Symbol table
|
||||||
|
|||||||
43
main.c
43
main.c
@@ -25,8 +25,6 @@ sv_t sv_copy(sv_t old)
|
|||||||
return SV(newstr, old.size);
|
return SV(newstr, old.size);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
|
||||||
{
|
|
||||||
const char *words[] = {
|
const char *words[] = {
|
||||||
"aliquam", "erat", "volutpat", "nunc", "eleifend",
|
"aliquam", "erat", "volutpat", "nunc", "eleifend",
|
||||||
"leo", "vitae", "magna", "in", "id",
|
"leo", "vitae", "magna", "in", "id",
|
||||||
@@ -45,31 +43,46 @@ int main(void)
|
|||||||
"euismod", "tellus", "id", "erat",
|
"euismod", "tellus", "id", "erat",
|
||||||
};
|
};
|
||||||
|
|
||||||
|
void vec_test(void)
|
||||||
|
{
|
||||||
vec_t vec = {0};
|
vec_t vec = {0};
|
||||||
vec_init(&vec, 0);
|
vec_init(&vec, 0);
|
||||||
|
|
||||||
for (u64 i = 0; i < ARRSIZE(words); ++i)
|
for (u64 i = 0; i < ARRSIZE(words); ++i)
|
||||||
{
|
{
|
||||||
vec_append(&vec, words[i], strlen(words[i]));
|
vec_append(&vec, words[i], strlen(words[i]));
|
||||||
vec_append(&vec, "\n", 1);
|
vec_append(&vec, " ", 1);
|
||||||
printf("%lu/%lu, inlined?: %s\n", vec.size, vec.capacity,
|
printf("[vec_test]: %lu/%lu, inlined?: %s\n", vec.size, vec.capacity,
|
||||||
vec.is_inlined ? "yes" : "no");
|
vec.is_inlined ? "yes" : "no");
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%lu/%lu: %.*s\n", vec.size, vec.capacity, (int)vec.size,
|
printf("[vec_test]: Final: %lu/%lu: %.*s\n", vec.size, vec.capacity,
|
||||||
vec_data(&vec));
|
(int)vec.size, (char *)vec_data(&vec));
|
||||||
|
|
||||||
vec_free(&vec);
|
vec_free(&vec);
|
||||||
|
}
|
||||||
|
|
||||||
// sym_table_t table = {0};
|
void symtable_test(void)
|
||||||
// sym_table_init(&table);
|
{
|
||||||
// // Let's hash the words of lorem ipsum
|
sym_table_t table = {0};
|
||||||
// for (u64 i = 0; i < ARRSIZE(words); ++i)
|
sym_table_init(&table);
|
||||||
// {
|
for (u64 i = 0; i < ARRSIZE(words); ++i)
|
||||||
// char *ptr = sym_table_find(&table, SV(words[i], strlen(words[i])));
|
{
|
||||||
// printf("%s => %p\n", words[i], ptr);
|
char *ptr = sym_table_find(&table, SV(words[i], strlen(words[i])));
|
||||||
// }
|
printf("[symtable_test]: %s => %p\n", words[i], ptr);
|
||||||
|
}
|
||||||
|
|
||||||
// sym_table_cleanup(&table);
|
printf(
|
||||||
|
"[symtable_test]: |words|=%lu, |table|= %lu => Unique word ratio: %lf\n",
|
||||||
|
ARRSIZE(words), table.count, table.count / (double)ARRSIZE(words));
|
||||||
|
|
||||||
|
sym_table_cleanup(&table);
|
||||||
|
}
|
||||||
|
|
||||||
|
int main(void)
|
||||||
|
{
|
||||||
|
vec_test();
|
||||||
|
printf("\n");
|
||||||
|
symtable_test();
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user