Skip to content

Commit

Permalink
Expand ScanRange checks with returning false if keyBeforeStart or key…
Browse files Browse the repository at this point in the history
…OutOfRange with empty arrays.
  • Loading branch information
jurmous committed Feb 24, 2025
1 parent 11a1325 commit 5c2f302
Showing 1 changed file with 13 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,22 @@ data class ScanRange internal constructor(
) {
/** Checks if [key] is before start of this scan range */
fun keyBeforeStart(key: ByteArray, offset: Int = 0, length: Int = key.size - offset) =
start.compareDefinedTo(key, offset, length).let {
if (startInclusive) it > 0 else it >= 0
if (start.isEmpty()) {
false
} else {
start.compareDefinedTo(key, offset, length).let {
if (startInclusive) it > 0 else it >= 0
}
}

/** Checks if [key] is after the end of this range start of this scan range */
/** Checks if [key] is after the end of this range end of this scan range */
fun keyOutOfRange(key: ByteArray, offset: Int = 0, length: Int = key.size - offset) = end?.let {
end.compareDefinedTo(key, offset, length).let {
if (endInclusive) it < 0 else it <= 0
if (end.isEmpty()) {
false
} else {
end.compareDefinedTo(key, offset, length).let {
if (endInclusive) it < 0 else it <= 0
}
}
} == true

Expand Down

0 comments on commit 5c2f302

Please sign in to comment.