// Path: src/main/java/org/lmdbjava/Dbi.java
// static final int MDB_KEYEXIST = -30_799;
// 
// Path: src/main/java/org/lmdbjava/Dbi.java
// static final int MDB_NOTFOUND = -30_798;
// 
// Path: src/main/java/org/lmdbjava/Env.java
// public static final boolean SHOULD_CHECK = !getBoolean(DISABLE_CHECKS_PROP);
// 
// Path: src/main/java/org/lmdbjava/Library.java
// static final Lmdb LIB;
// 
// Path: src/main/java/org/lmdbjava/MaskedFlag.java
// static boolean isSet(final int flags, final MaskedFlag test) {
//   requireNonNull(test);
//   return (flags & test.getMask()) == test.getMask();
// }
// 
// Path: src/main/java/org/lmdbjava/MaskedFlag.java
// static int mask(final MaskedFlag... flags) {
//   if (flags == null || flags.length == 0) {
//     return 0;
//   }
// 
//   int result = 0;
//   for (final MaskedFlag flag : flags) {
//     if (flag == null) {
//       continue;
//     }
//     result |= flag.getMask();
//   }
//   return result;
// }
// 
// Path: src/main/java/org/lmdbjava/ResultCodeMapper.java
// static void checkRc(final int rc) {
//   switch (rc) {
//     case MDB_SUCCESS:
//       return;
//     case Dbi.BadDbiException.MDB_BAD_DBI:
//       throw new Dbi.BadDbiException();
//     case BadReaderLockException.MDB_BAD_RSLOT:
//       throw new BadReaderLockException();
//     case BadException.MDB_BAD_TXN:
//       throw new BadException();
//     case Dbi.BadValueSizeException.MDB_BAD_VALSIZE:
//       throw new Dbi.BadValueSizeException();
//     case LmdbNativeException.PageCorruptedException.MDB_CORRUPTED:
//       throw new LmdbNativeException.PageCorruptedException();
//     case Cursor.FullException.MDB_CURSOR_FULL:
//       throw new Cursor.FullException();
//     case Dbi.DbFullException.MDB_DBS_FULL:
//       throw new Dbi.DbFullException();
//     case Dbi.IncompatibleException.MDB_INCOMPATIBLE:
//       throw new Dbi.IncompatibleException();
//     case Env.FileInvalidException.MDB_INVALID:
//       throw new Env.FileInvalidException();
//     case Dbi.KeyExistsException.MDB_KEYEXIST:
//       throw new Dbi.KeyExistsException();
//     case Env.MapFullException.MDB_MAP_FULL:
//       throw new Env.MapFullException();
//     case Dbi.MapResizedException.MDB_MAP_RESIZED:
//       throw new Dbi.MapResizedException();
//     case Dbi.KeyNotFoundException.MDB_NOTFOUND:
//       throw new Dbi.KeyNotFoundException();
//     case LmdbNativeException.PageFullException.MDB_PAGE_FULL:
//       throw new LmdbNativeException.PageFullException();
//     case LmdbNativeException.PageNotFoundException.MDB_PAGE_NOTFOUND:
//       throw new LmdbNativeException.PageNotFoundException();
//     case LmdbNativeException.PanicException.MDB_PANIC:
//       throw new LmdbNativeException.PanicException();
//     case Env.ReadersFullException.MDB_READERS_FULL:
//       throw new Env.ReadersFullException();
//     case LmdbNativeException.TlsFullException.MDB_TLS_FULL:
//       throw new LmdbNativeException.TlsFullException();
//     case TxFullException.MDB_TXN_FULL:
//       throw new TxFullException();
//     case Env.VersionMismatchException.MDB_VERSION_MISMATCH:
//       throw new Env.VersionMismatchException();
//     default:
//       break;
//   }
// 
//   final Constant constant = CONSTANTS.getConstant(rc);
//   if (constant == null) {
//     throw new IllegalArgumentException("Unknown result code " + rc);
//   }
//   final String msg = constant.name() + " " + constant.toString();
//   throw new LmdbNativeException.ConstantDerivedException(rc, msg);
// }


