merge
This commit is contained in:
+21
-1
@@ -114,7 +114,6 @@ struct Array_List {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void dealloc() {
|
void dealloc() {
|
||||||
free(data);
|
free(data);
|
||||||
data = nullptr;
|
data = nullptr;
|
||||||
@@ -124,6 +123,19 @@ struct Array_List {
|
|||||||
count = 0;
|
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<type> clone() {
|
Array_List<type> clone() {
|
||||||
Array_List<type> ret;
|
Array_List<type> ret;
|
||||||
ret.length = length;
|
ret.length = length;
|
||||||
@@ -309,6 +321,14 @@ struct Queue {
|
|||||||
return arr_list.count - next_index;
|
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() {
|
void clear() {
|
||||||
next_index = 0;
|
next_index = 0;
|
||||||
arr_list.clear();
|
arr_list.clear();
|
||||||
|
|||||||
+6
-6
@@ -82,15 +82,19 @@ struct Hash_Map {
|
|||||||
data = nullptr;
|
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) {
|
s32 get_index_of_living_cell_if_it_exists(key_type key, u64 hash_val) {
|
||||||
ZoneScoped;
|
|
||||||
s32 index = hash_val & (current_capacity - 1);
|
s32 index = hash_val & (current_capacity - 1);
|
||||||
HM_Cell cell = data[index];
|
HM_Cell cell = data[index];
|
||||||
/* test if there is or was something there */
|
/* test if there is or was something there */
|
||||||
if (cell.occupancy != HM_Cell::Occupancy::Avaliable) {
|
if (cell.occupancy != HM_Cell::Occupancy::Avaliable) {
|
||||||
/* check if objects match */
|
/* check if objects match */
|
||||||
if (hm_objects_match(key, cell.original)) {
|
if (hm_objects_match(key, cell.original)) {
|
||||||
ZoneScopedN("hm_objects_match check");
|
|
||||||
/* we found it, now check it it is deleted: */
|
/* we found it, now check it it is deleted: */
|
||||||
if (cell.occupancy == HM_Cell::Occupancy::Deleted) {
|
if (cell.occupancy == HM_Cell::Occupancy::Deleted) {
|
||||||
/* we found it but it was deleted, we */
|
/* we found it but it was deleted, we */
|
||||||
@@ -132,7 +136,6 @@ struct Hash_Map {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bool key_exists(key_type key) {
|
bool key_exists(key_type key) {
|
||||||
ZoneScoped;
|
|
||||||
return get_index_of_living_cell_if_it_exists(key, hm_hash((key_type)key)) != -1;
|
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) {
|
value_type get_object(key_type key) {
|
||||||
ZoneScoped;
|
|
||||||
return get_object(key, hm_hash((key_type)key));
|
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) {
|
void set_object(key_type key, value_type obj, u64 hash_val) {
|
||||||
ZoneScoped;
|
|
||||||
u32 index = hash_val & (current_capacity - 1);
|
u32 index = hash_val & (current_capacity - 1);
|
||||||
|
|
||||||
/* if we the desired cell is avaliable, write to it and done :) */
|
/* if we the desired cell is avaliable, write to it and done :) */
|
||||||
@@ -207,7 +208,6 @@ struct Hash_Map {
|
|||||||
} else {
|
} else {
|
||||||
/* collision, check resize */
|
/* collision, check resize */
|
||||||
if ((cell_count*1.0f / current_capacity) > 0.666f) {
|
if ((cell_count*1.0f / current_capacity) > 0.666f) {
|
||||||
ZoneScopedN("HM Resize");
|
|
||||||
auto old_data = data;
|
auto old_data = data;
|
||||||
data = (HM_Cell*)calloc(current_capacity*4, sizeof(HM_Cell));
|
data = (HM_Cell*)calloc(current_capacity*4, sizeof(HM_Cell));
|
||||||
cell_count = 0;
|
cell_count = 0;
|
||||||
|
|||||||
@@ -411,6 +411,28 @@ int print_u32(FILE* f, u32 num) {
|
|||||||
return print_to_file(f, "%u", 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) {
|
int print_u64(FILE* f, u64 num) {
|
||||||
return print_to_file(f, "%llu", num);
|
return print_to_file(f, "%llu", num);
|
||||||
}
|
}
|
||||||
@@ -484,6 +506,7 @@ void init_printer() {
|
|||||||
type_map.dealloc();
|
type_map.dealloc();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
register_printer("spaces", print_spaces, Printer_Function_Type::_32b);
|
||||||
register_printer("u32", print_u32, Printer_Function_Type::_32b);
|
register_printer("u32", print_u32, Printer_Function_Type::_32b);
|
||||||
register_printer("u64", print_u64, Printer_Function_Type::_64b);
|
register_printer("u64", print_u64, Printer_Function_Type::_64b);
|
||||||
register_printer("bool", print_bool, Printer_Function_Type::_32b);
|
register_printer("bool", print_bool, Printer_Function_Type::_32b);
|
||||||
|
|||||||
Reference in New Issue
Block a user