Skip to content

Commit

Permalink
update hashmap and hashset
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian LALU committed Jan 7, 2025
1 parent 6655d7a commit 8a578dd
Show file tree
Hide file tree
Showing 5 changed files with 747 additions and 17 deletions.
19 changes: 15 additions & 4 deletions interface/core/containers/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,21 +165,32 @@ namespace hud
return add(hud::move(pair.first), hud::move(pair.second));
}
};
} // namespace hud

namespace std
{
/** Specialize tuple_size for slot that permit structured binding. */
template<typename key_t, typename value_t>
struct tuple_size<hud::details::hashmap::slot<key_t, value_t>>
: std::integral_constant<std::size_t, 2>
: hud::integral_constant<usize, 2>
{
};

/** Specialize tuple_element for slot that permit structured binding. */
template<std::size_t index, typename key_t, typename value_t>
struct tuple_element<index, hud::details::hashmap::slot<key_t, value_t>>
{
using type = std::conditional_t<index == 0, key_t, value_t>;
};

} // namespace hud

namespace std
{

template<std::size_t index, typename key_t, typename value_t>
struct tuple_element<index, hud::details::hashmap::slot<key_t, value_t>>
: hud::tuple_element<index, hud::details::hashmap::slot<key_t, value_t>>
{
};

} // namespace std

#endif // HD_INC_CORE_HASHMAP_H
75 changes: 66 additions & 9 deletions interface/core/containers/hashset.h
Original file line number Diff line number Diff line change
Expand Up @@ -494,12 +494,12 @@ namespace hud
return control_ptr_ != other.control_ptr_;
}

template<usize index, typename iterator_t>
requires(hud::is_same_v<iterator, hud::decay_t<iterator_t>>)
friend constexpr decltype(auto) get(iterator_t &&it) noexcept
{
return get<index>(*it);
}
// template<usize index, typename iterator_t>
// requires(hud::is_same_v<iterator, hud::decay_t<iterator_t>>)
// friend constexpr decltype(auto) get(iterator_t &&it) noexcept
// {
// return get<index>(*it);
// }

private:
// The control to iterate over
Expand All @@ -514,6 +514,30 @@ namespace hud
usize slot_index_;
};

template<usize idx_to_reach, typename slot_t>
[[nodiscard]] HD_FORCEINLINE constexpr tuple_element_t<idx_to_reach, iterator<slot_t>> &get(iterator<slot_t> &it) noexcept
{
return get<idx_to_reach>(*it);
}

template<usize idx_to_reach, typename slot_t>
[[nodiscard]] HD_FORCEINLINE constexpr const tuple_element_t<idx_to_reach, iterator<slot_t>> &get(const iterator<slot_t> &it) noexcept
{
return get<idx_to_reach>(*it);
}

template<usize idx_to_reach, typename slot_t>
[[nodiscard]] HD_FORCEINLINE constexpr tuple_element_t<idx_to_reach, iterator<slot_t>> &&get(iterator<slot_t> &&it) noexcept
{
return hud::forward<tuple_element_t<idx_to_reach, iterator<slot_t>>>(get<idx_to_reach>(*it));
}

template<usize idx_to_reach, typename slot_t>
[[nodiscard]] HD_FORCEINLINE constexpr const tuple_element_t<idx_to_reach, iterator<slot_t>> &&get(const iterator<slot_t> &&it) noexcept
{
return hud::forward<const tuple_element_t<idx_to_reach, iterator<slot_t>>>(get<idx_to_reach>(*it));
}

template<
typename slot_t,
typename hasher_t,
Expand Down Expand Up @@ -1069,23 +1093,56 @@ namespace hud
public:
/** Type of the hash function. */
using hasher_type = typename super::hasher_type;
/** Type of the key. */
using key_type = typename super::key_type;
/** Type of the value. */
using value_type = typename super::value_type;
using typename super::const_iterator;
using typename super::iterator;
};

/** Specialize tuple_size for slot that permit structured binding. */
template<typename value_t>
struct tuple_size<hud::details::hashset::slot<value_t>>
: hud::integral_constant<usize, 1>
{
};

/** Specialize tuple_element for slot that permit structured binding. */
template<usize index, typename value_t>
struct tuple_element<index, hud::details::hashset::slot<value_t>>
{
using type = value_t;
};

/** Specialize tuple_size for iterator that permit structured binding. */
template<typename slot_t>
struct tuple_size<hud::details::hashset::iterator<slot_t>>
: hud::tuple_size<typename hud::details::hashset::iterator<slot_t>::slot_type>
{
};

/** Specialize tuple_element for iterator that permit structured binding. */
template<usize index, typename slot_t>
struct tuple_element<index, hud::details::hashset::iterator<slot_t>>
: hud::tuple_element<index, typename hud::details::hashset::iterator<slot_t>::slot_type>
{
};

} // namespace hud

namespace std
{
template<typename slot_t>
struct tuple_size<hud::details::hashset::iterator<slot_t>>
: tuple_size<typename hud::details::hashset::iterator<slot_t>::slot_type>
struct tuple_size
: hud::tuple_size<hud::details::hashset::iterator<slot_t>>
{
};

template<std::size_t index, typename slot_t>
struct tuple_element<index, hud::details::hashset::iterator<slot_t>>
: hud::tuple_element<index, hud::details::hashset::iterator<slot_t>>
{
using type = tuple_element<index, typename hud::details::hashset::iterator<slot_t>::slot_type>::type;
};

} // namespace std
Expand Down
15 changes: 15 additions & 0 deletions interface/core/containers/tuple.h
Original file line number Diff line number Diff line change
Expand Up @@ -1024,4 +1024,19 @@ namespace hud

} // namespace hud

namespace std
{
template<typename... types_t>
struct tuple_size<hud::tuple<types_t...>>
: hud::tuple_size<typename hud::tuple<types_t...>>
{
};

template<std::size_t index, typename... types_t>
struct tuple_element<index, hud::tuple<types_t...>>
: hud::tuple_element<index, hud::tuple<types_t...>>
{
};

} // namespace std
#endif // HD_INC_CORE_TUPLE_H
Loading

0 comments on commit 8a578dd

Please sign in to comment.