Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
87 commits
Select commit Hold shift + click to select a range
480e984
gh-249 Remove MDB_UNSIGNEDKEY, let CursorIterable call mdb_cmp
at055612 Mar 6, 2025
46f8d08
gh-249 Remove non-J8 features, use indent size 2
at055612 Mar 6, 2025
f92012e
gh-249 Fix indents
at055612 Mar 6, 2025
e1756d6
gh-249 Tidy code and refactor RangeComparator impls
at055612 Mar 6, 2025
9509f6b
gh-249 Remove commented code
at055612 Mar 6, 2025
67e2df1
gh-249 Add CursorIterableIntegerKeyTest
at055612 Mar 7, 2025
620a89f
gh-249 Remove MaskedFlag.isPropagatedToLmdb, add DbiBuilder WIP
at055612 Jun 5, 2025
75d87d0
Merge branch 'master' into mdb_cmp
at055612 Oct 26, 2025
47b4c4f
Merge branch 'master' into mdb_cmp
at055612 Oct 26, 2025
bfbf223
Add FlagSet, DbiFlagSet, PutFlagSet
at055612 Oct 27, 2025
0f66aaf
Rename FlagSet to AbstractFlagSet
at055612 Oct 27, 2025
aa000a1
Add remaining FlagSet impls
at055612 Oct 27, 2025
667dab3
Fix Javadoc
at055612 Oct 27, 2025
b46c916
Add more cursor tests to protect against future regression
stroomdev66 Oct 28, 2025
0234d32
Replace get(Uns|S)ignedComparator with getComparator(DbiFlagSet)
at055612 Oct 28, 2025
ef0c852
Add missing txn commit in DbiBuilder
at055612 Oct 28, 2025
1b3f94d
Change CursorIterableTest to use Parameterized
at055612 Oct 28, 2025
c0bbe73
Deprecate methods using varargs flags
at055612 Oct 28, 2025
4fd89ff
Add int key compare method to (Direct|Byte)BufferProxy
at055612 Oct 29, 2025
916b441
Merge branch 'master' of github.com:lmdbjava/lmdbjava into more-curso…
stroomdev66 Oct 29, 2025
58dcc6e
Tidy code
at055612 Oct 29, 2025
26665ba
Fix byte order issues with compareAsIntegerKeys
at055612 Oct 29, 2025
dc0b96b
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Oct 29, 2025
9db91a5
Merge branch 'master' of github.com:lmdbjava/lmdbjava into gh-267
stroomdev66 Oct 30, 2025
c427801
Add/refactor tests
at055612 Nov 4, 2025
f606e7e
Merge branch 'master' into mdb_cmp
at055612 Nov 4, 2025
e2be6bf
Add integer key comparator tests
at055612 Nov 5, 2025
7374fde
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
79c0df6
Merge branch 'master' of github.com:lmdbjava/lmdbjava into gh-267
stroomdev66 Nov 5, 2025
787d6d3
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
c289763
#267 Fix to establish start key when iterating backwards from a start…
stroomdev66 Nov 5, 2025
1acd971
Add ComparatorFactory
at055612 Nov 5, 2025
69eb5b7
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
915edce
#269 Initial iterator performance enhancements and testing.
stroomdev66 Nov 5, 2025
dea7975
Merge branch 'master' into mdb_cmp
at055612 Nov 5, 2025
5a62965
Merged new comparator code
stroomdev66 Nov 5, 2025
484a772
Merged new comparator code
stroomdev66 Nov 5, 2025
ad75cb2
Fix CodeQL issues, add setMapSizeXx methods
at055612 Nov 5, 2025
77a3494
Fix failing test
at055612 Nov 5, 2025
1d46e0b
Refactor deprecated method calls
at055612 Nov 6, 2025
577062f
Fix compile issue
at055612 Nov 6, 2025
12a9679
Improve FlagSet tests
at055612 Nov 6, 2025
7a6910b
Add licence header
at055612 Nov 6, 2025
167cdad
Rename buildDbi to createDbi to be consistent with Env.create()
at055612 Nov 6, 2025
d47694e
Remove ByteUnits dep, add ByteUnit enum, add setMapSize() overload
at055612 Nov 6, 2025
fb08779
Fix compile errors
at055612 Nov 6, 2025
a82d7f2
Add more test coverage
at055612 Nov 6, 2025
534b76b
Fix codeQL issue
at055612 Nov 6, 2025
e9f9ac4
Add test coverage on FlagSet
at055612 Nov 6, 2025
b0112bb
Add tests
at055612 Nov 6, 2025
c25a7d2
Run format plugin
at055612 Nov 7, 2025
cf3a11e
Remove class separators
at055612 Nov 7, 2025
0c97cf4
Run format plugin
at055612 Nov 7, 2025
72d4e3f
Remove binaries accidentally added, fix test
at055612 Nov 7, 2025
18013fb
Merged new comparator code
stroomdev66 Nov 7, 2025
6b40d0b
Merge branch 'gh-267_plus_new_comparators' into gh-249-remove-unsigne…
at055612 Nov 7, 2025
48aa0fd
Fix javadoc warnings and class visibility, fix licence warnings
at055612 Nov 7, 2025
72b5234
Auto-format
at055612 Nov 7, 2025
dd95dea
Add error handling for parse(Int|Long)
at055612 Nov 7, 2025
b53378a
Remove unused code
at055612 Nov 7, 2025
deb1f1b
Remove unused code
at055612 Nov 7, 2025
2bfe07c
Remove unused hashCode methods
at055612 Nov 7, 2025
a84ceaa
Change CursorIterableRangeTest to do default+native modes
at055612 Nov 9, 2025
a5e4cf2
Remove separator comments
at055612 Nov 9, 2025
f8e6e07
Add more tests to CursorIterableRangeTest
at055612 Nov 9, 2025
6982aca
Remove unused test, auto format
at055612 Nov 9, 2025
6740e2b
Add tests to stop CodeQL warnings
at055612 Nov 12, 2025
0103f13
Auto format
at055612 Nov 12, 2025
4249566
Fix typo in javadoc
at055612 Nov 12, 2025
35b0a9d
Tidy code
at055612 Nov 12, 2025
9a35718
Add in test classes for deprecated methods
at055612 Nov 14, 2025
8c19bf4
Add test coverage
at055612 Nov 14, 2025
496e5ea
Add test coverage
at055612 Nov 14, 2025
7bd3332
Auto format
at055612 Nov 14, 2025
06523f9
Add more tests
at055612 Nov 14, 2025
fe41338
Add test coverage
at055612 Nov 14, 2025
38eac0d
Add ByteBufProxyTest, refactor some test classes
at055612 Nov 14, 2025
53ac34d
Add missing licences
at055612 Nov 14, 2025
5ad4f0c
Add test assert
at055612 Nov 14, 2025
a0503d3
Add TxnDeprecatedTest for more coverage
at055612 Nov 17, 2025
29d5ba2
Auto format
at055612 Nov 17, 2025
1312e10
Add tests for XxxFlags.isSet
at055612 Nov 17, 2025
0216c92
Add more test coverage
at055612 Nov 17, 2025
8b60f29
Change FlagSet args to be requireNonNull
at055612 Nov 17, 2025
e53956d
Add requireNonNull checks to Dbi
at055612 Nov 17, 2025
654a5bc
Add more coverage
at055612 Nov 17, 2025
850c4e2
Add DirectBufferProxyTest
at055612 Nov 17, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Add int key compare method to (Direct|Byte)BufferProxy
  • Loading branch information
