Skip to content

Commit

Permalink
fix mistake in search and cleanup of search
Browse files Browse the repository at this point in the history
  • Loading branch information
BramDevlaminck committed Oct 25, 2023
1 parent 9eb0af0 commit 2bc69d7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
1 change: 1 addition & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ fn main() {
None => word,
Some(stripped) => stripped.to_string()
}.to_uppercase();
// println!("{}", searcher.search_if_match(word.as_bytes()))
let results = searcher.search_protein(word.as_bytes());
println!("found {} matches", results.len());
results.iter()
Expand Down
17 changes: 11 additions & 6 deletions src/searcher.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::thread::current;
use crate::cursor::CursorIterator;
use crate::read_only_cursor::ReadOnlyCursor;
use crate::tree::Tree;
Expand All @@ -24,18 +25,20 @@ impl<'a> Searcher<'a> {
}
let string_length = search_string.len();
let mut index_in_string: usize = 0;
let mut ret_value = self.cursor.next(search_string[0] as char, search_string);
let mut ret_value = self.cursor.next(search_string[0] as char, self.original_input_string);

while ret_value == CursorIterator::Ok && index_in_string + 1 < string_length {
index_in_string += 1;
ret_value = self.cursor.next(search_string[index_in_string] as char, search_string);
ret_value = self.cursor.next(search_string[index_in_string] as char, self.original_input_string);
}

let end_node = self.cursor.current_node_index_in_arena;
self.cursor.reset(); // prepare cursor for next search
if index_in_string == string_length - 1 && ret_value == CursorIterator::Ok {
return (true, self.cursor.current_node_index_in_arena);
return (true, end_node);
}

(false, self.cursor.current_node_index_in_arena)
(false, end_node)
}


Expand All @@ -59,8 +62,6 @@ impl<'a> Searcher<'a> {
}
}

self.cursor.reset();

let dollar_u8 = b'$';
let hashtag_u8 = b'#';
let mut solutions_list: Vec<String> = vec![];
Expand All @@ -79,4 +80,8 @@ impl<'a> Searcher<'a> {
});
solutions_list
}

pub fn search_if_match(&mut self, search_string: &[u8]) -> bool {
self.find_end_node(search_string).0
}
}

0 comments on commit 2bc69d7

Please sign in to comment.