X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=futatabi%2Fframe_on_disk.h;h=47fcb32d349d1b132835500374cb12d14dd98235;hb=931727fc4cccafc84023a053a6eff174b5ea8190;hp=184385792528130df7e3ba16637385c0c14a35db;hpb=9b7d691b4cc5db7dbfc18c82e86c1207fcac4722;p=nageru diff --git a/futatabi/frame_on_disk.h b/futatabi/frame_on_disk.h index 1843857..47fcb32 100644 --- a/futatabi/frame_on_disk.h +++ b/futatabi/frame_on_disk.h @@ -1,6 +1,7 @@ #ifndef _FRAME_ON_DISK_H #define _FRAME_ON_DISK_H 1 +#include #include #include #include @@ -34,4 +35,19 @@ private: int last_filename_idx = -1; }; +// Utility functions for dealing with binary search. +inline std::vector::iterator +find_last_frame_before(std::vector &frames, int64_t pts_origin) +{ + return std::lower_bound(frames.begin(), frames.end(), pts_origin, + [](const FrameOnDisk &frame, int64_t pts) { return frame.pts < pts; }); +} + +inline std::vector::iterator +find_first_frame_at_or_after(std::vector &frames, int64_t pts_origin) +{ + return std::upper_bound(frames.begin(), frames.end(), pts_origin - 1, + [](int64_t pts, const FrameOnDisk &frame) { return pts < frame.pts; }); +} + #endif // !defined(_FRAME_ON_DISK_H)