usearch 2.21.3 → 2.21.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -552,7 +552,7 @@ doi = {10.5281/zenodo.7949416},
552
552
  author = {Vardanian, Ash},
553
553
  title = {{USearch by Unum Cloud}},
554
554
  url = {https://github.com/unum-cloud/usearch},
555
- version = {2.21.3},
555
+ version = {2.21.4},
556
556
  year = {2023},
557
557
  month = oct,
558
558
  }
@@ -9,7 +9,7 @@
9
9
 
10
10
  #define USEARCH_VERSION_MAJOR 2
11
11
  #define USEARCH_VERSION_MINOR 21
12
- #define USEARCH_VERSION_PATCH 3
12
+ #define USEARCH_VERSION_PATCH 4
13
13
 
14
14
  // Inferring C++ version
15
15
  // https://stackoverflow.com/a/61552074
@@ -2624,7 +2624,10 @@ class index_gt {
2624
2624
  inline bool empty() const noexcept { return !count; }
2625
2625
  inline match_t operator[](std::size_t i) const noexcept { return at(i); }
2626
2626
  inline match_t front() const noexcept { return at(0); }
2627
- inline match_t back() const noexcept { return at(count - 1); }
2627
+ inline match_t back() const noexcept {
2628
+ usearch_assert_m(count > 0, "Can't call back() on an empty result set");
2629
+ return at(count - 1);
2630
+ }
2628
2631
  inline bool contains(vector_key_t key) const noexcept {
2629
2632
  for (std::size_t i = 0; i != count; ++i)
2630
2633
  if (at(i).member.key == key)
@@ -2987,7 +2990,8 @@ class index_gt {
2987
2990
  }
2988
2991
  form_reverse_links_(metric, updated_slot, closest_view, value, level, context);
2989
2992
  }
2990
- updated_node.key(key);
2993
+ if (static_cast<vector_key_t>(updated_node.key()) != key)
2994
+ updated_node.key(key);
2991
2995
 
2992
2996
  // Normalize stats
2993
2997
  result.computed_distances = context.computed_distances - result.computed_distances;
@@ -3836,7 +3840,11 @@ class index_gt {
3836
3840
 
3837
3841
  inline node_conditional_lock_t node_try_conditional_lock_(std::size_t slot, bool condition,
3838
3842
  bool& failed_to_acquire) const noexcept {
3839
- failed_to_acquire = condition ? nodes_mutexes_.atomic_set(slot) : false;
3843
+ if (!condition) {
3844
+ failed_to_acquire = false;
3845
+ return {nodes_mutexes_, std::numeric_limits<std::size_t>::max()};
3846
+ }
3847
+ failed_to_acquire = nodes_mutexes_.atomic_set(slot);
3840
3848
  return {nodes_mutexes_, failed_to_acquire ? std::numeric_limits<std::size_t>::max() : slot};
3841
3849
  }
3842
3850
 
@@ -4152,8 +4160,7 @@ class index_gt {
4152
4160
  node_try_conditional_lock_(candidate_slot, updated_slot != candidate_slot, failed_to_acquire);
4153
4161
  if (failed_to_acquire)
4154
4162
  continue;
4155
- auto optional_node_lock =
4156
- optional_node_lock_(candidate_slot, updated_slot == candidate_slot);
4163
+ auto optional_node_lock = optional_node_lock_(candidate_slot, updated_slot == candidate_slot);
4157
4164
  neighbors_ref_t candidate_neighbors = neighbors_(candidate_ref, level);
4158
4165
 
4159
4166
  // Optional prefetching
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "usearch",
3
- "version": "2.21.3",
3
+ "version": "2.21.4",
4
4
  "description": "Smaller & Faster Single-File Vector Search Engine from Unum",
5
5
  "author": "Ash Vardanian (https://ashvardanian.com/)",
6
6
  "license": "Apache 2.0",
Binary file
Binary file