Skip to content

Commit 4bb1ef9

Browse files
author
dagou
committed
bug fix
1 parent 147bc45 commit 4bb1ef9

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

kr2r/src/utils.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use std::collections::HashMap;
1+
use std::collections::{BTreeMap as Map, HashMap};
22
use std::fs::{self, create_dir_all, File, OpenOptions};
33
use std::io::{self, BufRead, BufReader, BufWriter, Result};
44
use std::path::{Path, PathBuf};
@@ -70,7 +70,7 @@ pub fn expand_spaced_seed_mask(spaced_seed_mask: u64, bit_expansion_factor: u64)
7070
}
7171

7272
pub fn find_files<P: AsRef<Path>>(path: P, prefix: &str, suffix: &str) -> Vec<PathBuf> {
73-
WalkDir::new(path)
73+
let mut files: Vec<PathBuf> = WalkDir::new(path)
7474
.into_iter()
7575
.filter_map(|e| e.ok())
7676
.filter(|e| {
@@ -81,7 +81,9 @@ pub fn find_files<P: AsRef<Path>>(path: P, prefix: &str, suffix: &str) -> Vec<Pa
8181
.unwrap_or(false)
8282
})
8383
.map(|e| e.path().to_path_buf())
84-
.collect()
84+
.collect();
85+
files.sort_unstable();
86+
files
8587
}
8688

8789
pub fn format_bytes(size: f64) -> String {
@@ -193,7 +195,7 @@ pub fn find_and_trans_files(
193195
prefix: &str,
194196
suffix: &str,
195197
check: bool,
196-
) -> io::Result<HashMap<usize, PathBuf>> {
198+
) -> io::Result<Map<usize, PathBuf>> {
197199
// 构建正则表达式以匹配文件名中的数字
198200
let pattern = format!(r"{}_(\d+){}", prefix, suffix);
199201
let re = Regex::new(&pattern).unwrap();
@@ -212,8 +214,8 @@ pub fn find_and_trans_files(
212214
})
213215
.collect::<Vec<PathBuf>>();
214216

215-
// 使用正则表达式提取数字,并将它们存入HashMap
216-
let mut map_entries = HashMap::new();
217+
// 使用正则表达式提取数字,并将它们存入BTreeMap
218+
let mut map_entries = Map::new();
217219
for path in entries {
218220
if let Some(fname) = path.file_name().and_then(|name| name.to_str()) {
219221
if let Some(cap) = re.captures(fname) {

0 commit comments

Comments
 (0)