From 2f7ddb4103a8b4161b47353d160ea75028c52936 Mon Sep 17 00:00:00 2001 From: Howard Chu Date: Thu, 11 Aug 2011 04:46:14 -0700 Subject: [PATCH] Cleanup, add mdb_cursor_count() --- libraries/libmdb/mdb.c | 22 ++++++++++++++++++++-- libraries/libmdb/mdb.h | 4 +--- libraries/libmdb/mtest.c | 2 +- libraries/libmdb/mtest2.c | 2 +- 4 files changed, 23 insertions(+), 7 deletions(-) diff --git a/libraries/libmdb/mdb.c b/libraries/libmdb/mdb.c index 6d90db2..53e5dde 100644 --- a/libraries/libmdb/mdb.c +++ b/libraries/libmdb/mdb.c @@ -1029,7 +1029,8 @@ mdbenv_write_meta(MDB_txn *txn) assert(txn != NULL); assert(txn->mt_env != NULL); - DPRINTF("writing meta page for root page %lu", txn->mt_dbs[MAIN_DBI].md_root); + DPRINTF("writing meta page %d for root page %lu", + !F_ISSET(txn->mt_flags, MDB_TXN_METOGGLE), txn->mt_dbs[MAIN_DBI].md_root); env = txn->mt_env; @@ -1125,7 +1126,7 @@ mdbenv_get_maxreaders(MDB_env *env, int *readers) return MDB_SUCCESS; } -int +static int mdbenv_open2(MDB_env *env, unsigned int flags) { int i, newenv = 0; @@ -2345,6 +2346,23 @@ mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **ret) return MDB_SUCCESS; } +/* Return the count of duplicate data items for the current key */ +int +mdb_cursor_count(MDB_cursor *mc, unsigned long *countp) +{ + if (mc == NULL || countp == NULL) + return EINVAL; + + if (!(mc->mc_txn->mt_dbs[mc->mc_dbi].md_flags & MDB_DUPSORT)) + return EINVAL; + + if (!mc->mc_xcursor->mx_cursor.mc_initialized) + return EINVAL; + + *countp = mc->mc_xcursor->mx_txn.mt_dbs[mc->mc_xcursor->mx_cursor.mc_dbi].md_entries; + return MDB_SUCCESS; +} + void mdb_cursor_close(MDB_cursor *cursor) { diff --git a/libraries/libmdb/mdb.h b/libraries/libmdb/mdb.h index 0ac2e35..1c111b5 100644 --- a/libraries/libmdb/mdb.h +++ b/libraries/libmdb/mdb.h @@ -131,9 +131,7 @@ int mdb_cursor_open(MDB_txn *txn, MDB_dbi dbi, MDB_cursor **cursor); void mdb_cursor_close(MDB_cursor *cursor); int mdb_cursor_get(MDB_cursor *cursor, MDB_val *key, MDB_val *data, MDB_cursor_op op); -int mdb_cursor_put(MDB_cursor *cursor, MDB_val *key, MDB_val *data, - MDB_cursor_op op); -int mdb_cursor_del(MDB_cursor *cursor, unsigned int flags); +int mdb_cursor_count(MDB_cursor *cursor, unsigned long *countp); int mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b); diff --git a/libraries/libmdb/mtest.c b/libraries/libmdb/mtest.c index 8d08c24..ef8b955 100644 --- a/libraries/libmdb/mtest.c +++ b/libraries/libmdb/mtest.c @@ -25,7 +25,7 @@ int main(int argc,char * argv[]) MDB_val key, data; MDB_txn *txn; MDB_stat mst; - MDB_cursor *cursor, *cur2; + MDB_cursor *cursor; int count; int *values; char sval[32]; diff --git a/libraries/libmdb/mtest2.c b/libraries/libmdb/mtest2.c index 7576027..ca84dc4 100644 --- a/libraries/libmdb/mtest2.c +++ b/libraries/libmdb/mtest2.c @@ -25,7 +25,7 @@ int main(int argc,char * argv[]) MDB_val key, data; MDB_txn *txn; MDB_stat mst; - MDB_cursor *cursor, *cur2; + MDB_cursor *cursor; int count; int *values; char sval[32];