import static org.lmdbjava.PutFlags.MDB_RESERVE;
import static org.lmdbjava.ResultCodeMapper.checkRc;
import static org.lmdbjava.SeekOp.MDB_FIRST;
import static org.lmdbjava.SeekOp.MDB_LAST;
import static org.lmdbjava.SeekOp.MDB_NEXT;
import static org.lmdbjava.SeekOp.MDB_PREV;
import jnr.ffi.Pointer;
import jnr.ffi.byref.NativeLongByReference;
import static java.util.Objects.requireNonNull;
import static org.lmdbjava.Dbi.KeyExistsException.MDB_KEYEXIST;
import static org.lmdbjava.Dbi.KeyNotFoundException.MDB_NOTFOUND;
import static org.lmdbjava.Env.SHOULD_CHECK;
import static org.lmdbjava.Library.LIB;
import static org.lmdbjava.MaskedFlag.isSet;
import static org.lmdbjava.MaskedFlag.mask;
import static org.lmdbjava.PutFlags.MDB_MULTIPLE;
import static org.lmdbjava.PutFlags.MDB_NODUPDATA;
import static org.lmdbjava.PutFlags.MDB_NOOVERWRITE;
   * <p>
   * This call is only valid on databases that support sorted duplicate data
   * items {@link DbiFlags#MDB_DUPSORT}.
   *
   * @return count of duplicates for current key
   */
  public long count() {
    if (SHOULD_CHECK) {
      checkNotClosed();
      txn.checkReady();
    }
    final NativeLongByReference longByReference = new NativeLongByReference();
    checkRc(LIB.mdb_cursor_count(ptrCursor, longByReference));
    return longByReference.longValue();
  }

  /**
   * Delete current key/data pair.
   *
   * <p>
   * This function deletes the key/data pair to which the cursor refers.
   *
   * @param f flags (either null or {@link PutFlags#MDB_NODUPDATA}
   */
  public void delete(final PutFlags... f) {
    if (SHOULD_CHECK) {
      checkNotClosed();
      txn.checkReady();
      txn.checkWritesAllowed();
    }
// Path: src/main/java/org/lmdbjava/Dbi.java
// static final int MDB_KEYEXIST = -30_799;
// 
// Path: src/main/java/org/lmdbjava/Dbi.java
// static final int MDB_NOTFOUND = -30_798;
// 
// Path: src/main/java/org/lmdbjava/Env.java
// public static final boolean SHOULD_CHECK = !getBoolean(DISABLE_CHECKS_PROP);
// 
// Path: src/main/java/org/lmdbjava/Library.java
// static final Lmdb LIB;
// 
// Path: src/main/java/org/lmdbjava/MaskedFlag.java
// static boolean isSet(final int flags, final MaskedFlag test) {
//   requireNonNull(test);
//   return (flags & test.getMask()) == test.getMask();
// }
// 
// Path: src/main/java/org/lmdbjava/MaskedFlag.java
// static int mask(final MaskedFlag... flags) {
//   if (flags == null || flags.length == 0) {
//     return 0;
//   }
// 
//   int result = 0;
//   for (final MaskedFlag flag : flags) {
//     if (flag == null) {
//       continue;
//     }
//     result |= flag.getMask();
//   }
//   return result;
// }
// 
// Path: src/main/java/org/lmdbjava/ResultCodeMapper.java
// static void checkRc(final int rc) {
//   switch (rc) {
//     case MDB_SUCCESS:
//       return;
//     case Dbi.BadDbiException.MDB_BAD_DBI:
//       throw new Dbi.BadDbiException();
//     case BadReaderLockException.MDB_BAD_RSLOT:
//       throw new BadReaderLockException();
//     case BadException.MDB_BAD_TXN:
//       throw new BadException();
//     case Dbi.BadValueSizeException.MDB_BAD_VALSIZE:
//       throw new Dbi.BadValueSizeException();
//     case LmdbNativeException.PageCorruptedException.MDB_CORRUPTED:
//       throw new LmdbNativeException.PageCorruptedException();
//     case Cursor.FullException.MDB_CURSOR_FULL:
//       throw new Cursor.FullException();
//     case Dbi.DbFullException.MDB_DBS_FULL:
//       throw new Dbi.DbFullException();
//     case Dbi.IncompatibleException.MDB_INCOMPATIBLE:
//       throw new Dbi.IncompatibleException();
//     case Env.FileInvalidException.MDB_INVALID:
//       throw new Env.FileInvalidException();
//     case Dbi.KeyExistsException.MDB_KEYEXIST:
//       throw new Dbi.KeyExistsException();
//     case Env.MapFullException.MDB_MAP_FULL:
//       throw new Env.MapFullException();
//     case Dbi.MapResizedException.MDB_MAP_RESIZED:
//       throw new Dbi.MapResizedException();
//     case Dbi.KeyNotFoundException.MDB_NOTFOUND:
//       throw new Dbi.KeyNotFoundException();
//     case LmdbNativeException.PageFullException.MDB_PAGE_FULL:
//       throw new LmdbNativeException.PageFullException();
//     case LmdbNativeException.PageNotFoundException.MDB_PAGE_NOTFOUND:
//       throw new LmdbNativeException.PageNotFoundException();
//     case LmdbNativeException.PanicException.MDB_PANIC:
//       throw new LmdbNativeException.PanicException();
//     case Env.ReadersFullException.MDB_READERS_FULL:
//       throw new Env.ReadersFullException();
//     case LmdbNativeException.TlsFullException.MDB_TLS_FULL:
//       throw new LmdbNativeException.TlsFullException();
//     case TxFullException.MDB_TXN_FULL:
//       throw new TxFullException();
//     case Env.VersionMismatchException.MDB_VERSION_MISMATCH:
//       throw new Env.VersionMismatchException();
//     default:
//       break;
//   }
// 
//   final Constant constant = CONSTANTS.getConstant(rc);
//   if (constant == null) {
//     throw new IllegalArgumentException("Unknown result code " + rc);
//   }
//   final String msg = constant.name() + " " + constant.toString();
//   throw new LmdbNativeException.ConstantDerivedException(rc, msg);
// }


// Path: src/main/java/org/lmdbjava/Cursor.java
import static org.lmdbjava.PutFlags.MDB_RESERVE;
import static org.lmdbjava.ResultCodeMapper.checkRc;
import static org.lmdbjava.SeekOp.MDB_FIRST;
import static org.lmdbjava.SeekOp.MDB_LAST;
import static org.lmdbjava.SeekOp.MDB_NEXT;
import static org.lmdbjava.SeekOp.MDB_PREV;
import jnr.ffi.Pointer;
import jnr.ffi.byref.NativeLongByReference;
import static java.util.Objects.requireNonNull;
import static org.lmdbjava.Dbi.KeyExistsException.MDB_KEYEXIST;
import static org.lmdbjava.Dbi.KeyNotFoundException.MDB_NOTFOUND;
import static org.lmdbjava.Env.SHOULD_CHECK;
import static org.lmdbjava.Library.LIB;
import static org.lmdbjava.MaskedFlag.isSet;
import static org.lmdbjava.MaskedFlag.mask;
import static org.lmdbjava.PutFlags.MDB_MULTIPLE;
import static org.lmdbjava.PutFlags.MDB_NODUPDATA;
import static org.lmdbjava.PutFlags.MDB_NOOVERWRITE;

   * <p>
   * This call is only valid on databases that support sorted duplicate data
   * items {@link DbiFlags#MDB_DUPSORT}.
   *
   * @return count of duplicates for current key
   */
  public long count() {
    if (SHOULD_CHECK) {
      checkNotClosed();
      txn.checkReady();
    }
    final NativeLongByReference longByReference = new NativeLongByReference();
    checkRc(LIB.mdb_cursor_count(ptrCursor, longByReference));
    return longByReference.longValue();
  }

  /**
   * Delete current key/data pair.
   *
   * <p>
   * This function deletes the key/data pair to which the cursor refers.
   *
   * @param f flags (either null or {@link PutFlags#MDB_NODUPDATA}
   */
  public void delete(final PutFlags... f) {
    if (SHOULD_CHECK) {
      checkNotClosed();
      txn.checkReady();
      txn.checkWritesAllowed();
    }
    final int flags = mask(f);