at055612 committed Oct 29, 2025
commit 4fd89fff1755e1572929da3097809dfdad5fa1bb
27 changes: 17 additions & 10 deletions src/main/java/org/lmdbjava/AbstractFlagSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ public boolean isSet(final T flag) {
// Probably cheaper to compare the masks than to use EnumSet.contains()
return flag != null
&& MaskedFlag.isSet(mask, flag);

}

/**
Expand Down Expand Up @@ -93,9 +92,7 @@ public Iterator<T> iterator() {

@Override
public boolean equals(Object object) {
if (this == object) return true;
// if (object == null || getClass() != object.getClass()) return false;
return FlagSet.equals(this, (FlagSet<?>) object);
return FlagSet.equals(this, object);
}

@Override
Expand Down Expand Up @@ -141,6 +138,15 @@ public boolean isSet(final T flag) {
return this.flag == flag;
}

@Override
public boolean areAnySet(FlagSet<T> flags) {
if (flags == null) {
return false;
} else {
return flags.isSet(this.flag);
}
}

@Override
public int size() {
return 1;
Expand All @@ -167,9 +173,7 @@ public String toString() {

@Override
public boolean equals(Object object) {
if (this == object) return true;
// if (object == null || getClass() != object.getClass()) return false;
return FlagSet.equals(this, (FlagSet<?>) object);
return FlagSet.equals(this, object);
}

@Override
Expand Down Expand Up @@ -205,6 +209,11 @@ public boolean isSet(final T flag) {
return false;
}

@Override
public boolean areAnySet(final FlagSet<T> flags) {
return false;
}

@Override
public int size() {
return 0;
Expand All @@ -227,9 +236,7 @@ public String toString() {

@Override
public boolean equals(Object object) {
if (this == object) return true;
// if (object == null || getClass() != object.getClass()) return false;
return FlagSet.equals(this, (FlagSet<?>) object);
return FlagSet.equals(this, object);
}

@Override
Expand Down
27 changes: 5 additions & 22 deletions src/main/java/org/lmdbjava/BufferProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,11 @@ public abstract class BufferProxy<T> {
/** Offset from a pointer of the <code>MDB_val.mv_size</code> field. */
protected static final int STRUCT_FIELD_OFFSET_SIZE = 0;

