From 5ab01e43dfc2956f220e5f5fb663c00078928f17 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Fri, 26 Jul 2024 22:08:25 -0400 Subject: [PATCH 1/2] ref utility --- CMakeLists.txt | 2 +- include/blt/std/utility.h | 3 +++ libraries/parallel-hashmap | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 98ae500..e3c388f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.18.13) +set(BLT_VERSION 0.18.14) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/include/blt/std/utility.h b/include/blt/std/utility.h index dafbea3..2be3245 100644 --- a/include/blt/std/utility.h +++ b/include/blt/std/utility.h @@ -31,6 +31,9 @@ namespace blt { + template + using ref = std::reference_wrapper; + static inline std::string demangle(const std::string& str) { int status; diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index d88c5e1..1036816 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit d88c5e15079047777b418132ece5879e7c9aaa2b +Subproject commit 10368163ab1f4367d2f0685b5928b1c973ebd1ec From f99e6b3db98a693ce57edca281134560efdce1a3 Mon Sep 17 00:00:00 2001 From: Brett Laptop Date: Mon, 29 Jul 2024 19:34:03 -0400 Subject: [PATCH 2/2] make expanding buffer externally expandable with copy! --- CMakeLists.txt | 2 +- arg_parse_variant_map.drawio | 20 ++++++++++---------- include/blt/std/memory.h | 23 ++++++++++++++--------- 3 files changed, 25 insertions(+), 20 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index e3c388f..d49806f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,7 +1,7 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 0.18.14) +set(BLT_VERSION 0.18.15) set(BLT_TEST_VERSION 0.0.1) set(BLT_TARGET BLT) diff --git a/arg_parse_variant_map.drawio b/arg_parse_variant_map.drawio index ac232d8..509f3a5 100644 --- a/arg_parse_variant_map.drawio +++ b/arg_parse_variant_map.drawio @@ -4,7 +4,7 @@ - + @@ -12,7 +12,7 @@ - + @@ -23,25 +23,25 @@ - + - + - + - + - + @@ -56,13 +56,13 @@ - + - + - + diff --git a/include/blt/std/memory.h b/include/blt/std/memory.h index 164e2da..69a9909 100644 --- a/include/blt/std/memory.h +++ b/include/blt/std/memory.h @@ -376,14 +376,14 @@ namespace blt constexpr inline T& operator[](size_t index) { if (index >= size()) - expand(index); + allocate_for(index); return buffer_[index]; } constexpr inline const T& operator[](size_t index) const { if (index >= size()) - expand(index); + allocate_for(index); return buffer_[index]; } @@ -461,13 +461,10 @@ namespace blt { delete_this(buffer_, size()); } - - private: - void expand(blt::size_t size) + + void expand(blt::size_t new_size) { - size = std::max(size_, size); - size = blt::mem::next_byte_allocation(size); - T* new_buffer = new T[size]; + T* new_buffer = new T[new_size]; if (buffer_ != nullptr) { if constexpr (std::is_trivially_copyable_v) @@ -486,7 +483,15 @@ namespace blt delete[] buffer_; } buffer_ = new_buffer; - size_ = size; + size_ = new_size; + } + + private: + void allocate_for(blt::size_t accessing_index) + { + accessing_index = std::max(size_, accessing_index); + accessing_index = blt::mem::next_byte_allocation(accessing_index); + expand(accessing_index); } inline void delete_this(T* buffer, blt::size_t)