Skip to content

Commit

Permalink
Fix: Narrowing conversions for WASM 32-bit builds
Browse files Browse the repository at this point in the history
  • Loading branch information
ashvardanian committed Jul 29, 2023
1 parent 9dff0fb commit 79add97
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
20 changes: 12 additions & 8 deletions include/usearch/index.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,10 @@ class usearch_pack_m uint40_t {
public:
inline uint40_t() noexcept { broadcast(0); }
inline uint40_t(std::uint32_t n) noexcept { std::memcpy(&octets[1], &n, 4); }

#ifdef USEARCH_64BIT_ENV
inline uint40_t(std::uint64_t n) noexcept { std::memcpy(octets, &n, 5); }
#endif

uint40_t(uint40_t&&) = default;
uint40_t(uint40_t const&) = default;
Expand Down Expand Up @@ -1987,7 +1990,7 @@ class index_gt {
std::size_t new_slot = nodes_count_.fetch_add(1);
nodes_[new_slot] = node;
result.new_size = new_slot + 1;
result.slot = static_cast<compressed_slot_t>(new_slot);
result.slot = new_slot;
callback(at(new_slot));
node_lock_t new_lock = node_lock_(new_slot);

Expand Down Expand Up @@ -2520,8 +2523,8 @@ class index_gt {
}

template <typename metric_at>
std::size_t connect_new_node_(std::size_t new_slot, level_t level, context_t& context,
metric_at&& metric) usearch_noexcept_m {
std::size_t connect_new_node_( //
std::size_t new_slot, level_t level, context_t& context, metric_at&& metric) usearch_noexcept_m {

node_t new_node = node_at_(new_slot);
top_candidates_t& top = context.top_candidates;
Expand All @@ -2543,8 +2546,9 @@ class index_gt {
}

template <typename value_at, typename metric_at>
void reconnect_neighbor_nodes_(std::size_t new_slot, value_at&& value, level_t level, context_t& context,
metric_at&& metric) usearch_noexcept_m {
void reconnect_neighbor_nodes_( //
std::size_t new_slot, value_at&& value, level_t level, context_t& context,
metric_at&& metric) usearch_noexcept_m {

node_t new_node = node_at_(new_slot);
top_candidates_t& top = context.top_candidates;
Expand All @@ -2564,7 +2568,7 @@ class index_gt {
// If `new_slot` is already present in the neighboring connections of `close_slot`
// then no need to modify any connections or run the heuristics.
if (close_header.size() < connectivity_max) {
close_header.push_back(new_slot);
close_header.push_back(static_cast<compressed_slot_t>(new_slot));
continue;
}

Expand Down Expand Up @@ -2624,8 +2628,8 @@ class index_gt {
* @return `true` if procedure succeeded, `false` if run out of memory.
*/
template <typename value_at, typename metric_at>
bool search_to_insert_( //
compressed_slot_t start_slot, value_at&& query, metric_at&& metric, //
bool search_to_insert_( //
std::size_t start_slot, value_at&& query, metric_at&& metric, //
level_t level, std::size_t top_limit, context_t& context) noexcept {

visits_bitset_t& visits = context.visits;
Expand Down
2 changes: 1 addition & 1 deletion include/usearch/index_dense.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ class index_dense_gt {
bytes_per_vector = dimensions[1];
offset += sizeof(dimensions);
}
vectors_buffer = {file.data() + offset, count_vectors * bytes_per_vector};
vectors_buffer = {file.data() + offset, static_cast<std::size_t>(count_vectors * bytes_per_vector)};
offset += vectors_buffer.size();
}

Expand Down

0 comments on commit 79add97

Please sign in to comment.