diff --git a/package.json b/package.json index 1bc7a90..f9c3a05 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "hnswlib-wasm", - "version": "0.0.10-0", + "version": "0.1.0-0", "description": "typescript and wasm bindings for Hnswlib", "module": "./dist/hnswlib.js", "types": "./dist/hnswlib.d.ts", diff --git a/src/hnswlib/bruteforce.h b/src/hnswlib/bruteforce.h index 62b4381..30b33ae 100644 --- a/src/hnswlib/bruteforce.h +++ b/src/hnswlib/bruteforce.h @@ -102,7 +102,7 @@ class BruteforceSearch : public AlgorithmInterface { assert(k <= cur_element_count); std::priority_queue> topResults; if (cur_element_count == 0) return topResults; - for (size_t i = 0; i < k; i++) { + for (int i = 0; i < k; i++) { dist_t dist = fstdistfunc_(query_data, data_ + size_per_element_ * i, dist_func_param_); labeltype label = *((labeltype*) (data_ + size_per_element_ * i + data_size_)); if ((!isIdAllowed) || (*isIdAllowed)(label)) { @@ -110,7 +110,7 @@ class BruteforceSearch : public AlgorithmInterface { } } dist_t lastdist = topResults.empty() ? std::numeric_limits::max() : topResults.top().first; - for (size_t i = k; i < cur_element_count; i++) { + for (int i = k; i < cur_element_count; i++) { dist_t dist = fstdistfunc_(query_data, data_ + size_per_element_ * i, dist_func_param_); if (dist <= lastdist) { labeltype label = *((labeltype *) (data_ + size_per_element_ * i + data_size_)); diff --git a/src/hnswlib/hnswalg.h b/src/hnswlib/hnswalg.h index c03516a..bef0017 100644 --- a/src/hnswlib/hnswalg.h +++ b/src/hnswlib/hnswalg.h @@ -92,8 +92,8 @@ class HierarchicalNSW : public AlgorithmInterface { size_t ef_construction = 200, size_t random_seed = 100, bool allow_replace_deleted = false) - : label_op_locks_(MAX_LABEL_OPERATION_LOCKS), - link_list_locks_(max_elements), + : link_list_locks_(max_elements), + label_op_locks_(MAX_LABEL_OPERATION_LOCKS), element_levels_(max_elements), allow_replace_deleted_(allow_replace_deleted) { max_elements_ = max_elements; @@ -739,7 +739,7 @@ class HierarchicalNSW : public AlgorithmInterface { std::vector getDataByLabel(labeltype label) const { // lock all operations with element by label std::unique_lock lock_label(getLabelOpMutex(label)); - + std::unique_lock lock_table(label_lookup_lock); auto search = label_lookup_.find(label); if (search == label_lookup_.end() || isMarkedDeleted(search->second)) { @@ -752,7 +752,7 @@ class HierarchicalNSW : public AlgorithmInterface { size_t dim = *((size_t *) dist_func_param_); std::vector data; data_t* data_ptr = (data_t*) data_ptrv; - for (size_t i = 0; i < dim; i++) { + for (int i = 0; i < dim; i++) { data.push_back(*data_ptr); data_ptr += 1; } @@ -801,7 +801,7 @@ class HierarchicalNSW : public AlgorithmInterface { /* * Removes the deleted mark of the node, does NOT really change the current graph. - * + * * Note: the method is not safe to use when replacement of deleted elements is enabled, * because elements marked as deleted can be completely removed by addPoint */ diff --git a/src/hnswlib/hnswlib.h b/src/hnswlib/hnswlib.h index 785cbd6..fb7118f 100644 --- a/src/hnswlib/hnswlib.h +++ b/src/hnswlib/hnswlib.h @@ -119,7 +119,6 @@ typedef size_t labeltype; class BaseFilterFunctor { public: virtual bool operator()(hnswlib::labeltype id) { return true; } - virtual ~BaseFilterFunctor() {}; }; template diff --git a/src/wrapper.cpp b/src/wrapper.cpp index 7bab78c..f275770 100644 --- a/src/wrapper.cpp +++ b/src/wrapper.cpp @@ -267,7 +267,7 @@ namespace emscripten { uint32_t dim_; std::unique_ptr ipspace_; - InnerProductSpace(uint32_t dim): dim_(dim) { + InnerProductSpace(uint32_t dim) : dim_(dim) { ipspace_ = std::unique_ptr(new hnswlib::InnerProductSpace(static_cast(dim_))); } @@ -287,9 +287,9 @@ namespace emscripten { /*****************/ - class CustomFilterFunctor: public hnswlib::BaseFilterFunctor { + class CustomFilterFunctor : public hnswlib::BaseFilterFunctor { public: - CustomFilterFunctor(emscripten::val callback): callback_(callback) {} + CustomFilterFunctor(emscripten::val callback) : callback_(callback) {} bool operator()(hnswlib::labeltype id) override { if (callback_.isUndefined() || callback_.isNull()) { @@ -306,7 +306,7 @@ namespace emscripten { } // Explicitly declare the destructor with the same exception specification as the base class - ~CustomFilterFunctor() noexcept override = default; + ~CustomFilterFunctor() noexcept = default; private: emscripten::val callback_; @@ -461,6 +461,7 @@ namespace emscripten { emscripten::val distances = emscripten::val::array(); emscripten::val neighbors = emscripten::val::array(); + // Reverse the loop order for (int32_t i = static_cast(n_results) - 1; i >= 0; i--) { auto nn = knn.top(); diff --git a/test/HierarchicalNSW.test.ts b/test/HierarchicalNSW.test.ts index 4702ce6..c541092 100644 --- a/test/HierarchicalNSW.test.ts +++ b/test/HierarchicalNSW.test.ts @@ -6,6 +6,7 @@ import { expect } from 'vitest'; describe('hnswlib.HierarchicalNSW', () => { afterAll(() => { + console.log(testHnswlibModule, (testHnswlibModule as any).FS); process.stdout.write(''); });