From ce4392425d274f13493f3be32106d2bf5bf8fa66 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Wed, 27 Sep 2023 21:43:12 +0900 Subject: [PATCH 1/2] mock level3 --- lib/NGT/Capi.cpp | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/lib/NGT/Capi.cpp b/lib/NGT/Capi.cpp index d2608aa..120e83a 100644 --- a/lib/NGT/Capi.cpp +++ b/lib/NGT/Capi.cpp @@ -17,6 +17,8 @@ #include #include #include +#include +#include #include "NGT/Index.h" #include "NGT/GraphOptimizer.h" @@ -867,17 +869,13 @@ ObjectID ngt_append_index(NGTIndex index, double *obj, uint32_t obj_dim, NGTErro } } +std::atomic id(1); ObjectID ngt_insert_index_as_float(NGTIndex index, float *obj, uint32_t obj_dim, NGTError error) { - if(index == NULL || obj == NULL || obj_dim == 0){ - std::stringstream ss; - ss << "Capi : " << __FUNCTION__ << "() : parametor error: index = " << index << " obj = " << obj << " obj_dim = " << obj_dim; - operate_error_string_(ss, error); - return 0; - } - try{ - NGT::Index* pindex = static_cast(index); - return pindex->insert(&obj[0], obj_dim); + std::vector vobj(obj, obj+obj_dim); + auto expected = id.load(); + ObjectID desired; + do { desired = expected + 1; } while(!id.compare_exchange_weak(expected, desired)); }catch(std::exception &err) { std::stringstream ss; ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what(); @@ -1092,15 +1090,9 @@ bool ngt_batch_insert_index_as_float16(NGTIndex index, NGTFloat16 *obj, uint32_t } bool ngt_create_index(NGTIndex index, uint32_t pool_size, NGTError error) { - if(index == NULL){ - std::stringstream ss; - ss << "Capi : " << __FUNCTION__ << "() : parametor error: idnex = " << index; - operate_error_string_(ss, error); - return false; - } - try{ - (static_cast(index))->createIndex(pool_size); + sleep(2); + auto _pool_size = pool_size; }catch(std::exception &err) { std::stringstream ss; ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what(); @@ -1111,15 +1103,8 @@ bool ngt_create_index(NGTIndex index, uint32_t pool_size, NGTError error) { } bool ngt_remove_index(NGTIndex index, ObjectID id, NGTError error) { - if(index == NULL){ - std::stringstream ss; - ss << "Capi : " << __FUNCTION__ << "() : parametor error: idnex = " << index; - operate_error_string_(ss, error); - return false; - } - try{ - (static_cast(index))->remove(id); + auto _id = id; }catch(std::exception &err) { std::stringstream ss; ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what(); From 86f42554b619a08adebc9e7e6432d3556114e877 Mon Sep 17 00:00:00 2001 From: Kosuke Morimoto Date: Thu, 28 Sep 2023 01:17:29 +0900 Subject: [PATCH 2/2] fix --- lib/NGT/Capi.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/lib/NGT/Capi.cpp b/lib/NGT/Capi.cpp index 120e83a..19e4210 100644 --- a/lib/NGT/Capi.cpp +++ b/lib/NGT/Capi.cpp @@ -876,6 +876,7 @@ ObjectID ngt_insert_index_as_float(NGTIndex index, float *obj, uint32_t obj_dim, auto expected = id.load(); ObjectID desired; do { desired = expected + 1; } while(!id.compare_exchange_weak(expected, desired)); + return desired; }catch(std::exception &err) { std::stringstream ss; ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what();