diff --git a/CMakeLists.txt b/CMakeLists.txt index 01485c6..19b30f5 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ cmake_minimum_required(VERSION 3.20) include(cmake/color.cmake) -set(BLT_VERSION 2.1.16) +set(BLT_VERSION 3.0.0) set(BLT_TARGET BLT) diff --git a/include/blt/std/memory.h b/include/blt/std/memory.h index c4950e7..597f31c 100644 --- a/include/blt/std/memory.h +++ b/include/blt/std/memory.h @@ -11,13 +11,9 @@ #include #include #include -#include "queue.h" -#include "utility.h" #include -#include #include #include -#include namespace blt { @@ -37,11 +33,14 @@ namespace blt { public: using element_type = T; - using value_type = std::remove_cv_t; - using pointer = T*; - using const_pointer = const T*; - using reference = T&; - using const_reference = const T&; + using value_type = typename std::iterator_traits::value_type; + using pointer = typename std::iterator_traits::pointer; + using const_pointer = const typename std::iterator_traits::pointer; + using reference = typename std::iterator_traits::reference; + using const_reference = const typename std::iterator_traits::reference; + using difference_type = typename std::iterator_traits::difference_type; + using iterator_category = typename std::iterator_traits::iterator_category; + using iterator = ptr_iterator; using const_iterator = ptr_iterator; using reverse_iterator = std::reverse_iterator; diff --git a/include/blt/std/memory_util.h b/include/blt/std/memory_util.h index 5e50bc0..1f7cd7e 100644 --- a/include/blt/std/memory_util.h +++ b/include/blt/std/memory_util.h @@ -19,12 +19,14 @@ #ifndef BLT_MEMORY_UTIL_H #define BLT_MEMORY_UTIL_H -#include #include #include +#include #include #include #include +#include +#include #if defined(__clang__) || defined(__llvm__) || defined(__GNUC__) || defined(__GNUG__) @@ -62,7 +64,7 @@ namespace blt::mem { template - inline static R type_cast(T type) + static R type_cast(T type) { static_assert(std::is_trivially_copyable_v, "Type must be trivially copyable to be type casted!"); static_assert(sizeof(T) == sizeof(R)); @@ -72,16 +74,16 @@ namespace blt::mem } template - inline void reverse(T& out) + void reverse(T& out) { static_assert(std::is_trivially_copyable_v, "Type must be trivially copyable to be reversible!"); // if we need to swap find the best way to do so - if constexpr (std::is_same_v || std::is_same_v) - out = type_cast(SWAP16(type_cast(out))); - else if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) - out = type_cast(SWAP32(type_cast(out))); - else if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) - out = type_cast(SWAP64(type_cast(out))); + if constexpr (std::is_same_v || std::is_same_v) + out = type_cast(SWAP16(type_cast(out))); + else if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) + out = type_cast(SWAP32(type_cast(out))); + else if constexpr (std::is_same_v || std::is_same_v || std::is_same_v) + out = type_cast(SWAP64(type_cast(out))); else { std::array data; @@ -93,7 +95,7 @@ namespace blt::mem // Used to grab the byte-data of any T element. Defaults to Big Endian, however can be configured to use little endian template - inline int toBytes(const T& in, BYTE_TYPE* out) + int toBytes(const T& in, BYTE_TYPE* out) { if constexpr (!(std::is_same_v || std::is_same_v)) static_assert("Must provide a signed/unsigned int8 type"); @@ -111,7 +113,7 @@ namespace blt::mem // Used to cast the binary data of any T object, into a T object. Assumes data is in big ending (configurable) template - inline int fromBytes(const BYTE_TYPE* in, T& out) + int fromBytes(const BYTE_TYPE* in, T& out) { if constexpr (!(std::is_same_v || std::is_same_v)) static_assert("Must provide a signed/unsigned int8 type"); @@ -126,12 +128,12 @@ namespace blt::mem } template - inline static int fromBytes(const BYTE_TYPE* in, T* out) + static int fromBytes(const BYTE_TYPE* in, T* out) { - return fromBytes(in, *out); + return fromBytes(in, *out); } - inline static size_t next_byte_allocation(size_t prev_size, size_t default_allocation_block = 8192, size_t default_size = 16) + static std::size_t next_byte_allocation(std::size_t prev_size, std::size_t default_allocation_block = 8192, std::size_t default_size = 16) { if (prev_size < default_size) return default_size; @@ -139,6 +141,81 @@ namespace blt::mem return prev_size * 2; return prev_size + default_allocation_block; } + + template + struct pointer_storage + { + static_assert(sizeof(Storage) * CHAR_BIT <= 16, "Storage type max size is 16 bits"); + + explicit pointer_storage(Ptr* ptr): ptr(ptr) + { + } + + Ptr* get() + { + Ptr* l_ptr; + std::memcpy(&l_ptr, &ptr, 6); + return l_ptr; + } + + const Ptr* get() const + { + Ptr* l_ptr; + std::memcpy(&l_ptr, &ptr, 6); + return l_ptr; + } + + private: + Ptr* ptr; + }; + + template + void print_bytes(OStream& stream, const Value& value) + { + constexpr auto size = sizeof(Value); + + std::string line; + for (std::size_t i = 0; i < size; i++) + { + std::uint8_t byte; + std::memcpy(&byte, reinterpret_cast(&value) + i, 1); + if constexpr (bits) + { + for (std::ptrdiff_t j = CHAR_BIT - 1; j >= 0; j--) + { + const auto bit = (byte >> j) & 1; + line += std::to_string(bit); + } + } + else + { + const auto byte_str = std::to_string(byte); + const auto amount = CHAR_BIT - byte_str.size(); + for (std::size_t j = 0; j < static_cast(std::ceil(static_cast(amount) / 2.0)); j++) + line += ' '; + line += byte_str; + for (std::size_t j = 0; j < static_cast(std::floor(static_cast(amount) / 2.0)); j++) + line += ' '; + } + if (i != size - 1) + line += " : "; + } + for (std::size_t i = 0; i < size; i++) + { + auto index = std::to_string(i); + const auto amount = CHAR_BIT - index.size(); + for (std::size_t j = 0; j < static_cast(std::ceil(static_cast(amount) / 2.0)); j++) + stream << ' '; + stream << index; + for (std::size_t j = 0; j < static_cast(std::floor(static_cast(amount) / 2.0)); j++) + stream << ' '; + if (i != size - 1) + stream << " | "; + } + stream << '\n'; + stream << line; + stream << '\n'; + } } namespace blt @@ -146,9 +223,8 @@ namespace blt template struct ptr_iterator { - public: using iterator_category = std::random_access_iterator_tag; - using difference_type = blt::ptrdiff_t; + using difference_type = std::ptrdiff_t; using value_type = V; using pointer = value_type*; using reference = value_type&; @@ -211,7 +287,7 @@ namespace blt return *(_v + index); } - reference operator[](blt::size_t index) + reference operator[](std::size_t index) { return *(_v + index); } diff --git a/include/blt/std/utility.h b/include/blt/std/utility.h index cf6ab87..2104233 100644 --- a/include/blt/std/utility.h +++ b/include/blt/std/utility.h @@ -19,9 +19,6 @@ #ifndef BLT_UTILITY_H #define BLT_UTILITY_H -#include -#include -#include #include #include @@ -59,13 +56,13 @@ namespace blt namespace blt { template - static BLT_CPP20_CONSTEXPR inline std::string type_string() + static std::string type_string() { return demangle(typeid(T).name()); } template - static BLT_CPP20_CONSTEXPR inline std::string type_string_raw() + static std::string type_string_raw() { return typeid(T).name(); } diff --git a/libraries/parallel-hashmap b/libraries/parallel-hashmap index d88c5e1..8a889d3 160000 --- a/libraries/parallel-hashmap +++ b/libraries/parallel-hashmap @@ -1 +1 @@ -Subproject commit d88c5e15079047777b418132ece5879e7c9aaa2b +Subproject commit 8a889d3699b3c09ade435641fb034427f3fd12b6