Skip to content

Commit

Permalink
Merge branch 'main' of https://github.com/HUD-Software/core
Browse files Browse the repository at this point in the history
  • Loading branch information
Julian LALU committed Jan 6, 2025
2 parents 7d10efb + 811aa1b commit 6655d7a
Show file tree
Hide file tree
Showing 4 changed files with 81 additions and 64 deletions.
6 changes: 5 additions & 1 deletion interface/core/containers/hashmap.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,18 @@ namespace hud
using typename super::hasher_type;
/** Type of the key. */
using typename super::key_type;
/** Type of the value. */
using typename super::value_type;
/** Type of the key, value pair. */
using type = super::slot_type;

/** Type of the value. */
using super::add;
using super::reserve;
using super::super;
using typename super::allocator_type;
using typename super::const_iterator;
using typename super::iterator;
using typename super::value_type;
explicit constexpr hashmap() noexcept = default;

constexpr explicit hashmap(const allocator_type &allocator) noexcept
Expand Down
4 changes: 2 additions & 2 deletions interface/core/containers/hashset.h
Original file line number Diff line number Diff line change
Expand Up @@ -530,9 +530,9 @@ namespace hud
using value_type = typename slot_type::value_type;
/** Type of the hash function. */
using hasher_type = hasher_t;
/** Type of the iterator/ */
/** Type of the iterator. */
using iterator = hud::details::hashset::iterator<slot_type>;
/** Type of the iterator/ */
/** Type of the const iterator. */
using const_iterator = hud::details::hashset::iterator<const slot_type>;
/** Type of the allocator. */
using allocator_type = allocator_t;
Expand Down
4 changes: 2 additions & 2 deletions test/array/array_iteration.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ GTEST_TEST(array, range_for_loop)
hud_assert_eq(arr[3], 40);

i32 result[4];
i32 index = 0;
usize index = 0;
// constexpr Iterator begin() noexcept
// constexpr Iterator end() noexcept
for (auto &value : arr)
Expand All @@ -82,7 +82,7 @@ GTEST_TEST(array, range_for_loop)
hud_assert_eq(arr[3], 40);

i32 result[4];
i32 index = 0;
usize index = 0;
// constexpr Iterator begin() noexcept
// constexpr Iterator end() noexcept
for (auto &value : arr)
Expand Down
131 changes: 72 additions & 59 deletions test/hashmap/hashmap_iterator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2,33 +2,47 @@

GTEST_TEST(hashmap, iterators)
{
// Non const Array
const auto test = []()
{
hud::hashmap<i32, i64> map;
map.add({1, 11});
map.add({2, 22});
map.add({3, 33});
map.add({4, 44});
hud_assert_eq(map.count(), 4u);
hud_assert_ge(map.max_count(), 4u);
hud::hashmap<i32, i64>::iterator it_begin = map.begin();
hud_assert_true((hud::is_same_v<decltype(it_begin->key()), const i32 &>));
hud_assert_true((hud::is_same_v<decltype(it_begin->value()), i64 &>));
}

// Const Array
{
const hud::hashmap<i32, i64> map {
hud::hashmap<i32, i64> map {
{1, 11},
{2, 22},
{3, 33},
{4, 44}
};
hud_assert_eq(map.count(), 4u);
hud_assert_ge(map.max_count(), 4u);
hud::hashmap<i32, i64>::const_iterator it_begin = map.begin();
hud_assert_true((hud::is_same_v<decltype(it_begin->key()), const i32 &>));
hud_assert_true((hud::is_same_v<decltype(it_begin->value()), const i64 &>));
const hud::hashmap<i32, i64> const_map {
{1, 11},
{2, 22},
{3, 33},
{4, 44}
};

hud::hashmap<i32, i64>::iterator it_begin = map.begin();
hud::hashmap<i32, i64>::const_iterator const_it_begin = const_map.begin();

return std::tuple {
hud::is_same_v<decltype(it_begin->key()), const i32 &>,
hud::is_same_v<decltype(it_begin->value()), i64 &>,
hud::is_same_v<decltype(const_it_begin->key()), const i32 &>,
hud::is_same_v<decltype(const_it_begin->value()), const i64 &>,
};
};

// Non constant
{
const auto result = test();
hud_assert_true(std::get<0>(result));
hud_assert_true(std::get<1>(result));
hud_assert_true(std::get<2>(result));
hud_assert_true(std::get<3>(result));
}
// Constant
{
constexpr auto result = test();
hud_assert_true(std::get<0>(result));
hud_assert_true(std::get<1>(result));
hud_assert_true(std::get<2>(result));
hud_assert_true(std::get<3>(result));
}
}

Expand Down Expand Up @@ -110,53 +124,52 @@ GTEST_TEST(hashmap, structure_binding)

// GTEST_TEST(hashmap, range_for_loop)
// {
// // Non const Array
// const auto test = []()
// {
// hud::array<i32> arr({10, 20, 30, 40});
// hud_assert_ne(arr.data(), nullptr);
// hud_assert_eq(arr.count(), 4u);
// hud_assert_eq(arr.max_count(), 4u);
// hud_assert_eq(arr[0], 10);
// hud_assert_eq(arr[1], 20);
// hud_assert_eq(arr[2], 30);
// hud_assert_eq(arr[3], 40);
// using map_type = hud::hashmap<i32, i64>;
// map_type map {
// {1, 11},
// {2, 22},
// {3, 33},
// {4, 44}
// };
// const map_type const_map {
// {1, 11},
// {2, 22},
// {3, 33},
// {4, 44}
// };

// i32 result[4];
// i32 index = 0;
// // constexpr Iterator begin() noexcept
// // constexpr Iterator end() noexcept
// for (auto &value : arr)
// map_type::type result[4];
// usize index = 0;
// for (const auto &value : map)
// {
// result[index++] = value;
// }
// hud_assert_eq(result[0], arr[0]);
// hud_assert_eq(result[1], arr[1]);
// hud_assert_eq(result[2], arr[2]);
// hud_assert_eq(result[3], arr[3]);
// map_type::type const_result[4];
// index = 0;
// for (const auto &value : const_map)
// {
// const_result[index++] = value;
// }

// // Const Array
// {
// const hud::array<i32> arr({10, 20, 30, 40});
// hud_assert_ne(arr.data(), nullptr);
// hud_assert_eq(arr.count(), 4u);
// hud_assert_eq(arr.max_count(), 4u);
// hud_assert_eq(arr[0], 10);
// hud_assert_eq(arr[1], 20);
// hud_assert_eq(arr[2], 30);
// hud_assert_eq(arr[3], 40);
// return std::tuple {
// result[0] == {1, 11},
// result[1] == {2, 22},
// result[2] == {3, 33},
// result[3] == {4, 44},
// const_result[0] == {1, 11},
// const_result[1] == {2, 22},
// const_result[2] == {3, 33},
// const_result[3] == {4, 44},
// };
// };

// i32 result[4];
// i32 index = 0;
// // constexpr Iterator begin() noexcept
// // constexpr Iterator end() noexcept
// for (auto &value : arr)
// // Non constant
// {
// result[index++] = value;
// }
// hud_assert_eq(result[0], arr[0]);
// hud_assert_eq(result[1], arr[1]);
// hud_assert_eq(result[2], arr[2]);
// hud_assert_eq(result[3], arr[3]);

// // Constant
// {
// }
// }

0 comments on commit 6655d7a

Please sign in to comment.