Pārlūkot izejas kodu

some small additions

master
Felix Brendel pirms 5 gadiem
vecāks
revīzija
2ef2b5ee35
2 mainītis faili ar 27 papildinājumiem un 1 dzēšanām
  1. +21
    -1
      arraylist.hpp
  2. +6
    -0
      hashmap.hpp

+ 21
- 1
arraylist.hpp Parādīt failu

@@ -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<type> clone() {
Array_List<type> 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();


+ 6
- 0
hashmap.hpp Parādīt failu

@@ -82,6 +82,12 @@ 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) {
s32 index = hash_val & (current_capacity - 1);
HM_Cell cell = data[index];


Notiek ielāde…
Atcelt
Saglabāt