Skip to content

fix bug Option::unwrap() on a None value #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 30 additions & 32 deletions DraftRetriever/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -256,9 +256,6 @@ impl Reader {
};
}
}
if start_of_indices.is_none() {
return;
}

// this binary search finds the end of the matching suffixes
let mut right_anchor = sub_index.suffixes_file_end - 4;
Expand All @@ -279,38 +276,39 @@ impl Reader {
}
}

let start_of_indices = start_of_indices.unwrap();
let end_of_indices = end_of_indices.unwrap();

let mut suffixes = vec![0; end_of_indices - start_of_indices + 4];

sub_index.index_file.seek(SeekFrom::Start(start_of_indices as u64)).unwrap();
sub_index.index_file.read_exact(&mut suffixes).unwrap();

let mut matches_ranges = AHashSet::new();

let mut cnt = 0;
let k = k.unwrap_or(5000);
let long = long.unwrap_or(10);
let indices_size = (end_of_indices - start_of_indices + 4) / 4;
let initial_capacity = std::cmp::min(indices_size, k as usize);
let mut local_results = Vec::with_capacity(initial_capacity);

for suffix in suffixes.chunks_mut(4) {
let data_index = LittleEndian::read_i32(suffix);
if matches_ranges.insert(data_index) {
let sub_string_plus = &sub_index.data[data_index as usize + substring_i32.len() ..std::cmp::min(data_index as usize + substring_i32.len() + long as usize, sub_index.data.len())];

local_results.push(sub_string_plus.to_vec());
cnt += 1;
if cnt >= k as usize {
break;
match (start_of_indices, end_of_indices) {
(Some(start), Some(end)) => {
let mut suffixes = vec![0; end - start + 4];

sub_index.index_file.seek(SeekFrom::Start(start as u64)).unwrap();
sub_index.index_file.read_exact(&mut suffixes).unwrap();

let mut matches_ranges = AHashSet::new();

let mut cnt = 0;
let k = k.unwrap_or(5000);
let long = long.unwrap_or(10);
let indices_size = (end - start + 4) / 4;
let initial_capacity = std::cmp::min(indices_size, k as usize);
let mut local_results = Vec::with_capacity(initial_capacity);

for suffix in suffixes.chunks_mut(4) {
let data_index = LittleEndian::read_i32(suffix);
if matches_ranges.insert(data_index) {
let sub_string_plus = &sub_index.data[data_index as usize + substring_i32.len() ..std::cmp::min(data_index as usize + substring_i32.len() + long as usize, sub_index.data.len())];

local_results.push(sub_string_plus.to_vec());
cnt += 1;
if cnt >= k as usize {
break;
}

}
}

results.lock().extend(local_results);
}
_ => return,
}

results.lock().extend(local_results);
}
);

Expand Down