/** The set of {@link DbiFlags} that indicate unsigned integer keys are being used. */
protected static final DbiFlagSet INTEGER_KEY_FLAGS = DbiFlagSet.of(
DbiFlags.MDB_INTEGERKEY,
DbiFlags.MDB_INTEGERDUP);

/** Explicitly-defined default constructor to avoid warnings. */
protected BufferProxy() {}

Expand Down Expand Up @@ -88,28 +93,6 @@ public Comparator<T> getComparator() {
return getComparator(DbiFlagSet.empty());
}

// /**
// * Get a suitable default {@link Comparator} to compare numeric key values as signed.
// *
// * <p>Note: LMDB's default comparator is unsigned so if this is used only for the {@link
// * CursorIterable} start/stop key comparisons then its behaviour will differ from the iteration
// * order. Use with caution.
// *
// * @return a comparator that can be used (never null)
// */
// public abstract Comparator<T> getSignedComparator();
//
// /**
// * Get a suitable default {@link Comparator} to compare numeric key values as unsigned.
// * <p>
// * This should match the behaviour of the LMDB's mdb_cmp comparator as it may be used for
// * {@link CursorIterable} start/stop keys comparisons, which must match LMDB's insertion order.
// * </p>
// *
// * @return a comparator that can be used (never null)
// */
// public abstract Comparator<T> getUnsignedComparator(final DbiFlagSet dbiFlagSet);

/**
* Called when the <code>MDB_val</code> should be set to reflect the passed buffer. This buffer
* will have been created by end users, not {@link #allocate()}.
Expand Down
31 changes: 0 additions & 31 deletions src/main/java/org/lmdbjava/ByteArrayProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ public final class ByteArrayProxy extends BufferProxy<byte[]> {

private static final MemoryManager MEM_MGR = RUNTIME.getMemoryManager();

private static final Comparator<byte[]> signedComparator = ByteArrayProxy::compareArraysSigned;
private static final Comparator<byte[]> unsignedComparator = ByteArrayProxy::compareArrays;

private ByteArrayProxy() {}
Expand Down Expand Up @@ -68,26 +67,6 @@ public static int compareArrays(final byte[] o1, final byte[] o2) {
return o1.length - o2.length;
}

/**
* Compare two byte arrays.
*
* @param b1 left operand (required)
* @param b2 right operand (required)
* @return as specified by {@link Comparable} interface
*/
public static int compareArraysSigned(final byte[] b1, final byte[] b2) {
requireNonNull(b1);
requireNonNull(b2);

if (b1 == b2) return 0;

for (int i = 0; i < min(b1.length, b2.length); ++i) {
if (b1[i] != b2[i]) return b1[i] - b2[i];
}

return b1.length - b2.length;
}

