Skip to content

Commit

Permalink
Clean up unnecessary diversion from upstream usearch
Browse files Browse the repository at this point in the history
  • Loading branch information
Ngalstyan4 committed Jan 30, 2024
1 parent e2378ca commit 0a87a66
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 27 deletions.
42 changes: 20 additions & 22 deletions c/lib.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,12 +187,11 @@ void usearch_update_header(usearch_index_t index, char* headerp, usearch_error_t
}

// ready!
USEARCH_EXPORT usearch_metadata_t usearch_metadata(usearch_index_t index, usearch_error_t* error) {
usearch_metadata_t res;
USEARCH_EXPORT usearch_index_metadata_t usearch_index_metadata(usearch_index_t index, usearch_error_t* error) {
usearch_index_metadata_t res;
precomputed_constants_t pre = reinterpret_cast<index_dense_t*>(index)->pre();

res.inverse_log_connectivity = pre.inverse_log_connectivity;
// res.connectivity_max_base = pre.connectivity_max_base;
res.neighbors_bytes = pre.neighbors_bytes;
res.neighbors_base_bytes = pre.neighbors_base_bytes;
res.dimensions = reinterpret_cast<index_dense_t*>(index)->dimensions();
Expand All @@ -204,6 +203,24 @@ USEARCH_EXPORT usearch_metadata_t usearch_metadata(usearch_index_t index, usearc
return res;
}

USEARCH_EXPORT void usearch_metadata(char const* path, usearch_init_options_t* options, usearch_error_t* error) {

assert(path && options && error);
index_dense_metadata_result_t result = index_dense_metadata_from_path(path);
if (!result)
*error = result.error.release();

options->metric_kind = metric_kind_to_c(result.head.kind_metric);
options->quantization = scalar_kind_to_c(result.head.kind_scalar);
options->dimensions = result.head.dimensions;
options->multi = result.head.multi;

options->connectivity = 0;
options->expansion_add = 0;
options->expansion_search = 0;
options->metric = NULL;
}

USEARCH_EXPORT void usearch_save_buffer(usearch_index_t index, void* buffer, size_t length, usearch_error_t* error) {

assert(index && buffer && length && error);
Expand Down Expand Up @@ -256,17 +273,6 @@ USEARCH_EXPORT void usearch_metadata_buffer(void const* buffer, size_t length, u
USEARCH_EXPORT size_t usearch_size(usearch_index_t index, usearch_error_t*) { //
return reinterpret_cast<index_dense_t*>(index)->size();
}
// USEARCH_EXPORT size_t usearch_expansion_add(usearch_index_t index, usearch_error_t*) {
// return reinterpret_cast<index_t*>(index)->expansion_add();
// }
//
// USEARCH_EXPORT size_t usearch_expansion_search(usearch_index_t index, usearch_error_t*) {
// return reinterpret_cast<index_t*>(index)->expansion_search();
// }
//
// USEARCH_EXPORT usearch_metric_kind_t usearch_metric_kind(usearch_index_t index, usearch_error_t*) {
// return to_usearch_metric(reinterpret_cast<index_t*>(index)->metric().kind());
// }

USEARCH_EXPORT size_t usearch_capacity(usearch_index_t index, usearch_error_t*) {
return reinterpret_cast<index_dense_t*>(index)->capacity();
Expand Down Expand Up @@ -375,14 +381,6 @@ USEARCH_EXPORT usearch_distance_t usearch_distance( //
return metric((byte_t const*)vector_first, (byte_t const*)vector_second);
}

USEARCH_EXPORT float usearch_dist(void const* a, void const* b, usearch_metric_kind_t metric, int dims,
usearch_scalar_kind_t kind) {
usearch_error_t error = nullptr;
float res = usearch_distance(a, b, kind, dims, metric, &error);
assert(!error);
return res;
}

USEARCH_EXPORT void usearch_exact_search( //
void const* dataset, size_t dataset_count, size_t dataset_stride, //
void const* queries, size_t queries_count, size_t queries_stride, //
Expand Down
14 changes: 9 additions & 5 deletions c/usearch.h
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,9 @@ USEARCH_EXPORT typedef struct {
size_t connectivity;
usearch_metric_kind_t metric_kind;

} usearch_metadata_t;
} usearch_index_metadata_t;

USEARCH_EXPORT typedef usearch_index_metadata_t metadata_t;

/**
* @brief Initializes a new instance of the index.
Expand Down Expand Up @@ -172,7 +174,12 @@ USEARCH_EXPORT void usearch_update_header(usearch_index_t, char* headerp, usearc
* @param[out] error Pointer to a string where the error message will be stored, if an error occurs.
* @return A handle to the initialized USearch index, or `NULL` on failure.
*/
USEARCH_EXPORT usearch_metadata_t usearch_metadata(usearch_index_t, usearch_error_t* error);
USEARCH_EXPORT void usearch_metadata(char const* path, usearch_init_options_t* options, usearch_error_t* error);

/**
* @ returns index metadata from argument index
*/
USEARCH_EXPORT usearch_index_metadata_t usearch_index_metadata(usearch_index_t, usearch_error_t* error);

/**
* @brief Saves the index to an in-memory buffer.
Expand Down Expand Up @@ -367,9 +374,6 @@ USEARCH_EXPORT void usearch_exact_search( //

USEARCH_EXPORT void usearch_cast(usearch_scalar_kind_t from, void const* vector, usearch_scalar_kind_t to, void* result,
size_t result_size, int dims, usearch_error_t* error);

USEARCH_EXPORT float usearch_dist(void const* a, void const* b, usearch_metric_kind_t metric, int dims,
usearch_scalar_kind_t kind);
#ifdef __cplusplus
}
#endif
Expand Down

0 comments on commit 0a87a66

Please sign in to comment.