|
16 | 16 | package org.lmdbjava; |
17 | 17 |
|
18 | 18 | import static java.lang.Long.BYTES; |
19 | | -import static org.lmdbjava.DbiFlags.MDB_INTEGERKEY; |
20 | | -import static org.lmdbjava.DbiFlags.MDB_UNSIGNEDKEY; |
21 | | -import static org.lmdbjava.MaskedFlag.isSet; |
22 | | -import static org.lmdbjava.MaskedFlag.mask; |
23 | 19 |
|
24 | 20 | import java.util.Comparator; |
25 | 21 | import jnr.ffi.Pointer; |
@@ -70,36 +66,25 @@ protected BufferProxy() {} |
70 | 66 | */ |
71 | 67 | protected abstract byte[] getBytes(T buffer); |
72 | 68 |
|
73 | | - /** |
74 | | - * Get a suitable default {@link Comparator} given the provided flags. |
75 | | - * |
76 | | - * <p>The provided comparator must strictly match the lexicographical order of keys in the native |
77 | | - * LMDB database. |
78 | | - * |
79 | | - * @param flags for the database |
80 | | - * @return a comparator that can be used (never null) |
81 | | - */ |
82 | | - protected Comparator<T> getComparator(DbiFlags... flags) { |
83 | | - final int intFlag = mask(flags); |
84 | | - |
85 | | - return isSet(intFlag, MDB_INTEGERKEY) || isSet(intFlag, MDB_UNSIGNEDKEY) |
86 | | - ? getUnsignedComparator() |
87 | | - : getSignedComparator(); |
88 | | - } |
89 | | - |
90 | 69 | /** |
91 | 70 | * Get a suitable default {@link Comparator} to compare numeric key values as signed. |
92 | 71 | * |
| 72 | + * <p> |
| 73 | + * Note: LMDB's default comparator is unsigned so if this is used only for the {@link CursorIterable} |
| 74 | + * start/stop key comparisons then its behaviour will differ from the iteration order. Use |
| 75 | + * with caution. |
| 76 | + * </p> |
| 77 | + * |
93 | 78 | * @return a comparator that can be used (never null) |
94 | 79 | */ |
95 | | - protected abstract Comparator<T> getSignedComparator(); |
| 80 | + public abstract Comparator<T> getSignedComparator(); |
96 | 81 |
|
97 | 82 | /** |
98 | 83 | * Get a suitable default {@link Comparator} to compare numeric key values as unsigned. |
99 | 84 | * |
100 | 85 | * @return a comparator that can be used (never null) |
101 | 86 | */ |
102 | | - protected abstract Comparator<T> getUnsignedComparator(); |
| 87 | + public abstract Comparator<T> getUnsignedComparator(); |
103 | 88 |
|
104 | 89 | /** |
105 | 90 | * Called when the <code>MDB_val</code> should be set to reflect the passed buffer. This buffer |
@@ -140,4 +125,13 @@ protected Comparator<T> getComparator(DbiFlags... flags) { |
140 | 125 | final KeyVal<T> keyVal() { |
141 | 126 | return new KeyVal<>(this); |
142 | 127 | } |
| 128 | + |
| 129 | + /** |
| 130 | + * Create a new {@link Key} to hold pointers for this buffer proxy. |
| 131 | + * |
| 132 | + * @return a non-null key holder |
| 133 | + */ |
| 134 | + final Key<T> key() { |
| 135 | + return new Key<>(this); |
| 136 | + } |
143 | 137 | } |
0 commit comments