Skip to content

Refactor: Extract binary search logic to generic upper_bound_binary_search utility #343

@coderabbitai

Description

@coderabbitai

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

Metadata

Metadata

Assignees

Labels

No labels
No labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions