Browse Source

Expose WriteBatch::Append in the C API.

-------------
Created by MOE: https://github.com/google/moe
MOE_MIGRATED_REVID=209345072
pull/1/head
costan 6 years ago
committed by Victor Costan
parent
commit
16a2b8bb3a
3 changed files with 16 additions and 3 deletions
  1. +6
    -1
      db/c.cc
  2. +7
    -1
      db/c_test.c
  3. +3
    -1
      include/leveldb/c.h

+ 6
- 1
db/c.cc View File

@ -359,7 +359,7 @@ void leveldb_writebatch_delete(
} }
void leveldb_writebatch_iterate( void leveldb_writebatch_iterate(
leveldb_writebatch_t* b,
const leveldb_writebatch_t* b,
void* state, void* state,
void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
void (*deleted)(void*, const char* k, size_t klen)) { void (*deleted)(void*, const char* k, size_t klen)) {
@ -382,6 +382,11 @@ void leveldb_writebatch_iterate(
b->rep.Iterate(&handler); b->rep.Iterate(&handler);
} }
void leveldb_writebatch_append(leveldb_writebatch_t *destination,
const leveldb_writebatch_t *source) {
destination->rep.Append(source->rep);
}
leveldb_options_t* leveldb_options_create() { leveldb_options_t* leveldb_options_create() {
return new leveldb_options_t; return new leveldb_options_t;
} }

+ 7
- 1
db/c_test.c View File

@ -228,12 +228,18 @@ int main(int argc, char** argv) {
leveldb_writebatch_clear(wb); leveldb_writebatch_clear(wb);
leveldb_writebatch_put(wb, "bar", 3, "b", 1); leveldb_writebatch_put(wb, "bar", 3, "b", 1);
leveldb_writebatch_put(wb, "box", 3, "c", 1); leveldb_writebatch_put(wb, "box", 3, "c", 1);
leveldb_writebatch_delete(wb, "bar", 3);
leveldb_writebatch_t* wb2 = leveldb_writebatch_create();
leveldb_writebatch_delete(wb2, "bar", 3);
leveldb_writebatch_append(wb, wb2);
leveldb_writebatch_destroy(wb2);
leveldb_write(db, woptions, wb, &err); leveldb_write(db, woptions, wb, &err);
CheckNoError(err); CheckNoError(err);
CheckGet(db, roptions, "foo", "hello"); CheckGet(db, roptions, "foo", "hello");
CheckGet(db, roptions, "bar", NULL); CheckGet(db, roptions, "bar", NULL);
CheckGet(db, roptions, "box", "c"); CheckGet(db, roptions, "box", "c");
int pos = 0; int pos = 0;
leveldb_writebatch_iterate(wb, &pos, CheckPut, CheckDel); leveldb_writebatch_iterate(wb, &pos, CheckPut, CheckDel);
CheckCondition(pos == 3); CheckCondition(pos == 3);

+ 3
- 1
include/leveldb/c.h View File

@ -155,9 +155,11 @@ LEVELDB_EXPORT void leveldb_writebatch_put(leveldb_writebatch_t*,
LEVELDB_EXPORT void leveldb_writebatch_delete(leveldb_writebatch_t*, LEVELDB_EXPORT void leveldb_writebatch_delete(leveldb_writebatch_t*,
const char* key, size_t klen); const char* key, size_t klen);
LEVELDB_EXPORT void leveldb_writebatch_iterate( LEVELDB_EXPORT void leveldb_writebatch_iterate(
leveldb_writebatch_t*, void* state,
const leveldb_writebatch_t*, void* state,
void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen), void (*put)(void*, const char* k, size_t klen, const char* v, size_t vlen),
void (*deleted)(void*, const char* k, size_t klen)); void (*deleted)(void*, const char* k, size_t klen));
LEVELDB_EXPORT void leveldb_writebatch_append(
leveldb_writebatch_t* destination, const leveldb_writebatch_t* source);
/* Options */ /* Options */

Loading…
Cancel
Save