From 2ef2b5ee35d47ba2e959898ecef459a6ad41b92d Mon Sep 17 00:00:00 2001 From: Felix Brendel Date: Wed, 5 May 2021 23:59:10 +0200 Subject: [PATCH] some small additions --- arraylist.hpp | 22 +++++++++++++++++++++- hashmap.hpp | 6 ++++++ 2 files changed, 27 insertions(+), 1 deletion(-) 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 234fd2f..3d0ab41 100644 --- a/hashmap.hpp +++ b/hashmap.hpp @@ -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];