pub fn search(&self, frame_ts: u64) -> SeekSearchResult {
            // The index must contain atleast one SeekPoint to return a useful result.
            if !self.points.is_empty() {
                let mut lower = 0;
                let mut upper = self.points.len() - 1;

                // If the desired timestamp is less than the first SeekPoint within the index,
                // indicate that the stream should be searched from the beginning.
                if frame_ts < self.points[lower].frame_ts {
                    return SeekSearchResult::Upper(self.points[lower]);
                }
                // If the desired timestamp is greater than or equal to the last SeekPoint within
                // the index, indicate that the stream should be searched from the last SeekPoint.
                else if frame_ts >= self.points[upper].frame_ts {
                    return SeekSearchResult::Lower(self.points[upper]);
                }

                // Desired timestamp is between the lower and upper indicies. Perform a binary
                // search to find a range of SeekPoints containing the desired timestamp. The binary
                // search exits when either two adjacent SeekPoints or a single SeekPoint is found.
                while upper - lower > 1 {
                    let mid = (lower + upper) / 2;
                    let mid_ts = self.points[mid].frame_ts;

                    if frame_ts < mid_ts {
                        upper = mid;
                    }
                    else {
                        lower = mid;
                    }
                }

                return SeekSearchResult::Range(self.points[lower], self.points[upper]);
            }

            // The index is empty, the stream must be searched manually.
            SeekSearchResult::Stream
        }
/// Search the index to find a bounded range of bytes wherein the specified frame timestamp
/// will be contained. If the index is empty, this function simply returns a result
/// indicating the entire stream should be searched manually.
Search the index to find a bounded range of bytes wherein the specified frame timestamp
will be contained. If the index is empty, this function simply returns a result
indicating the entire stream should be searched manually.
Search the index to find a bounded range of bytes wherein the specified frame timestamp will be contained . If the index is empty this function simply returns a result indicating the entire stream should be searched manually .
pub fn search(&self, frame_ts: u64) -> SeekSearchResult {
            // The index must contain atleast one SeekPoint to return a useful result.
            if !self.points.is_empty() {
                let mut lower = 0;
                let mut upper = self.points.len() - 1;
                // If the desired timestamp is less than the first SeekPoint within the index,
                // indicate that the stream should be searched from the beginning.
                if frame_ts < self.points[lower].frame_ts {
                    return SeekSearchResult::Upper(self.points[lower]);
                }
                // If the desired timestamp is greater than or equal to the last SeekPoint within
                // the index, indicate that the stream should be searched from the last SeekPoint.
                else if frame_ts >= self.points[upper].frame_ts {
                    return SeekSearchResult::Lower(self.points[upper]);
                }
                // Desired timestamp is between the lower and upper indicies. Perform a binary
                // search to find a range of SeekPoints containing the desired timestamp. The binary
                // search exits when either two adjacent SeekPoints or a single SeekPoint is found.
                while upper - lower > 1 {
                    let mid = (lower + upper) / 2;
                    let mid_ts = self.points[mid].frame_ts;
                    if frame_ts < mid_ts {
                        upper = mid;
                    }
                    else {
                        lower = mid;
                    }
                }
                return SeekSearchResult::Range(self.points[lower], self.points[upper]);
            }
            // The index is empty, the stream must be searched manually.
            SeekSearchResult::Stream
        }
pub fn search ( & self , frame_ts : u64 ) -> SeekSearchResult { // The index must contain atleast one SeekPoint to return a useful result. if ! self . points . is_empty ( ) { let mut lower = 0 ; let mut upper = self . points . len ( ) - 1 ; // If the desired timestamp is less than the first SeekPoint within the index, // indicate that the stream should be searched from the beginning. if frame_ts < self . points [ lower ] . frame_ts { return SeekSearchResult :: Upper ( self . points [ lower ] ) ; } // If the desired timestamp is greater than or equal to the last SeekPoint within // the index, indicate that the stream should be searched from the last SeekPoint. else if frame_ts >= self . points [ upper ] . frame_ts { return SeekSearchResult :: Lower ( self . points [ upper ] ) ; } // Desired timestamp is between the lower and upper indicies. Perform a binary // search to find a range of SeekPoints containing the desired timestamp. The binary // search exits when either two adjacent SeekPoints or a single SeekPoint is found. while upper - lower > 1 { let mid = ( lower + upper ) / 2 ; let mid_ts = self . points [ mid ] . frame_ts ; if frame_ts < mid_ts { upper = mid ; } else { lower = mid ; } } return SeekSearchResult :: Range ( self . points [ lower ] , self . points [ upper ] ) ; } // The index is empty, the stream must be searched manually. SeekSearchResult :: Stream }
Search the index to find a bounded range of bytes wherein the specified frame timestamp
will be contained.
Search the index to find a bounded range of bytes wherein the specified frame timestamp will be contained .
&self
frame_ts
u64
&self
frame_ts
u64