mirror of
https://github.com/Start9Labs/start-os.git
synced 2026-03-30 04:01:58 +00:00
prefer btreemap over hashmap
This commit is contained in:
committed by
Aiden McClelland
parent
f8472135f5
commit
7622616856
@@ -1,4 +1,4 @@
|
||||
use std::collections::HashMap;
|
||||
use std::collections::BTreeMap;
|
||||
use std::sync::atomic::{AtomicBool, AtomicU64, Ordering};
|
||||
use std::sync::Arc;
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct ModuleMap {
|
||||
trie: SequenceTrie<String, (LevelFilter, bool)>,
|
||||
}
|
||||
impl ModuleMap {
|
||||
fn new(vals: HashMap<String, LevelFilter>) -> Self {
|
||||
fn new(vals: BTreeMap<String, LevelFilter>) -> Self {
|
||||
let mut module_trie = SequenceTrie::new();
|
||||
for (k, v) in vals {
|
||||
let mut include_submodules = false;
|
||||
@@ -97,7 +97,7 @@ impl EmbassyLogger {
|
||||
log_epoch: Arc<AtomicU64>,
|
||||
share_dest: Option<Url>,
|
||||
share_errors: bool,
|
||||
module_map: HashMap<String, LevelFilter>,
|
||||
module_map: BTreeMap<String, LevelFilter>,
|
||||
) -> Self {
|
||||
let share_dest = match share_dest {
|
||||
None => Url::parse("https://beta-registry-0-3.start9labs.com/error-logs").unwrap(), // TODO
|
||||
@@ -145,7 +145,7 @@ impl log::Log for EmbassyLogger {
|
||||
}
|
||||
if self.sharing.load(Ordering::SeqCst) {
|
||||
if record.level() <= log::Level::Warn {
|
||||
let mut body = HashMap::new();
|
||||
let mut body = BTreeMap::new();
|
||||
body.insert(
|
||||
"log-epoch",
|
||||
format!("{}", self.log_epoch.load(Ordering::SeqCst)),
|
||||
@@ -180,7 +180,7 @@ proptest::proptest! {
|
||||
#[test]
|
||||
fn submodules_handled_by_parent(s0 in "[a-z][a-z0-9_]+", s1 in "[a-z][a-z0-9_]+", level in filter_strategy()) {
|
||||
proptest::prop_assume!(level > LevelFilter::Off);
|
||||
let mut hm = HashMap::new();
|
||||
let mut hm = BTreeMap::new();
|
||||
hm.insert(format!("{}::*", s0.clone()), level);
|
||||
let mod_map = ModuleMap::new(hm);
|
||||
proptest::prop_assert_eq!(mod_map.level_for(&format!("{}::{}", s0, s1)), &level)
|
||||
@@ -188,7 +188,7 @@ proptest::proptest! {
|
||||
#[test]
|
||||
fn submodules_ignored_by_parent(s0 in "[a-z][a-z0-9_]+", s1 in "[a-z][a-z0-9_]+", level in filter_strategy()) {
|
||||
proptest::prop_assume!(level > LevelFilter::Off);
|
||||
let mut hm = HashMap::new();
|
||||
let mut hm = BTreeMap::new();
|
||||
hm.insert(s0.clone(), level);
|
||||
let mod_map = ModuleMap::new(hm);
|
||||
proptest::prop_assert_eq!(mod_map.level_for(&format!("{}::{}", s0, s1)), &LevelFilter::Off)
|
||||
@@ -196,7 +196,7 @@ proptest::proptest! {
|
||||
#[test]
|
||||
fn duplicate_insertion_ignored(s0 in "[a-z][a-z0-9_]+", s1 in "[a-z][a-z0-9_]+", level in filter_strategy()) {
|
||||
proptest::prop_assume!(level > LevelFilter::Off);
|
||||
let mut hm = HashMap::new();
|
||||
let mut hm = BTreeMap::new();
|
||||
hm.insert(format!("{}::*", s0.clone()), level);
|
||||
let sub = format!("{}::{}", s0, s1);
|
||||
hm.insert(sub.clone(), level);
|
||||
@@ -205,7 +205,7 @@ proptest::proptest! {
|
||||
}
|
||||
#[test]
|
||||
fn parent_child_simul(s0 in "[a-z][a-z0-9_]+", s1 in "[a-z][a-z0-9_]+", level0 in filter_strategy(), level1 in filter_strategy()) {
|
||||
let mut hm = HashMap::new();
|
||||
let mut hm = BTreeMap::new();
|
||||
hm.insert(s0.clone(), level0);
|
||||
let sub = format!("{}::{}", s0, s1);
|
||||
hm.insert(sub.clone(), level1);
|
||||
|
||||
@@ -387,6 +387,16 @@ impl PartialEq for Version {
|
||||
}
|
||||
}
|
||||
impl Eq for Version {}
|
||||
impl PartialOrd for Version {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
|
||||
self.version.partial_cmp(&other.version)
|
||||
}
|
||||
}
|
||||
impl Ord for Version {
|
||||
fn cmp(&self, other: &Self) -> std::cmp::Ordering {
|
||||
self.version.cmp(&other.version)
|
||||
}
|
||||
}
|
||||
impl Hash for Version {
|
||||
fn hash<H: Hasher>(&self, state: &mut H) {
|
||||
self.version.hash(state)
|
||||
|
||||
Reference in New Issue
Block a user