Description
Currently, the findNearestLogEventByTimestamp method in JsonlDecoder contains binary search logic that could be extracted into a generic, reusable utility function. This would improve code reusability and make the logic unit testable.
Suggested Implementation
Create a generic upper_bound_binary_search function in src/utils/binary_search.ts similar to std::upper_bound.
Proposed Function Signature
const upper_bound_binary_search = <T>(get: (index: number)=>T, begin: number, end: number, upperboundValue: T) => {
...
}
Benefits
- Makes binary search logic reusable across the codebase
- Enables unit testing of the binary search implementation
- Improves code maintainability and reduces duplication
References