Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[DO NOT MERGE] mock level3 #2

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 11 additions & 25 deletions lib/NGT/Capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
#include <string>
#include <iostream>
#include <sstream>
#include <atomic>
#include <unistd.h>

#include "NGT/Index.h"
#include "NGT/GraphOptimizer.h"
Expand Down Expand Up @@ -867,17 +869,14 @@ ObjectID ngt_append_index(NGTIndex index, double *obj, uint32_t obj_dim, NGTErro
}
}

std::atomic<ObjectID> 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<NGT::Index*>(index);
return pindex->insert(&obj[0], obj_dim);
std::vector<float> vobj(obj, obj+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();
Expand Down Expand Up @@ -1092,15 +1091,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<NGT::Index*>(index))->createIndex(pool_size);
sleep(2);
auto _pool_size = pool_size;
}catch(std::exception &err) {
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what();
Expand All @@ -1111,15 +1104,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<NGT::Index*>(index))->remove(id);
auto _id = id;
}catch(std::exception &err) {
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what();
Expand Down