Skip to content

Commit 47191a7

Browse files
committed
Merge branch 'main-dev' of https://github.com/unum-cloud/usearch into main-dev
2 parents d615d58 + f29f174 commit 47191a7

File tree

2 files changed

+13
-14
lines changed

2 files changed

+13
-14
lines changed
File renamed without changes.

include/usearch/usearch.hpp

+13-14
Original file line numberDiff line numberDiff line change
@@ -923,11 +923,14 @@ class index_gt {
923923

924924
static constexpr std::size_t head_bytes() { return sizeof(label_t) + sizeof(dim_t) + sizeof(level_t); }
925925

926-
struct node_t {
926+
class node_t {
927927
byte_t* tape_{};
928928
scalar_t* vector_{};
929929

930+
public:
930931
explicit node_t(byte_t* tape, scalar_t* vector) noexcept : tape_(tape), vector_(vector) {}
932+
byte_t* tape() const noexcept { return tape_; }
933+
scalar_t* vector() const noexcept { return vector_; }
931934

932935
node_t() = default;
933936
node_t(node_t const&) = default;
@@ -1127,9 +1130,9 @@ class index_gt {
11271130
inline std::size_t size() const noexcept { return count; }
11281131
inline search_result_t operator[](std::size_t i) const noexcept {
11291132
candidate_t const* top_ordered = top_.data();
1130-
return {member_cref_t(index_.node(top_ordered[i].id)), top_ordered[i].distance};
1133+
return {member_cref_t(index_.node(index_.nodes_[top_ordered[i].id])), top_ordered[i].distance};
11311134
}
1132-
inline std::size_t dump_to(label_t* labels, distance_t* distances) noexcept {
1135+
inline std::size_t dump_to(label_t* labels, distance_t* distances) const noexcept {
11331136
for (std::size_t i = 0; i != count; ++i) {
11341137
search_result_t result = operator[](i);
11351138
labels[i] = result.member.label;
@@ -1453,8 +1456,7 @@ class index_gt {
14531456
node_head_t const& head = *(node_head_t const*)(file + progress);
14541457
std::size_t bytes_to_dump = node_dump_size(head.dim, head.level);
14551458
std::size_t bytes_in_vec = head.dim * sizeof(scalar_t);
1456-
nodes_[i].tape_ = (byte_t*)(file + progress);
1457-
nodes_[i].vector_ = (scalar_t*)(file + progress + bytes_to_dump - bytes_in_vec);
1459+
nodes_[i] = node_t{(byte_t*)(file + progress), (scalar_t*)(file + progress + bytes_to_dump - bytes_in_vec)};
14581460
progress += bytes_to_dump;
14591461
max_level_ = (std::max)(max_level_, head.level);
14601462
}
@@ -1487,20 +1489,17 @@ class index_gt {
14871489

14881490
// This function is rarely called and can be as expensive as needed for higher space-efficiency.
14891491
node_t& node = nodes_[id];
1490-
if (!node.tape_)
1491-
return;
1492-
1493-
node_head_t const& head = *(node_head_t const*)(node.tape_ + pre_.mutex_bytes);
1492+
node_head_t const& head = *(node_head_t const*)(node.tape() + pre_.mutex_bytes);
14941493
std::size_t levels_bytes = pre_.neighbors_base_bytes + pre_.neighbors_bytes * head.level;
1495-
bool store_vector = (byte_t*)(node.tape_ + pre_.mutex_bytes + head_bytes() + levels_bytes) == //
1496-
(byte_t*)(node.vector_);
1494+
bool store_vector = (byte_t*)(node.tape() + pre_.mutex_bytes + head_bytes() + levels_bytes) == //
1495+
(byte_t*)(node.vector());
14971496
std::size_t node_bytes = //
14981497
pre_.mutex_bytes + // Optional concurrency-control
14991498
head_bytes() + levels_bytes + // Obligatory neighborhood index
15001499
head.dim * store_vector // Optional vector copy
15011500
;
15021501

1503-
allocator_t{}.deallocate(node.tape_, node_bytes);
1502+
allocator_t{}.deallocate(node.tape(), node_bytes);
15041503
node = node_t{};
15051504
}
15061505

@@ -1537,10 +1536,10 @@ class index_gt {
15371536
inline node_ref_t node(id_t id) const noexcept { return node(nodes_[id]); }
15381537

15391538
inline node_ref_t node(node_t node) const noexcept {
1540-
byte_t* data = node.tape_;
1539+
byte_t* data = node.tape();
15411540
mutex_t* mutex = synchronize() ? (mutex_t*)data : nullptr;
15421541
node_head_t& head = *(node_head_t*)(data + pre_.mutex_bytes);
1543-
scalar_t* scalars = node.vector_;
1542+
scalar_t* scalars = node.vector();
15441543

15451544
return {*mutex, head, scalars};
15461545
}

0 commit comments

Comments
 (0)