{
    "Function": "binarySearch",
    "File": "src/libraries/Oracle.sol",
    "Parent Contracts": [],
    "High-Level Calls": [
        "Buffer",
        "Samples"
    ],
    "Internal Calls": [
        "addmod(uint256,uint256,uint256)",
        "addmod(uint256,uint256,uint256)"
    ],
    "Library Calls": [
        "before",
        "timestamp"
    ],
    "Low-Level Calls": [],
    "Code": "function binarySearch(\n        bytes32[65_535] storage _oracle,\n        uint256 _index,\n        uint256 _lookUpTimestamp,\n        uint256 _activeSize\n    ) private view returns (bytes32 prev, bytes32 next) {\n        // The sample with the lowest timestamp is the one right after _index\n        uint256 _low = 1;\n        uint256 _high = _activeSize;\n\n        uint256 _middle;\n        uint256 _id;\n\n        bytes32 _sample;\n        uint256 _sampleTimestamp;\n        while (_high >= _low) {\n            unchecked {\n                _middle = (_low + _high) / 2;\n                assembly {\n                    _id := addmod(_middle, _index, _activeSize)\n                }\n                _sample = _oracle[_id];\n                _sampleTimestamp = _sample.timestamp();\n                if (_sampleTimestamp < _lookUpTimestamp) {\n                    _low = _middle + 1;\n                } else if (_sampleTimestamp > _lookUpTimestamp) {\n                    _high = _middle - 1;\n                } else {\n                    return (_sample, _sample);\n                }\n            }\n        }\n        if (_sampleTimestamp < _lookUpTimestamp) {\n            assembly {\n                _id := addmod(_id, 1, _activeSize)\n            }\n            (prev, next) = (_sample, _oracle[_id]);\n        } else (prev, next) = (_oracle[_id.before(_activeSize)], _sample);\n    }"
}