diff --git a/cpp/example/test.c b/cpp/example/test.c index f8cbaa6..1d85951 100644 --- a/cpp/example/test.c +++ b/cpp/example/test.c @@ -129,4 +129,10 @@ int main(){ free(b3.data); free(b4.data); free_result(&res1); + + void* subrange = subrange_new(st1, 0 , UINT64_MAX); + if (subrange == NULL){ + perror("failed to init subrange"); + } + printf("subrange init successful"); } diff --git a/cpp/negentropy_wrapper.c b/cpp/negentropy_wrapper.c index 99e458d..9f927ac 100644 --- a/cpp/negentropy_wrapper.c +++ b/cpp/negentropy_wrapper.c @@ -4,6 +4,7 @@ #include "negentropy.h" #include "negentropy/storage/BTreeMem.h" #include "negentropy_wrapper.h" +#include "negentropy/storage/SubRange.h" //This is a C-wrapper for the C++ library that helps in integrating negentropy with nim code. //TODO: Do error handling by catching exceptions @@ -44,6 +45,22 @@ int storage_size(void* storage){ return lmdbStorage->size(); } +void* subrange_new(void* storage, uint64_t startTimeStamp, uint64_t endTimeStamp){ + negentropy::storage::BTreeMem* st = reinterpret_cast(storage); + negentropy::storage::SubRange* subRange = NULL; + try { + subRange = new negentropy::storage::SubRange(*st, negentropy::Bound(startTimeStamp), negentropy::Bound(endTimeStamp)); + } catch (negentropy::err e){ + return NULL; + } + return subRange; +} + +void subrange_delete(void* range){ + negentropy::storage::SubRange* subRange = reinterpret_cast(range); + delete subRange; +} + void negentropy_delete(void* negentropy){ Negentropy* ngn_inst = reinterpret_cast*>(negentropy); delete ngn_inst; diff --git a/cpp/negentropy_wrapper.h b/cpp/negentropy_wrapper.h index 36a84e6..7e07241 100644 --- a/cpp/negentropy_wrapper.h +++ b/cpp/negentropy_wrapper.h @@ -31,6 +31,10 @@ EXTERNC void storage_delete(void* storage); EXTERNC int storage_size(void* storage); +EXTERNC void* subrange_new(void* storage, uint64_t startTimeStamp, uint64_t endTimeStamp); + +EXTERNC void subrange_delete(void* range); + EXTERNC void* negentropy_new(void* storage, uint64_t frameSizeLimit); EXTERNC void negentropy_delete(void* negentropy);