From be91bcd1c9868659b0270d69b45ae56276a925e1 Mon Sep 17 00:00:00 2001 From: DmitryAstafyev Date: Fri, 10 Jan 2025 10:43:30 +0100 Subject: [PATCH] Add missed documentation --- application/apps/indexer/processor/src/map.rs | 30 +++++++++++++++++++ .../apps/indexer/session/src/state/mod.rs | 12 ++++++++ 2 files changed, 42 insertions(+) diff --git a/application/apps/indexer/processor/src/map.rs b/application/apps/indexer/processor/src/map.rs index 7d81a7b21..2023591d2 100644 --- a/application/apps/indexer/processor/src/map.rs +++ b/application/apps/indexer/processor/src/map.rs @@ -196,6 +196,16 @@ impl SearchMap { Ok(&self.matches[*range.start() as usize..=*range.end() as usize]) } + /// Returns information about all matches in the search results occurring after the specified position. + /// + /// # Parameters + /// + /// * `from` - The starting position from which to retrieve matches. + /// + /// # Returns + /// + /// * `Ok(&[stypes::FilterMatch])` - A slice of matches starting from the specified position. + /// * `Err(MapError::OutOfRange)` - If the `from` position exceeds the available matches. pub fn indexes_from(&self, from: u64) -> Result<&[stypes::FilterMatch], MapError> { if from >= self.len() as u64 { return Err(MapError::OutOfRange(format!( @@ -206,6 +216,16 @@ impl SearchMap { Ok(&self.matches[from as usize..]) } + /// Returns information about all matches in the search results occurring before the specified position. + /// + /// # Parameters + /// + /// * `to` - The ending position up to which to retrieve matches. + /// + /// # Returns + /// + /// * `Ok(&[stypes::FilterMatch])` - A slice of matches up to the specified position. + /// * `Err(MapError::OutOfRange)` - If the `to` position exceeds the available matches. pub fn indexes_to_rev(&self, to: u64) -> Result<&[stypes::FilterMatch], MapError> { if to >= self.len() as u64 { return Err(MapError::OutOfRange(format!( @@ -216,6 +236,16 @@ impl SearchMap { Ok(&self.matches[..to as usize]) } + /// Returns the search result line index corresponding to a line index in the session file. + /// + /// # Parameters + /// + /// * `pos` - The line index in the session file. + /// + /// # Returns + /// + /// * `Some(u64)` - The index of the matching line in the search results. + /// * `None` - If no match is found for the specified position. pub fn get_match_index(&self, pos: u64) -> Option { self.matches.iter().enumerate().find_map(|(index, m)| { if m.index == pos { diff --git a/application/apps/indexer/session/src/state/mod.rs b/application/apps/indexer/session/src/state/mod.rs index b36ff35db..855e936ba 100644 --- a/application/apps/indexer/session/src/state/mod.rs +++ b/application/apps/indexer/session/src/state/mod.rs @@ -106,6 +106,18 @@ impl SessionState { Ok(elements) } + /// Transforms search match data into ranges of line numbers in the original session file. + /// + /// This function is used to retrieve the line number ranges in the session file based on the + /// search results. These ranges are necessary for reading data related to the search results. + /// + /// # Parameters + /// + /// * `search_indexes` - A slice of `FilterMatch` instances containing information about search matches. + /// + /// # Returns + /// + /// * `Vec>` - A vector of inclusive ranges representing line numbers in the session file. fn transform_indexes(&self, search_indexes: &[FilterMatch]) -> Vec> { let mut ranges = vec![]; let mut from_pos: u64 = 0;