Skip to content

Commit

Permalink
upd
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Jul 8, 2024
1 parent 4da7626 commit 91d6482
Show file tree
Hide file tree
Showing 39 changed files with 3,532 additions and 4,025 deletions.
8 changes: 1 addition & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -80,13 +80,7 @@ target_link_libraries(wjr PRIVATE
${WJR_LIBS}
)

set(WJR_PCH PUBLIC ${WJR_INCLUDE_DIR}/wjr/preprocessor.hpp
PUBLIC ${WJR_INCLUDE_DIR}/wjr/assert.hpp
PUBLIC ${WJR_INCLUDE_DIR}/wjr/type_traits.hpp)

if(WJR_X86)
list(APPEND WJR_PCH PUBLIC ${WJR_INCLUDE_DIR}/wjr/x86/simd/intrin.hpp PUBLIC ${WJR_INCLUDE_DIR}/wjr/x86/simd/simd.hpp)
endif()
set(WJR_PCH PUBLIC ${WJR_INCLUDE_DIR}/wjr/math.hpp)

target_precompile_headers(
wjr
Expand Down
4,892 changes: 2,187 additions & 2,705 deletions godbolt/wjr.hpp

Large diffs are not rendered by default.

7 changes: 5 additions & 2 deletions include/wjr/biginteger/biginteger.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -194,12 +194,15 @@ class default_biginteger_vector_storage {
// extension

WJR_PURE int32_t get_ssize() const noexcept { return m_storage.m_size; }
template <typename T, WJR_REQUIRES(is_any_of_v<T, int32_t>)>
void set_ssize(T size) noexcept {

void set_ssize(int32_t size) noexcept {
WJR_ASSERT_ASSUME(__fasts_abs(size) <= capacity());
m_storage.m_size = size;
}

template <typename T>
void set_ssize(int32_t size) noexcept = delete;

WJR_PURE const biginteger_data *__get_data() const noexcept { return &m_storage; }

private:
Expand Down
23 changes: 12 additions & 11 deletions include/wjr/container/generic/bplus_tree.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,9 @@
* number of queries will be less. If the comparison operation of key_type is more
* complex, it is not recommended to use B+ tree, because the number of queries of B+ tree
* will be more, thus offsetting the advantages of B+ tree.
*
*
* @note Currently not needed for use, and some bugs exists, don't use it.
*
*
* @version 0.1
* @date 2024-05-06
*
Expand All @@ -30,7 +30,7 @@
#include <wjr/compressed_pair.hpp>
#include <wjr/container/generic/container_fn.hpp>
#include <wjr/container/intrusive/list.hpp>
#include <wjr/inline_key.hpp>
#include <wjr/inline_arg.hpp>
#include <wjr/memory/uninitialized.hpp>

#if defined(WJR_X86)
Expand All @@ -57,7 +57,6 @@ WJR_INTRINSIC_INLINE static void copy(Other *first, Other *last, Other *dest) no
builtin_bplus_tree_copy<Min, Max>(first, last, dest);
} else {
#endif
WJR_ASSUME((last - first) >= Min && (last - first) <= Max);
(void)std::copy(first, last, dest);
#if WJR_HAS_BUILTIN(BPLUS_TREE_COPY)
}
Expand All @@ -72,7 +71,6 @@ WJR_INTRINSIC_INLINE static void copy_backward(Other *first, Other *last,
builtin_bplus_tree_copy_backward<Min, Max>(first, last, dest);
} else {
#endif
WJR_ASSUME((last - first) >= Min && (last - first) <= Max);
(void)std::copy_backward(first, last, dest);
#if WJR_HAS_BUILTIN(BPLUS_TREE_COPY)
}
Expand All @@ -91,12 +89,15 @@ struct bplus_tree_traits {
using key_compare = Compare;

static constexpr size_t node_size = Size;
static constexpr bool inline_keys =
is_possible_inline_key_v<std::remove_const_t<key_type>> && sizeof(key_type) <= 8;
using InlineKey = inline_key<std::remove_const_t<key_type>, inline_keys>;
using InlineKey = auto_key<std::remove_const_t<key_type>, 8>;
static constexpr bool is_inline_key = InlineKey::is_inlined;
static constexpr bool is_inline_value =
std::is_trivially_copyable_v<value_type> && sizeof(value_type) <= 16;
using InlineValue = std::conditional_t<is_inline_value, value_type, value_type *>;

using node_type = bplus_tree_node<bplus_tree_traits>;
using inner_node_type = bplus_tree_inner_node<bplus_tree_traits>;
using leaf_node_type = bplus_tree_leaf_node<bplus_tree_traits, inline_keys>;
using leaf_node_type = bplus_tree_leaf_node<bplus_tree_traits, is_inline_key>;
static constexpr bool multi = Multi;

WJR_INTRINSIC_INLINE static const key_type &
Expand Down Expand Up @@ -441,7 +442,7 @@ class basic_bplus_tree {

using mapped_type = typename Traits::mapped_type;
static constexpr size_t node_size = Traits::node_size;
static constexpr bool inline_keys = Traits::inline_keys;
static constexpr bool is_inline_key = Traits::is_inline_key;
using InlineKey = typename Traits::InlineKey;
static constexpr size_t floor_half = node_size / 2;
static constexpr size_t ceil_half = node_size - floor_half;
Expand Down Expand Up @@ -1545,7 +1546,7 @@ class basic_bplus_tree {
} while (0);

lhs->m_size = -(merge_size - 1);
remove_uninit(lhs);
remove_uninit(rhs);
_Alty_traits::deallocate(__get_allocator(), (uint8_t *)rhs,
sizeof(leaf_node_type));

Expand Down
92 changes: 45 additions & 47 deletions include/wjr/container/generic/details.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ __uninitialized_resize(std::basic_string<CharT, Traits, Alloc> &str,
str.resize_and_overwrite(sz, [](char *, Size sz) { return sz; });
}

#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(NAME, Container)
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(Name, Container)

#elif (defined(__clang_major__) && __clang_major__ <= 11) || \
(defined(_MSC_VER) && _MSC_VER <= 1920)
Expand All @@ -90,58 +90,43 @@ template <typename Container>
void string_set_length_hacker(Container &bank, typename Container::size_type sz);

#if defined(__GLIBCXX__) || defined(_LIBCPP_VERSION)
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_CLASS(NAME, Container) \
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_CLASS(Name, Container) \
inline void WJR_PP_CONCAT(string_set_length_hacker_of_, \
NAME)(Container & bank, typename Container::size_type sz); \
Name)(Container & bank, typename Container::size_type sz); \
template <typename Money_t, Money_t Container::*p> \
class WJR_PP_CONCAT(string_thief_of_, NAME) { \
public: \
struct WJR_PP_CONCAT(string_thief_of_, Name) { \
friend void WJR_PP_CONCAT(string_set_length_hacker_of_, \
NAME)(Container & bank, \
Name)(Container & bank, \
typename Container::size_type sz) { \
(bank.*p)(sz); \
} \
}; \
template <> \
inline void string_set_length_hacker<Container>(Container & bank, \
typename Container::size_type sz) { \
WJR_PP_CONCAT(string_set_length_hacker_of_, NAME)(bank, sz); \
}
#else
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_CLASS(NAME, Container) \
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_CLASS(Name, Container) \
inline void WJR_PP_CONCAT(string_set_length_hacker_of_, \
NAME)(Container & bank, typename Container::size_type sz); \
Name)(Container & bank, typename Container::size_type sz); \
template <typename Money_t, Money_t Container::*p> \
class WJR_PP_CONCAT(string_thief_of_, NAME) { \
public: \
struct WJR_PP_CONCAT(string_thief_of_, Name) { \
friend void WJR_PP_CONCAT(string_set_length_hacker_of_, \
NAME)(Container & bank, \
Name)(Container & bank, \
typename Container::size_type sz) { \
(bank.*p)._Myval2._Mysize = sz; \
} \
}; \
template <> \
inline void string_set_length_hacker<Container>(Container & bank, \
typename Container::size_type sz) { \
WJR_PP_CONCAT(string_set_length_hacker_of_, NAME)(bank, sz); \
}
#endif

#if defined(__GLIBCXX__)
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(NAME, Container) \
__WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_CLASS(NAME, Container); \
template class WJR_PP_CONCAT( \
string_thief_of_, NAME)<void(Container::size_type), &Container::_M_set_length>
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(Name, Container) \
template struct WJR_PP_CONCAT( \
string_thief_of_, Name)<void(Container::size_type), &Container::_M_set_length>
#elif defined(_LIBCPP_VERSION)
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(NAME, Container) \
__WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_CLASS(NAME, Container); \
template class WJR_PP_CONCAT( \
string_thief_of_, NAME)<void(Container::size_type), &Container::__set_size>
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(Name, Container) \
template struct WJR_PP_CONCAT( \
string_thief_of_, Name)<void(Container::size_type), &Container::__set_size>
#else
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(NAME, Container) \
__WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_CLASS(NAME, Container); \
template class WJR_PP_CONCAT( \
string_thief_of_, NAME)<decltype(Container::_Mypair), &Container::_Mypair>
#define __WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(Name, Container) \
template struct WJR_PP_CONCAT( \
string_thief_of_, Name)<decltype(Container::_Mypair), &Container::_Mypair>
#endif

template <typename CharT, typename Traits, typename Alloc>
Expand All @@ -161,35 +146,48 @@ __uninitialized_resize(std::basic_string<CharT, Traits, Alloc> &str,

#if WJR_HAS_FEATURE(STRING_UNINITIALIZED_RESIZE)

template <typename Container>
struct __uninitialized_resize_fn_impl : resize_fn_impl_base<Container> {
using resize_fn_impl_base<Container>::resize;
WJR_INTRINSIC_INLINE static void resize(Container &cont,
typename Container::size_type sz, dctor_t) {
__uninitialized_resize(cont, sz);
}
};

template <typename Container>
struct __uninitialized_append_fn_impl : append_fn_impl_base<Container> {
using append_fn_impl_base<Container>::append;
WJR_INTRINSIC_INLINE static void append(Container &cont,
typename Container::size_type sz, dctor_t) {
__uninitialized_resize(cont, cont.size() + sz);
}
};

#define WJR_REGISTER_STRING_UNINITIALIZED_RESIZE(Name, Container) \
__WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_CLASS(Name, Container); \
__WJR_REGISTER_STRING_UNINITIALIZED_RESIZE_TEMPLATE(Name, Container); \
template <> \
struct resize_fn_impl<Container> : resize_fn_impl_base<Container> { \
using resize_fn_impl_base<Container>::resize; \
WJR_INTRINSIC_INLINE static void \
resize(Container &cont, typename Container::size_type sz, dctor_t) { \
__uninitialized_resize(cont, sz); \
} \
inline void string_set_length_hacker<Container>(Container & bank, \
typename Container::size_type sz) { \
WJR_PP_CONCAT(string_set_length_hacker_of_, Name)(bank, sz); \
}; \
template <> \
struct append_fn_impl<Container> : append_fn_impl_base<Container> { \
using append_fn_impl_base<Container>::append; \
WJR_INTRINSIC_INLINE static void \
append(Container &cont, typename Container::size_type sz, dctor_t) { \
__uninitialized_resize(cont, cont.size() + sz); \
} \
}
struct resize_fn_impl<Container> : __uninitialized_resize_fn_impl<Container> {}; \
template <> \
struct append_fn_impl<Container> : __uninitialized_append_fn_impl<Container> {}
#else
#define WJR_REGISTER_STRING_UNINITIALIZED_RESIZE(Name, Container)
#endif

WJR_REGISTER_STRING_UNINITIALIZED_RESIZE(string, std::string);
WJR_REGISTER_STRING_UNINITIALIZED_RESIZE(std_string, std::string);

WJR_REGISTER_HAS_TYPE(container_resize,
resize_fn_impl<Container>::resize(std::declval<Container &>(),
std::declval<Size>(),
std::declval<Args>()...),
Container, Size);

WJR_REGISTER_HAS_TYPE(container_reserve,
std::declval<Container>().reserve(std::declval<Size>()), Container,
Size);
Expand Down
3 changes: 3 additions & 0 deletions include/wjr/container/generic/type_traits.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
#ifndef WJR_CONTAINER_GENERIC_TYPE_TRAITS_HPP__
#define WJR_CONTAINER_GENERIC_TYPE_TRAITS_HPP__

#include <array>
#include <vector>

#include <wjr/vector.hpp>

namespace wjr {
Expand Down
Loading

0 comments on commit 91d6482

Please sign in to comment.