Skip to content

Commit

Permalink
Switch from HashMap to BTreeMap for uc
Browse files Browse the repository at this point in the history
  • Loading branch information
Ionizing committed Sep 13, 2024
1 parent f3ea5f0 commit ee54bf1
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions src/commands/uc.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use std::sync::OnceLock;
use std::hash::Hash;
use std::collections::HashMap;
use std::collections::BTreeMap;
use std::str::FromStr;
use std::fmt;

Expand Down Expand Up @@ -31,7 +30,7 @@ use crate::Result;
use crate::OptProcess;


#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
/// Metrix prefixes
pub enum MetricPrefix {
/// 10⁻¹⁸
Expand Down Expand Up @@ -161,8 +160,8 @@ impl MetricPrefix {
}


fn get_prefix_scale() -> &'static HashMap<MetricPrefix, f64> {
static INSTANCE: OnceLock<HashMap<MetricPrefix, f64>> = OnceLock::new();
fn get_prefix_scale() -> &'static BTreeMap<MetricPrefix, f64> {
static INSTANCE: OnceLock<BTreeMap<MetricPrefix, f64>> = OnceLock::new();
INSTANCE.get_or_init(|| {
[
(MetricPrefix::Atto, 1E-18),
Expand All @@ -183,8 +182,8 @@ fn get_prefix_scale() -> &'static HashMap<MetricPrefix, f64> {
}


fn get_prefix_str() -> &'static HashMap<MetricPrefix, &'static str> {
static INSTANCE: OnceLock<HashMap<MetricPrefix, &'static str>> = OnceLock::new();
fn get_prefix_str() -> &'static BTreeMap<MetricPrefix, &'static str> {
static INSTANCE: OnceLock<BTreeMap<MetricPrefix, &'static str>> = OnceLock::new();
INSTANCE.get_or_init(|| {
[
(MetricPrefix::Atto, "a"),
Expand Down Expand Up @@ -216,7 +215,7 @@ impl fmt::Display for MetricPrefix {
}


#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug, Hash)]
#[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]
/// Energy units.
pub enum Unit {
/// eV, treated as the basic unit
Expand Down Expand Up @@ -248,8 +247,8 @@ pub enum Unit {
}


fn get_unit_str() -> &'static HashMap<Unit, &'static str> {
static INSTANCE: OnceLock<HashMap<Unit, &'static str>> = OnceLock::new();
fn get_unit_str() -> &'static BTreeMap<Unit, &'static str> {
static INSTANCE: OnceLock<BTreeMap<Unit, &'static str>> = OnceLock::new();
INSTANCE.get_or_init(|| {
[
(Unit::ElectronVolt, "eV"),
Expand Down Expand Up @@ -329,8 +328,8 @@ impl Unit {
}


fn get_ratio_ev_to_other() -> &'static HashMap<Unit, f64> {
static INSTANCE: OnceLock<HashMap<Unit, f64>> = OnceLock::new();
fn get_ratio_ev_to_other() -> &'static BTreeMap<Unit, f64> {
static INSTANCE: OnceLock<BTreeMap<Unit, f64>> = OnceLock::new();
INSTANCE.get_or_init(|| {
[
(Unit::ElectronVolt, 1.0f64),
Expand Down

0 comments on commit ee54bf1

Please sign in to comment.