Add MDB_INTEGERKEY db flag

This commit is contained in:
Howard Chu 2011-08-11 11:35:39 -07:00
parent d499c244cd
commit ce9456d95c
2 changed files with 9 additions and 7 deletions

View File

@ -440,7 +440,11 @@ mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *a, const MDB_val *b)
static int static int
_mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *key1, const MDB_val *key2) _mdb_cmp(MDB_txn *txn, MDB_dbi dbi, const MDB_val *key1, const MDB_val *key2)
{ {
if (F_ISSET(txn->mt_dbs[dbi].md_flags, MDB_REVERSEKEY)) if (txn->mt_dbs[dbi].md_flags & (MDB_REVERSEKEY
#if __BYTE_ORDER == __LITTLE_ENDIAN
|MDB_INTEGERKEY
#endif
))
return memnrcmp(key1->mv_data, key1->mv_size, key2->mv_data, key2->mv_size); return memnrcmp(key1->mv_data, key1->mv_size, key2->mv_data, key2->mv_size);
else else
return memncmp((char *)key1->mv_data, key1->mv_size, key2->mv_data, key2->mv_size); return memncmp((char *)key1->mv_data, key1->mv_size, key2->mv_data, key2->mv_size);
@ -990,10 +994,7 @@ mdbenv_init_meta(MDB_env *env, MDB_meta *meta)
meta->mm_psize = psize; meta->mm_psize = psize;
meta->mm_last_pg = 1; meta->mm_last_pg = 1;
meta->mm_flags = env->me_flags & 0xffff; meta->mm_flags = env->me_flags & 0xffff;
#if __BYTE_ORDER == __LITTLE_ENDIAN meta->mm_flags |= MDB_INTEGERKEY;
/* freeDB keys are pgno_t's, must compare in int order */
meta->mm_flags |= MDB_REVERSEKEY;
#endif
meta->mm_dbs[0].md_root = P_INVALID; meta->mm_dbs[0].md_root = P_INVALID;
meta->mm_dbs[1].md_root = P_INVALID; meta->mm_dbs[1].md_root = P_INVALID;
@ -3121,8 +3122,8 @@ int mdb_open(MDB_txn *txn, const char *name, unsigned int flags, MDB_dbi *dbi)
/* main DB? */ /* main DB? */
if (!name) { if (!name) {
*dbi = MAIN_DBI; *dbi = MAIN_DBI;
if (flags & (MDB_DUPSORT|MDB_REVERSEKEY)) if (flags & (MDB_DUPSORT|MDB_REVERSEKEY|MDB_INTEGERKEY))
txn->mt_dbs[MAIN_DBI].md_flags |= (flags & (MDB_DUPSORT|MDB_REVERSEKEY)); txn->mt_dbs[MAIN_DBI].md_flags |= (flags & (MDB_DUPSORT|MDB_REVERSEKEY|MDB_INTEGERKEY));
return MDB_SUCCESS; return MDB_SUCCESS;
} }

View File

@ -79,6 +79,7 @@ typedef enum MDB_cursor_op { /* cursor operations */
/* DB flags */ /* DB flags */
#define MDB_REVERSEKEY 0x02 /* use reverse string keys */ #define MDB_REVERSEKEY 0x02 /* use reverse string keys */
#define MDB_DUPSORT 0x04 /* use sorted duplicates */ #define MDB_DUPSORT 0x04 /* use sorted duplicates */
#define MDB_INTEGERKEY 0x08 /* numeric keys in native byte order */
/* environment flags */ /* environment flags */
#define MDB_FIXEDMAP 0x01 /* mmap at a fixed address */ #define MDB_FIXEDMAP 0x01 /* mmap at a fixed address */