DataFabricRus / textfile-utils

A simple JVM library with utilitarian methods for working with text files of any size, including merge sorting and binary search. The library is based on the Java NIO and Kotlin coroutines.
Apache License 2.0
3 stars 1 forks source link

BinareSearch: Possibly incorrect calculation result if no rows found #5

Open sszuev opened 11 months ago

sszuev commented 11 months ago

Looks suspicious, need review

https://github.com/DataFabricRus/textfile-utils/blob/main/src/main/kotlin/files/ByteArrays.kt#L174

            if (!includeLeftBound && low == sourceStartInclusive) {
                val endExclusive = (high - 1)
                return Lines(startInclusive = -1, endExclusive = endExclusive, lines = emptyList())
            }
            if (!includeRightBound && high == sourceEndExclusive) {
                // end
                val startInclusive = low
                return Lines(startInclusive = startInclusive, endExclusive = -1, lines = emptyList())
            }
            val insertPosition = high
            return Lines(startInclusive = insertPosition, endExclusive = insertPosition, lines = emptyList())