Skip to content

Commit

Permalink
Improve hashmap and hashset
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian LALU committed Jan 23, 2025
1 parent 4b7e0d3 commit 43ab777
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 35 deletions.
14 changes: 6 additions & 8 deletions interface/core/containers/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,15 @@ namespace hud
using key_type = key_t;
using value_type = value_t;

template<typename... params_t>
requires(hud::is_constructible_v<key_type, params_t...>)
constexpr explicit slot(params_t &&...params) noexcept
: element_(hud::forward<params_t>(params)..., value_type {})
constexpr explicit slot(const key_type &key, const value_type &value) noexcept
: element_(key, value)
{
}

template<typename... params_t>
requires(hud::is_constructible_v<hud::pair<key_type, value_type>, params_t...>)
constexpr explicit slot(params_t &&...params) noexcept
: element_(hud::forward<params_t>(params)...)
template<typename u_key_t, typename u_value_t>
requires(hud::is_constructible_v<hud::pair<key_type, value_type>, u_key_t, u_value_t>)
constexpr explicit slot(u_key_t &&key, u_value_t &&value) noexcept
: element_(hud::forward<u_key_t>(key), hud::forward<u_value_t>(value))
{
}

Expand Down
38 changes: 11 additions & 27 deletions interface/core/containers/hashset.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,15 @@ namespace hud
{
using key_type = value_t;

template<typename... params_t>
requires(hud::is_constructible_v<key_type, params_t...>)
constexpr explicit slot(params_t &&...params) noexcept
: element_(hud::forward<params_t>(params)...)
constexpr explicit slot(const key_type &key) noexcept
: element_(key)
{
}

template<typename u_key_t>
requires(hud::is_constructible_v<key_type, u_key_t>)
constexpr explicit slot(u_key_t &&key) noexcept
: element_(hud::forward<u_key_t>(key))
{
}

Expand Down Expand Up @@ -644,35 +649,14 @@ namespace hud
}
}

/**
* Insert a key in the hashset.
* @param key The key associated with the `value`
* @param args List of arguments pass to `value_type` constructor after the `key` itself
* @return Reference to the `value`
*/
// template<typename... args_t>
// // requires(hud::is_constructible_v<slot_type, args_t...>)
// constexpr slot_type &add_to_ref(slot_type::key_type &&key, args_t &&...args) noexcept

// {
// hud::pair<usize, bool> res = find_or_insert_no_construct(key);
// slot_type *slot_ptr = slot_ptr_ + res.first;
// if (res.second)
// {
// hud::memory::construct_at<args_t...>(slot_ptr, hud::move(key), hud::forward<args_t>(args)...);
// }
// return &slot_ptr;
// }

/**
* Insert a key in the hashset.
* @param key The key associated with the `value`
* @param args List of arguments pass to `value_type` constructor after the `key` itself
* @return Iterator to the `value`
*/
template<typename... args_t>

// requires(hud::is_constructible_v<slot_type, args_t...>)
requires(hud::is_constructible_v<slot_type, key_type, args_t...>)
constexpr iterator add(key_type &&key, args_t &&...args) noexcept
{
hud::pair<usize, bool> res = find_or_insert_no_construct(key);
Expand All @@ -691,7 +675,7 @@ namespace hud
* @return Iterator to the `value`
*/
template<typename... args_t>
requires(hud::is_constructible_v<slot_type, args_t...>)
requires(hud::is_constructible_v<slot_type, const key_type &, args_t...>)
constexpr iterator add(const key_type &key, args_t &&...args) noexcept
{
hud::pair<usize, bool> res = find_or_insert_no_construct(key);
Expand Down

0 comments on commit 43ab777

Please sign in to comment.