Skip to content

Commit 1f93994

Browse files
committed
Fix: Dereferencing member_iterator_t
1 parent c3930b4 commit 1f93994

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

cpp/test.cpp

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -58,20 +58,20 @@ template <typename index_at> struct aligned_wrapper_gt {
5858
};
5959

6060
/**
61-
* Tests the functionality of the custom uint40_t type ensuring consistent
61+
* Tests the functionality of the custom uint40_t type ensuring consistent
6262
* behavior across various constructors from uint32_t, uint64_t, and size_t types.
6363
*/
6464
void test_uint40() {
6565
// Constants for tests
6666
std::uint64_t max_uint40_k = (1ULL << 40) - 1;
6767

6868
for (std::uint64_t original_value : {
69-
42ull, // Typical small number
70-
4242ull, // Larger number still within uint40 range
71-
1ull << 40, // Exactly at the boundary of uint40
72-
(1ull << 40) + 1, // Just beyond the boundary of uint40
73-
1ull << 63 // Well beyond the uint40 boundary, tests masking
74-
}) {
69+
42ull, // Typical small number
70+
4242ull, // Larger number still within uint40 range
71+
1ull << 40, // Exactly at the boundary of uint40
72+
(1ull << 40) + 1, // Just beyond the boundary of uint40
73+
1ull << 63 // Well beyond the uint40 boundary, tests masking
74+
}) {
7575
std::uint32_t v_32 = static_cast<std::uint32_t>(original_value);
7676
std::uint64_t v_64 = original_value;
7777
std::size_t v_size = static_cast<std::size_t>(original_value);
@@ -742,10 +742,10 @@ template <typename key_at, typename slot_at> void test_strings() {
742742
return between(some_vector, str_at(get_slot(member)));
743743
}
744744
levenshtein_distance_t operator()(member_citerator_t const& a, member_citerator_t const& b) const {
745-
return between(str_at(get_slot(b)), str_at(get_slot(a)));
745+
return between(str_at(get_slot(*b)), str_at(get_slot(*a)));
746746
}
747747
levenshtein_distance_t operator()(std::string_view some_vector, member_citerator_t const& member) const {
748-
return between(some_vector, str_at(get_slot(member)));
748+
return between(some_vector, str_at(get_slot(*member)));
749749
}
750750
};
751751

include/usearch/index.hpp

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1749,6 +1749,9 @@ class index_gt {
17491749
member_iterator_gt() noexcept {}
17501750
member_iterator_gt(index_t* index, std::size_t slot) noexcept : index_(index), slot_(slot) {}
17511751

1752+
ref_t call_key(std::true_type) const noexcept { return ref_t{index_->node_at_(slot_).ckey(), slot_}; }
1753+
ref_t call_key(std::false_type) const noexcept { return ref_t{index_->node_at_(slot_).key(), slot_}; }
1754+
17521755
index_t* index_{};
17531756
std::size_t slot_{};
17541757

@@ -1759,8 +1762,8 @@ class index_gt {
17591762
using pointer = void;
17601763
using reference = ref_t;
17611764

1762-
reference operator*() const noexcept { return {index_->node_at_(slot_).key(), slot_}; }
1763-
vector_key_t key() const noexcept { return index_->node_at_(slot_).key(); }
1765+
reference operator*() const noexcept { return call_key(std::is_const<index_t>()); }
1766+
vector_key_t key() const noexcept { return index_->node_at_(slot_).ckey(); }
17641767

17651768
friend inline std::size_t get_slot(member_iterator_gt const& it) noexcept { return it.slot_; }
17661769
friend inline vector_key_t get_key(member_iterator_gt const& it) noexcept { return it.key(); }
@@ -1865,8 +1868,10 @@ class index_gt {
18651868
node_t& operator=(node_t const&) = default;
18661869

18671870
misaligned_ref_gt<vector_key_t const> ckey() const noexcept { return {tape_}; }
1868-
misaligned_ref_gt<vector_key_t> key() const noexcept { return {tape_}; }
1869-
misaligned_ref_gt<level_t> level() const noexcept { return {tape_ + sizeof(vector_key_t)}; }
1871+
misaligned_ref_gt<vector_key_t const> ckey() noexcept { return {tape_}; }
1872+
misaligned_ref_gt<vector_key_t const> key() const noexcept { return {tape_}; }
1873+
misaligned_ref_gt<vector_key_t> key() noexcept { return {tape_}; }
1874+
misaligned_ref_gt<level_t> level() noexcept { return {tape_ + sizeof(vector_key_t)}; }
18701875

18711876
void key(vector_key_t v) noexcept { return misaligned_store<vector_key_t>(tape_, v); }
18721877
void level(level_t v) noexcept { return misaligned_store<level_t>(tape_ + sizeof(vector_key_t), v); }

0 commit comments

Comments
 (0)