diff --git a/arraylist.hpp b/arraylist.hpp index 297d31a..9d00e8b 100644 --- a/arraylist.hpp +++ b/arraylist.hpp @@ -114,7 +114,6 @@ struct Array_List { } } - void dealloc() { free(data); data = nullptr; @@ -124,6 +123,19 @@ struct Array_List { count = 0; } + bool contains_linear_search(type elem) { + for (u32 i = 0; i < count; ++i) { + if (data[i] == elem) + return true; + } + return false; + } + + bool contains_binary_search(type elem) { + return sorted_find(elem) != -1; + } + + Array_List clone() { Array_List ret; ret.length = length; @@ -309,6 +321,14 @@ struct Queue { return arr_list.count - next_index; } + bool contains(type elem) { + for (u32 i = next_index; i < arr_list.count; ++i) { + if (arr_list[i] == elem) + return true; + } + return false; + } + void clear() { next_index = 0; arr_list.clear(); diff --git a/hashmap.hpp b/hashmap.hpp index 7ace602..3d0ab41 100644 --- a/hashmap.hpp +++ b/hashmap.hpp @@ -82,15 +82,19 @@ struct Hash_Map { data = nullptr; } + void clear() { + cell_count = 0; + memset(data, 0, current_capacity * sizeof(HM_Cell)); + } + + s32 get_index_of_living_cell_if_it_exists(key_type key, u64 hash_val) { - ZoneScoped; s32 index = hash_val & (current_capacity - 1); HM_Cell cell = data[index]; /* test if there is or was something there */ if (cell.occupancy != HM_Cell::Occupancy::Avaliable) { /* check if objects match */ if (hm_objects_match(key, cell.original)) { - ZoneScopedN("hm_objects_match check"); /* we found it, now check it it is deleted: */ if (cell.occupancy == HM_Cell::Occupancy::Deleted) { /* we found it but it was deleted, we */ @@ -132,7 +136,6 @@ struct Hash_Map { } bool key_exists(key_type key) { - ZoneScoped; return get_index_of_living_cell_if_it_exists(key, hm_hash((key_type)key)) != -1; } @@ -168,7 +171,6 @@ struct Hash_Map { } value_type get_object(key_type key) { - ZoneScoped; return get_object(key, hm_hash((key_type)key)); } @@ -193,7 +195,6 @@ struct Hash_Map { } void set_object(key_type key, value_type obj, u64 hash_val) { - ZoneScoped; u32 index = hash_val & (current_capacity - 1); /* if we the desired cell is avaliable, write to it and done :) */ @@ -207,7 +208,6 @@ struct Hash_Map { } else { /* collision, check resize */ if ((cell_count*1.0f / current_capacity) > 0.666f) { - ZoneScopedN("HM Resize"); auto old_data = data; data = (HM_Cell*)calloc(current_capacity*4, sizeof(HM_Cell)); cell_count = 0; diff --git a/print.hpp b/print.hpp index 165d35e..4164353 100644 --- a/print.hpp +++ b/print.hpp @@ -411,6 +411,28 @@ int print_u32(FILE* f, u32 num) { return print_to_file(f, "%u", num); } +int print_spaces(FILE* f, s32 num) { + int sum = 0; + + while (num >= 8) { + // println("%d", 8); + sum += print_to_file(f, " "); + num -= 8; + } + while (num >= 4) { + // println("%d", 4); + sum += print_to_file(f, " "); + num -= 4; + } + while (num --> 0) { + // println("%d", 1); + sum += print_to_file(f, " "); + num--; + } + return sum; +} + + int print_u64(FILE* f, u64 num) { return print_to_file(f, "%llu", num); } @@ -484,6 +506,7 @@ void init_printer() { type_map.dealloc(); }; + register_printer("spaces", print_spaces, Printer_Function_Type::_32b); register_printer("u32", print_u32, Printer_Function_Type::_32b); register_printer("u64", print_u64, Printer_Function_Type::_64b); register_printer("bool", print_bool, Printer_Function_Type::_32b);