diff options
author | Kyohei Uto <im@kyoheiu.dev> | 2022-11-23 05:56:29 +0900 |
---|---|---|
committer | kyoheiu <kyoheiu@outlook.com> | 2022-11-23 06:51:34 +0900 |
commit | 2b8a48919f26088385cc11f9587d15676ca6053e (patch) | |
tree | 9c9467df370b7d427d9c2bc84ce43220e3b997d4 /src | |
parent | fceb25493f3ee29e8b58c631e19fa558355e6e78 (diff) |
Use BTreeMap/Set instead of HashMap/Set
Diffstat (limited to 'src')
-rw-r--r-- | src/config.rs | 4 | ||||
-rw-r--r-- | src/functions.rs | 12 | ||||
-rw-r--r-- | src/run.rs | 4 | ||||
-rw-r--r-- | src/state.rs | 12 |
4 files changed, 16 insertions, 16 deletions
diff --git a/src/config.rs b/src/config.rs index 9408d5d..2465197 100644 --- a/src/config.rs +++ b/src/config.rs @@ -2,7 +2,7 @@ use super::errors::FxError; use super::state::FX_CONFIG_DIR; use serde::Deserialize; -use std::collections::HashMap; +use std::collections::BTreeMap; use std::fs::read_to_string; use std::path::{Path, PathBuf}; @@ -74,7 +74,7 @@ color: #[derive(Deserialize, Debug, Clone)] pub struct Config { pub default: Option<String>, - pub exec: Option<HashMap<String, Vec<String>>>, + pub exec: Option<BTreeMap<String, Vec<String>>>, pub color: ConfigColor, pub syntax_highlight: Option<bool>, pub default_theme: Option<DefaultTheme>, diff --git a/src/functions.rs b/src/functions.rs index e2edb55..85935e7 100644 --- a/src/functions.rs +++ b/src/functions.rs @@ -5,7 +5,7 @@ use super::term::*; use crossterm::style::Stylize; use log::{info, warn}; use simplelog::{ConfigBuilder, LevelFilter, WriteLogger}; -use std::collections::{HashMap, HashSet}; +use std::collections::{BTreeMap, BTreeSet}; use std::ffi::OsString; use std::path::{Path, PathBuf}; use std::time::Duration; @@ -21,7 +21,7 @@ pub fn format_time(time: &Option<String>) -> String { } /// Rename the put file, in order to avoid the name conflict. -pub fn rename_file(file_name: &str, name_set: &HashSet<String>) -> String { +pub fn rename_file(file_name: &str, name_set: &BTreeSet<String>) -> String { let mut count: usize = 1; let (stem, extension) = { let file_name = PathBuf::from(file_name); @@ -53,7 +53,7 @@ pub fn rename_file(file_name: &str, name_set: &HashSet<String>) -> String { } /// Rename the put directory, in order to avoid the name conflict. -pub fn rename_dir(dir_name: &str, name_set: &HashSet<String>) -> String { +pub fn rename_dir(dir_name: &str, name_set: &BTreeSet<String>) -> String { let mut count: usize = 1; let mut new_name = dir_name.to_owned(); while name_set.contains(&new_name) { @@ -137,9 +137,9 @@ pub fn display_count(i: usize, all: usize) -> String { /// Convert extension setting in the config to HashMap. pub fn to_extension_map( - config: &Option<HashMap<String, Vec<String>>>, -) -> Option<HashMap<String, String>> { - let mut new_map = HashMap::new(); + config: &Option<BTreeMap<String, Vec<String>>>, +) -> Option<BTreeMap<String, String>> { + let mut new_map = BTreeMap::new(); match config { Some(config) => { for (command, extensions) in config.iter() { @@ -15,7 +15,7 @@ use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyModifiers}; use crossterm::execute; use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen}; use log::{error, info}; -use std::collections::HashSet; +use std::collections::BTreeSet; use std::env::set_current_dir; use std::fmt::Write as _; use std::io::{stdout, Write}; @@ -316,7 +316,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> { if let Ok(item) = state.get_item() { let p = item.file_path.clone(); - let mut name_set: HashSet<String> = HashSet::new(); + let mut name_set: BTreeSet<String> = BTreeSet::new(); for item in state.list.iter() { name_set.insert(item.file_name.clone()); diff --git a/src/state.rs b/src/state.rs index ae91527..bb5539b 100644 --- a/src/state.rs +++ b/src/state.rs @@ -13,8 +13,8 @@ use crossterm::event; use crossterm::event::{KeyCode, KeyEvent}; use crossterm::style::Stylize; use log::{error, info}; -use std::collections::HashMap; -use std::collections::HashSet; +use std::collections::BTreeMap; +use std::collections::BTreeSet; use std::env; use std::ffi::OsStr; use std::fmt::Write as _; @@ -37,7 +37,7 @@ pub struct State { pub current_dir: PathBuf, pub trash_dir: PathBuf, pub default: String, - pub commands: Option<HashMap<String, String>>, + pub commands: Option<BTreeMap<String, String>>, pub registered: Vec<ItemInfo>, pub operations: Operation, pub c_memo: Vec<StateMemo>, @@ -425,7 +425,7 @@ impl State { target_dir: Option<PathBuf>, ) -> Result<(), FxError> { //make HashSet<String> of file_name - let mut name_set = HashSet::new(); + let mut name_set = BTreeSet::new(); match &target_dir { None => { for item in self.list.iter() { @@ -486,7 +486,7 @@ impl State { &mut self, item: &ItemInfo, target_dir: &Option<PathBuf>, - name_set: &mut HashSet<String>, + name_set: &mut BTreeSet<String>, ) -> Result<PathBuf, FxError> { match target_dir { None => { @@ -537,7 +537,7 @@ impl State { &mut self, buf: &ItemInfo, target_dir: &Option<PathBuf>, - name_set: &mut HashSet<String>, + name_set: &mut BTreeSet<String>, ) -> Result<PathBuf, FxError> { let mut base: usize = 0; let mut target: PathBuf = PathBuf::new(); |