Skip to content
Merged
Show file tree
Hide file tree
Changes from 6 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
22 changes: 18 additions & 4 deletions cpp/example/test.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
#include <string>
#include "../negentropy_wrapper.h"

#define MAX_FRAME_SIZE 153600

void printHexBuffer(buffer buf){
for (uint64_t i = 0; i < buf.len; ++i) {
printf("%0hhx", buf.data[i]);
Expand Down Expand Up @@ -83,30 +85,36 @@ int main(){
void* subrange = subrange_new(st2, 0 , UINT64_MAX);
if (subrange == NULL){
perror("failed to init subrange");
Comment thread
chaitanyaprem marked this conversation as resolved.
return -1;
}
printf("subrange init successful");
printf("subrange init successful with size %d \n ", subrange_size(subrange) );


void* subrange1 = subrange_new(st1, 0 , UINT64_MAX);
if (subrange == NULL){
perror("failed to init subrange");
return -1;
}
printf("subrange init successful");
printf("subrange init successful with size %d \n ", subrange_size(subrange1) );

void* ngn_inst1 = negentropy_new(subrange1, 153600);
void* ngn_inst1 = negentropy_new(subrange1, MAX_FRAME_SIZE);
if(ngn_inst1 == NULL){
perror("failed to create negentropy instance");
return -1;
}

void* ngn_inst2 = negentropy_new(subrange, 153600);
void* ngn_inst2 = negentropy_new(subrange, MAX_FRAME_SIZE);
if(ngn_inst2 == NULL){
perror("failed to create negentropy instance");
return -1;
}


result res;
int ret1 = negentropy_subrange_initiate(ngn_inst1, &res);
if(ret1 < 0){
perror("failed to initiate negentropy instance");
return -1;
}
printf("initiated negentropy successfully with output of len %llu \n", res.output.len);
b4.len = res.output.len;
Expand Down Expand Up @@ -148,6 +156,12 @@ int main(){
free(b4.data);
free_result(&res1);

ret = storage_insert(st1, time(NULL), &b2);
if (ret){
printf("inserted hash successfully in st1\n");
}
printf("\n storage size after adding 1 more elem is %d, subrange size is %d \n", storage_size(st1), subrange_size(subrange1));

subrange_delete(subrange);
subrange_delete(subrange1);

Expand Down
9 changes: 9 additions & 0 deletions cpp/negentropy_wrapper.c
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ void* negentropy_new(void* storage, uint64_t frameSizeLimit){
try{
ne = new Negentropy<negentropy::storage::BTreeMem>(*lmdbStorage, frameSizeLimit);
}catch(negentropy::err e){
//TODO: Error handling
return NULL;
}
return ne;
Expand All @@ -77,6 +78,7 @@ int negentropy_initiate(void* negentropy, result* result){
printHexString(std::string_view(*output)); */
} catch(negentropy::err e){
//std::cout << "Exception raised in initiate " << e.what() << std::endl;
//TODO: Error handling
return -1;
}
if (output->size() > 0 ){
Expand Down Expand Up @@ -292,6 +294,7 @@ void* subrange_new(void* storage, uint64_t startTimeStamp, uint64_t endTimeStamp
try {
subRange = new negentropy::storage::SubRange(*st, negentropy::Bound(startTimeStamp), negentropy::Bound(endTimeStamp));
} catch (negentropy::err e){
//TODO: Error handling
return NULL;
Comment thread
chaitanyaprem marked this conversation as resolved.
}
return subRange;
Expand All @@ -302,6 +305,11 @@ void subrange_delete(void* range){
delete subRange;
}

int subrange_size(void* range){
negentropy::storage::SubRange* subrange = reinterpret_cast<negentropy::storage::SubRange*>(range);
return subrange->size();
}

void negentropy_subrange_delete(void* negentropy){
Negentropy<negentropy::storage::SubRange>* ngn_inst = reinterpret_cast<Negentropy<negentropy::storage::SubRange>*>(negentropy);
delete ngn_inst;
Expand All @@ -317,6 +325,7 @@ void* negentropy_subrange_new(void* subrange, uint64_t frameSizeLimit){
try{
ne = new Negentropy<negentropy::storage::SubRange>(*sub_range, frameSizeLimit);
}catch(negentropy::err e){
//TODO: Error handling
return NULL;
}
return ne;
Expand Down
35 changes: 19 additions & 16 deletions cpp/negentropy_wrapper.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,6 @@ EXTERNC void storage_delete(void* storage);

EXTERNC int storage_size(void* storage);

//SubRange methods
EXTERNC void* subrange_new(void* storage, uint64_t startTimeStamp, uint64_t endTimeStamp);

EXTERNC void subrange_delete(void* range);

EXTERNC void* negentropy_subrange_new(void* subrange, uint64_t frameSizeLimit);

EXTERNC void negentropy_subrange_delete(void* negentropy);

EXTERNC int negentropy_subrange_initiate(void* negentropy, result* result);

EXTERNC int reconcile_subrange(void* negentropy, buffer* query, result* result);

EXTERNC int reconcile_with_ids_subrange_no_cbk(void* negentropy, buffer* query, result* result);

//End of SubRange methods
EXTERNC void* negentropy_new(void* storage, uint64_t frameSizeLimit);

EXTERNC void negentropy_delete(void* negentropy);
Expand All @@ -69,5 +53,24 @@ EXTERNC int reconcile_with_ids_no_cbk(void* negentropy, buffer* query, result*

EXTERNC void free_result(result* result);

//SubRange methods
EXTERNC void* subrange_new(void* storage, uint64_t startTimeStamp, uint64_t endTimeStamp);

EXTERNC void subrange_delete(void* range);

EXTERNC void* negentropy_subrange_new(void* subrange, uint64_t frameSizeLimit);

EXTERNC void negentropy_subrange_delete(void* negentropy);

EXTERNC int negentropy_subrange_initiate(void* negentropy, result* result);

EXTERNC int reconcile_subrange(void* negentropy, buffer* query, result* result);

EXTERNC int reconcile_with_ids_subrange_no_cbk(void* negentropy, buffer* query, result* result);

EXTERNC int subrange_size(void* storage);

//End of SubRange methods

#endif