@Override
protected byte[] allocate() {
return new byte[0];
Expand All @@ -108,16 +87,6 @@ public Comparator<byte[]> getComparator(final DbiFlagSet dbiFlagSet) {
return unsignedComparator;
}

// @Override
// public Comparator<byte[]> getSignedComparator() {
// return signedComparator;
// }
//
// @Override
// public Comparator<byte[]> getUnsignedComparator() {
// return unsignedComparator;
// }

@Override
protected Pointer in(final byte[] buffer, final Pointer ptr) {
final Pointer pointer = MEM_MGR.allocateDirect(buffer.length);
Expand Down
10 changes: 0 additions & 10 deletions src/main/java/org/lmdbjava/ByteBufProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,16 +118,6 @@ public Comparator<ByteBuf> getComparator(final DbiFlagSet dbiFlagSet) {
return comparator;
}

// @Override
// public Comparator<ByteBuf> getSignedComparator() {
// return comparator;
// }
//
// @Override
// public Comparator<ByteBuf> getUnsignedComparator() {
// return comparator;
// }

@Override
protected void deallocate(final ByteBuf buff) {
buff.release();
Expand Down
122 changes: 67 additions & 55 deletions src/main/java/org/lmdbjava/ByteBufferProxy.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,19 @@ public final class ByteBufferProxy {
*/
public static final BufferProxy<ByteBuffer> PROXY_OPTIMAL;

/** The safe, reflective {@link ByteBuffer} proxy for this system. Guaranteed to never be null. */
/**
* The safe, reflective {@link ByteBuffer} proxy for this system. Guaranteed to never be null.
*/
public static final BufferProxy<ByteBuffer> PROXY_SAFE;


static {
PROXY_SAFE = new ReflectiveProxy();
PROXY_OPTIMAL = getProxyOptimal();
}

private ByteBufferProxy() {}
private ByteBufferProxy() {
}

private static BufferProxy<ByteBuffer> getProxyOptimal() {
try {
Expand All @@ -72,17 +76,25 @@ private static BufferProxy<ByteBuffer> getProxyOptimal() {
}
}

/** The buffer must be a direct buffer (not heap allocated). */
/**
* The buffer must be a direct buffer (not heap allocated).
*/
public static final class BufferMustBeDirectException extends LmdbException {

private static final long serialVersionUID = 1L;

/** Creates a new instance. */
/**
* Creates a new instance.
*/
public BufferMustBeDirectException() {
super("The buffer must be a direct buffer (not heap allocated");
}
}


// --------------------------------------------------------------------------------


/**
* Provides {@link ByteBuffer} pooling and address resolution for concrete {@link BufferProxy}
* implementations.
Expand All @@ -92,16 +104,6 @@ abstract static class AbstractByteBufferProxy extends BufferProxy<ByteBuffer> {
protected static final String FIELD_NAME_ADDRESS = "address";
protected static final String FIELD_NAME_CAPACITY = "capacity";

private static final Comparator<ByteBuffer> signedComparator =
(o1, o2) -> {
requireNonNull(o1);
requireNonNull(o2);

return o1.compareTo(o2);
};
private static final Comparator<ByteBuffer> unsignedComparator =
AbstractByteBufferProxy::compareBuff;

/**
* A thread-safe pool for a given length. If the buffer found is valid (ie not of a negative
* length) then that buffer is used. If no valid buffer is found, a new buffer is created.
Expand All @@ -116,7 +118,7 @@ abstract static class AbstractByteBufferProxy extends BufferProxy<ByteBuffer> {
* @param o2 right operand (required)
* @return as specified by {@link Comparable} interface
*/
public static int compareBuff(final ByteBuffer o1, final ByteBuffer o2) {
public static int compareLexicographically(final ByteBuffer o1, final ByteBuffer o2) {
requireNonNull(o1);
requireNonNull(o2);
if (o1.equals(o2)) {
Expand Down Expand Up @@ -148,34 +150,42 @@ public static int compareBuff(final ByteBuffer o1, final ByteBuffer o2) {
return o1.remaining() - o2.remaining();
}

// /**
// * Possible compareBuff method specifically for 4/8 byte keys when using MDB_INTEGER_KEY
// */
// public static int compareBuff(final ByteBuffer o1, final ByteBuffer o2) {
// requireNonNull(o1);
// requireNonNull(o2);
// // Both buffers should be same len
// final int len1 = o1.limit();
// final int len2 = o2.limit();
// if (len1 != len2) {
// throw new RuntimeException("Length mismatch, len1: " + len1 + ", len2: " + len2
// + ". Lengths must be identical and either 4 or 8 bytes.");
// }
// final boolean reverse1 = o1.order() == LITTLE_ENDIAN;
// final boolean reverse2 = o2.order() == LITTLE_ENDIAN;
// if (len1 == 8) {
// final long lw = reverse1 ? Long.reverseBytes(o1.getLong()) : o1.getLong();
// final long rw = reverse2 ? Long.reverseBytes(o2.getLong()) : o2.getLong();
// return Long.compareUnsigned(lw, rw);
// } else if (len1 == 4) {
// final int lw = reverse1 ? Integer.reverseBytes(o1.getInt()) : o1.getInt();
// final int rw = reverse2 ? Integer.reverseBytes(o2.getInt()) : o2.getInt();
// return Integer.compareUnsigned(lw, rw);
// } else {
// throw new RuntimeException("Unexpected length len1: " + len1 + ", len2: " + len2
// + ". Lengths must be identical and either 4 or 8 bytes.");
// }
// }
/**
* Buffer comparator specifically for 4/8 byte keys that are unsigned ints/longs,
* i.e. when using MDB_INTEGER_KEY/MDB_INTEGERDUP. Compares the buffers numerically.
* <p>
* Both buffer must have 4 or 8 bytes remaining
* </p>
*
* @param o1 left operand (required)
* @param o2 right operand (required)
* @return as specified by {@link Comparable} interface
*/
public static int compareAsIntegerKeys(final ByteBuffer o1, final ByteBuffer o2) {
requireNonNull(o1);
requireNonNull(o2);
// Both buffers should be same len
final int len1 = o1.limit();
final int len2 = o2.limit();
if (len1 != len2) {
throw new RuntimeException("Length mismatch, len1: " + len1 + ", len2: " + len2
+ ". Lengths must be identical and either 4 or 8 bytes.");
}
final boolean reverse1 = o1.order() == LITTLE_ENDIAN;
final boolean reverse2 = o2.order() == LITTLE_ENDIAN;
if (len1 == 8) {
final long lw = reverse1 ? Long.reverseBytes(o1.getLong(0)) : o1.getLong(0);
final long rw = reverse2 ? Long.reverseBytes(o2.getLong(0)) : o2.getLong(0);
return Long.compareUnsigned(lw, rw);
} else if (len1 == 4) {
final int lw = reverse1 ? Integer.reverseBytes(o1.getInt(0)) : o1.getInt(0);
final int rw = reverse2 ? Integer.reverseBytes(o2.getInt(0)) : o2.getInt(0);
return Integer.compareUnsigned(lw, rw);
} else {
throw new RuntimeException("Unexpected length1: " + len1
+ ". Lengths must be identical and either 4 or 8 bytes.");
}
}

static Field findField(final Class<?> c, final String name) {
Class<?> clazz = c;
Expand Down Expand Up @@ -211,20 +221,14 @@ protected final ByteBuffer allocate() {
}

@Override
public Comparator<ByteBuffer> getComparator(DbiFlagSet dbiFlagSet) {
return unsignedComparator;
public Comparator<ByteBuffer> getComparator(final DbiFlagSet dbiFlagSet) {
if (dbiFlagSet.areAnySet(INTEGER_KEY_FLAGS)) {
return AbstractByteBufferProxy::compareAsIntegerKeys;
} else {
return AbstractByteBufferProxy::compareLexicographically;
}
}

// @Override
// public Comparator<ByteBuffer> getSignedComparator() {
// return signedComparator;
// }
//
// @Override
// public Comparator<ByteBuffer> getUnsignedComparator(final DbiFlagSet dbiFlagSet) {
// return unsignedComparator;
// }

@Override
protected final void deallocate(final ByteBuffer buff) {
buff.order(BIG_ENDIAN);
Expand All @@ -240,6 +244,10 @@ protected byte[] getBytes(final ByteBuffer buffer) {
}
}


// --------------------------------------------------------------------------------


/**
* A proxy that uses Java reflection to modify byte buffer fields, and official JNR-FFF methods to
* manipulate native pointers.
Expand Down Expand Up @@ -284,6 +292,10 @@ protected ByteBuffer out(final ByteBuffer buffer, final Pointer ptr) {
}
}


// --------------------------------------------------------------------------------


/**
* A proxy that uses Java's "unsafe" class to directly manipulate byte buffer fields and JNR-FFF
* allocated memory pointers.
Expand Down
Loading