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_data(vec_t *);
|
||||
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 *);
|
||||
|
||||
/// Symbol table
|
||||
|
||||
77
main.c
77
main.c
@@ -25,51 +25,64 @@ sv_t sv_copy(sv_t old)
|
||||
return SV(newstr, old.size);
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
const char *words[] = {
|
||||
"aliquam", "erat", "volutpat", "nunc", "eleifend",
|
||||
"leo", "vitae", "magna", "in", "id",
|
||||
"erat", "non", "orci", "commodo", "lobortis",
|
||||
"proin", "neque", "massa", "cursus", "ut",
|
||||
"gravida", "ut", "lobortis", "eget", "lacus",
|
||||
"sed", "diam", "praesent", "fermentum", "tempor",
|
||||
"tellus", "nullam", "tempus", "mauris", "ac",
|
||||
"felis", "vel", "velit", "tristique", "imperdiet",
|
||||
"donec", "at", "pede", "etiam", "vel",
|
||||
"neque", "nec", "dui", "dignissim", "bibendum",
|
||||
"vivamus", "id", "enim", "phasellus", "neque",
|
||||
"orci", "porta", "a", "aliquet", "quis",
|
||||
"semper", "a", "massa", "phasellus", "purus",
|
||||
"pellentesque", "tristique", "imperdiet", "tortor", "nam",
|
||||
"euismod", "tellus", "id", "erat",
|
||||
};
|
||||
const char *words[] = {
|
||||
"aliquam", "erat", "volutpat", "nunc", "eleifend",
|
||||
"leo", "vitae", "magna", "in", "id",
|
||||
"erat", "non", "orci", "commodo", "lobortis",
|
||||
"proin", "neque", "massa", "cursus", "ut",
|
||||
"gravida", "ut", "lobortis", "eget", "lacus",
|
||||
"sed", "diam", "praesent", "fermentum", "tempor",
|
||||
"tellus", "nullam", "tempus", "mauris", "ac",
|
||||
"felis", "vel", "velit", "tristique", "imperdiet",
|
||||
"donec", "at", "pede", "etiam", "vel",
|
||||
"neque", "nec", "dui", "dignissim", "bibendum",
|
||||
"vivamus", "id", "enim", "phasellus", "neque",
|
||||
"orci", "porta", "a", "aliquet", "quis",
|
||||
"semper", "a", "massa", "phasellus", "purus",
|
||||
"pellentesque", "tristique", "imperdiet", "tortor", "nam",
|
||||
"euismod", "tellus", "id", "erat",
|
||||
};
|
||||
|
||||
void vec_test(void)
|
||||
{
|
||||
vec_t vec = {0};
|
||||
vec_init(&vec, 0);
|
||||
|
||||
for (u64 i = 0; i < ARRSIZE(words); ++i)
|
||||
{
|
||||
vec_append(&vec, words[i], strlen(words[i]));
|
||||
vec_append(&vec, "\n", 1);
|
||||
printf("%lu/%lu, inlined?: %s\n", vec.size, vec.capacity,
|
||||
vec_append(&vec, " ", 1);
|
||||
printf("[vec_test]: %lu/%lu, inlined?: %s\n", vec.size, vec.capacity,
|
||||
vec.is_inlined ? "yes" : "no");
|
||||
}
|
||||
|
||||
printf("%lu/%lu: %.*s\n", vec.size, vec.capacity, (int)vec.size,
|
||||
vec_data(&vec));
|
||||
printf("[vec_test]: Final: %lu/%lu: %.*s\n", vec.size, vec.capacity,
|
||||
(int)vec.size, (char *)vec_data(&vec));
|
||||
|
||||
vec_free(&vec);
|
||||
}
|
||||
|
||||
// sym_table_t table = {0};
|
||||
// sym_table_init(&table);
|
||||
// // Let's hash the words of lorem ipsum
|
||||
// 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);
|
||||
// }
|
||||
void symtable_test(void)
|
||||
{
|
||||
sym_table_t table = {0};
|
||||
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("[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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user