Constant ord_lmdb_zero::db::INTEGERKEY
source · [−]pub const INTEGERKEY: Flags;
Expand description
Keys are binary integers in native byte order, either
libc::c_uint
or libc::size_t
, and will be sorted as such.
The keys must all be of the same size.
Example
use lmdb::unaligned as u;
let db = lmdb::Database::open(
&env, Some("reversed"), &lmdb::DatabaseOptions::new(
lmdb::db::INTEGERKEY | lmdb::db::CREATE)).unwrap();
let txn = lmdb::WriteTransaction::new(&env).unwrap();
{
let mut access = txn.access();
let f = lmdb::put::Flags::empty();
// Write the keys in native byte order.
// Note that on little-endian systems this means a
// byte-by-byte comparison would not order the keys the way
// one might expect.
access.put(&db, &42u32, "Fourty-two", f).unwrap();
access.put(&db, &65536u32, "65'536", f).unwrap();
access.put(&db, &0u32, "Zero", f).unwrap();
let mut cursor = txn.cursor(&db).unwrap();
// But because we used `INTEGERKEY`, they are in fact sorted
// ascending by integer value.
assert_eq!((u(&0u32), "Zero"), cursor.first(&access).unwrap());
assert_eq!((u(&42u32), "Fourty-two"), cursor.next(&access).unwrap());
assert_eq!((u(&65536u32), "65'536"), cursor.next(&access).unwrap());
}
txn.commit().unwrap();