mdbx: add mdbx_dbi_open_ex() for libfpta.

This commit is contained in:
Leo Yuriev 2017-01-31 02:47:54 +03:00
parent e080be1631
commit 61e1efeb85
3 changed files with 34 additions and 11 deletions

29
mdb.c
View File

@ -1183,7 +1183,6 @@ static void mdb_xcursor_init1(MDB_cursor *mc, MDB_node *node);
static void mdb_xcursor_init2(MDB_cursor *mc, MDB_xcursor *src_mx, int force);
static int mdb_drop0(MDB_cursor *mc, int subs);
static void mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi);
static int mdb_reader_check0(MDB_env *env, int rlocked, int *dead);
/** @cond */
@ -10024,6 +10023,21 @@ mdb_env_info(MDB_env *env, MDB_envinfo *arg)
return mdbx_env_info(env, (MDBX_envinfo*) arg, sizeof(MDB_envinfo));
}
static MDB_cmp_func*
mdbx_default_keycmp(unsigned flags)
{
return (flags & MDB_REVERSEKEY) ? mdb_cmp_memnr :
(flags & MDB_INTEGERKEY) ? mdb_cmp_int_a2 : mdb_cmp_memn;
}
static MDB_cmp_func*
mdbx_default_datacmp(unsigned flags)
{
return !(flags & MDB_DUPSORT) ? 0 :
((flags & MDB_INTEGERDUP) ? mdb_cmp_int_ua :
((flags & MDB_REVERSEDUP) ? mdb_cmp_memnr : mdb_cmp_memn));
}
/** Set the default comparison functions for a database.
* Called immediately after a database is opened to set the defaults.
* The user can then override them with #mdb_set_compare() or
@ -10034,16 +10048,9 @@ mdb_env_info(MDB_env *env, MDB_envinfo *arg)
static void
mdb_default_cmp(MDB_txn *txn, MDB_dbi dbi)
{
unsigned f = txn->mt_dbs[dbi].md_flags;
txn->mt_dbxs[dbi].md_cmp =
(f & MDB_REVERSEKEY) ? mdb_cmp_memnr :
(f & MDB_INTEGERKEY) ? mdb_cmp_int_a2 : mdb_cmp_memn;
txn->mt_dbxs[dbi].md_dcmp =
!(f & MDB_DUPSORT) ? 0 :
((f & MDB_INTEGERDUP) ? mdb_cmp_int_ua :
((f & MDB_REVERSEDUP) ? mdb_cmp_memnr : mdb_cmp_memn));
unsigned flags = txn->mt_dbs[dbi].md_flags;
txn->mt_dbxs[dbi].md_cmp = mdbx_default_keycmp(flags);
txn->mt_dbxs[dbi].md_dcmp = mdbx_default_datacmp(flags);
}
int mdb_dbi_open(MDB_txn *txn, const char *name, unsigned flags, MDB_dbi *dbi)

13
mdbx.c
View File

@ -654,3 +654,16 @@ int mdbx_is_dirty(const MDB_txn *txn, const void* ptr)
* проверяемый адрес "не грязный". */
return MDBX_RESULT_FALSE;
}
int mdbx_dbi_open_ex(MDB_txn *txn, const char *name, unsigned flags,
MDB_dbi *pdbi, MDB_cmp_func *keycmp, MDB_cmp_func *datacmp)
{
int rc = mdbx_dbi_open(txn, name, flags, pdbi);
if (likely(rc == MDB_SUCCESS)) {
MDB_dbi dbi = *pdbi;
unsigned flags = txn->mt_dbs[dbi].md_flags;
txn->mt_dbxs[dbi].md_cmp = keycmp ? keycmp : mdbx_default_keycmp(flags);
txn->mt_dbxs[dbi].md_dcmp = datacmp ? datacmp : mdbx_default_datacmp(flags);
}
return rc;
}

3
mdbx.h
View File

@ -237,6 +237,9 @@ int mdbx_get_ex(MDB_txn *txn, MDB_dbi dbi, MDB_val *key, MDB_val *data, int* val
int mdbx_is_dirty(const MDB_txn *txn, const void* ptr);
int mdbx_dbi_open_ex(MDB_txn *txn, const char *name, unsigned flags,
MDB_dbi *dbi, MDB_cmp_func *keycmp, MDB_cmp_func *datacmp);
/** @} */
#ifdef __cplusplus