Commit 35d46c4d authored by Bradley C. Kuszmaul's avatar Bradley C. Kuszmaul

Make all external symbols in pma.o start with toku_. Addresses #8

git-svn-id: file:///svn/tokudb@677 c7de825b-a66e-492c-adef-691d508d4ae1
parent 37cc9732
......@@ -152,8 +152,8 @@ void toku_seralize_brtnode_to(int fd, DISKOFF off, DISKOFF size, BRTNODE node) {
assert(check_local_fingerprint==node->local_fingerprint);
}
} else {
//printf(" n_entries=%d\n", pma_n_entries(node->u.l.buffer));
wbuf_int(&w, pma_n_entries(node->u.l.buffer));
//printf(" n_entries=%d\n", toku_pma_n_entries(node->u.l.buffer));
wbuf_int(&w, toku_pma_n_entries(node->u.l.buffer));
PMA_ITERATE(node->u.l.buffer, key, keylen, data, datalen,
(wbuf_bytes(&w, key, keylen),
wbuf_bytes(&w, data, datalen)));
......@@ -341,13 +341,13 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl
} else {
int n_in_buf = rbuf_int(&rc);
result->u.l.n_bytes_in_buffer = 0;
r=pma_create(&result->u.l.buffer, bt_compare, nodesize);
r=toku_pma_create(&result->u.l.buffer, bt_compare, nodesize);
if (r!=0) {
if (0) { died_21: pma_free(&result->u.l.buffer); }
if (0) { died_21: toku_pma_free(&result->u.l.buffer); }
goto died1;
}
pma_set_dup_mode(result->u.l.buffer, flags);
if (flags & TOKU_DB_DUPSORT) pma_set_dup_compare(result->u.l.buffer, dup_compare);
toku_pma_set_dup_mode(result->u.l.buffer, flags);
if (flags & TOKU_DB_DUPSORT) toku_pma_set_dup_compare(result->u.l.buffer, dup_compare);
//printf("%s:%d r PMA= %p\n", __FILE__, __LINE__, result->u.l.buffer);
#define BRT_USE_PMA_BULK_INSERT 1
#if BRT_USE_PMA_BULK_INSERT
......@@ -366,7 +366,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl
}
if (n_in_buf > 0) {
u_int32_t actual_sum = 0;
r = pma_bulk_insert(result->u.l.buffer, keys, vals, n_in_buf, result->rand4fingerprint, &actual_sum);
r = toku_pma_bulk_insert(result->u.l.buffer, keys, vals, n_in_buf, result->rand4fingerprint, &actual_sum);
if (r!=0) goto died_21;
if (actual_sum!=result->local_fingerprint) {
//fprintf(stderr, "%s:%d Corrupted checksum stored=%08x rand=%08x actual=%08x height=%d n_keys=%d\n", __FILE__, __LINE__, result->rand4fingerprint, result->local_fingerprint, actual_sum, result->height, n_in_buf);
......@@ -386,7 +386,7 @@ int toku_deserialize_brtnode_from (int fd, DISKOFF off, BRTNODE *brtnode, int fl
rbuf_bytes(&rc, &val, &vallen);
{
DBT k,v;
r = pma_insert(result->u.l.buffer, fill_dbt(&k, key, keylen), fill_dbt(&v, val, vallen), 0);
r = toku_pma_insert(result->u.l.buffer, fill_dbt(&k, key, keylen), fill_dbt(&v, val, vallen), 0);
if (r!=0) goto died_21;
}
result->u.l.n_bytes_in_buffer += keylen + vallen + KEY_VALUE_OVERHEAD;
......
......@@ -606,7 +606,7 @@ static void test_read_what_was_written (void) {
printf(" ok\n");
}
extern void pma_show_stats (void);
extern void toku_pma_show_stats (void);
/* Test c_get(DB_LAST) on an empty tree */
void test_cursor_last_empty(void) {
......@@ -2249,7 +2249,7 @@ static void brt_blackbox_test (void) {
test4(2048, 1<<15, 1);
printf("test3 fast\n");
pma_show_stats();
toku_pma_show_stats();
test3(1<<15, 1024, 1);
test4(1<<15, 1024, 1);
......
......@@ -27,7 +27,7 @@ static void verify_local_fingerprint (BRTNODE node) {
}));
assert(fp==node->local_fingerprint);
} else {
pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->local_fingerprint);
toku_pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->local_fingerprint);
}
}
......
......@@ -54,7 +54,7 @@ void brtnode_free (BRTNODE *nodep) {
}
} else {
if (node->u.l.buffer) // The buffer may have been freed already, in some cases.
pma_free(&node->u.l.buffer);
toku_pma_free(&node->u.l.buffer);
}
toku_free(node);
*nodep=0;
......@@ -138,7 +138,7 @@ static int brt_compare_pivot(BRT brt, DBT *key, DBT *data, bytevec ck, unsigned
void brtnode_flush_callback (CACHEFILE cachefile, DISKOFF nodename, void *brtnode_v, long size __attribute((unused)), BOOL write_me, BOOL keep_me, LSN modified_lsn, BOOL rename_p __attribute__((__unused__))) {
BRTNODE brtnode = brtnode_v;
// if ((write_me || keep_me) && (brtnode->height==0)) {
// pma_verify_fingerprint(brtnode->u.l.buffer, brtnode->rand4fingerprint, brtnode->subtree_fingerprint);
// toku_pma_verify_fingerprint(brtnode->u.l.buffer, brtnode->rand4fingerprint, brtnode->subtree_fingerprint);
// }
if (0) {
printf("%s:%d brtnode_flush_callback %p keep_me=%d height=%d", __FILE__, __LINE__, brtnode, keep_me, brtnode->height);
......@@ -320,11 +320,11 @@ static void initialize_brtnode (BRT t, BRTNODE n, DISKOFF nodename, int height)
}
n->u.n.n_bytes_in_hashtables = 0;
} else {
int r = pma_create(&n->u.l.buffer, t->compare_fun, n->nodesize);
int r = toku_pma_create(&n->u.l.buffer, t->compare_fun, n->nodesize);
assert(r==0);
pma_set_dup_mode(n->u.l.buffer, t->flags & (TOKU_DB_DUP+TOKU_DB_DUPSORT));
toku_pma_set_dup_mode(n->u.l.buffer, t->flags & (TOKU_DB_DUP+TOKU_DB_DUPSORT));
if (t->flags & TOKU_DB_DUPSORT)
pma_set_dup_compare(n->u.l.buffer, t->dup_compare);
toku_pma_set_dup_compare(n->u.l.buffer, t->dup_compare);
static int rcount=0;
//printf("%s:%d n PMA= %p (rcount=%d)\n", __FILE__, __LINE__, n->u.l.buffer, rcount);
rcount++;
......@@ -355,7 +355,7 @@ void delete_node (BRT t, BRTNODE node) {
assert(node->height>=0);
if (node->height==0) {
if (node->u.l.buffer) {
pma_free(&node->u.l.buffer);
toku_pma_free(&node->u.l.buffer);
}
node->u.l.n_bytes_in_buffer=0;
} else {
......@@ -402,7 +402,7 @@ int brtleaf_split (BRT t, BRTNODE node, BRTNODE *nodea, BRTNODE *nodeb, DBT *spl
//printf("%s:%d B is at %lld nodesize=%d\n", __FILE__, __LINE__, B->thisnodename, B->nodesize);
assert(node->height>0 || node->u.l.buffer!=0);
int r;
r = pma_split(node->u.l.buffer, &node->u.l.n_bytes_in_buffer, splitk, db,
r = toku_pma_split(node->u.l.buffer, &node->u.l.n_bytes_in_buffer, splitk, db,
A->u.l.buffer, &A->u.l.n_bytes_in_buffer, A->rand4fingerprint, &A->local_fingerprint,
B->u.l.buffer, &B->u.l.n_bytes_in_buffer, B->rand4fingerprint, &B->local_fingerprint);
assert(r == 0);
......@@ -921,13 +921,13 @@ static int brt_leaf_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
int *did_split, BRTNODE *nodea, BRTNODE *nodeb, DBT *splitk,
int debug,
TOKUTXN txn) {
// pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->subtree_fingerprint);
// toku_pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->subtree_fingerprint);
if (cmd->type == BRT_INSERT) {
DBT *k = cmd->u.id.key;
DBT *v = cmd->u.id.val;
DB *db = cmd->u.id.db;
int replaced_v_size;
enum pma_errors pma_status = pma_insert_or_replace(node->u.l.buffer, k, v, &replaced_v_size, db, txn, node->thisnodename, node->rand4fingerprint, &node->local_fingerprint);
enum pma_errors pma_status = toku_pma_insert_or_replace(node->u.l.buffer, k, v, &replaced_v_size, db, txn, node->thisnodename, node->rand4fingerprint, &node->local_fingerprint);
assert(pma_status==BRT_OK);
//printf("replaced_v_size=%d\n", replaced_v_size);
if (replaced_v_size>=0) {
......@@ -937,7 +937,7 @@ static int brt_leaf_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
}
node->dirty = 1;
// pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->subtree_fingerprint);
// toku_pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->subtree_fingerprint);
// If it doesn't fit, then split the leaf.
if (toku_serialize_brtnode_size(node) > node->nodesize) {
......@@ -950,8 +950,8 @@ static int brt_leaf_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
if (debug) printf("%s:%d %*snodeb->thisnodename=%lld nodeb->size=%d\n", __FILE__, __LINE__, debug, "", (*nodeb)->thisnodename, (*nodeb)->nodesize);
assert(toku_serialize_brtnode_size(*nodea)<=(*nodea)->nodesize);
assert(toku_serialize_brtnode_size(*nodeb)<=(*nodeb)->nodesize);
// pma_verify_fingerprint((*nodea)->u.l.buffer, (*nodea)->rand4fingerprint, (*nodea)->subtree_fingerprint);
// pma_verify_fingerprint((*nodeb)->u.l.buffer, (*nodeb)->rand4fingerprint, (*nodeb)->subtree_fingerprint);
// toku_pma_verify_fingerprint((*nodea)->u.l.buffer, (*nodea)->rand4fingerprint, (*nodea)->subtree_fingerprint);
// toku_pma_verify_fingerprint((*nodeb)->u.l.buffer, (*nodeb)->rand4fingerprint, (*nodeb)->subtree_fingerprint);
} else {
*did_split = 0;
}
......@@ -959,7 +959,7 @@ static int brt_leaf_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
} else if (cmd->type == BRT_DELETE) {
u_int32_t delta;
int r = pma_delete(node->u.l.buffer, cmd->u.id.key, cmd->u.id.db, node->rand4fingerprint, &node->local_fingerprint, &delta);
int r = toku_pma_delete(node->u.l.buffer, cmd->u.id.key, cmd->u.id.db, node->rand4fingerprint, &node->local_fingerprint, &delta);
if (r == BRT_OK) {
node->u.l.n_bytes_in_buffer -= delta;
node->dirty = 1;
......@@ -1387,7 +1387,7 @@ static int brtnode_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
int r;
//counter++; tmpcounter=counter;
if (node->height==0) {
// pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->subtree_fingerprint);
// toku_pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->subtree_fingerprint);
r = brt_leaf_put_cmd(t, node, cmd,
did_split, nodea, nodeb, splitk,
debug, txn);
......@@ -1402,13 +1402,13 @@ static int brtnode_put_cmd (BRT t, BRTNODE node, BRT_CMD *cmd,
assert(toku_serialize_brtnode_size(*nodea)<=(*nodea)->nodesize);
assert(toku_serialize_brtnode_size(*nodeb)<=(*nodeb)->nodesize);
// if ((*nodea)->height==0) {
// pma_verify_fingerprint((*nodea)->u.l.buffer, (*nodea)->rand4fingerprint, (*nodea)->subtree_fingerprint);
// pma_verify_fingerprint((*nodeb)->u.l.buffer, (*nodeb)->rand4fingerprint, (*nodeb)->subtree_fingerprint);
// toku_pma_verify_fingerprint((*nodea)->u.l.buffer, (*nodea)->rand4fingerprint, (*nodea)->subtree_fingerprint);
// toku_pma_verify_fingerprint((*nodeb)->u.l.buffer, (*nodeb)->rand4fingerprint, (*nodeb)->subtree_fingerprint);
// }
} else {
assert(toku_serialize_brtnode_size(node)<=node->nodesize);
// if (node->height==0) {
// pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->local_fingerprint);
// toku_pma_verify_fingerprint(node->u.l.buffer, node->rand4fingerprint, node->local_fingerprint);
// } else {
// verify_local_fingerprint_nonleaf(node);
// }
......@@ -1852,7 +1852,7 @@ int brt_lookup_node (BRT brt, DISKOFF off, DBT *k, DBT *v, DB *db, BRTNODE paren
node->parent_brtnode = parent_brtnode;
if (node->height==0) {
result = pma_lookup(node->u.l.buffer, k, v, db);
result = toku_pma_lookup(node->u.l.buffer, k, v, db);
//printf("%s:%d looked up something, got answerlen=%d\n", __FILE__, __LINE__, answerlen);
//verify_local_fingerprint_nonleaf(node);
r = toku_cachetable_unpin(brt->cf, off, 0, 0);
......@@ -2219,7 +2219,7 @@ void brt_cursor_leaf_split(BRT_CURSOR cursor, BRT t, BRTNODE oldnode, BRTNODE le
if (cursor->path[cursor->path_len-1] == oldnode) {
assert(left->height == 0 && right->height == 0);
r = pma_cursor_get_pma(cursor->pmacurs, &pma);
r = toku_pma_cursor_get_pma(cursor->pmacurs, &pma);
assert(r == 0);
if (pma == left->u.l.buffer)
newnode = left;
......@@ -2357,7 +2357,7 @@ int brt_cursor_close (BRT_CURSOR curs) {
curs->next->prev = curs->prev;
}
if (curs->pmacurs) {
int r2=pma_cursor_free(&curs->pmacurs);
int r2=toku_pma_cursor_free(&curs->pmacurs);
if (r==0) r=r2;
}
toku_free(curs);
......@@ -2431,13 +2431,13 @@ int brtcurs_set_position_last (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db,
cursor->path_len--;
goto died0;
} else {
r=pma_cursor(node->u.l.buffer, &cursor->pmacurs);
r=toku_pma_cursor(node->u.l.buffer, &cursor->pmacurs);
if (r!=0) {
if (0) { died10: pma_cursor_free(&cursor->pmacurs); }
if (0) { died10: toku_pma_cursor_free(&cursor->pmacurs); }
cursor->path_len--;
goto died0;
}
r=pma_cursor_set_position_last(cursor->pmacurs);
r=toku_pma_cursor_set_position_last(cursor->pmacurs);
if (r!=0) goto died10; /* we'll deallocate this cursor, and unpin this node, and go back up. */
return 0;
}
......@@ -2494,13 +2494,13 @@ int brtcurs_set_position_first (BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db
cursor->path_len--;
goto died0;
} else {
r=pma_cursor(node->u.l.buffer, &cursor->pmacurs);
r=toku_pma_cursor(node->u.l.buffer, &cursor->pmacurs);
if (r!=0) {
if (0) { died10: pma_cursor_free(&cursor->pmacurs); }
if (0) { died10: toku_pma_cursor_free(&cursor->pmacurs); }
cursor->path_len--;
goto died0;
}
r=pma_cursor_set_position_first(cursor->pmacurs);
r=toku_pma_cursor_set_position_first(cursor->pmacurs);
if (r!=0) goto died10; /* we'll deallocate this cursor, and unpin this node, and go back up. */
return 0;
}
......@@ -2555,12 +2555,12 @@ int brtcurs_set_position_next2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
/* requires that the cursor is initialized. */
int brtcurs_set_position_next (BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn) {
int r = pma_cursor_set_position_next(cursor->pmacurs);
int r = toku_pma_cursor_set_position_next(cursor->pmacurs);
if (r==DB_NOTFOUND) {
/* We fell off the end of the pma. */
if (cursor->path_len==1) return DB_NOTFOUND;
/* Part of the trickyness is we need to leave the cursor pointing at the current (possibly deleted) value if there is no next value. */
r = pma_cursor_free(&cursor->pmacurs);
r = toku_pma_cursor_free(&cursor->pmacurs);
assert(r == 0);
return brtcurs_set_position_next2(cursor, key, db, txn);
}
......@@ -2615,11 +2615,11 @@ int brtcurs_set_position_prev2(BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn)
}
int brtcurs_set_position_prev (BRT_CURSOR cursor, DBT *key, DB *db, TOKUTXN txn) {
int r = pma_cursor_set_position_prev(cursor->pmacurs);
int r = toku_pma_cursor_set_position_prev(cursor->pmacurs);
if (r==DB_NOTFOUND) {
if (cursor->path_len==1)
return DB_NOTFOUND;
r = pma_cursor_free(&cursor->pmacurs);
r = toku_pma_cursor_free(&cursor->pmacurs);
assert(r == 0);
return brtcurs_set_position_prev2(cursor, key, db, txn);
}
......@@ -2663,18 +2663,18 @@ int brtcurs_set_key(BRT_CURSOR cursor, DISKOFF off, DBT *key, DBT *val, int flag
} else {
cursor->path_len += 1;
cursor->path[cursor->path_len-1] = node;
r = pma_cursor(node->u.l.buffer, &cursor->pmacurs);
r = toku_pma_cursor(node->u.l.buffer, &cursor->pmacurs);
if (r == 0) {
if (flag == DB_SET)
r = pma_cursor_set_key(cursor->pmacurs, key, db);
r = toku_pma_cursor_set_key(cursor->pmacurs, key, db);
else if (flag == DB_GET_BOTH)
r = pma_cursor_set_both(cursor->pmacurs, key, val, db);
r = toku_pma_cursor_set_both(cursor->pmacurs, key, val, db);
else {
assert(0);
r = DB_NOTFOUND;
}
if (r != 0) {
int rr = pma_cursor_free(&cursor->pmacurs);
int rr = toku_pma_cursor_free(&cursor->pmacurs);
assert(rr == 0);
}
}
......@@ -2734,11 +2734,11 @@ int brtcurs_set_range(BRT_CURSOR cursor, DISKOFF off, DBT *key, DB *db, TOKUTXN
} else {
cursor->path_len += 1;
cursor->path[cursor->path_len-1] = node;
r = pma_cursor(node->u.l.buffer, &cursor->pmacurs);
r = toku_pma_cursor(node->u.l.buffer, &cursor->pmacurs);
if (r == 0) {
r = pma_cursor_set_range(cursor->pmacurs, key, db);
r = toku_pma_cursor_set_range(cursor->pmacurs, key, db);
if (r != 0) {
int rr = pma_cursor_free(&cursor->pmacurs);
int rr = toku_pma_cursor_free(&cursor->pmacurs);
assert(rr == 0);
}
}
......@@ -2764,7 +2764,7 @@ static int unpin_cursor (BRT_CURSOR cursor) {
if (r==0) r=r2;
}
if (cursor->pmacurs) {
r = pma_cursor_free(&cursor->pmacurs);
r = toku_pma_cursor_free(&cursor->pmacurs);
assert(r == 0);
}
cursor->path_len=0;
......@@ -2812,7 +2812,7 @@ int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, DB *db, TO
r=unpin_cursor(cursor); if (r!=0) goto died0;
assert(cursor->pmacurs == 0);
r=brtcurs_set_position_last(cursor, *rootp, kbt, db, txn, null_brtnode); if (r!=0) goto died0;
r=pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
r=toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
if (r == 0) assert_cursor_path(cursor);
break;
case DB_FIRST:
......@@ -2820,21 +2820,21 @@ int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, DB *db, TO
r=unpin_cursor(cursor); if (r!=0) goto died0;
assert(cursor->pmacurs == 0);
r=brtcurs_set_position_first(cursor, *rootp, kbt, db, txn, null_brtnode); if (r!=0) goto died0;
r=pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
r=toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
if (r == 0) assert_cursor_path(cursor);
break;
case DB_NEXT:
if (cursor->path_len<=0)
goto do_db_first;
r=brtcurs_set_position_next(cursor, kbt, db, txn); if (r!=0) goto died0;
r=pma_cursor_get_current(cursor->pmacurs, kbt, vbt); if (r!=0) goto died0;
r=toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt); if (r!=0) goto died0;
if (r == 0) assert_cursor_path(cursor);
break;
case DB_PREV:
if (cursor->path_len<= 0)
goto do_db_last;
r = brtcurs_set_position_prev(cursor, kbt, db, txn); if (r!=0) goto died0;
r = pma_cursor_get_current(cursor->pmacurs, kbt, vbt); if (r!=0) goto died0;
r = toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt); if (r!=0) goto died0;
if (r == 0) assert_cursor_path(cursor);
break;
case DB_SET:
......@@ -2842,7 +2842,7 @@ int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, DB *db, TO
assert(r == 0);
r = brtcurs_set_key(cursor, *rootp, kbt, vbt, DB_SET, db, txn, null_brtnode);
if (r != 0) goto died0;
r = pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
r = toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
if (r != 0) goto died0;
break;
case DB_GET_BOTH:
......@@ -2856,7 +2856,7 @@ int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int flags, DB *db, TO
assert(r == 0);
r = brtcurs_set_range(cursor, *rootp, kbt, db, txn, null_brtnode);
if (r != 0) goto died0;
r = pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
r = toku_pma_cursor_get_current(cursor->pmacurs, kbt, vbt);
if (r != 0) goto died0;
break;
default:
......@@ -2876,7 +2876,7 @@ int brt_cursor_delete(BRT_CURSOR cursor, int flags __attribute__((__unused__)))
BRTNODE node = cursor->path[cursor->path_len-1];
assert(node->height == 0);
int kvsize;
r = pma_cursor_delete_under(cursor->pmacurs, &kvsize);
r = toku_pma_cursor_delete_under(cursor->pmacurs, &kvsize);
if (r == 0) {
node->u.l.n_bytes_in_buffer -= KEY_VALUE_OVERHEAD + kvsize;
node->dirty = 1;
......
......@@ -13,7 +13,7 @@ int mdict_create (MDICT* mdict) {
int r;
MALLOC(result);
if (result==0) return -1;
r = pma_create(&result->pma);
r = toku_pma_create(&result->pma);
if (r==0) {
*mdict = result;
}
......@@ -21,12 +21,12 @@ int mdict_create (MDICT* mdict) {
}
void mdict_free (MDICT m) {
pma_free(m->pma);
toku_pma_free(m->pma);
my_free(m);
}
int mdict_n_entries (MDICT m) {
return pma_n_entries(m->pma);
return toku_pma_n_entries(m->pma);
}
......@@ -34,28 +34,28 @@ int mdict_n_entries (MDICT m) {
/* The values returned should not be modified. */
/* May damage the cursor. */
int mdict_insert (MDICT m, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen) {
return pma_insert(m->pma, key, keylen, data, datalen);
return toku_pma_insert(m->pma, key, keylen, data, datalen);
}
/* This returns an error if the key is NOT present. */
int mdict_replace (MDICT, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
/* This returns an error if the key is NOT present. */
int mdict_delete (MDICT m, bytevec key, ITEMLEN keylen) {
return pma_delete(m->pma, key, keylen);
return toku_pma_delete(m->pma, key, keylen);
}
/* Exposes internals of the MDICT by returning a pointer to the guts.
* Don't modify the returned data. Don't free it. */
int mdict_lookup (MDICT m, bytevec key, ITEMLEN keylen, bytevec*data, ITEMLEN *datalen) {
return pma_lookup(m->pma, key, keylen, data, datalen);
return toku_pma_lookup(m->pma, key, keylen, data, datalen);
}
int mdict_random_pick(MDICT m, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen) {
return pma_random_pick(m->pma, key, keylen, data, datalen);
return toku_pma_random_pick(m->pma, key, keylen, data, datalen);
}
void mdict_iterate (MDICT m, void(*f)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*v) {
pma_iterate(m->pma, f, v);
toku_pma_iterate(m->pma, f, v);
}
......
......@@ -14,14 +14,14 @@ int toku_keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2le
#define MDICT PMA
#define MDICT_OK PMA_OK
#define MDICT_NOTFOUND PMA_NOTFOUND
#define mdict_free pma_free
#define mdict_n_entries pma_n_entries
#define mdict_free toku_pma_free
#define mdict_n_entries toku_pma_n_entries
#define MDICT_ITERATE PMA_ITERATE
#define mdict_insert pma_insert
#define mdict_insert toku_pma_insert
#define mdict_create pma_create
#define mdict_delete pma_delete
#define mdict_lookup pma_lookup
#define mdict_random_pick pma_random_pick
#define mdict_lookup toku_pma_lookup
#define mdict_random_pick toku_pma_random_pick
#define mdict_iterate pma_iterate
#elif defined(USEHASH)
......
......@@ -30,13 +30,13 @@ struct pma {
struct mempool kvspace;
};
int pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi);
void pmainternal_calculate_parameters (PMA pma);
int pmainternal_smooth_region (struct kv_pair *pairs[], int n, int idx, int base, PMA pma);
int pmainternal_printpairs (struct kv_pair *pairs[], int N);
int pmainternal_make_space_at (PMA pma, int idx);
int pmainternal_find (PMA pma, DBT *, DB*); // The DB is so the comparison fuction can be called.
void print_pma (PMA pma); /* useful for debugging, so keep the name short. I.e., not pmainternal_print_pma() */
int toku_pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi);
void toku_pmainternal_calculate_parameters (PMA pma);
int toku_pmainternal_smooth_region (struct kv_pair *pairs[], int n, int idx, int base, PMA pma);
int toku_pmainternal_printpairs (struct kv_pair *pairs[], int N);
int toku_pmainternal_make_space_at (PMA pma, int idx);
int toku_pmainternal_find (PMA pma, DBT *, DB*); // The DB is so the comparison fuction can be called.
void toku_print_pma (PMA pma); /* useful for debugging, so keep the name short. I.e., not pmainternal_print_pma() */
/* density thresholds */
#define PMA_LDT_HIGH 0.25
......
......@@ -25,35 +25,35 @@ static void test_make_space_at (void) {
key = "B";
key_B = kv_pair_malloc(key, strlen(key)+1, 0, 0);
r=pma_create(&pma, toku_default_compare_fun, 0);
r=toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(r==0);
assert(pma_n_entries(pma)==0);
r=pmainternal_make_space_at(pma, 2);
assert(pma_index_limit(pma)==4);
assert((unsigned long)pma->pairs[pma_index_limit(pma)]==0xdeadbeefL);
print_pma(pma);
assert(toku_pma_n_entries(pma)==0);
r=toku_pmainternal_make_space_at(pma, 2);
assert(toku_pma_index_limit(pma)==4);
assert((unsigned long)pma->pairs[toku_pma_index_limit(pma)]==0xdeadbeefL);
toku_print_pma(pma);
pma->pairs[2] = key_A;
pma->n_pairs_present++;
r=pmainternal_make_space_at(pma,2);
r=toku_pmainternal_make_space_at(pma,2);
printf("Requested space at 2, got space at %d\n", r);
print_pma(pma);
toku_print_pma(pma);
assert(pma->pairs[r]==0);
assert((unsigned long)pma->pairs[pma_index_limit(pma)]==0xdeadbeefL);
assert((unsigned long)pma->pairs[toku_pma_index_limit(pma)]==0xdeadbeefL);
assert(pma_index_limit(pma)==4);
assert(toku_pma_index_limit(pma)==4);
pma->pairs[0] = key_A;
pma->pairs[1] = key_B;
pma->pairs[2] = 0;
pma->pairs[3] = 0;
pma->n_pairs_present=2;
print_pma(pma);
r=pmainternal_make_space_at(pma,0);
toku_print_pma(pma);
r=toku_pmainternal_make_space_at(pma,0);
printf("Requested space at 0, got space at %d\n", r);
print_pma(pma);
assert((unsigned long)pma->pairs[pma_index_limit(pma)]==0xdeadbeefL); // make sure it doesn't go off the end.
toku_print_pma(pma);
assert((unsigned long)pma->pairs[toku_pma_index_limit(pma)]==0xdeadbeefL); // make sure it doesn't go off the end.
assert(pma_index_limit(pma)==8);
assert(toku_pma_index_limit(pma)==8);
pma->pairs[0] = key_A;
pma->pairs[1] = 0;
pma->pairs[2] = 0;
......@@ -63,13 +63,13 @@ static void test_make_space_at (void) {
pma->pairs[6] = 0;
pma->pairs[7] = 0;
pma->n_pairs_present=2;
print_pma(pma);
r=pmainternal_make_space_at(pma,5);
print_pma(pma);
toku_print_pma(pma);
r=toku_pmainternal_make_space_at(pma,5);
toku_print_pma(pma);
printf("r=%d\n", r);
{
int i;
for (i=0; i<pma_index_limit(pma); i++) {
for (i=0; i<toku_pma_index_limit(pma); i++) {
if (pma->pairs[i]) {
assert(i<r);
pma->pairs[i] = 0;
......@@ -77,7 +77,7 @@ static void test_make_space_at (void) {
}
}
pma->n_pairs_present = 0;
r=pma_free(&pma); assert(r==0);
r=toku_pma_free(&pma); assert(r==0);
assert(pma==0);
kv_pair_free(key_A);
kv_pair_free(key_B);
......@@ -94,31 +94,31 @@ static void test_pma_find (void) {
// All that is needed to test pma_find is N and pairs.
pma->N = N;
for (i=0; i<N; i++) pma->pairs[i]=0;
assert(pma_index_limit(pma)==N);
assert(toku_pma_index_limit(pma)==N);
pma->compare_fun = toku_default_compare_fun;
r=pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
assert(r==0);
pma->pairs[5] = kv_pair_malloc("hello", 5, 0, 0);
assert(pma_index_limit(pma)==N);
r=pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
assert(pma_index_limit(pma)==N);
assert(toku_pma_index_limit(pma)==N);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
assert(toku_pma_index_limit(pma)==N);
assert(r==5);
r=pmainternal_find(pma, fill_dbt(&k, "there", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "there", 5), 0);
assert(r==6);
r=pmainternal_find(pma, fill_dbt(&k, "aaa", 3), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "aaa", 3), 0);
assert(r==0);
pma->pairs[N-1] = kv_pair_malloc("there", 5, 0, 0);
r=pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hello", 5), 0);
assert(r==5);
r=pmainternal_find(pma, fill_dbt(&k, "there", 5), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "there", 5), 0);
assert(r==N-1);
r=pmainternal_find(pma, fill_dbt(&k, "aaa", 3), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "aaa", 3), 0);
assert(r==0);
r=pmainternal_find(pma, fill_dbt(&k, "hellob", 6), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "hellob", 6), 0);
assert(r==6);
r=pmainternal_find(pma, fill_dbt(&k, "zzz", 3), 0);
r=toku_pmainternal_find(pma, fill_dbt(&k, "zzz", 3), 0);
assert(r==N);
for (i=0; i<N; i++)
......@@ -156,9 +156,9 @@ void test_smooth_region_N (int N) {
pairs[j] = 0;
}
}
pmainternal_printpairs(pairs, N); printf(" at %d becomes f", insertat);
r = pmainternal_smooth_region(pairs, N, insertat, 0, 0);
pmainternal_printpairs(pairs, N); printf(" at %d\n", r);
toku_pmainternal_printpairs(pairs, N); printf(" at %d becomes f", insertat);
r = toku_pmainternal_smooth_region(pairs, N, insertat, 0, 0);
toku_pmainternal_printpairs(pairs, N); printf(" at %d\n", r);
assert(0<=r); assert(r<N);
assert(pairs[r]==0);
/* Now verify that things are in the right place:
......@@ -198,7 +198,7 @@ void test_smooth_region6 (void) {
key = "B";
pairs[1] = kv_pair_malloc(key, strlen(key)+1, 0, 0);
int r = pmainternal_smooth_region(pairs, N, 2, 0, 0);
int r = toku_pmainternal_smooth_region(pairs, N, 2, 0, 0);
printf("{ ");
for (i=0; i<N; i++)
printf("%s ", pairs[i] ? pairs[i]->key : "?");
......@@ -218,8 +218,8 @@ static void test_smooth_region (void) {
static void test_calculate_parameters (void) {
struct pma pma;
pma.N=4; pmainternal_calculate_parameters(&pma); assert(pma.uplgN==2); assert(pma.udt_step==0.5);
pma.N=8; pmainternal_calculate_parameters(&pma); assert(pma.uplgN==4); assert(pma.udt_step==0.5);
pma.N=4; toku_pmainternal_calculate_parameters(&pma); assert(pma.uplgN==2); assert(pma.udt_step==0.5);
pma.N=8; toku_pmainternal_calculate_parameters(&pma); assert(pma.uplgN==4); assert(pma.udt_step==0.5);
}
......@@ -231,21 +231,21 @@ static void test_count_region (void) {
for (i=0; i<N; i++)
pairs[i] = 0;
assert(pmainternal_count_region(pairs,0,4)==0);
assert(pmainternal_count_region(pairs,2,4)==0);
assert(pmainternal_count_region(pairs,0,2)==0);
assert(toku_pmainternal_count_region(pairs,0,4)==0);
assert(toku_pmainternal_count_region(pairs,2,4)==0);
assert(toku_pmainternal_count_region(pairs,0,2)==0);
key = "A";
pairs[2] = kv_pair_malloc(key, strlen(key)+1, 0, 0);
assert(pmainternal_count_region(pairs,0,4)==1);
assert(pmainternal_count_region(pairs,2,4)==1);
assert(pmainternal_count_region(pairs,0,2)==0);
assert(pmainternal_count_region(pairs,2,2)==0);
assert(pmainternal_count_region(pairs,2,3)==1);
assert(toku_pmainternal_count_region(pairs,0,4)==1);
assert(toku_pmainternal_count_region(pairs,2,4)==1);
assert(toku_pmainternal_count_region(pairs,0,2)==0);
assert(toku_pmainternal_count_region(pairs,2,2)==0);
assert(toku_pmainternal_count_region(pairs,2,3)==1);
key = "B";
pairs[3] = kv_pair_malloc(key, strlen(key)+1, 0, 0);
key = "a";
pairs[0] = kv_pair_malloc(key, strlen(key)+1, 0, 0);
assert(pmainternal_count_region(pairs,0,4)==3);
assert(toku_pmainternal_count_region(pairs,0,4)==3);
for (i=0; i<N; i++)
if (pairs[i])
kv_pair_free(pairs[i]);
......@@ -261,24 +261,24 @@ void add_fingerprint_and_check(u_int32_t rand4fingerprint, u_int32_t actual_fing
static void do_insert (PMA pma, const void *key, int keylen, const void *data, int datalen, u_int32_t rand4fingerprint, u_int32_t *sum, u_int32_t *expect_fingerprint) {
DBT k,v;
assert(*sum==*expect_fingerprint);
int r = pma_insert(pma, fill_dbt(&k, key, keylen), fill_dbt(&v, data, datalen), NULL_ARGS, rand4fingerprint, sum);
int r = toku_pma_insert(pma, fill_dbt(&k, key, keylen), fill_dbt(&v, data, datalen), NULL_ARGS, rand4fingerprint, sum);
assert(r==BRT_OK);
add_fingerprint_and_check(rand4fingerprint, *sum, expect_fingerprint, key, keylen, data, datalen);
pma_verify_fingerprint(pma, rand4fingerprint, *sum);
toku_pma_verify_fingerprint(pma, rand4fingerprint, *sum);
}
static void do_delete (PMA pma, const void *key, int keylen, const void *data, int datalen, u_int32_t rand4fingerprint, u_int32_t *sum, u_int32_t *expect_fingerprint) {
DBT k;
assert(*sum==*expect_fingerprint);
int r = pma_delete(pma, fill_dbt(&k, key, keylen), 0, rand4fingerprint, sum, 0);
int r = toku_pma_delete(pma, fill_dbt(&k, key, keylen), 0, rand4fingerprint, sum, 0);
assert(r==BRT_OK);
add_fingerprint_and_check(-rand4fingerprint, *sum, expect_fingerprint, key, keylen, data, datalen); // negative rand4 means subtract.
pma_verify_fingerprint(pma, rand4fingerprint, *sum);
toku_pma_verify_fingerprint(pma, rand4fingerprint, *sum);
}
static void test_pma_random_pick (void) {
PMA pma;
int r = pma_create(&pma, toku_default_compare_fun, 0);
int r = toku_pma_create(&pma, toku_default_compare_fun, 0);
bytevec key,val;
ITEMLEN keylen,vallen;
DBT k;
......@@ -287,28 +287,28 @@ static void test_pma_random_pick (void) {
u_int32_t expect_fingerprint = 0;
assert(r==0);
r = pma_random_pick(pma, &key, &keylen, &val, &vallen);
r = toku_pma_random_pick(pma, &key, &keylen, &val, &vallen);
assert(r==DB_NOTFOUND);
do_insert(pma, "hello", 6, "there", 6, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify_fingerprint(pma, rand4fingerprint, sum);
toku_pma_verify_fingerprint(pma, rand4fingerprint, sum);
r = pma_random_pick(pma, &key, &keylen, &val, &vallen);
r = toku_pma_random_pick(pma, &key, &keylen, &val, &vallen);
assert(r==0);
assert(keylen==6); assert(vallen==6);
assert(strcmp(key,"hello")==0);
assert(strcmp(val,"there")==0);
r = pma_delete(pma, fill_dbt(&k, "nothello", 9), 0, rand4fingerprint, &sum, 0);
r = toku_pma_delete(pma, fill_dbt(&k, "nothello", 9), 0, rand4fingerprint, &sum, 0);
assert(r==DB_NOTFOUND);
assert(sum==expect_fingerprint); // didn't change because nothing was deleted.
do_delete(pma, "hello", 6, "there", 6, rand4fingerprint, &sum, &expect_fingerprint);
r = pma_random_pick(pma, &key, &keylen, &val, &vallen);
r = toku_pma_random_pick(pma, &key, &keylen, &val, &vallen);
assert(r==DB_NOTFOUND);
do_insert(pma, "hello", 6, "there", 6, rand4fingerprint, &sum, &expect_fingerprint);
r = pma_random_pick(pma, &key, &keylen, &val, &vallen);
r = toku_pma_random_pick(pma, &key, &keylen, &val, &vallen);
assert(r==0);
assert(keylen==6); assert(vallen==6);
assert(strcmp(key,"hello")==0);
......@@ -321,7 +321,7 @@ static void test_pma_random_pick (void) {
do_insert(pma, "aae", 4, "ethere", 7, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "aaf", 4, "fthere", 7, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "aag", 4, "gthere", 7, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify_fingerprint(pma, rand4fingerprint, sum);
toku_pma_verify_fingerprint(pma, rand4fingerprint, sum);
do_delete(pma, "aaa", 4, "athere", 7, rand4fingerprint, &sum, &expect_fingerprint);
do_delete(pma, "aab", 4, "bthere", 7, rand4fingerprint, &sum, &expect_fingerprint);
do_delete(pma, "aac", 4, "cthere", 7, rand4fingerprint, &sum, &expect_fingerprint);
......@@ -331,13 +331,13 @@ static void test_pma_random_pick (void) {
do_delete(pma, "aag", 4, "gthere", 7, rand4fingerprint, &sum, &expect_fingerprint);
do_delete(pma, "hello", 6, "there", 6, rand4fingerprint, &sum, &expect_fingerprint);
r = pma_random_pick(pma, &key, &keylen, &val, &vallen);
r = toku_pma_random_pick(pma, &key, &keylen, &val, &vallen);
assert(r==0);
assert(keylen==4); assert(vallen==7);
assert(strcmp(key,"aaf")==0);
assert(strcmp(val,"fthere")==0);
pma_verify_fingerprint(pma, rand4fingerprint, sum);
r=pma_free(&pma); assert(r==0);
toku_pma_verify_fingerprint(pma, rand4fingerprint, sum);
r=toku_pma_free(&pma); assert(r==0);
assert(pma==0);
}
......@@ -351,14 +351,14 @@ static void test_find_insert (void) {
u_int32_t expect_fingerprint = 0;
pma_create(&pma, toku_default_compare_fun, 0);
r=pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
toku_pma_create(&pma, toku_default_compare_fun, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
assert(r==DB_NOTFOUND);
do_insert(pma, "aaa", 3, "aaadata", 7, rand4fingerprint, &sum, &expect_fingerprint);
init_dbt(&v);
r=pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
assert(r==BRT_OK);
assert(v.size==7);
assert(toku_keycompare(v.data,v.size,"aaadata", 7)==0);
......@@ -367,23 +367,23 @@ static void test_find_insert (void) {
do_insert(pma, "bbb", 4, "bbbdata", 8, rand4fingerprint, &sum, &expect_fingerprint);
init_dbt(&v);
r=pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "aaa", 3), &v, 0);
assert(r==BRT_OK);
assert(toku_keycompare(v.data,v.size,"aaadata", 7)==0);
init_dbt(&v);
r=pma_lookup(pma, fill_dbt(&k, "bbb", 4), &v, 0);
r=toku_pma_lookup(pma, fill_dbt(&k, "bbb", 4), &v, 0);
assert(r==BRT_OK);
assert(toku_keycompare(v.data,v.size,"bbbdata", 8)==0);
assert((unsigned long)pma->pairs[pma_index_limit(pma)]==0xdeadbeefL);
assert((unsigned long)pma->pairs[toku_pma_index_limit(pma)]==0xdeadbeefL);
do_insert(pma, "00000", 6, "d0", 3, rand4fingerprint, &sum, &expect_fingerprint);
assert((unsigned long)pma->pairs[pma_index_limit(pma)]==0xdeadbeefL);
assert((unsigned long)pma->pairs[toku_pma_index_limit(pma)]==0xdeadbeefL);
r=pma_free(&pma); assert(r==0); assert(pma==0);
pma_create(&pma, toku_default_compare_fun, 0); assert(pma!=0);
r=toku_pma_free(&pma); assert(r==0); assert(pma==0);
toku_pma_create(&pma, toku_default_compare_fun, 0); assert(pma!=0);
rand4fingerprint = random();
sum = expect_fingerprint = 0;
......@@ -399,7 +399,7 @@ static void test_find_insert (void) {
do_insert(pma, string, strlen(string)+1, dstring, strlen(dstring)+1, rand4fingerprint, &sum, &expect_fingerprint);
}
}
r=pma_free(&pma); assert(r==0); assert(pma==0);
r=toku_pma_free(&pma); assert(r==0); assert(pma==0);
}
static int tpi_k,tpi_v;
......@@ -413,7 +413,7 @@ static void do_sum_em (bytevec key, ITEMLEN keylen, bytevec val, ITEMLEN vallen,
static void test_pma_iterate_internal (PMA pma, int expected_k, int expected_v) {
tpi_k=tpi_v=0;
pma_iterate(pma, do_sum_em, (void*)0xdeadbeefL);
toku_pma_iterate(pma, do_sum_em, (void*)0xdeadbeefL);
assert(tpi_k==expected_k);
assert(tpi_v==expected_v);
}
......@@ -426,13 +426,13 @@ static void test_pma_iterate (void) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
pma_create(&pma, toku_default_compare_fun, 0);
toku_pma_create(&pma, toku_default_compare_fun, 0);
do_insert(pma, "42", 3, "-19", 4, rand4fingerprint, &sum, &expect_fingerprint);
test_pma_iterate_internal(pma, 42, -19);
do_insert(pma, "12", 3, "-100", 5, rand4fingerprint, &sum, &expect_fingerprint);
test_pma_iterate_internal(pma, 42+12, -19-100);
r=pma_free(&pma); assert(r==0); assert(pma==0);
r=toku_pma_free(&pma); assert(r==0); assert(pma==0);
}
static void test_pma_iterate2 (void) {
......@@ -449,8 +449,8 @@ static void test_pma_iterate2 (void) {
u_int32_t sum1 = 0;
u_int32_t expect_fingerprint1 = 0;
r=pma_create(&pma0, toku_default_compare_fun, 0); assert(r==0);
r=pma_create(&pma1, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma0, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma1, toku_default_compare_fun, 0); assert(r==0);
do_insert(pma0, "a", 2, "aval", 5, rand4fingerprint0, &sum0, &expect_fingerprint0);
do_insert(pma0, "b", 2, "bval", 5, rand4fingerprint0, &sum0, &expect_fingerprint0);
do_insert(pma1, "x", 2, "xval", 5, rand4fingerprint1, &sum1, &expect_fingerprint1);
......@@ -458,8 +458,8 @@ static void test_pma_iterate2 (void) {
PMA_ITERATE(pma1,kv __attribute__((__unused__)),kl,dv __attribute__((__unused__)), dl, (n_items++,sum+=kl+dl));
assert(sum==21);
assert(n_items==3);
r=pma_free(&pma0); assert(r==0); assert(pma0==0);
r=pma_free(&pma1); assert(r==0); assert(pma1==0);
r=toku_pma_free(&pma0); assert(r==0); assert(pma0==0);
r=toku_pma_free(&pma1); assert(r==0); assert(pma1==0);
}
/* Check to see if we can create and kill a cursor. */
......@@ -467,14 +467,14 @@ void test_pma_cursor_0 (void) {
PMA pma;
PMA_CURSOR c=0;
int r;
r=pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=pma_cursor(pma, &c); assert(r==0); assert(c!=0);
r=toku_pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_cursor(pma, &c); assert(r==0); assert(c!=0);
printf("%s:%d\n", __FILE__, __LINE__);
r=pma_free(&pma); assert(r!=0); /* didn't deallocate the cursor. */
r=toku_pma_free(&pma); assert(r!=0); /* didn't deallocate the cursor. */
printf("%s:%d\n", __FILE__, __LINE__);
r=pma_cursor_free(&c); assert(r==0);
r=toku_pma_cursor_free(&c); assert(r==0);
printf("%s:%d\n", __FILE__, __LINE__);
r=pma_free(&pma); assert(r==0); /* did deallocate the cursor. */
r=toku_pma_free(&pma); assert(r==0); /* did deallocate the cursor. */
}
/* Make sure we can free the cursors in any order. There is a doubly linked list of cursors
......@@ -485,27 +485,27 @@ void test_pma_cursor_1 (void) {
int r;
int order;
for (order=0; order<6; order++) {
r=pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=pma_cursor(pma, &c0); assert(r==0); assert(c0!=0);
r=pma_cursor(pma, &c1); assert(r==0); assert(c1!=0);
r=pma_cursor(pma, &c2); assert(r==0); assert(c2!=0);
r=toku_pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_cursor(pma, &c0); assert(r==0); assert(c0!=0);
r=toku_pma_cursor(pma, &c1); assert(r==0); assert(c1!=0);
r=toku_pma_cursor(pma, &c2); assert(r==0); assert(c2!=0);
r=pma_free(&pma); assert(r!=0);
r=toku_pma_free(&pma); assert(r!=0);
if (order<2) { r=pma_cursor_free(&c0); assert(r==0); c0=c1; c1=c2; }
else if (order<4) { r=pma_cursor_free(&c1); assert(r==0); c1=c2; }
else { r=pma_cursor_free(&c2); assert(r==0); }
if (order<2) { r=toku_pma_cursor_free(&c0); assert(r==0); c0=c1; c1=c2; }
else if (order<4) { r=toku_pma_cursor_free(&c1); assert(r==0); c1=c2; }
else { r=toku_pma_cursor_free(&c2); assert(r==0); }
r=pma_free(&pma); assert(r!=0);
r=toku_pma_free(&pma); assert(r!=0);
if (order%2==0) { r=pma_cursor_free(&c0); assert(r==0); c0=c1; }
else { r=pma_cursor_free(&c1); assert(r==0); }
if (order%2==0) { r=toku_pma_cursor_free(&c0); assert(r==0); c0=c1; }
else { r=toku_pma_cursor_free(&c1); assert(r==0); }
r=pma_free(&pma); assert(r!=0);
r=toku_pma_free(&pma); assert(r!=0);
r = pma_cursor_free(&c0); assert(r==0);
r = toku_pma_cursor_free(&c0); assert(r==0);
r=pma_free(&pma); assert(r==0);
r=toku_pma_free(&pma); assert(r==0);
}
}
......@@ -516,11 +516,11 @@ void test_pma_cursor_2 (void) {
DBT key,val;
init_dbt(&key); key.flags=DB_DBT_REALLOC;
init_dbt(&val); val.flags=DB_DBT_REALLOC;
r=pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=pma_cursor(pma, &c); assert(r==0); assert(c!=0);
r=pma_cursor_set_position_last(c); assert(r==DB_NOTFOUND);
r=pma_cursor_free(&c); assert(r==0);
r=pma_free(&pma); assert(r==0);
r=toku_pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_cursor(pma, &c); assert(r==0); assert(c!=0);
r=toku_pma_cursor_set_position_last(c); assert(r==DB_NOTFOUND);
r=toku_pma_cursor_free(&c); assert(r==0);
r=toku_pma_free(&pma); assert(r==0);
}
void test_pma_cursor_3 (void) {
......@@ -533,44 +533,44 @@ void test_pma_cursor_3 (void) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r=pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
r=toku_pma_create(&pma, toku_default_compare_fun, 0); assert(r==0);
do_insert(pma, "x", 2, "xx", 3, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "m", 2, "mm", 3, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "aa", 3, "a", 2, rand4fingerprint, &sum, &expect_fingerprint);
init_dbt(&key); key.flags=DB_DBT_REALLOC;
init_dbt(&val); val.flags=DB_DBT_REALLOC;
r=pma_cursor(pma, &c); assert(r==0); assert(c!=0);
r=toku_pma_cursor(pma, &c); assert(r==0); assert(c!=0);
r=pma_cursor_set_position_first(c); assert(r==0);
r=pma_cursor_get_current(c, &key, &val); assert(r==0);
r=toku_pma_cursor_set_position_first(c); assert(r==0);
r=toku_pma_cursor_get_current(c, &key, &val); assert(r==0);
assert(key.size=3); assert(memcmp(key.data,"aa",3)==0);
assert(val.size=2); assert(memcmp(val.data,"a",2)==0);
r=pma_cursor_set_position_next(c); assert(r==0);
r=pma_cursor_get_current(c, &key, &val); assert(r==0);
r=toku_pma_cursor_set_position_next(c); assert(r==0);
r=toku_pma_cursor_get_current(c, &key, &val); assert(r==0);
assert(key.size=2); assert(memcmp(key.data,"m",2)==0);
assert(val.size=3); assert(memcmp(val.data,"mm",3)==0);
r=pma_cursor_set_position_next(c); assert(r==0);
r=pma_cursor_get_current(c, &key, &val); assert(r==0);
r=toku_pma_cursor_set_position_next(c); assert(r==0);
r=toku_pma_cursor_get_current(c, &key, &val); assert(r==0);
assert(key.size=2); assert(memcmp(key.data,"x",2)==0);
assert(val.size=3); assert(memcmp(val.data,"xx",3)==0);
r=pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND);
r=toku_pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND);
/* After an error, the cursor should still point at the same thing. */
r=pma_cursor_get_current(c, &key, &val); assert(r==0);
r=toku_pma_cursor_get_current(c, &key, &val); assert(r==0);
assert(key.size=2); assert(memcmp(key.data,"x",2)==0);
assert(val.size=3); assert(memcmp(val.data,"xx",3)==0);
r=pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND);
r=toku_pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND);
toku_free(key.data);
toku_free(val.data);
r=pma_cursor_free(&c); assert(r==0);
r=pma_free(&pma); assert(r==0);
r=toku_pma_cursor_free(&c); assert(r==0);
r=toku_pma_free(&pma); assert(r==0);
}
......@@ -580,7 +580,7 @@ void assert_cursor_val(PMA_CURSOR cursor, int v) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &key, &val);
error = toku_pma_cursor_get_current(cursor, &key, &val);
assert(error == 0);
assert( v == *(int *)val.data);
toku_free(key.data);
......@@ -599,7 +599,7 @@ void test_pma_cursor_4 (void) {
u_int32_t expect_fingerprint = 0;
printf("test_pma_cursor_4\n");
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
for (i=1; i<=4; i += 1) {
......@@ -609,27 +609,27 @@ void test_pma_cursor_4 (void) {
v = i;
do_insert(pma, k, strlen(k)+1, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
}
assert(pma_n_entries(pma) == 4);
printf("a:"); print_pma(pma);
assert(toku_pma_n_entries(pma) == 4);
printf("a:"); toku_print_pma(pma);
error = pma_cursor(pma, &cursora);
error = toku_pma_cursor(pma, &cursora);
assert(error == 0);
error = pma_cursor_set_position_first(cursora);
error = toku_pma_cursor_set_position_first(cursora);
assert(error == 0);
assert_cursor_val(cursora, 1);
error = pma_cursor(pma, &cursorb);
error = toku_pma_cursor(pma, &cursorb);
assert(error == 0);
error = pma_cursor_set_position_first(cursorb);
error = toku_pma_cursor_set_position_first(cursorb);
assert(error == 0);
assert_cursor_val(cursorb, 1);
error = pma_cursor_set_position_next(cursorb);
error = toku_pma_cursor_set_position_next(cursorb);
assert(error == 0);
assert_cursor_val(cursorb, 2);
error = pma_cursor(pma, &cursorc);
error = toku_pma_cursor(pma, &cursorc);
assert(error == 0);
error = pma_cursor_set_position_last(cursorc);
error = toku_pma_cursor_set_position_last(cursorc);
assert(error == 0);
assert_cursor_val(cursorc, 4);
......@@ -640,21 +640,21 @@ void test_pma_cursor_4 (void) {
v = i;
do_insert(pma, k, strlen(k)+1, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
}
assert(pma_n_entries(pma) == 8);
printf("a:"); print_pma(pma);
assert(toku_pma_n_entries(pma) == 8);
printf("a:"); toku_print_pma(pma);
assert_cursor_val(cursora, 1);
assert_cursor_val(cursorb, 2);
assert_cursor_val(cursorc, 4);
error = pma_cursor_free(&cursora);
error = toku_pma_cursor_free(&cursora);
assert(error == 0);
error = pma_cursor_free(&cursorb);
error = toku_pma_cursor_free(&cursorb);
assert(error == 0);
error = pma_cursor_free(&cursorc);
error = toku_pma_cursor_free(&cursorc);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -668,7 +668,7 @@ void test_pma_cursor_delete(int n) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
/* insert 1 -> 42 */
......@@ -681,22 +681,22 @@ void test_pma_cursor_delete(int n) {
/* point the cursor to the first kv */
PMA_CURSOR cursor;
error = pma_cursor(pma, &cursor);
error = toku_pma_cursor(pma, &cursor);
assert(error == 0);
DBT cursorkey, cursorval;
init_dbt(&cursorkey); cursorkey.flags = DB_DBT_MALLOC;
init_dbt(&cursorval); cursorval.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &cursorkey, &cursorval);
error = toku_pma_cursor_get_current(cursor, &cursorkey, &cursorval);
assert(error != 0);
error = pma_cursor_set_position_first(cursor);
error = toku_pma_cursor_set_position_first(cursor);
assert(error == 0);
int kk;
init_dbt(&cursorkey); cursorkey.flags = DB_DBT_MALLOC;
init_dbt(&cursorval); cursorval.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &cursorkey, &cursorval);
error = toku_pma_cursor_get_current(cursor, &cursorkey, &cursorval);
assert(error == 0);
assert(cursorkey.size == sizeof kk);
kk = 0;
......@@ -711,17 +711,17 @@ void test_pma_cursor_delete(int n) {
/* cursor get should fail */
init_dbt(&cursorkey); cursorkey.flags = DB_DBT_MALLOC;
init_dbt(&cursorval); cursorval.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &cursorkey, &cursorval);
error = toku_pma_cursor_get_current(cursor, &cursorkey, &cursorval);
assert(error != 0);
error = pma_cursor_set_position_next(cursor);
error = toku_pma_cursor_set_position_next(cursor);
if (n <= 1)
assert(error != 0);
else {
assert(error == 0);
init_dbt(&cursorkey); cursorkey.flags = DB_DBT_MALLOC;
init_dbt(&cursorval); cursorval.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &cursorkey, &cursorval);
error = toku_pma_cursor_get_current(cursor, &cursorkey, &cursorval);
assert(error == 0);
assert(cursorkey.size == sizeof kk);
kk = 1;
......@@ -730,10 +730,10 @@ void test_pma_cursor_delete(int n) {
toku_free(cursorval.data);
}
error = pma_cursor_free(&cursor);
error = toku_pma_cursor_free(&cursor);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -776,35 +776,35 @@ void test_pma_compare_fun (int wrong_endian_p) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = pma_create(&pma, wrong_endian_p ? wrong_endian_compare_fun : toku_default_compare_fun, 0); assert(r==0);
r = toku_pma_create(&pma, wrong_endian_p ? wrong_endian_compare_fun : toku_default_compare_fun, 0); assert(r==0);
do_insert(pma, "10", 3, "10v", 4, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "00", 3, "00v", 4, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "01", 3, "01v", 4, rand4fingerprint, &sum, &expect_fingerprint);
do_insert(pma, "11", 3, "11v", 4, rand4fingerprint, &sum, &expect_fingerprint);
init_dbt(&key); key.flags=DB_DBT_REALLOC;
init_dbt(&val); val.flags=DB_DBT_REALLOC;
r=pma_cursor(pma, &c); assert(r==0); assert(c!=0);
r=toku_pma_cursor(pma, &c); assert(r==0); assert(c!=0);
for (i=0; i<4; i++) {
if (i==0) {
r=pma_cursor_set_position_first(c); assert(r==0);
r=toku_pma_cursor_set_position_first(c); assert(r==0);
} else {
r=pma_cursor_set_position_next(c); assert(r==0);
r=toku_pma_cursor_set_position_next(c); assert(r==0);
}
r=pma_cursor_get_current(c, &key, &val); assert(r==0);
r=toku_pma_cursor_get_current(c, &key, &val); assert(r==0);
//printf("Got %s, expect %s\n", (char*)key.data, expected_keys[i]);
assert(key.size=3); assert(memcmp(key.data,expected_keys[i],3)==0);
assert(val.size=4); assert(memcmp(val.data,expected_keys[i],2)==0);
assert(memcmp(2+(char*)val.data,"v",2)==0);
}
r=pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND);
r=toku_pma_cursor_set_position_next(c); assert(r==DB_NOTFOUND);
toku_free(key.data);
toku_free(val.data);
r=pma_cursor_free(&c); assert(r==0);
r=pma_free(&pma); assert(r==0);
r=toku_pma_cursor_free(&c); assert(r==0);
r=toku_pma_free(&pma); assert(r==0);
}
void test_pma_split_n(int n) {
......@@ -824,11 +824,11 @@ void test_pma_split_n(int n) {
printf("test_pma_split_n:%d\n", n);
error = pma_create(&pmaa, toku_default_compare_fun, 0);
error = toku_pma_create(&pmaa, toku_default_compare_fun, 0);
assert(error == 0);
error = pma_create(&pmab, toku_default_compare_fun, 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, 0);
assert(error == 0);
error = pma_create(&pmac, toku_default_compare_fun, 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, 0);
assert(error == 0);
/* insert some kv pairs */
......@@ -839,34 +839,34 @@ void test_pma_split_n(int n) {
v = i;
do_insert(pmaa, k, strlen(k)+1, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pmaa, null_db);
toku_pma_verify(pmaa, null_db);
}
printf("a:"); print_pma(pmaa);
printf("a:"); toku_print_pma(pmaa);
error = pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
error = toku_pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
assert(error == 0);
pma_verify(pmaa, null_db);
pma_verify(pmab, null_db);
pma_verify(pmac, null_db);
pma_verify_fingerprint(pmab, brand, bsum);
pma_verify_fingerprint(pmac, crand, csum);
toku_pma_verify(pmaa, null_db);
toku_pma_verify(pmab, null_db);
toku_pma_verify(pmac, null_db);
toku_pma_verify_fingerprint(pmab, brand, bsum);
toku_pma_verify_fingerprint(pmac, crand, csum);
printf("a:"); print_pma(pmaa);
na = pma_n_entries(pmaa);
printf("b:"); print_pma(pmab);
nb = pma_n_entries(pmab);
printf("c:"); print_pma(pmac);
nc = pma_n_entries(pmac);
printf("a:"); toku_print_pma(pmaa);
na = toku_pma_n_entries(pmaa);
printf("b:"); toku_print_pma(pmab);
nb = toku_pma_n_entries(pmab);
printf("c:"); toku_print_pma(pmac);
nc = toku_pma_n_entries(pmac);
assert(na == 0);
assert(nb + nc == n);
error = pma_free(&pmaa);
error = toku_pma_free(&pmaa);
assert(error == 0);
error = pma_free(&pmab);
error = toku_pma_free(&pmab);
assert(error == 0);
error = pma_free(&pmac);
error = toku_pma_free(&pmac);
assert(error == 0);
}
......@@ -887,15 +887,15 @@ void test_pma_dup_split_n(int n, int dup_mode) {
printf("test_pma_dup_split_n:%d %d\n", n, dup_mode);
error = pma_create(&pmaa, toku_default_compare_fun, 0);
error = toku_pma_create(&pmaa, toku_default_compare_fun, 0);
assert(error == 0);
pma_set_dup_mode(pmaa, dup_mode);
error = pma_create(&pmab, toku_default_compare_fun, 0);
toku_pma_set_dup_mode(pmaa, dup_mode);
error = toku_pma_create(&pmab, toku_default_compare_fun, 0);
assert(error == 0);
pma_set_dup_mode(pmab, dup_mode);
error = pma_create(&pmac, toku_default_compare_fun, 0);
toku_pma_set_dup_mode(pmab, dup_mode);
error = toku_pma_create(&pmac, toku_default_compare_fun, 0);
assert(error == 0);
pma_set_dup_mode(pmac, dup_mode);
toku_pma_set_dup_mode(pmac, dup_mode);
/* insert some kv pairs */
int dupkey = random();
......@@ -903,27 +903,27 @@ void test_pma_dup_split_n(int n, int dup_mode) {
int v = i;
do_insert(pmaa, &dupkey, sizeof dupkey, &v, sizeof v, rand4sum, &sum, &expect_sum);
pma_verify(pmaa, null_db);
toku_pma_verify(pmaa, null_db);
}
printf("a:"); print_pma(pmaa);
printf("a:"); toku_print_pma(pmaa);
DBT splitk;
error = pma_split(pmaa, 0, &splitk, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
error = toku_pma_split(pmaa, 0, &splitk, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
assert(error == 0);
pma_verify(pmaa, null_db);
pma_verify(pmab, null_db);
pma_verify(pmac, null_db);
pma_verify_fingerprint(pmab, brand, bsum);
pma_verify_fingerprint(pmac, crand, csum);
toku_pma_verify(pmaa, null_db);
toku_pma_verify(pmab, null_db);
toku_pma_verify(pmac, null_db);
toku_pma_verify_fingerprint(pmab, brand, bsum);
toku_pma_verify_fingerprint(pmac, crand, csum);
if (0) { printf("a:"); print_pma(pmaa); }
na = pma_n_entries(pmaa);
if (0) { printf("b:"); print_pma(pmab); }
nb = pma_n_entries(pmab);
if (0) { printf("c:"); print_pma(pmac); }
nc = pma_n_entries(pmac);
if (0) { printf("a:"); toku_print_pma(pmaa); }
na = toku_pma_n_entries(pmaa);
if (0) { printf("b:"); toku_print_pma(pmab); }
nb = toku_pma_n_entries(pmab);
if (0) { printf("c:"); toku_print_pma(pmac); }
nc = toku_pma_n_entries(pmac);
if (na > 0) {
int kk;
......@@ -939,11 +939,11 @@ void test_pma_dup_split_n(int n, int dup_mode) {
assert(na == 0);
assert(nb + nc == n);
error = pma_free(&pmaa);
error = toku_pma_free(&pmaa);
assert(error == 0);
error = pma_free(&pmab);
error = toku_pma_free(&pmab);
assert(error == 0);
error = pma_free(&pmac);
error = toku_pma_free(&pmac);
assert(error == 0);
}
......@@ -966,11 +966,11 @@ void test_pma_split_varkey(void) {
printf("test_pma_split_varkey\n");
error = pma_create(&pmaa, toku_default_compare_fun, 0);
error = toku_pma_create(&pmaa, toku_default_compare_fun, 0);
assert(error == 0);
error = pma_create(&pmab, toku_default_compare_fun, 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, 0);
assert(error == 0);
error = pma_create(&pmac, toku_default_compare_fun, 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, 0);
assert(error == 0);
/* insert some kv pairs */
......@@ -980,31 +980,31 @@ void test_pma_split_varkey(void) {
}
n = i;
printf("a:"); print_pma(pmaa);
printf("a:"); toku_print_pma(pmaa);
error = pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
error = toku_pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
assert(error == 0);
pma_verify(pmaa, null_db);
pma_verify(pmab, null_db);
pma_verify(pmac, null_db);
pma_verify_fingerprint(pmab, brand, bsum);
pma_verify_fingerprint(pmac, crand, csum);
toku_pma_verify(pmaa, null_db);
toku_pma_verify(pmab, null_db);
toku_pma_verify(pmac, null_db);
toku_pma_verify_fingerprint(pmab, brand, bsum);
toku_pma_verify_fingerprint(pmac, crand, csum);
printf("a:"); print_pma(pmaa);
na = pma_n_entries(pmaa);
printf("b:"); print_pma(pmab);
nb = pma_n_entries(pmab);
printf("c:"); print_pma(pmac);
nc = pma_n_entries(pmac);
printf("a:"); toku_print_pma(pmaa);
na = toku_pma_n_entries(pmaa);
printf("b:"); toku_print_pma(pmab);
nb = toku_pma_n_entries(pmab);
printf("c:"); toku_print_pma(pmac);
nc = toku_pma_n_entries(pmac);
assert(na == 0);
assert(nb + nc == n);
error = pma_free(&pmaa);
error = toku_pma_free(&pmaa);
assert(error == 0);
error = pma_free(&pmab);
error = toku_pma_free(&pmab);
assert(error == 0);
error = pma_free(&pmac);
error = toku_pma_free(&pmac);
assert(error == 0);
}
......@@ -1015,7 +1015,7 @@ void print_cursor(const char *str, PMA_CURSOR cursor) {
printf("cursor %s: ", str);
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &key, &val);
error = toku_pma_cursor_get_current(cursor, &key, &val);
assert(error == 0);
printf("%s ", (char*)key.data);
toku_free(key.data);
......@@ -1031,13 +1031,13 @@ void walk_cursor(const char *str, PMA_CURSOR cursor) {
for (;;) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &key, &val);
error = toku_pma_cursor_get_current(cursor, &key, &val);
assert(error == 0);
printf("%s ", (char*)key.data);
toku_free(key.data);
toku_free(val.data);
error = pma_cursor_set_position_next(cursor);
error = toku_pma_cursor_set_position_next(cursor);
if (error != 0)
break;
}
......@@ -1052,13 +1052,13 @@ void walk_cursor_reverse(const char *str, PMA_CURSOR cursor) {
for (;;) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &key, &val);
error = toku_pma_cursor_get_current(cursor, &key, &val);
assert(error == 0);
printf("%s ", (char*)key.data);
toku_free(key.data);
toku_free(val.data);
error = pma_cursor_set_position_prev(cursor);
error = toku_pma_cursor_set_position_prev(cursor);
if (error != 0)
break;
}
......@@ -1084,11 +1084,11 @@ void test_pma_split_cursor(void) {
printf("test_pma_split_cursor\n");
error = pma_create(&pmaa, toku_default_compare_fun, 0);
error = toku_pma_create(&pmaa, toku_default_compare_fun, 0);
assert(error == 0);
error = pma_create(&pmab, toku_default_compare_fun, 0);
error = toku_pma_create(&pmab, toku_default_compare_fun, 0);
assert(error == 0);
error = pma_create(&pmac, toku_default_compare_fun, 0);
error = toku_pma_create(&pmac, toku_default_compare_fun, 0);
assert(error == 0);
/* insert some kv pairs */
......@@ -1100,49 +1100,49 @@ void test_pma_split_cursor(void) {
do_insert(pmaa, k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
}
assert(pma_n_entries(pmaa) == 16);
printf("a:"); print_pma(pmaa);
assert(toku_pma_n_entries(pmaa) == 16);
printf("a:"); toku_print_pma(pmaa);
error = pma_cursor(pmaa, &cursora);
error = toku_pma_cursor(pmaa, &cursora);
assert(error == 0);
error = pma_cursor_set_position_first(cursora);
error = toku_pma_cursor_set_position_first(cursora);
assert(error == 0);
// print_cursor("cursora", cursora);
assert_cursor_val(cursora, 1);
error = pma_cursor(pmaa, &cursorb);
error = toku_pma_cursor(pmaa, &cursorb);
assert(error == 0);
error = pma_cursor_set_position_first(cursorb);
error = toku_pma_cursor_set_position_first(cursorb);
assert(error == 0);
error = pma_cursor_set_position_next(cursorb);
error = toku_pma_cursor_set_position_next(cursorb);
assert(error == 0);
// print_cursor("cursorb", cursorb);
assert_cursor_val(cursorb, 2);
error = pma_cursor(pmaa, &cursorc);
error = toku_pma_cursor(pmaa, &cursorc);
assert(error == 0);
error = pma_cursor_set_position_last(cursorc);
error = toku_pma_cursor_set_position_last(cursorc);
assert(error == 0);
// print_cursor("cursorc", cursorc);
assert_cursor_val(cursorc, 16);
error = pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
error = toku_pma_split(pmaa, 0, 0, null_db, pmab, 0, brand, &bsum, pmac, 0, crand, &csum);
assert(error == 0);
pma_verify_fingerprint(pmab, brand, bsum);
pma_verify_fingerprint(pmac, crand, csum);
toku_pma_verify_fingerprint(pmab, brand, bsum);
toku_pma_verify_fingerprint(pmac, crand, csum);
printf("a:"); print_pma(pmaa);
na = pma_n_entries(pmaa);
printf("a:"); toku_print_pma(pmaa);
na = toku_pma_n_entries(pmaa);
assert(na == 0);
printf("b:"); print_pma(pmab);
nb = pma_n_entries(pmab);
printf("c:"); print_pma(pmac);
nc = pma_n_entries(pmac);
printf("b:"); toku_print_pma(pmab);
nb = toku_pma_n_entries(pmab);
printf("c:"); toku_print_pma(pmac);
nc = toku_pma_n_entries(pmac);
assert(nb + nc == 16);
/* cursors open, should fail */
error = pma_free(&pmab);
error = toku_pma_free(&pmab);
assert(error != 0);
/* walk cursora */
......@@ -1158,18 +1158,18 @@ void test_pma_split_cursor(void) {
walk_cursor("cursorc", cursorc);
walk_cursor_reverse("cursorc reverse", cursorc);
error = pma_cursor_free(&cursora);
error = toku_pma_cursor_free(&cursora);
assert(error == 0);
error = pma_cursor_free(&cursorb);
error = toku_pma_cursor_free(&cursorb);
assert(error == 0);
error = pma_cursor_free(&cursorc);
error = toku_pma_cursor_free(&cursorc);
assert(error == 0);
error = pma_free(&pmaa);
error = toku_pma_free(&pmaa);
assert(error == 0);
error = pma_free(&pmab);
error = toku_pma_free(&pmab);
assert(error == 0);
error = pma_free(&pmac);
error = toku_pma_free(&pmac);
assert(error == 0);
}
......@@ -1188,7 +1188,7 @@ void test_pma_split(void) {
}
/*
* test the pma_bulk_insert function by creating n kv pairs and bulk
* test the toku_pma_bulk_insert function by creating n kv pairs and bulk
* inserting them into an empty pma. verify that the pma contains all
* of the kv pairs.
*/
......@@ -1204,7 +1204,7 @@ void test_pma_bulk_insert_n(int n) {
printf("test_pma_bulk_insert_n: %d\n", n);
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
/* init n kv pairs */
......@@ -1236,19 +1236,19 @@ void test_pma_bulk_insert_n(int n) {
}
/* bulk insert n kv pairs */
error = pma_bulk_insert(pma, keys, vals, n, rand4fingerprint, &sum);
error = toku_pma_bulk_insert(pma, keys, vals, n, rand4fingerprint, &sum);
assert(error == 0);
assert(sum==expect_fingerprint);
pma_verify(pma, null_db);
pma_verify_fingerprint(pma, rand4fingerprint, sum);
toku_pma_verify(pma, null_db);
toku_pma_verify_fingerprint(pma, rand4fingerprint, sum);
/* verify */
if (0) print_pma(pma);
assert(n == pma_n_entries(pma));
if (0) toku_print_pma(pma);
assert(n == toku_pma_n_entries(pma));
for (i=0; i<n; i++) {
DBT val;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_lookup(pma, &keys[i], &val, 0);
error = toku_pma_lookup(pma, &keys[i], &val, 0);
assert(error == 0);
assert(vals[i].size == val.size);
assert(memcmp(vals[i].data, val.data, val.size) == 0);
......@@ -1261,7 +1261,7 @@ void test_pma_bulk_insert_n(int n) {
toku_free(vals[i].data);
}
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
toku_free(keys);
......@@ -1287,38 +1287,38 @@ void test_pma_insert_or_replace(void) {
u_int32_t rand4fingerprint = random();
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = pma_create(&pma, toku_default_compare_fun, 0);
r = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(r==0);
r = pma_insert_or_replace(pma, fill_dbt(&dbtk, "aaa", 4), fill_dbt(&dbtv, "zzz", 4), &n_diff, NULL_ARGS, rand4fingerprint, &sum);
r = toku_pma_insert_or_replace(pma, fill_dbt(&dbtk, "aaa", 4), fill_dbt(&dbtv, "zzz", 4), &n_diff, NULL_ARGS, rand4fingerprint, &sum);
assert(r==0); assert(n_diff==-1);
add_fingerprint_and_check(rand4fingerprint, sum, &expect_fingerprint, "aaa", 4, "zzz", 4);
r = pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
assert(r==0); assert(dbtv.size==4); assert(memcmp(dbtv.data, "zzz", 4)==0);
r = pma_insert_or_replace(pma, fill_dbt(&dbtk, "bbbb", 5), fill_dbt(&dbtv, "ww", 3), &n_diff, NULL_ARGS, rand4fingerprint, &sum);
r = toku_pma_insert_or_replace(pma, fill_dbt(&dbtk, "bbbb", 5), fill_dbt(&dbtv, "ww", 3), &n_diff, NULL_ARGS, rand4fingerprint, &sum);
assert(r==0); assert(n_diff==-1);
add_fingerprint_and_check(rand4fingerprint, sum, &expect_fingerprint, "bbbb", 5, "ww", 3);
r = pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
assert(r==0); assert(dbtv.size==4); assert(memcmp(dbtv.data, "zzz", 4)==0);
r = pma_lookup(pma, fill_dbt(&dbtk, "bbbb", 5), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "bbbb", 5), init_dbt(&dbtv), 0);
assert(r==0); assert(dbtv.size==3); assert(memcmp(dbtv.data, "ww", 3)==0);
// replae bbbb
r = pma_insert_or_replace(pma, fill_dbt(&dbtk, "bbbb", 5), fill_dbt(&dbtv, "xxxx", 5), &n_diff, NULL_ARGS, rand4fingerprint, &sum);
r = toku_pma_insert_or_replace(pma, fill_dbt(&dbtk, "bbbb", 5), fill_dbt(&dbtv, "xxxx", 5), &n_diff, NULL_ARGS, rand4fingerprint, &sum);
assert(r==0); assert(n_diff==3);
expect_fingerprint -= rand4fingerprint*toku_calccrc32_kvpair("bbbb", 5, "ww", 3);
add_fingerprint_and_check(rand4fingerprint, sum, &expect_fingerprint, "bbbb", 5, "xxxx", 5);
r = pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "aaa", 4), init_dbt(&dbtv), 0);
assert(r==0); assert(dbtv.size==4); assert(memcmp(dbtv.data, "zzz", 4)==0);
r = pma_lookup(pma, fill_dbt(&dbtk, "bbbb", 5), init_dbt(&dbtv), 0);
r = toku_pma_lookup(pma, fill_dbt(&dbtk, "bbbb", 5), init_dbt(&dbtv), 0);
assert(r==0); assert(dbtv.size==5); assert(memcmp(dbtv.data, "xxxx", 3)==0);
r=pma_free(&pma);
r=toku_pma_free(&pma);
assert(r==0);
}
......@@ -1336,7 +1336,7 @@ void test_pma_delete_shrink(int n) {
printf("test_pma_delete_shrink:%d\n", n);
r = pma_create(&pma, toku_default_compare_fun, n*(8 + 11 + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, n*(8 + 11 + sizeof (int)));
assert(r == 0);
/* insert */
......@@ -1360,7 +1360,7 @@ void test_pma_delete_shrink(int n) {
}
assert(pma->N == PMA_MIN_ARRAY_SIZE);
r = pma_free(&pma);
r = toku_pma_free(&pma);
assert(r == 0);
}
......@@ -1380,7 +1380,7 @@ void test_pma_delete_random(int n) {
printf("test_pma_delete_random:%d\n", n);
r = pma_create(&pma, toku_default_compare_fun, n * (8 + 11 + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, n * (8 + 11 + sizeof (int)));
assert(r == 0);
for (i=0; i<n; i++) {
......@@ -1408,7 +1408,7 @@ void test_pma_delete_random(int n) {
}
assert(pma->N == PMA_MIN_ARRAY_SIZE);
r = pma_free(&pma);
r = toku_pma_free(&pma);
assert(r == 0);
}
......@@ -1417,7 +1417,7 @@ void assert_cursor_equal(PMA_CURSOR pmacursor, int v) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
int r;
r = pma_cursor_get_current(pmacursor, &key, &val);
r = toku_pma_cursor_get_current(pmacursor, &key, &val);
assert(r == 0);
if (0) printf("key %s\n", (char*) key.data);
int thev;
......@@ -1433,7 +1433,7 @@ void assert_cursor_nokey(PMA_CURSOR pmacursor) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
int r;
r = pma_cursor_get_current(pmacursor, &key, &val);
r = toku_pma_cursor_get_current(pmacursor, &key, &val);
assert(r != 0);
}
......@@ -1454,7 +1454,7 @@ void test_pma_delete_cursor(int n) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = pma_create(&pma, toku_default_compare_fun, 0);
r = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(r == 0);
int i;
......@@ -1469,10 +1469,10 @@ void test_pma_delete_cursor(int n) {
PMA_CURSOR pmacursor;
r = pma_cursor(pma, &pmacursor);
r = toku_pma_cursor(pma, &pmacursor);
assert(r == 0);
r = pma_cursor_set_position_last(pmacursor);
r = toku_pma_cursor_set_position_last(pmacursor);
assert(r == 0);
assert_cursor_equal(pmacursor, n-1);
......@@ -1490,10 +1490,10 @@ void test_pma_delete_cursor(int n) {
}
assert(pma->N == PMA_MIN_ARRAY_SIZE);
r = pma_cursor_free(&pmacursor);
r = toku_pma_cursor_free(&pmacursor);
assert(r == 0);
r = pma_free(&pma);
r = toku_pma_free(&pma);
assert(r == 0);
}
......@@ -1517,12 +1517,12 @@ void test_pma_delete_insert() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
PMA_CURSOR pmacursor;
error = pma_cursor(pma, &pmacursor);
error = toku_pma_cursor(pma, &pmacursor);
assert(error == 0);
DBT key, val;
......@@ -1531,7 +1531,7 @@ void test_pma_delete_insert() {
k = 1; v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
error = pma_cursor_set_position_first(pmacursor);
error = toku_pma_cursor_set_position_first(pmacursor);
assert(error == 0);
assert_cursor_equal(pmacursor, 1);
......@@ -1542,17 +1542,17 @@ void test_pma_delete_insert() {
k = 1;
fill_dbt(&key, &k, sizeof k);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_lookup(pma, &key, &val, 0);
error = toku_pma_lookup(pma, &key, &val, 0);
assert(error != 0);
k = 1; v = 2;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
assert_cursor_equal(pmacursor, 2);
error = pma_cursor_free(&pmacursor);
error = toku_pma_cursor_free(&pmacursor);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -1566,12 +1566,12 @@ void test_pma_double_delete() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
PMA_CURSOR pmacursor;
error = pma_cursor(pma, &pmacursor);
error = toku_pma_cursor(pma, &pmacursor);
assert(error == 0);
DBT key;
......@@ -1580,7 +1580,7 @@ void test_pma_double_delete() {
k = 1; v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
error = pma_cursor_set_position_first(pmacursor);
error = toku_pma_cursor_set_position_first(pmacursor);
assert(error == 0);
assert_cursor_equal(pmacursor, 1);
......@@ -1590,14 +1590,14 @@ void test_pma_double_delete() {
k = 1;
fill_dbt(&key, &k, sizeof k);
error = pma_delete(pma, &key, 0, rand4fingerprint, &sum, 0);
error = toku_pma_delete(pma, &key, 0, rand4fingerprint, &sum, 0);
assert(error == DB_NOTFOUND);
assert(sum == expect_fingerprint);
error = pma_cursor_free(&pmacursor);
error = toku_pma_cursor_free(&pmacursor);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -1611,7 +1611,7 @@ void test_pma_cursor_first_delete_last() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
int k, v;
......@@ -1622,29 +1622,29 @@ void test_pma_cursor_first_delete_last() {
v = i;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
}
assert(pma_n_entries(pma) == 2);
assert(toku_pma_n_entries(pma) == 2);
PMA_CURSOR pmacursor;
error = pma_cursor(pma, &pmacursor);
error = toku_pma_cursor(pma, &pmacursor);
assert(error == 0);
error = pma_cursor_set_position_first(pmacursor);
error = toku_pma_cursor_set_position_first(pmacursor);
assert(error == 0);
k = htonl(1);
v = 1;
do_delete(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
assert(pma_n_entries(pma) == 2);
assert(toku_pma_n_entries(pma) == 2);
error = pma_cursor_set_position_last(pmacursor);
error = toku_pma_cursor_set_position_last(pmacursor);
assert(error == 0);
assert(pma_n_entries(pma) == 1);
assert(toku_pma_n_entries(pma) == 1);
error = pma_cursor_free(&pmacursor);
error = toku_pma_cursor_free(&pmacursor);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -1658,7 +1658,7 @@ void test_pma_cursor_last_delete_first() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
int k, v;
......@@ -1669,29 +1669,29 @@ void test_pma_cursor_last_delete_first() {
v = i;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
}
assert(pma_n_entries(pma) == 2);
assert(toku_pma_n_entries(pma) == 2);
PMA_CURSOR pmacursor;
error = pma_cursor(pma, &pmacursor);
error = toku_pma_cursor(pma, &pmacursor);
assert(error == 0);
error = pma_cursor_set_position_last(pmacursor);
error = toku_pma_cursor_set_position_last(pmacursor);
assert(error == 0);
k = htonl(2);
v = 2;
do_delete(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
assert(pma_n_entries(pma) == 2);
assert(toku_pma_n_entries(pma) == 2);
error = pma_cursor_set_position_first(pmacursor);
error = toku_pma_cursor_set_position_first(pmacursor);
assert(error == 0);
assert(pma_n_entries(pma) == 1);
assert(toku_pma_n_entries(pma) == 1);
error = pma_cursor_free(&pmacursor);
error = toku_pma_cursor_free(&pmacursor);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -1714,7 +1714,7 @@ void test_pma_already_there() {
u_int32_t rand4fingerprint = random();
u_int32_t sum = 0;
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
DBT key, val;
......@@ -1723,14 +1723,14 @@ void test_pma_already_there() {
k = 1; v = 1;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = pma_insert(pma, &key, &val, NULL_ARGS, rand4fingerprint, &sum);
error = toku_pma_insert(pma, &key, &val, NULL_ARGS, rand4fingerprint, &sum);
assert(error == 0);
u_int32_t savesum = sum;
error = pma_insert(pma, &key, &val, NULL_ARGS, rand4fingerprint, &sum);
error = toku_pma_insert(pma, &key, &val, NULL_ARGS, rand4fingerprint, &sum);
assert(error == BRT_ALREADY_THERE);
assert(sum==savesum);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -1740,7 +1740,7 @@ void test_pma_cursor_set_key() {
int error;
PMA pma;
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
DBT key, val;
......@@ -1759,17 +1759,17 @@ void test_pma_cursor_set_key() {
}
PMA_CURSOR cursor;
error = pma_cursor(pma, &cursor);
error = toku_pma_cursor(pma, &cursor);
assert(error == 0);
for (i=0; i<n; i += 1) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
error = pma_cursor_set_key(cursor, &key, 0);
error = toku_pma_cursor_set_key(cursor, &key, 0);
if (i % 10 == 0) {
assert(error == 0);
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &key, &val);
error = toku_pma_cursor_get_current(cursor, &key, &val);
assert(error == 0);
int vv;
assert(val.size == sizeof vv);
......@@ -1780,10 +1780,10 @@ void test_pma_cursor_set_key() {
assert(error == DB_NOTFOUND);
}
error = pma_cursor_free(&cursor);
error = toku_pma_cursor_free(&cursor);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -1800,7 +1800,7 @@ void test_pma_cursor_set_range() {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
error = pma_create(&pma, toku_default_compare_fun, 0);
error = toku_pma_create(&pma, toku_default_compare_fun, 0);
assert(error == 0);
DBT key, val;
......@@ -1816,19 +1816,19 @@ void test_pma_cursor_set_range() {
}
PMA_CURSOR cursor;
error = pma_cursor(pma, &cursor);
error = toku_pma_cursor(pma, &cursor);
assert(error == 0);
for (i=0; i<100; i += 1) {
k = htonl(i);
fill_dbt(&key, &k, sizeof k);
error = pma_cursor_set_range(cursor, &key, 0);
error = toku_pma_cursor_set_range(cursor, &key, 0);
if (error != 0) {
assert(error == DB_NOTFOUND);
assert(i > largest_key);
} else {
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &key, &val);
error = toku_pma_cursor_get_current(cursor, &key, &val);
assert(error == 0);
int vv;
assert(val.size == sizeof vv);
......@@ -1841,10 +1841,10 @@ void test_pma_cursor_set_range() {
}
}
error = pma_cursor_free(&cursor);
error = toku_pma_cursor_free(&cursor);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -1860,17 +1860,17 @@ void test_pma_cursor_delete_under() {
const int n = 1000;
error = pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
error = toku_pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
assert(error == 0);
PMA_CURSOR cursor;
error = pma_cursor(pma, &cursor);
error = toku_pma_cursor(pma, &cursor);
assert(error == 0);
int kvsize;
/* delete under an uninitialized cursor should fail */
error = pma_cursor_delete_under(cursor, &kvsize);
error = toku_pma_cursor_delete_under(cursor, &kvsize);
assert(error == DB_NOTFOUND);
DBT key, val;
......@@ -1886,14 +1886,14 @@ void test_pma_cursor_delete_under() {
}
for (i=0;;i++) {
error = pma_cursor_set_position_next(cursor);
error = toku_pma_cursor_set_position_next(cursor);
if (error != 0) {
assert(error == DB_NOTFOUND);
break;
}
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &key, &val);
error = toku_pma_cursor_get_current(cursor, &key, &val);
assert(error == 0);
int vv;
assert(val.size == sizeof vv);
......@@ -1903,20 +1903,20 @@ void test_pma_cursor_delete_under() {
toku_free(val.data);
/* delete under should succeed */
error = pma_cursor_delete_under(cursor, &kvsize);
error = toku_pma_cursor_delete_under(cursor, &kvsize);
assert(error == 0);
/* 2nd delete under should fail */
error = pma_cursor_delete_under(cursor, &kvsize);
error = toku_pma_cursor_delete_under(cursor, &kvsize);
assert(error == DB_NOTFOUND);
}
assert(i == n);
error = pma_cursor_free(&cursor);
error = toku_pma_cursor_free(&cursor);
assert(error == 0);
assert(pma_n_entries(pma) == 0);
assert(toku_pma_n_entries(pma) == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -1932,11 +1932,11 @@ void test_pma_cursor_set_both() {
const int n = 1000;
error = pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
error = toku_pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
assert(error == 0);
PMA_CURSOR cursor;
error = pma_cursor(pma, &cursor);
error = toku_pma_cursor(pma, &cursor);
assert(error == 0);
DBT key, val;
......@@ -1955,7 +1955,7 @@ void test_pma_cursor_set_both() {
k = n+1; v = 0;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = pma_cursor_set_both(cursor, &key, &val, 0);
error = toku_pma_cursor_set_both(cursor, &key, &val, 0);
assert(error == DB_NOTFOUND);
/* key match, data mismatch should fail */
......@@ -1964,7 +1964,7 @@ void test_pma_cursor_set_both() {
v = i+1;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = pma_cursor_set_both(cursor, &key, &val, 0);
error = toku_pma_cursor_set_both(cursor, &key, &val, 0);
assert(error == DB_NOTFOUND);
}
......@@ -1974,12 +1974,12 @@ void test_pma_cursor_set_both() {
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
error = pma_cursor_set_both(cursor, &key, &val, 0);
error = toku_pma_cursor_set_both(cursor, &key, &val, 0);
assert(error == 0);
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
error = pma_cursor_get_current(cursor, &key, &val);
error = toku_pma_cursor_get_current(cursor, &key, &val);
assert(error == 0);
int vv;
assert(val.size == sizeof vv);
......@@ -1989,10 +1989,10 @@ void test_pma_cursor_set_both() {
toku_free(val.data);
}
error = pma_cursor_free(&cursor);
error = toku_pma_cursor_free(&cursor);
assert(error == 0);
error = pma_free(&pma);
error = toku_pma_free(&pma);
assert(error == 0);
}
......@@ -2007,7 +2007,7 @@ void test_nodup_key_insert(int n) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, n * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
/* insert 0->0, 0->1, .. 0->n-1 */
......@@ -2019,7 +2019,7 @@ void test_nodup_key_insert(int n) {
v = i;
fill_dbt(&key, &k, sizeof k);
fill_dbt(&val, &v, sizeof v);
r = pma_insert(pma, &key, &val, NULL_ARGS, rand4fingerprint, &sum);
r = toku_pma_insert(pma, &key, &val, NULL_ARGS, rand4fingerprint, &sum);
if (i == 0) {
assert(r == 0);
add_fingerprint_and_check(rand4fingerprint, sum, &expect_fingerprint, &k, sizeof k, &v, sizeof v);
......@@ -2029,7 +2029,7 @@ void test_nodup_key_insert(int n) {
}
}
r = pma_free(&pma);
r = toku_pma_free(&pma);
assert(r == 0);
}
......@@ -2044,11 +2044,11 @@ void test_dup_key_insert(int n) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
r = pma_set_dup_mode(pma, TOKU_DB_DUP);
r = toku_pma_set_dup_mode(pma, TOKU_DB_DUP);
assert(r == 0);
......@@ -2058,10 +2058,10 @@ void test_dup_key_insert(int n) {
/* insert 1->1, 3->3 */
k = htonl(1); v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
k = htonl(3); v = 3;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
int i;
/* insert 2->0, 2->1, .. 2->n-1 */
......@@ -2069,17 +2069,17 @@ void test_dup_key_insert(int n) {
k = htonl(2);
v = i;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
}
/* cursor walk from key k should find values 0, 1, .. n-1 */
PMA_CURSOR cursor;
r = pma_cursor(pma, &cursor);
r = toku_pma_cursor(pma, &cursor);
assert(r == 0);
k = htonl(2);
fill_dbt(&key, &k, sizeof k);
r = pma_cursor_set_key(cursor, &key, 0);
r = toku_pma_cursor_set_key(cursor, &key, 0);
if (r != 0) {
assert(n == 0);
} else {
......@@ -2087,7 +2087,7 @@ void test_dup_key_insert(int n) {
while (1) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = pma_cursor_get_current(cursor, &key, &val);
r = toku_pma_cursor_get_current(cursor, &key, &val);
assert(r == 0);
int kk;
assert(key.size == sizeof kk);
......@@ -2106,17 +2106,17 @@ void test_dup_key_insert(int n) {
i += 1;
r = pma_cursor_set_position_next(cursor);
r = toku_pma_cursor_set_position_next(cursor);
if (r != 0)
break;
}
assert(i == n);
}
r = pma_cursor_free(&cursor);
r = toku_pma_cursor_free(&cursor);
assert(r == 0);
r = pma_free(&pma);
r = toku_pma_free(&pma);
assert(r == 0);
}
......@@ -2131,15 +2131,15 @@ void test_dup_key_delete(int n, int mode) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
r = pma_set_dup_mode(pma, mode);
r = toku_pma_set_dup_mode(pma, mode);
assert(r == 0);
if (mode & TOKU_DB_DUPSORT) {
r = pma_set_dup_compare(pma, toku_default_compare_fun);
r = toku_pma_set_dup_compare(pma, toku_default_compare_fun);
assert(r == 0);
}
......@@ -2149,10 +2149,10 @@ void test_dup_key_delete(int n, int mode) {
/* insert 1->1, 3->3 */
k = htonl(1); v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
k = htonl(3); v = 3;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
u_int32_t sum_before_all_the_duplicates = sum;
int i;
......@@ -2161,23 +2161,23 @@ void test_dup_key_delete(int n, int mode) {
k = htonl(2);
v = i;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
}
k = htonl(2);
r = pma_delete(pma, fill_dbt(&key, &k, sizeof k), null_db, rand4fingerprint, &sum, 0);
r = toku_pma_delete(pma, fill_dbt(&key, &k, sizeof k), null_db, rand4fingerprint, &sum, 0);
if (r != 0) assert(n == 0);
expect_fingerprint = sum_before_all_the_duplicates;
assert(sum == expect_fingerprint);
pma_verify(pma, null_db);
pma_verify_fingerprint(pma, rand4fingerprint, sum);
toku_pma_verify(pma, null_db);
toku_pma_verify_fingerprint(pma, rand4fingerprint, sum);
/* cursor walk should find keys 1, 3 */
PMA_CURSOR cursor;
r = pma_cursor(pma, &cursor);
r = toku_pma_cursor(pma, &cursor);
assert(r == 0);
r = pma_cursor_set_position_first(cursor);
r = toku_pma_cursor_set_position_first(cursor);
assert(r == 0);
int kk, vv;
......@@ -2185,7 +2185,7 @@ void test_dup_key_delete(int n, int mode) {
k = htonl(1); v = 1;
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = pma_cursor_get_current(cursor, &key, &val);
r = toku_pma_cursor_get_current(cursor, &key, &val);
assert(r == 0);
assert(key.size == sizeof kk);
memcpy(&kk, key.data, key.size);
......@@ -2196,13 +2196,13 @@ void test_dup_key_delete(int n, int mode) {
toku_free(key.data);
toku_free(val.data);
r = pma_cursor_set_position_next(cursor);
r = toku_pma_cursor_set_position_next(cursor);
assert(r == 0);
k = htonl(3); v = 3;
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = pma_cursor_get_current(cursor, &key, &val);
r = toku_pma_cursor_get_current(cursor, &key, &val);
assert(r == 0);
assert(key.size == sizeof kk);
memcpy(&kk, key.data, key.size);
......@@ -2213,10 +2213,10 @@ void test_dup_key_delete(int n, int mode) {
toku_free(key.data);
toku_free(val.data);
r = pma_cursor_free(&cursor);
r = toku_pma_cursor_free(&cursor);
assert(r == 0);
r = pma_free(&pma);
r = toku_pma_free(&pma);
assert(r == 0);
}
......@@ -2232,14 +2232,14 @@ void test_dupsort_key_insert(int n, int dup_data) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
r = pma_set_dup_mode(pma, TOKU_DB_DUP+TOKU_DB_DUPSORT);
r = toku_pma_set_dup_mode(pma, TOKU_DB_DUP+TOKU_DB_DUPSORT);
assert(r == 0);
r = pma_set_dup_compare(pma, toku_default_compare_fun);
r = toku_pma_set_dup_compare(pma, toku_default_compare_fun);
assert(r == 0);
DBT key, val;
......@@ -2248,10 +2248,10 @@ void test_dupsort_key_insert(int n, int dup_data) {
/* insert 1->1, 3->3 */
k = htonl(1); v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
k = htonl(3); v = 3;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
k = htonl(2);
int values[n];
......@@ -2262,16 +2262,16 @@ void test_dupsort_key_insert(int n, int dup_data) {
/* insert 2->n-i */
for (i=0; i<n; i++) {
do_insert(pma, &k, sizeof k, &values[i], sizeof values[i], rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
}
/* cursor walk from key k should find values 0, 1, .. n-1 */
PMA_CURSOR cursor;
r = pma_cursor(pma, &cursor);
r = toku_pma_cursor(pma, &cursor);
assert(r == 0);
fill_dbt(&key, &k, sizeof k);
r = pma_cursor_set_key(cursor, &key, 0);
r = toku_pma_cursor_set_key(cursor, &key, 0);
if (r != 0) {
assert(n == 0);
} else {
......@@ -2283,7 +2283,7 @@ void test_dupsort_key_insert(int n, int dup_data) {
while (1) {
init_dbt(&key); key.flags = DB_DBT_MALLOC;
init_dbt(&val); val.flags = DB_DBT_MALLOC;
r = pma_cursor_get_current(cursor, &key, &val);
r = toku_pma_cursor_get_current(cursor, &key, &val);
assert(r == 0);
int kk;
assert(key.size == sizeof kk);
......@@ -2302,17 +2302,17 @@ void test_dupsort_key_insert(int n, int dup_data) {
i += 1;
r = pma_cursor_set_position_next(cursor);
r = toku_pma_cursor_set_position_next(cursor);
if (r != 0)
break;
}
assert(i == n);
}
r = pma_cursor_free(&cursor);
r = toku_pma_cursor_free(&cursor);
assert(r == 0);
r = pma_free(&pma);
r = toku_pma_free(&pma);
assert(r == 0);
}
......@@ -2326,15 +2326,15 @@ void test_dup_key_lookup(int n, int mode) {
u_int32_t sum = 0;
u_int32_t expect_fingerprint = 0;
r = pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
r = toku_pma_create(&pma, toku_default_compare_fun, (n + 2) * (8 + sizeof (int) + sizeof (int)));
assert(r == 0);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
r = pma_set_dup_mode(pma, mode);
r = toku_pma_set_dup_mode(pma, mode);
assert(r == 0);
if (mode & TOKU_DB_DUPSORT) {
r = pma_set_dup_compare(pma, toku_default_compare_fun);
r = toku_pma_set_dup_compare(pma, toku_default_compare_fun);
assert(r == 0);
}
......@@ -2344,10 +2344,10 @@ void test_dup_key_lookup(int n, int mode) {
/* insert 1->1, 3->3 */
k = htonl(1); v = 1;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
k = htonl(3); v = 3;
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
int i;
/* insert 2->0, 2->1, .. 2->n-1 */
......@@ -2355,12 +2355,12 @@ void test_dup_key_lookup(int n, int mode) {
k = htonl(2);
v = htonl(i);
do_insert(pma, &k, sizeof k, &v, sizeof v, rand4fingerprint, &sum, &expect_fingerprint);
pma_verify(pma, null_db);
toku_pma_verify(pma, null_db);
}
/* lookup should find the first insert and smallest value */
k = htonl(2);
r = pma_lookup(pma, fill_dbt(&key, &k, sizeof k), fill_dbt(&val, &v, sizeof v), null_db);
r = toku_pma_lookup(pma, fill_dbt(&key, &k, sizeof k), fill_dbt(&val, &v, sizeof v), null_db);
assert(r == 0);
int kk;
assert(key.size == sizeof k);
......@@ -2371,7 +2371,7 @@ void test_dup_key_lookup(int n, int mode) {
memcpy(&vv, val.data, val.size);
assert(vv == 0);
r = pma_free(&pma);
r = toku_pma_free(&pma);
assert(r == 0);
}
......
......@@ -137,58 +137,58 @@ static void pma_mfree_kv_pair(PMA pma __attribute__((unused)), struct kv_pair *k
#endif
}
int pma_n_entries (PMA pma) {
int toku_pma_n_entries (PMA pma) {
return pma->n_pairs_present;
}
int pma_index_limit (PMA pma) {
int toku_pma_index_limit (PMA pma) {
return pma->N;
}
int pmanode_valid (PMA pma, int i) {
assert(0<=i); assert(i<pma_index_limit(pma));
int toku_pmanode_valid (PMA pma, int i) {
assert(0<=i); assert(i<toku_pma_index_limit(pma));
return kv_pair_valid(pma->pairs[i]);
}
bytevec pmanode_key (PMA pma, int i) {
bytevec toku_pmanode_key (PMA pma, int i) {
struct kv_pair *pair;
assert(0<=i); assert(i<pma_index_limit(pma));
assert(0<=i); assert(i<toku_pma_index_limit(pma));
pair = pma->pairs[i];
assert(kv_pair_valid(pair));
return kv_pair_key(pair);
}
ITEMLEN pmanode_keylen (PMA pma, int i) {
ITEMLEN toku_pmanode_keylen (PMA pma, int i) {
struct kv_pair *pair;
assert(0<=i); assert(i<pma_index_limit(pma));
assert(0<=i); assert(i<toku_pma_index_limit(pma));
pair = pma->pairs[i];
assert(kv_pair_valid(pair));
return kv_pair_keylen(pair);
}
bytevec pmanode_val (PMA pma, int i) {
bytevec toku_pmanode_val (PMA pma, int i) {
struct kv_pair *pair;
assert(0<=i); assert(i<pma_index_limit(pma));
assert(0<=i); assert(i<toku_pma_index_limit(pma));
pair = pma->pairs[i];
assert(kv_pair_valid(pair));
return kv_pair_val(pair);
}
ITEMLEN pmanode_vallen (PMA pma, int i) {
ITEMLEN toku_pmanode_vallen (PMA pma, int i) {
struct kv_pair *pair;
assert(0<=i); assert(i<pma_index_limit(pma));
assert(0<=i); assert(i<toku_pma_index_limit(pma));
pair = pma->pairs[i];
assert(kv_pair_valid(pair));
return kv_pair_vallen(pair);
}
/* Could pick the same one every time if we wanted. */
int pma_random_pick(PMA pma, bytevec *key, ITEMLEN *keylen, bytevec *val, ITEMLEN *vallen) {
int toku_pma_random_pick(PMA pma, bytevec *key, ITEMLEN *keylen, bytevec *val, ITEMLEN *vallen) {
#if 1
int i;
/* For now a simple implementation where we simply start at the beginning and look. */
for (i=0; i<pma_index_limit(pma); i++) {
for (i=0; i<toku_pma_index_limit(pma); i++) {
struct kv_pair *pair = pma->pairs[i];
if (kv_pair_valid(pair)) {
*key = kv_pair_key(pair);
......@@ -202,7 +202,7 @@ int pma_random_pick(PMA pma, bytevec *key, ITEMLEN *keylen, bytevec *val, ITEMLE
#else
/* Maybe we should pick a random item to remove in order to reduce the unbalancing. */
int i;
int l = pma_index_limit(pma);
int l = toku_pma_index_limit(pma);
int r = random()%l;
/* For now a simple implementation where we simply start at the beginning and look. */
for (i=0; i<l; i++) {
......@@ -225,7 +225,7 @@ static int pma_count_finds=0;
static int pma_count_divides=0;
static int pma_count_scans=0;
void pma_show_stats (void) {
void toku_pma_show_stats (void) {
printf("%d finds, %d divides, %d scans\n", pma_count_finds, pma_count_divides, pma_count_scans);
}
......@@ -354,14 +354,14 @@ static int __pma_dup_search(PMA pma, DBT *k, DBT *v, DB *db, int lo, int hi, int
}
// Return the smallest index such that no lower index contains a larger key.
// This will be in the range 0 (inclusive) to pma_index_limit(pma) (inclusive).
// Thus the returned index may not be a valid index into the array if it is == pma_index_limit(pma)
// This will be in the range 0 (inclusive) to toku_pma_index_limit(pma) (inclusive).
// Thus the returned index may not be a valid index into the array if it is == toku_pma_index_limit(pma)
// For example: if the array is empty, that means we return 0.
// For example: if the array is full of small keys, that means we return pma_index_limit(pma), which is off the end of teh array.
// For example: if the array is full of small keys, that means we return toku_pma_index_limit(pma), which is off the end of teh array.
// For example: if the array is full of large keys, then we return 0.
int pmainternal_find (PMA pma, DBT *k, DB *db) {
int toku_pmainternal_find (PMA pma, DBT *k, DB *db) {
#if 1
int lo=0, hi=pma_index_limit(pma);
int lo=0, hi=toku_pma_index_limit(pma);
/* lo and hi are the minimum and maximum values (inclusive) that we could possibly return. */
pma_count_finds++;
while (lo<hi) {
......@@ -398,10 +398,10 @@ int pmainternal_find (PMA pma, DBT *k, DB *db) {
}
assert(0<=lo);
assert(lo==hi);
assert(hi <= pma_index_limit(pma));
assert(hi <= toku_pma_index_limit(pma));
#if 0
/* If lo points at something, the something should not be smaller than key. */
if (lo>0 && lo < pma_index_limit(pma) && pma->pairs[lo]) {
if (lo>0 && lo < toku_pma_index_limit(pma) && pma->pairs[lo]) {
//printf("lo=%d\n", lo);
DBT k2;
assert(0 >= pma->compare_fun(db, k, fill_dbt(&k2, pma->pairs[lo]->key, pma->pairs[lo]->keylen)));
......@@ -412,7 +412,7 @@ int pmainternal_find (PMA pma, DBT *k, DB *db) {
int found, lo;
lo = __pma_search(pma, k, db, 0, pma->N, &found);
if (lo>0 && lo < pma_index_limit(pma) && pma->pairs[lo]) {
if (lo>0 && lo < toku_pma_index_limit(pma) && pma->pairs[lo]) {
//printf("lo=%d\n", lo);
DBT k2;
assert(0 >= pma->compare_fun(db, k, fill_dbt(&k2, pma->pairs[lo]->key, pma->pairs[lo]->keylen)));
......@@ -425,7 +425,7 @@ int pmainternal_find (PMA pma, DBT *k, DB *db) {
//int max (int i, int j) { if (i<j) return j; else return i; }
//double lg (int n) { return log((double)n)/log(2.0); }
int pmainternal_printpairs (struct kv_pair *pairs[], int N) {
int toku_pmainternal_printpairs (struct kv_pair *pairs[], int N) {
int count=0;
int i;
printf("{");
......@@ -441,10 +441,10 @@ int pmainternal_printpairs (struct kv_pair *pairs[], int N) {
return count;
}
void print_pma (PMA pma) {
void toku_print_pma (PMA pma) {
int count;
printf("N=%d n_present=%d ", pma_index_limit(pma), pma->n_pairs_present);
count=pmainternal_printpairs(pma->pairs, pma_index_limit(pma));
printf("N=%d n_present=%d ", toku_pma_index_limit(pma), pma->n_pairs_present);
count=toku_pmainternal_printpairs(pma->pairs, toku_pma_index_limit(pma));
printf("\n");
assert(count==pma->n_pairs_present);
}
......@@ -476,7 +476,7 @@ static int distribute_data (struct kv_pair *destpairs[], int dcount,
/* spread the non-empty pairs around. There are n of them. Create an empty slot just before the IDXth
element, and return that slot's index in the smoothed array. */
int pmainternal_smooth_region (struct kv_pair *pairs[], int n, int idx, int base, PMA pma) {
int toku_pmainternal_smooth_region (struct kv_pair *pairs[], int n, int idx, int base, PMA pma) {
int i;
int n_present=0;
for (i=0; i<n; i++) {
......@@ -532,8 +532,8 @@ int toku_lg (int n) {
}
/* Calculate densitysteps and uplgN, given N. */
void pmainternal_calculate_parameters (PMA pma) {
int N = pma_index_limit(pma);
void toku_pmainternal_calculate_parameters (PMA pma) {
int N = toku_pma_index_limit(pma);
int lgN = toku_lg(N);
int n_divisions=0;
//printf("N=%d lgN=%d\n", N, lgN);
......@@ -548,7 +548,7 @@ void pmainternal_calculate_parameters (PMA pma) {
pma->ldt_step = (PMA_LDT_HIGH - PMA_LDT_LOW)/n_divisions;
}
int pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi) {
int toku_pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi) {
int n=0;
while (lo<hi) {
if (kv_pair_inuse(pairs[lo])) n++;
......@@ -557,7 +557,7 @@ int pmainternal_count_region (struct kv_pair *pairs[], int lo, int hi) {
return n;
}
int pma_create(PMA *pma, pma_compare_fun_t compare_fun, int maxsize) {
int toku_pma_create(PMA *pma, pma_compare_fun_t compare_fun, int maxsize) {
int error;
TAGMALLOC(PMA, result);
if (result==0) return -1;
......@@ -612,28 +612,28 @@ static int __pma_resize_array(PMA pma, int asksize, int startz) {
for (i=startz; i<pma->N; i++) {
pma->pairs[i] = 0;
}
pmainternal_calculate_parameters(pma);
toku_pmainternal_calculate_parameters(pma);
return 0;
}
int pma_set_compare(PMA pma, pma_compare_fun_t compare_fun) {
int toku_pma_set_compare(PMA pma, pma_compare_fun_t compare_fun) {
pma->compare_fun = compare_fun;
return 0;
}
int pma_set_dup_mode(PMA pma, int dup_mode) {
int toku_pma_set_dup_mode(PMA pma, int dup_mode) {
assert(dup_mode == 0 || dup_mode == TOKU_DB_DUP || dup_mode == (TOKU_DB_DUP+TOKU_DB_DUPSORT));
pma->dup_mode = dup_mode;
return 0;
}
int pma_set_dup_compare(PMA pma, pma_compare_fun_t dup_compare_fun) {
int toku_pma_set_dup_compare(PMA pma, pma_compare_fun_t dup_compare_fun) {
assert(pma->dup_mode & TOKU_DB_DUPSORT);
pma->dup_compare_fun = dup_compare_fun;
return 0;
}
int pma_cursor (PMA pma, PMA_CURSOR *cursp) {
int toku_pma_cursor (PMA pma, PMA_CURSOR *cursp) {
PMA_CURSOR MALLOC(curs);
assert(curs!=0);
if (errno!=0) return errno;
......@@ -646,12 +646,12 @@ int pma_cursor (PMA pma, PMA_CURSOR *cursp) {
return 0;
}
int pma_cursor_get_pma(PMA_CURSOR c, PMA *pmap) {
int toku_pma_cursor_get_pma(PMA_CURSOR c, PMA *pmap) {
*pmap = c->pma;
return 0;
}
int pma_cursor_set_position_last (PMA_CURSOR c) {
int toku_pma_cursor_set_position_last (PMA_CURSOR c) {
PMA pma = c->pma;
int result = 0;
int old_position = c->position;
......@@ -670,7 +670,7 @@ int pma_cursor_set_position_last (PMA_CURSOR c) {
return result;
}
int pma_cursor_set_position_prev (PMA_CURSOR c) {
int toku_pma_cursor_set_position_prev (PMA_CURSOR c) {
PMA pma = c->pma;
int old_position = c->position;
c->position--;
......@@ -685,7 +685,7 @@ int pma_cursor_set_position_prev (PMA_CURSOR c) {
return DB_NOTFOUND;
}
int pma_cursor_set_position_first (PMA_CURSOR c) {
int toku_pma_cursor_set_position_first (PMA_CURSOR c) {
PMA pma = c->pma;
int result = 0;
int old_position = c->position;
......@@ -704,7 +704,7 @@ int pma_cursor_set_position_first (PMA_CURSOR c) {
return result;
}
int pma_cursor_set_position_next (PMA_CURSOR c) {
int toku_pma_cursor_set_position_next (PMA_CURSOR c) {
PMA pma = c->pma;
int old_position=c->position;
c->position++;
......@@ -719,7 +719,7 @@ int pma_cursor_set_position_next (PMA_CURSOR c) {
return DB_NOTFOUND;
}
int pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) {
int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) {
if (c->position == -1)
return DB_NOTFOUND;
PMA pma = c->pma;
......@@ -731,14 +731,14 @@ int pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) {
return 0;
}
int pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db) {
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db) {
PMA pma = c->pma;
int here, found;
if (pma->dup_mode & TOKU_DB_DUP) {
here = __pma_left_search(pma, key, db, 0, pma->N, &found);
} else
here = pmainternal_find(pma, key, db);
assert(0<=here ); assert(here<=pma_index_limit(pma));
here = toku_pmainternal_find(pma, key, db);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma));
int r = DB_NOTFOUND;
if (here < pma->N) {
DBT k2;
......@@ -753,10 +753,10 @@ int pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db) {
return r;
}
int pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val, DB *db) {
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val, DB *db) {
PMA pma = c->pma;
int here = pmainternal_find(pma, key, db);
assert(0<=here ); assert(here<=pma_index_limit(pma));
int here = toku_pmainternal_find(pma, key, db);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma));
int r = DB_NOTFOUND;
if (here < pma->N) {
DBT k2, v2;
......@@ -772,14 +772,14 @@ int pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val, DB *db) {
return r;
}
int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db) {
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db) {
PMA pma = c->pma;
int here, found;
if (pma->dup_mode & TOKU_DB_DUP)
here = __pma_left_search(pma, key, db, 0, pma->N, &found);
else
here = pmainternal_find(pma, key, db);
assert(0<=here ); assert(here<=pma_index_limit(pma));
here = toku_pmainternal_find(pma, key, db);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma));
/* find the first valid pair where key[here] >= key */
int r = DB_NOTFOUND;
......@@ -796,7 +796,7 @@ int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db) {
return r;
}
int pma_cursor_delete_under(PMA_CURSOR c, int *kvsize) {
int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize) {
int r = DB_NOTFOUND;
if (c->position >= 0) {
PMA pma = c->pma;
......@@ -812,7 +812,7 @@ int pma_cursor_delete_under(PMA_CURSOR c, int *kvsize) {
return r;
}
int pma_cursor_free (PMA_CURSOR *cursp) {
int toku_pma_cursor_free (PMA_CURSOR *cursp) {
PMA_CURSOR curs=*cursp;
PMA pma = curs->pma;
list_remove(&curs->next);
......@@ -829,7 +829,7 @@ int pma_cursor_free (PMA_CURSOR *cursp) {
/* Make some space for a key to go at idx (the thing currently at idx should end up at to the right.) */
/* Return the new index. (Making space may involve moving things around, including the hole at index.) */
int pmainternal_make_space_at (PMA pma, int idx) {
int toku_pmainternal_make_space_at (PMA pma, int idx) {
/* Within a range LO to HI we have a limit of how much packing we will tolerate.
* We allow the entire array to be 50% full.
* We allow a region of size lgN to be full.
......@@ -845,23 +845,23 @@ int pmainternal_make_space_at (PMA pma, int idx) {
hi=idx+size/2;
//printf("lo=%d hi=%d\n", lo, hi);
if (lo<0) { hi-=lo; lo=0; }
else if (hi>pma_index_limit(pma)) { lo-=(hi-pma_index_limit(pma)); hi=pma_index_limit(pma); }
else if (hi>toku_pma_index_limit(pma)) { lo-=(hi-toku_pma_index_limit(pma)); hi=toku_pma_index_limit(pma); }
else { ; /* nothing */ }
//printf("lo=%d hi=%d\n", lo, hi);
assert(0<=lo); assert(lo<hi); assert(hi<=pma_index_limit(pma)); assert(hi-lo==size); // separate into separate assertions so that gcov doesn't see branches not taken.
assert(0<=lo); assert(lo<hi); assert(hi<=toku_pma_index_limit(pma)); assert(hi-lo==size); // separate into separate assertions so that gcov doesn't see branches not taken.
assert(udt>0.499); assert(udt<=1);
if (udt<0.5001) { assert(lo==0); assert(hi==pma_index_limit(pma)); }
if (udt<0.5001) { assert(lo==0); assert(hi==toku_pma_index_limit(pma)); }
{
int count = (1+ /* Don't forget space for the new guy. */
pmainternal_count_region(pma->pairs, lo, hi));
toku_pmainternal_count_region(pma->pairs, lo, hi));
double density = (double) count / (double) (hi - lo);
if (density <= udt)
break;
if (lo==0 && hi==pma_index_limit(pma)) {
if (lo==0 && hi==toku_pma_index_limit(pma)) {
/* The array needs to be doubled in size. */
assert(size==pma_index_limit(pma));
assert(size==toku_pma_index_limit(pma));
size*=2;
// printf("pma_make_space_realloc %d to %d hi %d\n", pma->N, size, hi);
......@@ -877,20 +877,20 @@ int pmainternal_make_space_at (PMA pma, int idx) {
}
//printf("%s:%d Smoothing from %d to %d to density %f\n", __FILE__, __LINE__, lo, hi, density);
{
int new_index = pmainternal_smooth_region(pma->pairs+lo, hi-lo, idx-lo, lo, pma);
int new_index = toku_pmainternal_smooth_region(pma->pairs+lo, hi-lo, idx-lo, lo, pma);
return new_index+lo;
}
}
enum pma_errors pma_lookup (PMA pma, DBT *k, DBT *v, DB *db) {
enum pma_errors toku_pma_lookup (PMA pma, DBT *k, DBT *v, DB *db) {
int here, found;
if (pma->dup_mode & TOKU_DB_DUP) {
here = __pma_left_search(pma, k, db, 0, pma->N, &found);
} else
here = pmainternal_find(pma, k, db);
assert(0<=here ); assert(here<=pma_index_limit(pma));
if (here==pma_index_limit(pma)) return DB_NOTFOUND;
here = toku_pmainternal_find(pma, k, db);
assert(0<=here ); assert(here<=toku_pma_index_limit(pma));
if (here==toku_pma_index_limit(pma)) return DB_NOTFOUND;
DBT k2;
struct kv_pair *pair;
pair = pma->pairs[here];
......@@ -903,7 +903,7 @@ enum pma_errors pma_lookup (PMA pma, DBT *k, DBT *v, DB *db) {
/* returns 0 if OK.
* You must have freed all the cursors, otherwise returns nonzero and does nothing. */
int pma_free (PMA *pmap) {
int toku_pma_free (PMA *pmap) {
int i;
PMA pma=*pmap;
if (!list_empty(&pma->cursors))
......@@ -935,7 +935,7 @@ int pma_free (PMA *pmap) {
/* Copies keylen and datalen */
/* returns an error if the key is already present. */
int pma_insert (PMA pma, DBT *k, DBT *v, DB* db, TOKUTXN txn, DISKOFF diskoff, u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
int toku_pma_insert (PMA pma, DBT *k, DBT *v, DB* db, TOKUTXN txn, DISKOFF diskoff, u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
int found, idx;
if (pma->dup_mode & TOKU_DB_DUPSORT) {
......@@ -947,8 +947,8 @@ int pma_insert (PMA pma, DBT *k, DBT *v, DB* db, TOKUTXN txn, DISKOFF diskoff, u
if (found)
idx += 1;
} else {
idx = pmainternal_find(pma, k, db);
if (idx < pma_index_limit(pma) && pma->pairs[idx]) {
idx = toku_pmainternal_find(pma, k, db);
if (idx < toku_pma_index_limit(pma) && pma->pairs[idx]) {
DBT k2;
struct kv_pair *kv = kv_pair_ptr(pma->pairs[idx]);
if (0==pma->compare_fun(db, k, fill_dbt(&k2, kv->key, kv->keylen))) {
......@@ -965,7 +965,7 @@ int pma_insert (PMA pma, DBT *k, DBT *v, DB* db, TOKUTXN txn, DISKOFF diskoff, u
}
}
if (kv_pair_inuse(pma->pairs[idx])) {
idx = pmainternal_make_space_at (pma, idx); /* returns the new idx. */
idx = toku_pmainternal_make_space_at (pma, idx); /* returns the new idx. */
}
assert(0 <= idx && idx < pma->N);
assert(!kv_pair_inuse(pma->pairs[idx]));
......@@ -1020,7 +1020,7 @@ static int pma_delete_dup (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_
}
static int pma_delete_nodup (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
int idx = pmainternal_find(pma, k, db);
int idx = toku_pmainternal_find(pma, k, db);
struct kv_pair *kv = pma->pairs[idx];
if (!kv_pair_valid(kv)) {
if (0) printf("%s:%d l=%d r=%d\n", __FILE__, __LINE__, idx, DB_NOTFOUND);
......@@ -1034,7 +1034,7 @@ static int pma_delete_nodup (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int3
return BRT_OK;
}
int pma_delete (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
int toku_pma_delete (PMA pma, DBT *k, DB *db, u_int32_t rand4sem, u_int32_t *fingerprint, u_int32_t *deleted_size) {
u_int32_t my_deleted_size;
if (!deleted_size)
deleted_size = &my_deleted_size;
......@@ -1093,7 +1093,7 @@ static void __pma_delete_at(PMA pma, int here) {
assert(lo <= hi);
/* compute the density of the region */
count = pmainternal_count_region(pma->pairs, lo, hi);
count = toku_pmainternal_count_region(pma->pairs, lo, hi);
density = (double) count / ((double) (hi - lo));
/* rebalance if the density exceeds the lower threadshold */
......@@ -1129,7 +1129,7 @@ static void __pma_delete_at(PMA pma, int here) {
toku_free(newpairs);
}
int pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
int *replaced_v_size, /* If it is a replacement, set to the size of the old value, otherwise set to -1. */
DB *db, TOKUTXN txn, DISKOFF diskoff,
u_int32_t rand4fingerprint, u_int32_t *fingerprint) {
......@@ -1145,9 +1145,9 @@ int pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
if (found)
idx += 1;
} else {
idx = pmainternal_find(pma, k, db);
idx = toku_pmainternal_find(pma, k, db);
struct kv_pair *kv;
if (idx < pma_index_limit(pma) && (kv = pma->pairs[idx])) {
if (idx < toku_pma_index_limit(pma) && (kv = pma->pairs[idx])) {
DBT k2;
// printf("%s:%d\n", __FILE__, __LINE__);
kv = kv_pair_ptr(kv);
......@@ -1172,7 +1172,7 @@ int pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
}
}
if (kv_pair_inuse(pma->pairs[idx])) {
idx = pmainternal_make_space_at (pma, idx); /* returns the new idx. */
idx = toku_pmainternal_make_space_at (pma, idx); /* returns the new idx. */
}
assert(!kv_pair_inuse(pma->pairs[idx]));
//printf("%s:%d v->size=%d\n", __FILE__, __LINE__, v->size);
......@@ -1186,9 +1186,9 @@ int pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
return r;
}
void pma_iterate (PMA pma, void(*f)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*v) {
void toku_pma_iterate (PMA pma, void(*f)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*v) {
int i;
for (i=0; i<pma_index_limit(pma); i++) {
for (i=0; i<toku_pma_index_limit(pma); i++) {
struct kv_pair *pair = pma->pairs[i];
if (pair) {
f(pair->key, pair->keylen,
......@@ -1307,7 +1307,7 @@ static int __pma_compare_kv(PMA pma, struct kv_pair *a, struct kv_pair *b, DB *d
return cmp;
}
int pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
int toku_pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
PMA leftpma, unsigned int *leftpma_size, u_int32_t leftrand4fp, u_int32_t *leftfingerprint,
PMA rightpma, unsigned int *rightpma_size, u_int32_t rightrand4fp, u_int32_t *rightfingerprint) {
int error;
......@@ -1321,14 +1321,14 @@ int pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
struct list cursors;
/* extract the pairs */
npairs = pma_n_entries(origpma);
npairs = toku_pma_n_entries(origpma);
if (npairs == 0) {
if (splitk)
memset(splitk, 0, sizeof *splitk);
return 0;
}
assert(pma_n_entries(leftpma) == 0);
assert(pma_n_entries(rightpma) == 0);
assert(toku_pma_n_entries(leftpma) == 0);
assert(toku_pma_n_entries(rightpma) == 0);
/* TODO move pairs to the stack */
pairs = __pma_extract_pairs(origpma, npairs, 0, origpma->N);
......@@ -1402,7 +1402,7 @@ int pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
n = spliti;
error = __pma_resize_array(leftpma, n + n/4, 0);
assert(error == 0);
distribute_data(leftpma->pairs, pma_index_limit(leftpma), &pairs[0], n, leftpma);
distribute_data(leftpma->pairs, toku_pma_index_limit(leftpma), &pairs[0], n, leftpma);
#if PMA_USE_MEMPOOL
__pma_relocate_kvpairs(leftpma);
#endif
......@@ -1413,7 +1413,7 @@ int pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
n = npairs - spliti;
error = __pma_resize_array(rightpma, n + n/4, 0);
assert(error == 0);
distribute_data(rightpma->pairs, pma_index_limit(rightpma), &pairs[spliti], n, rightpma);
distribute_data(rightpma->pairs, toku_pma_index_limit(rightpma), &pairs[spliti], n, rightpma);
#if PMA_USE_MEMPOOL
__pma_relocate_kvpairs(rightpma);
#endif
......@@ -1440,7 +1440,7 @@ static void __pma_bulk_cleanup(struct pma *pma, struct kv_pair_tag *pairs, int n
pma_mfree_kv_pair(pma, pairs[i].pair);
}
int pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs, u_int32_t rand4fp, u_int32_t *sum) {
int toku_pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs, u_int32_t rand4fp, u_int32_t *sum) {
struct kv_pair_tag *newpairs;
int i;
int error;
......@@ -1450,7 +1450,7 @@ int pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs, u_int32_t ran
return 0;
if (!list_empty(&pma->cursors))
return -1;
if (pma_n_entries(pma) > 0)
if (toku_pma_n_entries(pma) > 0)
return -2;
/* TODO put newpairs on the stack */
......@@ -1480,7 +1480,7 @@ int pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs, u_int32_t ran
toku_free(newpairs);
error = -5; return error;
}
distribute_data(pma->pairs, pma_index_limit(pma), newpairs, n_newpairs, pma);
distribute_data(pma->pairs, toku_pma_index_limit(pma), newpairs, n_newpairs, pma);
pma->n_pairs_present = n_newpairs;
toku_free(newpairs);
......@@ -1493,7 +1493,7 @@ int pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs, u_int32_t ran
* no duplications, duplicates, sorted duplicates.
*/
void pma_verify(PMA pma, DB *db) {
void toku_pma_verify(PMA pma, DB *db) {
int i;
struct kv_pair *kv;
......@@ -1543,7 +1543,7 @@ void pma_verify(PMA pma, DB *db) {
#endif
}
void pma_verify_fingerprint (PMA pma, u_int32_t rand4fingerprint, u_int32_t fingerprint) {
void toku_pma_verify_fingerprint (PMA pma, u_int32_t rand4fingerprint, u_int32_t fingerprint) {
u_int32_t actual_fingerprint=0;
PMA_ITERATE(pma, kv, kl, dv, dl,
actual_fingerprint+=rand4fingerprint*toku_calccrc32_kvpair(kv,kl,dv,dl)
......
......@@ -19,39 +19,39 @@ typedef struct pma_cursor *PMA_CURSOR;
return a value < 0, = 0, > 0 if a < b, a == b, a > b respectively */
typedef int (*pma_compare_fun_t)(DB *, const DBT *a, const DBT *b);
int pma_create(PMA *, pma_compare_fun_t compare_fun, int maxsize);
int toku_pma_create(PMA *, pma_compare_fun_t compare_fun, int maxsize);
int pma_set_compare(PMA pma, pma_compare_fun_t compare_fun);
int toku_pma_set_compare(PMA pma, pma_compare_fun_t compare_fun);
/* set the duplicate mode
0 -> no duplications, TOKU_DB_DUP, TOKU_DB_DUPSORT */
int pma_set_dup_mode(PMA pma, int mode);
int toku_pma_set_dup_mode(PMA pma, int mode);
/* set the duplicate compare function */
int pma_set_dup_compare(PMA pma, pma_compare_fun_t dup_compare_fun);
int toku_pma_set_dup_compare(PMA pma, pma_compare_fun_t dup_compare_fun);
/* verify the integrity of a pma */
void pma_verify(PMA pma, DB *db);
void toku_pma_verify(PMA pma, DB *db);
/* returns 0 if OK.
* You must have freed all the cursors, otherwise returns nonzero and does nothing. */
int pma_free (PMA *);
int toku_pma_free (PMA *);
int pma_n_entries (PMA);
int toku_pma_n_entries (PMA);
/* Returns an error if the key is already present. */
/* The values returned should not be modified.by the caller. */
/* Any cursors should be updated. */
/* Duplicates the key and keylen. */
//enum pma_errors pma_insert (PMA, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
//enum pma_errors toku_pma_insert (PMA, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
// The DB pointer is there so that the comparison function can be called.
enum pma_errors pma_insert (PMA, DBT*, DBT*, DB*, TOKUTXN txn, DISKOFF, u_int32_t /*random for fingerprint */, u_int32_t */*fingerprint*/);
enum pma_errors toku_pma_insert (PMA, DBT*, DBT*, DB*, TOKUTXN txn, DISKOFF, u_int32_t /*random for fingerprint */, u_int32_t */*fingerprint*/);
/* This returns an error if the key is NOT present. */
int pma_replace (PMA, bytevec key, ITEMLEN keylen, bytevec data, ITEMLEN datalen);
/* This returns an error if the key is NOT present. */
int pma_delete (PMA, DBT *, DB*, u_int32_t /*random for fingerprint*/, u_int32_t */*fingerprint*/, u_int32_t *deleted_size);
int toku_pma_delete (PMA, DBT *, DB*, u_int32_t /*random for fingerprint*/, u_int32_t */*fingerprint*/, u_int32_t *deleted_size);
int pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
int toku_pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
int *replaced_v_size, /* If it is a replacement, set to the size of the old value, otherwise set to -1. */
DB *db, TOKUTXN txn, DISKOFF,
u_int32_t /*random for fingerprint*/, u_int32_t */*fingerprint*/);
......@@ -59,7 +59,7 @@ int pma_insert_or_replace (PMA pma, DBT *k, DBT *v,
/* Exposes internals of the PMA by returning a pointer to the guts.
* Don't modify the returned data. Don't free it. */
enum pma_errors pma_lookup (PMA, DBT*, DBT*, DB*);
enum pma_errors toku_pma_lookup (PMA, DBT*, DBT*, DB*);
/*
* The kv pairs in the original pma are split into 2 equal sized sets
......@@ -71,7 +71,7 @@ enum pma_errors pma_lookup (PMA, DBT*, DBT*, DB*);
* leftpma - the pma assigned keys <= pivot key
* rightpma - the pma assigned keys > pivot key
*/
int pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
int toku_pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
PMA leftpma, unsigned int *leftpma_size, u_int32_t leftrand4sum, u_int32_t *leftfingerprint,
PMA rightpma, unsigned int *rightpma_size, u_int32_t rightrand4sum, u_int32_t *rightfingerprint);
......@@ -86,56 +86,56 @@ int pma_split(PMA origpma, unsigned int *origpma_size, DBT *splitk, DB *db,
* vals - an array of values
* n_newpairs - the number of key value pairs
*/
int pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs, u_int32_t rand4sem, u_int32_t *fingerprint);
int toku_pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs, u_int32_t rand4sem, u_int32_t *fingerprint);
/* Move the cursor to the beginning or the end or to a key */
int pma_cursor (PMA, PMA_CURSOR *);
int pma_cursor_free (PMA_CURSOR*);
int toku_pma_cursor (PMA, PMA_CURSOR *);
int toku_pma_cursor_free (PMA_CURSOR*);
/* get the pma that a pma cursor is bound to */
int pma_cursor_get_pma(PMA_CURSOR c, PMA *pma);
int pma_cursor_set_position_last (PMA_CURSOR c);
int pma_cursor_set_position_first (PMA_CURSOR c);
int pma_cursor_set_position_next (PMA_CURSOR c); /* Requires the cursor is init'd. Returns DB_NOTFOUND if we fall off the end. */
int pma_cursor_set_position_prev (PMA_CURSOR c);
int toku_pma_cursor_get_pma(PMA_CURSOR c, PMA *pma);
int toku_pma_cursor_set_position_last (PMA_CURSOR c);
int toku_pma_cursor_set_position_first (PMA_CURSOR c);
int toku_pma_cursor_set_position_next (PMA_CURSOR c); /* Requires the cursor is init'd. Returns DB_NOTFOUND if we fall off the end. */
int toku_pma_cursor_set_position_prev (PMA_CURSOR c);
/* get the key and data under the cursor */
int pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val);
int toku_pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val);
/* set the cursor to the matching key and value pair */
int pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val, DB *db);
int toku_pma_cursor_set_both(PMA_CURSOR c, DBT *key, DBT *val, DB *db);
/* move the cursor to the kv pair matching the key */
int pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db);
int toku_pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db);
/* set the cursor to the smallest key in the pma >= key */
int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db);
int toku_pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db);
/* delete the key value pair under the cursor, return the size of the pair */
int pma_cursor_delete_under(PMA_CURSOR c, int *kvsize);
int toku_pma_cursor_delete_under(PMA_CURSOR c, int *kvsize);
int pma_random_pick(PMA, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen);
int toku_pma_random_pick(PMA, bytevec *key, ITEMLEN *keylen, bytevec *data, ITEMLEN *datalen);
int pma_index_limit(PMA);
int pmanode_valid(PMA,int);
bytevec pmanode_key(PMA,int);
ITEMLEN pmanode_keylen(PMA,int);
bytevec pmanode_val(PMA,int);
ITEMLEN pmanode_vallen(PMA,int);
int toku_pma_index_limit(PMA);
int toku_pmanode_valid(PMA,int);
bytevec toku_pmanode_key(PMA,int);
ITEMLEN toku_pmanode_keylen(PMA,int);
bytevec toku_pmanode_val(PMA,int);
ITEMLEN toku_pmanode_vallen(PMA,int);
void pma_iterate (PMA, void(*)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*);
void toku_pma_iterate (PMA, void(*)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*);
#define PMA_ITERATE(table,keyvar,keylenvar,datavar,datalenvar,body) ({ \
int __i; \
for (__i=0; __i<pma_index_limit(table); __i++) { \
if (pmanode_valid(table,__i)) { \
bytevec keyvar = pmanode_key(table,__i); \
ITEMLEN keylenvar = pmanode_keylen(table,__i); \
bytevec datavar = pmanode_val(table, __i); \
ITEMLEN datalenvar = pmanode_vallen(table, __i); \
for (__i=0; __i<toku_pma_index_limit(table); __i++) { \
if (toku_pmanode_valid(table,__i)) { \
bytevec keyvar = toku_pmanode_key(table,__i); \
ITEMLEN keylenvar = toku_pmanode_keylen(table,__i); \
bytevec datavar = toku_pmanode_val(table, __i); \
ITEMLEN datalenvar = toku_pmanode_vallen(table, __i); \
body; \
} } })
void pma_verify_fingerprint (PMA pma, u_int32_t rand4fingerprint, u_int32_t fingerprint);
void toku_pma_verify_fingerprint (PMA pma, u_int32_t rand4fingerprint, u_int32_t fingerprint);
#endif
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment