Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
wjr-z committed Oct 15, 2024
1 parent a9934cf commit d150bf2
Show file tree
Hide file tree
Showing 10 changed files with 121 additions and 114 deletions.
39 changes: 0 additions & 39 deletions include/wjr/concurrency/spin_mutex.hpp

This file was deleted.

7 changes: 0 additions & 7 deletions include/wjr/container/constant_radix_tree.hpp

This file was deleted.

4 changes: 0 additions & 4 deletions include/wjr/container/container_fn.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

namespace wjr {

template <typename T, typename D>
struct get_relocate_mode<std::unique_ptr<T, D>> {
static constexpr relocate_t value = relocate_t::maybe_trivial;
};

/**
* @class container_fn<Alloc>
Expand Down
5 changes: 0 additions & 5 deletions include/wjr/container/detail.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -156,11 +156,6 @@ struct __container_traits_base {
template <typename Container>
struct container_traits;

template <typename Char, typename Traits, typename Alloc>
struct get_relocate_mode<std::basic_string<Char, Traits, Alloc>> {
static constexpr relocate_t value = relocate_t::maybe_trivial;
};

} // namespace wjr

#endif // WJR_CONTAINER_DETAIL_HPP__
6 changes: 6 additions & 0 deletions include/wjr/container/ring_buffer.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#ifndef WJR_CONTAINER_RING_BUFFER_HPP__
#define WJR_CONTAINER_RING_BUFFER_HPP__

namespace wjr {}

#endif // WJR_CONTAINER_RING_BUFFER_HPP__
16 changes: 8 additions & 8 deletions include/wjr/container/vector.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -231,16 +231,17 @@ struct get_relocate_mode<default_vector_storage<T, Alloc>> {

template <typename T, typename Alloc>
class fixed_vector_storage
: public __default_vector_storage<T, Alloc, default_vector_storage<T, Alloc>,
: public __default_vector_storage<T, Alloc, fixed_vector_storage<T, Alloc>,
std::false_type> {};

template <typename T, typename Alloc>
struct get_relocate_mode<fixed_vector_storage<T, Alloc>> {
static constexpr relocate_t value = relocate_t::trivial;
};

template <typename T, size_t Capacity, typename Alloc>
template <typename T, size_t Capacity>
class inplace_vector_storage {
using Alloc = memory_pool<T>;
using _Alty = typename std::allocator_traits<Alloc>::template rebind_alloc<T>;
using _Alty_traits = std::allocator_traits<_Alty>;

Expand Down Expand Up @@ -278,8 +279,7 @@ class inplace_vector_storage {

~inplace_vector_storage() = default;

WJR_CONSTEXPR20 void
deallocate(WJR_MAYBE_UNUSED _Alty &al) noexcept { /* do nothing */
WJR_CONSTEXPR20 void deallocate(_Alty &) noexcept { /* do nothing */
}

WJR_CONSTEXPR20 static void
Expand Down Expand Up @@ -378,8 +378,8 @@ class inplace_vector_storage {
data_type m_storage;
};

template <typename T, size_t Capacity, typename Alloc>
struct get_relocate_mode<inplace_vector_storage<T, Capacity, Alloc>> {
template <typename T, size_t Capacity>
struct get_relocate_mode<inplace_vector_storage<T, Capacity>> {
static constexpr relocate_t value = relocate_t::trivial;
};

Expand Down Expand Up @@ -1790,8 +1790,8 @@ using vector = basic_vector<default_vector_storage<T, Alloc>>;
* @brief A vector with elements stored on the stack.
*
*/
template <typename T, size_t Capacity, typename Alloc = memory_pool<T>>
using inplace_vector = basic_vector<inplace_vector_storage<T, Capacity, Alloc>>;
template <typename T, size_t Capacity>
using inplace_vector = basic_vector<inplace_vector_storage<T, Capacity>>;

/**
* @brief A vector with fixed capacity by construction.
Expand Down
98 changes: 97 additions & 1 deletion include/wjr/format/encoding/huffman.hpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,102 @@
#ifndef WJR_FORMAT_ENCODING_HUFFMAN_HPP__
#define WJR_FORMAT_ENCODING_HUFFMAN_HPP__

namespace wjr {}
#include <algorithm>

#include <wjr/compressed_pair.hpp>
#include <wjr/vector.hpp>

namespace wjr {

class huffman_node {
public:
huffman_node() = default;
huffman_node(const huffman_node &) = delete;
huffman_node &operator=(const huffman_node &) = delete;

void set_left(huffman_node *left) noexcept { m_left = left; }
void set_right(huffman_node *right) noexcept { m_right = right; }
huffman_node *get_left() noexcept { return m_left; }
const huffman_node *get_left() const noexcept { return m_left; }
huffman_node *get_right() noexcept { return m_right; }

bool is_leaf() const noexcept { return m_left == nullptr; }
bool is_inner() const noexcept { return m_left != nullptr; }

private:
huffman_node *m_left = nullptr;
huffman_node *m_right = nullptr;
};

template <typename T>
class huffman_leaf_node : public huffman_node {
public:
huffman_leaf_node() noexcept : huffman_node(), m_value() {}

template <typename... Args, WJR_REQUIRES(std::is_constructible_v<T, Args &&...>)>
huffman_leaf_node(Args &&...args) noexcept(
std::is_nothrow_constructible_v<T, Args &&...>)
: m_value(std::forward<Args>(args)...) {}

huffman_leaf_node(const huffman_leaf_node &) = delete;
huffman_leaf_node &operator=(const huffman_leaf_node &) = delete;

T *operator->() noexcept { return std::addressof(m_value); }
const T *operator->() const noexcept { return std::addressof(m_value); }

T &operator*() noexcept { return m_value; }
const T &operator*() const noexcept { return m_value; }

private:
T m_value;
};

template <typename T>
constexpr huffman_leaf_node<T> *get_leaf(huffman_node *node) {
WJR_ASSERT(node->is_leaf());
return static_cast<huffman_leaf_node<T> *>(node);
}

/// @todo Allocator.
template <typename T, typename Alloc>
class huffman_tree {
public:
using vector_type = fixed_vector<T, Alloc>;
using size_type = typename vector_type::size_type;

private:
fixed_vector<T, Alloc> m_vec;
};

template <typename Getter>
struct huffman_encode_node {
using size_type = typename Getter::size_type;
using value_type = typename Getter::value_type;

value_type m_value;
};

class huffman_encoder {
public:
/// @brief Iter doesn't necessarily need to be an iterator.
template <typename Iter, typename Getter>
static decltype(auto) encode_tree(Iter first, Iter last, Getter getter) noexcept {
using size_type = typename Getter::size_type;
using value_type = typename Getter::value_type;
static constexpr size_type npos = std::numeric_limits<size_type>::max();

const auto n = last - first;
fixed_vector<compressed_pair<size_type, value_type>> tmp_vec(n, in_place_reserve);
for (; first != last; ++first) {
tmp_vec.emplace_back(getter.get_size(first), getter.get_value(first));
}

std::sort(tmp_vec.begin(), tmp_vec.end(), [](const auto &lhs, const auto &rhs) {
return lhs.first() < rhs.first();
});
}
};

} // namespace wjr

#endif // WJR_FORMAT_ENCODING_HUFFMAN_HPP__
5 changes: 5 additions & 0 deletions include/wjr/string.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,11 @@ using default_string = std::basic_string<char, std::char_traits<char>, memory_po

WJR_REGISTER_STRING_UNINITIALIZED_RESIZE(default_string, default_string);

template <typename Char, typename Traits, typename Alloc>
struct get_relocate_mode<std::basic_string<Char, Traits, Alloc>> {
static constexpr relocate_t value = relocate_t::maybe_trivial;
};

} // namespace wjr

#endif // WJR_STRING_HPP__
5 changes: 5 additions & 0 deletions include/wjr/type_traits.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,11 @@ struct get_relocate_mode {
template <typename T>
inline constexpr relocate_t get_relocate_mode_v = get_relocate_mode<T>::value;

template <typename T, typename D>
struct get_relocate_mode<std::unique_ptr<T, D>> {
static constexpr relocate_t value = relocate_t::maybe_trivial;
};

template <relocate_t Mode, typename... Args>
struct __get_common_relocate_mode_impl;

Expand Down
50 changes: 0 additions & 50 deletions src/wjr/concurrency/spin_mutex.cpp

This file was deleted.

0 comments on commit d150bf2

Please sign in to comment.