Commit 4564dd3b authored by Rich Prohaska's avatar Rich Prohaska

brt cursor get both feature

git-svn-id: file:///svn/tokudb@301 c7de825b-a66e-492c-adef-691d508d4ae1
parent cbc53004
This diff is collapsed.
This diff is collapsed.
...@@ -30,7 +30,7 @@ int show_brt_blocknumbers(BRT); ...@@ -30,7 +30,7 @@ int show_brt_blocknumbers(BRT);
typedef struct brt_cursor *BRT_CURSOR; typedef struct brt_cursor *BRT_CURSOR;
int brt_cursor (BRT, BRT_CURSOR*); int brt_cursor (BRT, BRT_CURSOR*);
int brt_c_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int brtc_flags); int brt_cursor_get (BRT_CURSOR cursor, DBT *kbt, DBT *vbt, int brtc_flags, DB *db);
int brt_cursor_delete(BRT_CURSOR cursor, int flags); int brt_cursor_delete(BRT_CURSOR cursor, int flags);
int brt_cursor_close (BRT_CURSOR curs); int brt_cursor_close (BRT_CURSOR curs);
......
This diff is collapsed.
...@@ -442,7 +442,7 @@ int pma_cursor_set_position_next (PMA_CURSOR c) { ...@@ -442,7 +442,7 @@ int pma_cursor_set_position_next (PMA_CURSOR c) {
return DB_NOTFOUND; return DB_NOTFOUND;
} }
int pma_cget_current (PMA_CURSOR c, DBT *key, DBT *val) { int pma_cursor_get_current(PMA_CURSOR c, DBT *key, DBT *val) {
if (c->position == -1) if (c->position == -1)
return DB_NOTFOUND; return DB_NOTFOUND;
PMA pma = c->pma; PMA pma = c->pma;
...@@ -458,16 +458,37 @@ int pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db) { ...@@ -458,16 +458,37 @@ int pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db) {
PMA pma = c->pma; PMA pma = c->pma;
int here = pmainternal_find(pma, key, db); int here = pmainternal_find(pma, key, db);
assert(0<=here ); assert(here<=pma_index_limit(pma)); assert(0<=here ); assert(here<=pma_index_limit(pma));
if (here==pma_index_limit(pma)) int r = DB_NOTFOUND;
return DB_NOTFOUND; if (here < pma->N) {
DBT k2; DBT k2;
struct kv_pair *pair = pma->pairs[here]; struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair) && pma->compare_fun(db, key, fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair)))==0) { if (kv_pair_valid(pair) &&
pma->compare_fun(db, key, fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair)))==0) {
__pma_delete_resume(c->pma, c->position); __pma_delete_resume(c->pma, c->position);
c->position = here; c->position = here;
return 0; r = 0;
} else }
return DB_NOTFOUND; }
return r;
}
int 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 r = DB_NOTFOUND;
if (here < pma->N) {
DBT k2, v2;
struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair) &&
pma->compare_fun(db, key, fill_dbt(&k2, kv_pair_key(pair), kv_pair_keylen(pair))) == 0 &&
pma->compare_fun(db, val, fill_dbt(&v2, kv_pair_val(pair), kv_pair_vallen(pair))) == 0) {
__pma_delete_resume(c->pma, c->position);
c->position = here;
r = 0;
}
}
return r;
} }
int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db) { int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db) {
...@@ -476,51 +497,36 @@ int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db) { ...@@ -476,51 +497,36 @@ int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db) {
assert(0<=here ); assert(here<=pma_index_limit(pma)); assert(0<=here ); assert(here<=pma_index_limit(pma));
/* find the first valid pair where key[here] >= key */ /* find the first valid pair where key[here] >= key */
int r = DB_NOTFOUND;
while (here < pma->N) { while (here < pma->N) {
struct kv_pair *pair = pma->pairs[here]; struct kv_pair *pair = pma->pairs[here];
if (kv_pair_valid(pair)) { if (kv_pair_valid(pair)) {
__pma_delete_resume(c->pma, c->position); __pma_delete_resume(c->pma, c->position);
c->position = here; c->position = here;
return 0; r = 0;
break;
} }
here += 1; here += 1;
} }
return r;
return DB_NOTFOUND;
} }
int pma_cursor_delete_under(PMA_CURSOR c, int *kvsize) { int pma_cursor_delete_under(PMA_CURSOR c, int *kvsize) {
int r = DB_NOTFOUND; int r = DB_NOTFOUND;
if (c->position >= 0) { if (c->position >= 0) {
PMA pma = c->pma; PMA pma = c->pma;
assert(c->position < pma->N); assert(c->position < pma->N);
struct kv_pair *kv = pma->pairs[c->position]; struct kv_pair *kv = pma->pairs[c->position];
if (kv_pair_valid(kv)) { if (kv_pair_valid(kv)) {
if (kvsize) *kvsize = kv_pair_keylen(kv) + kv_pair_vallen(kv); if (kvsize)
*kvsize = kv_pair_keylen(kv) + kv_pair_vallen(kv);
pma->pairs[c->position] = kv_pair_set_deleted(kv); pma->pairs[c->position] = kv_pair_set_deleted(kv);
r = 0; r = 0;
} }
} }
return r; return r;
} }
#if 0
int pma_cget_first (PMA_CURSOR c, YBT *key, YBT *val) {
PMA pma=c->pma;
c->position=0;
if (pma->n_pairs_present==0) return DB_NOTFOUND;
while (pma->pairs[c->position].key==0 && c->position<pma->N) {
c->position++;
}
assert(c->position<pma->N && pma->pairs[c->position].key!=0);
ybt_set_value(key, pma->pairs[c->position].key, pma->pairs[c->position].keylen, &c->skey);
ybt_set_value(val, pma->pairs[c->position].val, pma->pairs[c->position].vallen, &c->sval);
return 0;
}
#endif
int pma_cursor_free (PMA_CURSOR *cursp) { int pma_cursor_free (PMA_CURSOR *cursp) {
PMA_CURSOR curs=*cursp; PMA_CURSOR curs=*cursp;
PMA pma = curs->pma; PMA pma = curs->pma;
......
...@@ -71,26 +71,26 @@ int pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs); ...@@ -71,26 +71,26 @@ int pma_bulk_insert(PMA pma, DBT *keys, DBT *vals, int n_newpairs);
int pma_cursor (PMA, PMA_CURSOR *); int pma_cursor (PMA, PMA_CURSOR *);
int pma_cursor_free (PMA_CURSOR*); int pma_cursor_free (PMA_CURSOR*);
/* /* get the pma that a pma cursor is bound to */
* get the pma that a pma cursor is bound to
*
* c - the pma cursor
* pma - the pma that the cursor is bound to
*/
int pma_cursor_get_pma(PMA_CURSOR c, PMA *pma); int pma_cursor_get_pma(PMA_CURSOR c, PMA *pma);
int pma_cursor_set_position_last (PMA_CURSOR c); int pma_cursor_set_position_last (PMA_CURSOR c);
int pma_cursor_set_position_first (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_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 pma_cursor_set_position_prev (PMA_CURSOR c);
int pma_cget_current (PMA_CURSOR c, DBT *key, DBT *val);
/* set the cursor by key */ /* get the key and data under the cursor */
int 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);
/* move the cursor to the kv pair matching the key */
int pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db); int pma_cursor_set_key(PMA_CURSOR c, DBT *key, DB *db);
/* set the cursor to the smallest key >= requested key */ /* set the cursor to the smallest key in the pma >= key */
int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db); int pma_cursor_set_range(PMA_CURSOR c, DBT *key, DB *db);
/* delete the key under the cursor */ /* 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 pma_cursor_delete_under(PMA_CURSOR c, int *kvsize);
/* get the last key and value in the pma */ /* get the last key and value in the pma */
...@@ -117,7 +117,7 @@ void pma_iterate (PMA, void(*)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*); ...@@ -117,7 +117,7 @@ void pma_iterate (PMA, void(*)(bytevec,ITEMLEN,bytevec,ITEMLEN, void*), void*);
ITEMLEN datalenvar = pmanode_vallen(table, __i); \ ITEMLEN datalenvar = pmanode_vallen(table, __i); \
body; \ body; \
} } }) } } })
#endif
int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len); int keycompare (bytevec key1, ITEMLEN key1len, bytevec key2, ITEMLEN key2len);
#endif
CFLAGS = -W -Wall -Wno-unused -g -fPIC CFLAGS = -W -Wall -Wno-unused -g -fPIC
CPPFLAGS = -I../include -I../newbrt CPPFLAGS = -I../include -I../newbrt
install: libdb.so install: libdb.so
cp libdb.so ../lib/ cp libdb.so ../lib/
clean:
rm -rf *.so *.o
ydb.o: ../include/db.h ../newbrt/cachetable.h ydb.o: ../include/db.h ../newbrt/cachetable.h
DBBINS = ydb.o ../newbrt/brt.o ../newbrt/brt-serialize.o ../newbrt/cachetable.o ../newbrt/hashtable.o ../newbrt/header-io.o ../newbrt/key.o ../newbrt/memory.o ../newbrt/pma.o ../newbrt/ybt.o DBBINS = ydb.o ../newbrt/brt.o ../newbrt/brt-serialize.o ../newbrt/cachetable.o ../newbrt/hashtable.o ../newbrt/header-io.o ../newbrt/key.o ../newbrt/memory.o ../newbrt/pma.o ../newbrt/ybt.o
libdb.so: $(DBBINS) libdb.so: $(DBBINS)
......
...@@ -260,7 +260,7 @@ struct __toku_dbc_internal { ...@@ -260,7 +260,7 @@ struct __toku_dbc_internal {
}; };
int __toku_c_get (DBC *c, DBT *key, DBT *data, u_int32_t flag) { int __toku_c_get (DBC *c, DBT *key, DBT *data, u_int32_t flag) {
int r = brt_c_get(c->i->c, key, data, flag); int r = brt_cursor_get(c->i->c, key, data, flag, c->i->db);
return r; return r;
} }
......
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