aboutsummaryrefslogtreecommitdiff
path: root/main.c
diff options
context:
space:
mode:
authorGravatar Moon Flower <moon@coffin.ir> 2025-03-01 15:36:05 +0330
committerGravatar Moon Flower <moon@coffin.ir> 2025-03-01 15:36:05 +0330
commitf375db2ee2adcfe30c536478017669eddfafe01c (patch)
treeb44e2dc80dc7504601596f7de2564ae6a6ec106a /main.c
parentupdate gitignore (diff)
updated get and set
Diffstat (limited to 'main.c')
-rw-r--r--main.c19
1 files changed, 13 insertions, 6 deletions
diff --git a/main.c b/main.c
index 5c8732d..0abfa69 100644
--- a/main.c
+++ b/main.c
@@ -2,14 +2,14 @@
#include "moonshine.h"
-const enum { test_datatype, test_linkedlist, test_hashtable, test_alloc } current_test = test_hashtable;
+const enum { test_datatype, test_linkedlist, test_hashtable, test_alloc, test_array } current_test = test_array;
int main() {
- if(current_test == test_alloc) {
+ if (current_test == test_alloc) {
auto v1 = obj(i4);
auto v2 = obj(u8);
- for(u8 i = 1; i <= 1000; i++) print(alloc(i * 1000));
+ for (u8 i = 1; i <= 1000; i++) print(alloc(i * 1000));
*v1 = 2;
*v2 = 99;
@@ -18,6 +18,12 @@ int main() {
release(v1);
print(*v2);
+ } else if (current_test == test_array) {
+ auto arr = new (int);
+ push(arr, 4);
+ push(arr, 9);
+ set(arr, 0, 2);
+ print(get(arr, 0));
} else if (current_test == test_datatype) {
datatype(binarytree, ((leaf, int), (node, binarytree *, int, binarytree *) ));
const auto tree = instance(binarytree, leaf, 3);
@@ -36,15 +42,16 @@ int main() {
print((u8) index_to_ptr(ll, 12)->data);
} else if (current_test == test_hashtable) {
- const auto ht = create_table(table_hash_2, (struct hashtable_optimizations) { .run_ptr_check = true, .collision_character_check_count = 10 });
+ const auto ht = create_table(
+ table_hash_2, (struct hashtable_optimizations) { .run_ptr_check = true, .collision_character_check_count = 10 });
for (u8 i = 0; i < 10000; i++) {
- if(i % 1000 == 0) print("I ", i);
+ if (i % 1000 == 0) print("I ", i);
set_hashtable(ht, "hello", "world");
set_hashtable(ht, "how", "are you");
}
- print((string)get_hashtable(ht, "hello"), ' ', (string)get_hashtable(ht, "how"), ' ', get_hashtable(ht, "wowie"));
+ print((string) get_hashtable(ht, "hello"), ' ', (string) get_hashtable(ht, "how"), ' ', get_hashtable(ht, "wowie"));
}
else {