[][src]Constant tari_storage::lmdb_store::db::DUPFIXED

pub const DUPFIXED: Flags;

This flag may only be used in combination with DUPSORT. This option tells the library that the data items for this database are all the same size, which allows further optimizations in storage and retrieval. When all data items are the same size, the get_multiple and next_multiple cursor operations may be used to retrieve multiple items at once.

Notes

There are no runtime checks that values are actually the same size; failing to uphold this constraint may result in unpredictable behaviour.

Example

use lmdb::Unaligned as U;
use lmdb::LmdbResultExt;

let db = lmdb::Database::open(
  &env, Some("reversed"), &lmdb::DatabaseOptions::new(
    lmdb::db::DUPSORT | lmdb::db::DUPFIXED |
    lmdb::db::INTEGERDUP | lmdb::db::CREATE))
  .unwrap();
let txn = lmdb::WriteTransaction::new(&env).unwrap();
{
  let mut access = txn.access();
  let f = lmdb::put::Flags::empty();
  // Map strings to their constituent chars
  for s in &["foo", "bar", "xyzzy"] {
    for c in s.chars() {
      access.put(&db, *s, &c, f).unwrap();
    }
  }

  // Read in all the chars of "xyzzy" in sorted order via
  // cursoring.
  // Note that we have to read `u32`s because `char`s are not
  // directly convertable from byte arrays.
  let mut xyzzy: Vec<u32> = Vec::new();
  let mut cursor = txn.cursor(&db).unwrap();
  cursor.seek_k::<str,U<u32>>(&access, "xyzzy").unwrap();
  loop {
    let chars = if xyzzy.is_empty() {
      // First page.
      // Note that in this example we probably get everything
      // on the first page, but with more values we'd need to
      // use `next_multiple` to get the rest.
      cursor.get_multiple::<[U<u32>]>(&access).unwrap()
    } else {
      // .to_opt() to turn NOTFOUND into None
      match cursor.next_multiple::<[U<u32>]>(&access).to_opt() {
        // Ok if there's still more for the current key
        Ok(Some(c)) => c,
        // NOTFOUND error (=> None) at end of key
        Ok(None) => break,
        // Handle other errors
        Err(e) => panic!("LMDB error: {}", e),
      }
    };
    for ch in chars {
      xyzzy.push(ch.get());
    }
  }
  // Now we've read in all the values in sorted order.
  assert_eq!(&['x' as u32, 'y' as u32, 'z' as u32],
             &xyzzy[..]);
}
txn.commit().unwrap();