Skip to content

Commit

Permalink
Add missed documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
DmitryAstafyev committed Jan 10, 2025
1 parent 5d9d84d commit be91bcd
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 0 deletions.
30 changes: 30 additions & 0 deletions application/apps/indexer/processor/src/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand All @@ -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!(
Expand All @@ -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<u64> {
self.matches.iter().enumerate().find_map(|(index, m)| {
if m.index == pos {
Expand Down
12 changes: 12 additions & 0 deletions application/apps/indexer/session/src/state/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<RangeInclusive<u64>>` - A vector of inclusive ranges representing line numbers in the session file.
fn transform_indexes(&self, search_indexes: &[FilterMatch]) -> Vec<RangeInclusive<u64>> {
let mut ranges = vec![];
let mut from_pos: u64 = 0;
Expand Down

0 comments on commit be91bcd

Please sign in to comment.