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 level6.3 #10

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
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
8 changes: 6 additions & 2 deletions lib/NGT/Capi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1100,7 +1100,9 @@ bool ngt_create_index(NGTIndex index, uint32_t pool_size, NGTError error) {
}

try{
(static_cast<NGT::Index*>(index))->createIndex(pool_size);
// (static_cast<NGT::Index*>(index))->createIndex(pool_size);
auto _ps = pool_size;
return _ps == pool_size;
}catch(std::exception &err) {
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what();
Expand All @@ -1119,7 +1121,9 @@ bool ngt_remove_index(NGTIndex index, ObjectID id, NGTError error) {
}

try{
(static_cast<NGT::Index*>(index))->remove(id);
// (static_cast<NGT::Index*>(index))->remove(id);
auto _id = id;
return _id == id;
}catch(std::exception &err) {
std::stringstream ss;
ss << "Capi : " << __FUNCTION__ << "() : Error: " << err.what();
Expand Down
10 changes: 6 additions & 4 deletions lib/NGT/Index.h
Original file line number Diff line number Diff line change
Expand Up @@ -1825,7 +1825,9 @@ size_t NGT::Index::insert(const T* object, size_t size)
getObjectSpace().getRepository().initialize();
}

auto *o = getObjectSpace().getRepository().allocateNormalizedPersistentObject(object, size);
size_t oid = getObjectSpace().getRepository().insert(dynamic_cast<PersistentObject*>(o));
return oid;
}
// auto *o = getObjectSpace().getRepository().allocateNormalizedPersistentObject(object, size);
// size_t oid = getObjectSpace().getRepository().insert(dynamic_cast<PersistentObject*>(o));
// return oid;
getObjectSpace().getRepository().allocateNormalizedPersistentObject(object, size);
return 0;
}
66 changes: 34 additions & 32 deletions lib/NGT/ObjectRepository.h
Original file line number Diff line number Diff line change
Expand Up @@ -228,43 +228,45 @@ namespace NGT {
}

template <typename T>
Object *allocateObject(T *o, size_t size) {
Object *allocateObject(T *o, size_t size) {
size_t osize = paddedByteSize;
if (sparse) {
size_t vsize = size * (type == typeid(float) ? 4 : 1);
osize = osize < vsize ? vsize : osize;
size_t vsize = size * (type == typeid(float) ? 4 : 1);
osize = osize < vsize ? vsize : osize;
} else {
if (dimension != size) {
std::stringstream msg;
msg << "ObjectSpace::allocateObject: Fatal error! The specified dimension is invalid. The indexed objects="
<< dimension << " The specified object=" << size;
NGTThrowException(msg);
}
if (dimension != size) {
std::stringstream msg;
msg << "ObjectSpace::allocateObject: Fatal error! The specified dimension is invalid. The indexed objects="
<< dimension << " The specified object=" << size;
NGTThrowException(msg);
}
}
Object *po = new Object(osize);
void *object = static_cast<void*>(&(*po)[0]);
if (type == typeid(uint8_t)) {
uint8_t *obj = static_cast<uint8_t*>(object);
for (size_t i = 0; i < size; i++) {
obj[i] = static_cast<uint8_t>(o[i]);
}
} else if (type == typeid(float)) {
float *obj = static_cast<float*>(object);
for (size_t i = 0; i < size; i++) {
obj[i] = static_cast<float>(o[i]);
}
#ifdef NGT_HALF_FLOAT
} else if (type == typeid(float16)) {
float16 *obj = static_cast<float16*>(object);
for (size_t i = 0; i < size; i++) {
obj[i] = static_cast<float16>(o[i]);
}
#endif
} else {
std::cerr << "ObjectSpace::allocateObject: Fatal error: unsupported type!" << std::endl;
abort();
}
return po;
// void *object = static_cast<void*>(&(*po)[0]);
// if (type == typeid(uint8_t)) {
// uint8_t *obj = static_cast<uint8_t*>(object);
// for (size_t i = 0; i < size; i++) {
// obj[i] = static_cast<uint8_t>(o[i]);
// }
// } else if (type == typeid(float)) {
// float *obj = static_cast<float*>(object);
// for (size_t i = 0; i < size; i++) {
// obj[i] = static_cast<float>(o[i]);
// }
// #ifdef NGT_HALF_FLOAT
// } else if (type == typeid(float16)) {
// float16 *obj = static_cast<float16*>(object);
// for (size_t i = 0; i < size; i++) {
// obj[i] = static_cast<float16>(o[i]);
// }
// #endif
// } else {
// std::cerr << "ObjectSpace::allocateObject: Fatal error: unsupported type!" << std::endl;
// abort();
// }
// return po;
delete po;
return nullptr;
}

template <typename T>
Expand Down